diff --git a/ClickUp/Actions/AttachmentActions.cs b/ClickUp/Actions/AttachmentActions.cs index 48b4926..6c3a6c8 100644 --- a/ClickUp/Actions/AttachmentActions.cs +++ b/ClickUp/Actions/AttachmentActions.cs @@ -12,6 +12,10 @@ using Blackbird.Applications.Sdk.Utils.Extensions.String; using RestSharp; using Method = RestSharp.Method; +using Apps.ClickUp.Models.Request.Task; +using System.Threading.Tasks; +using Apps.ClickUp.Models.Response.Attachment; +using System.Net.Mail; namespace Apps.ClickUp.Actions; @@ -39,4 +43,35 @@ public async Task CreateAttachment( return await Client.ExecuteWithErrorHandling(request); } + + [Action("Get Attachments from task", Description = "Get attachment list from tasks")] + public async Task GetAttachment([ActionParameter] GetAttachmentRequest attachmentRequest) + { + var endpoint = $"{ApiEndpoints.Tasks}/{attachmentRequest.TaskId}"; + var request = new ClickUpRequest(endpoint, Method.Get, Creds); + + var result = await Client.ExecuteWithErrorHandling(request); + + + var attachments = result?.Attachments?.Where((a) => a.Id == attachmentRequest.AttachmentId).ToList(); + return new AttachmentsResponse { Attachments = attachments }; + } + + [Action("Download attachment", Description = "Download attachment from ID")] + public async Task DownloadAttachment([ActionParameter] DownloadAttachmentRequest attachmentRequest) + { + + var request = new ClickUpRequest(attachmentRequest.AttachmentURL, Method.Get, Creds); + + var response = await Client.ExecuteWithHandling(request); + + var filename = response.ContentHeaders.First(h => h.Name == "Content-Disposition").Value.ToString() + .Split(';')[1].Split('=')[1].Trim('"'); + + var contentType = response.ContentHeaders.First(h => h.Name == "Content-Type").Value.ToString(); + + using var stream = new MemoryStream(response.RawBytes); + var file = await _fileManagementClient.UploadAsync(stream, contentType, filename); + return new DownloadAttachmentResponse { Attachment = file }; + } } \ No newline at end of file diff --git a/ClickUp/Actions/TaskActions.cs b/ClickUp/Actions/TaskActions.cs index ef7a162..3cf1771 100644 --- a/ClickUp/Actions/TaskActions.cs +++ b/ClickUp/Actions/TaskActions.cs @@ -57,6 +57,20 @@ public Task CreateTask( return Client.ExecuteWithErrorHandling(request); } + + [Action("Update task", Description = "Update the details of a specific task")] + public Task UpdateTask( + [ActionParameter] TaskRequest task, + [ActionParameter] CreateRequestQuery query, + [ActionParameter] UpdateTaskRequest requestBody) + { + var endpoint = $"{ApiEndpoints.Tasks}/{task.TaskId}"; + var request = new ClickUpRequest(endpoint.WithQuery(query), Method.Put, Creds) + .WithJsonBody(requestBody, JsonConfig.Settings); + + return Client.ExecuteWithErrorHandling(request); + } + [Action("Delete task", Description = "Delete specific task")] public Task DeleteTask( [ActionParameter] TaskRequest task) diff --git a/ClickUp/Api/ClickUpClient.cs b/ClickUp/Api/ClickUpClient.cs index da6f675..23443a6 100644 --- a/ClickUp/Api/ClickUpClient.cs +++ b/ClickUp/Api/ClickUpClient.cs @@ -25,6 +25,16 @@ public ClickUpClient() : base(new RestClientOptions() throw new($"Could not parse {json} to {typeof(T)}"); } + public async Task ExecuteWithHandling(RestRequest request) + { + var response = await ExecuteAsync(request); + + if (response.IsSuccessful) + return response; + + throw ConfigureErrorException(response); + } + protected override Exception ConfigureErrorException(RestResponse response) { var error = JsonConvert.DeserializeObject(response.Content); diff --git a/ClickUp/Models/Entities/CustomField.cs b/ClickUp/Models/Entities/CustomField.cs index fd498b2..d808cac 100644 --- a/ClickUp/Models/Entities/CustomField.cs +++ b/ClickUp/Models/Entities/CustomField.cs @@ -22,5 +22,5 @@ public class CustomField public bool Required { get; set; } - public List Value { get; set; } + public string Value { get; set; } } \ No newline at end of file diff --git a/ClickUp/Models/Entities/TaskEntity.cs b/ClickUp/Models/Entities/TaskEntity.cs index d52aad3..945e7f6 100644 --- a/ClickUp/Models/Entities/TaskEntity.cs +++ b/ClickUp/Models/Entities/TaskEntity.cs @@ -47,4 +47,8 @@ public class TaskEntity : ClickUpEntity public int? TimeSpent { get; set; } public SimpleList List { get; set; } + + [Display("Attachments")] + + public List Attachments { get; set; } } \ No newline at end of file diff --git a/ClickUp/Models/Request/Attachment/DownloadAttachmentRequest.cs b/ClickUp/Models/Request/Attachment/DownloadAttachmentRequest.cs new file mode 100644 index 0000000..c64f1c1 --- /dev/null +++ b/ClickUp/Models/Request/Attachment/DownloadAttachmentRequest.cs @@ -0,0 +1,11 @@ +using Blackbird.Applications.Sdk.Common; +using Blackbird.Applications.Sdk.Common.Files; + +namespace Apps.ClickUp.Models.Request.Attachment; + +public class DownloadAttachmentRequest +{ + [Display("Attachment URL")] + + public string AttachmentURL { get; set; } +} \ No newline at end of file diff --git a/ClickUp/Models/Request/Attachment/GetAttachmentRequest.cs b/ClickUp/Models/Request/Attachment/GetAttachmentRequest.cs new file mode 100644 index 0000000..3261a51 --- /dev/null +++ b/ClickUp/Models/Request/Attachment/GetAttachmentRequest.cs @@ -0,0 +1,14 @@ +using Blackbird.Applications.Sdk.Common; +using Blackbird.Applications.Sdk.Common.Files; + +namespace Apps.ClickUp.Models.Request.Attachment; + +public class GetAttachmentRequest +{ + [Display("Task ID")] + public string TaskId { get; set; } + + [Display("Attachment ID")] + + public string AttachmentId { get; set; } +} \ No newline at end of file diff --git a/ClickUp/Models/Request/Task/UpdateTaskRequest.cs b/ClickUp/Models/Request/Task/UpdateTaskRequest.cs new file mode 100644 index 0000000..7d79177 --- /dev/null +++ b/ClickUp/Models/Request/Task/UpdateTaskRequest.cs @@ -0,0 +1,43 @@ +using Apps.ClickUp.DataSourceHandlers.EnumHandlers; +using Apps.ClickUp.Models.Entities.Simple; +using Apps.ClickUp.Utils.Converters; +using Blackbird.Applications.Sdk.Common; +using Blackbird.Applications.Sdk.Common.Dynamic; +using Newtonsoft.Json; + +namespace Apps.ClickUp.Models.Request.Task; + +public class UpdateTaskRequest +{ + public string? Name { get; set; } + public string? Description { get; set; } + + public IEnumerable? Assignees { get; set; } + + public string? Status { get; set; } + + [DataSource(typeof(TaskPriorityDataHandler))] + public string? Priority { get; set; } + + [Display("Due date")] + [JsonConverter(typeof(UnixTimestampConverter))] + public DateTime? DueDate { get; set; } + + [Display("Due date time")] + public bool? DueDateTime { get; set; } + + [Display("Time estimate")] + public int? TimeEstimate { get; set; } + + [Display("Start date")] + [JsonConverter(typeof(UnixTimestampConverter))] + public DateTime? StartDate { get; set; } + + [Display("Start date time")] + public bool? StartDateTime { get; set; } + + public string? Parent { get; set; } + + [Display("Custom fields")] + public IEnumerable? CustomFields { get; set; } +} \ No newline at end of file diff --git a/ClickUp/Models/Response/Attachment/AttachmentsResponse.cs b/ClickUp/Models/Response/Attachment/AttachmentsResponse.cs new file mode 100644 index 0000000..f84b159 --- /dev/null +++ b/ClickUp/Models/Response/Attachment/AttachmentsResponse.cs @@ -0,0 +1,9 @@ +using Apps.ClickUp.Models.Entities; + +namespace Apps.ClickUp.Models.Response.Attachment +{ + public class AttachmentsResponse + { + public List? Attachments { get; set; } + } +} \ No newline at end of file diff --git a/ClickUp/Models/Response/Attachment/DownloadAttachmentResponse.cs b/ClickUp/Models/Response/Attachment/DownloadAttachmentResponse.cs new file mode 100644 index 0000000..ce9bc14 --- /dev/null +++ b/ClickUp/Models/Response/Attachment/DownloadAttachmentResponse.cs @@ -0,0 +1,10 @@ +using Blackbird.Applications.Sdk.Common.Files; + +namespace Apps.ClickUp.Models.Response.Attachment +{ + public class DownloadAttachmentResponse + { + public FileReference Attachment { get; set; } + + } +} \ No newline at end of file