Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions ClickUp/Actions/AttachmentActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -39,4 +43,35 @@ public async Task<AttachmentEntity> CreateAttachment(

return await Client.ExecuteWithErrorHandling<AttachmentEntity>(request);
}

[Action("Get Attachments from task", Description = "Get attachment list from tasks")]
public async Task<AttachmentsResponse> GetAttachment([ActionParameter] GetAttachmentRequest attachmentRequest)
{
var endpoint = $"{ApiEndpoints.Tasks}/{attachmentRequest.TaskId}";
var request = new ClickUpRequest(endpoint, Method.Get, Creds);

var result = await Client.ExecuteWithErrorHandling<TaskEntity>(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<DownloadAttachmentResponse> 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 };
}
}
14 changes: 14 additions & 0 deletions ClickUp/Actions/TaskActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ public Task<TaskEntity> CreateTask(
return Client.ExecuteWithErrorHandling<TaskEntity>(request);
}


[Action("Update task", Description = "Update the details of a specific task")]
public Task<TaskEntity> 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<TaskEntity>(request);
}

[Action("Delete task", Description = "Delete specific task")]
public Task DeleteTask(
[ActionParameter] TaskRequest task)
Expand Down
10 changes: 10 additions & 0 deletions ClickUp/Api/ClickUpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ public ClickUpClient() : base(new RestClientOptions()
throw new($"Could not parse {json} to {typeof(T)}");
}

public async Task<RestResponse> 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<Error>(response.Content);
Expand Down
2 changes: 1 addition & 1 deletion ClickUp/Models/Entities/CustomField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ public class CustomField

public bool Required { get; set; }

public List<string> Value { get; set; }
public string Value { get; set; }
}
4 changes: 4 additions & 0 deletions ClickUp/Models/Entities/TaskEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ public class TaskEntity : ClickUpEntity
public int? TimeSpent { get; set; }

public SimpleList List { get; set; }

[Display("Attachments")]

public List<AttachmentEntity> Attachments { get; set; }
}
11 changes: 11 additions & 0 deletions ClickUp/Models/Request/Attachment/DownloadAttachmentRequest.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
14 changes: 14 additions & 0 deletions ClickUp/Models/Request/Attachment/GetAttachmentRequest.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
43 changes: 43 additions & 0 deletions ClickUp/Models/Request/Task/UpdateTaskRequest.cs
Original file line number Diff line number Diff line change
@@ -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<int>? 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<SimpleCustomField>? CustomFields { get; set; }
}
9 changes: 9 additions & 0 deletions ClickUp/Models/Response/Attachment/AttachmentsResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Apps.ClickUp.Models.Entities;

namespace Apps.ClickUp.Models.Response.Attachment
{
public class AttachmentsResponse
{
public List<AttachmentEntity>? Attachments { get; set; }
}
}
10 changes: 10 additions & 0 deletions ClickUp/Models/Response/Attachment/DownloadAttachmentResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Blackbird.Applications.Sdk.Common.Files;

namespace Apps.ClickUp.Models.Response.Attachment
{
public class DownloadAttachmentResponse
{
public FileReference Attachment { get; set; }

}
}