Skip to content

Commit

Permalink
General
Browse files Browse the repository at this point in the history
- All internal usage of `UpdateCardAsync` now uses the new 'partial update'-variant described below for better performance and more secure async usage in the Automation Engine

TrelloClient
- Added overload to UpdateCardAsync that instead of a full update with a card can do partial updates with only the parameters you provide
  • Loading branch information
rwjdk committed Oct 12, 2023
1 parent 101c690 commit c1717e1
Show file tree
Hide file tree
Showing 19 changed files with 226 additions and 78 deletions.
9 changes: 9 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Changelog
*Below is the version history of [TrelloDotNet](https://github.com/rwjdk/TrelloDotNet) (An wrapper of the Trello API)*

## 1.9.2 (12th of October 2023)
#### General
- All internal usage of `UpdateCardAsync` now uses the new 'partial update'-variant described below for better performance and more secure async usage in the Automation Engine

#### TrelloClient
- Added overload to [`UpdateCardAsync`](https://github.com/rwjdk/TrelloDotNet/wiki/UpdateCardAsync) that instead of a full update with a card can do partial updates with only the parameters you provide

<hr>

## 1.9.1 (11th of October 2023)
#### Automation Engine
- Added Automation Trigger [`AddChecklistToCardTrigger`](https://github.com/rwjdk/TrelloDotNet/wiki/AddChecklistToCardTrigger)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading.Tasks;
using TrelloDotNet.AutomationEngine.Interface;
using TrelloDotNet.Control;
using TrelloDotNet.Model;
using TrelloDotNet.Model.Options;
using TrelloDotNet.Model.Webhook;

namespace TrelloDotNet.AutomationEngine.Model.Actions
Expand Down Expand Up @@ -40,9 +44,10 @@ public async Task PerformActionAsync(WebhookAction webhookAction, ProcessingResu
throw new AutomationException("Could not perform AddCoverOnCardAction as WebhookAction did not involve a Card");
}
var trelloClient = webhookAction.TrelloClient;
var card = await webhookAction.Data.Card.GetAsync();
card.Cover = CardCoverToAdd;
await trelloClient.UpdateCardAsync(card);
await trelloClient.UpdateCardAsync(webhookAction.Data.Card.Id, new List<QueryParameter>
{
new QueryParameter(CardFieldsType.Cover.GetJsonPropertyName(), JsonSerializer.Serialize(CardCoverToAdd))
});
processingResult.AddToLog($"Updated Card '{webhookAction.Data.Card.Name}' with new Cover");
processingResult.ActionsExecuted++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using System.Linq;
using System.Threading.Tasks;
using TrelloDotNet.AutomationEngine.Interface;
using TrelloDotNet.Control;
using TrelloDotNet.Model;
using TrelloDotNet.Model.Options;
using TrelloDotNet.Model.Webhook;

namespace TrelloDotNet.AutomationEngine.Model.Actions
Expand Down Expand Up @@ -77,7 +80,10 @@ public async Task PerformActionAsync(WebhookAction webhookAction, ProcessingResu

if (updateNeeded)
{
await trelloClient.UpdateCardAsync(card);
await trelloClient.UpdateCardAsync(card.Id, new List<QueryParameter>()
{
new QueryParameter(CardFieldsType.LabelIds.GetJsonPropertyName(), card.LabelIds)
});
processingResult.AddToLog($"Added labels '{string.Join(",", LabelIds)}' to card '{webhookAction.Data.Card.Name}'");
processingResult.ActionsExecuted++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using System.Linq;
using System.Threading.Tasks;
using TrelloDotNet.AutomationEngine.Interface;
using TrelloDotNet.Control;
using TrelloDotNet.Model.Options;
using TrelloDotNet.Model;
using TrelloDotNet.Model.Webhook;

namespace TrelloDotNet.AutomationEngine.Model.Actions
Expand Down Expand Up @@ -75,7 +78,10 @@ public async Task PerformActionAsync(WebhookAction webhookAction, ProcessingResu

if (updateNeeded)
{
await trelloClient.UpdateCardAsync(card);
await trelloClient.UpdateCardAsync(card.Id, new List<QueryParameter>()
{
new QueryParameter(CardFieldsType.MemberIds.GetJsonPropertyName(), card.MemberIds)
});
processingResult.AddToLog($"Added members '{string.Join(",", MemberIds)}' to card '{webhookAction.Data.Card.Name}'");
processingResult.ActionsExecuted++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@ public interface ISetCardFieldValue
/// <param name="card">The Card to set the values on</param>
/// <returns>If card was modified (aka need to be updated against the API)</returns>
bool SetIfNeeded(Card card);

/// <summary>
/// Get a Query Parameter representing the change (or null if not needed)
/// </summary>
/// <param name="card">Card to apply the change to</param>
/// <returns>Query parameter of null</returns>
QueryParameter GetQueryParameter(Card card);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
using System.Linq;
using System.Threading.Tasks;
using TrelloDotNet.AutomationEngine.Interface;
using TrelloDotNet.Control;
using TrelloDotNet.Model;
using TrelloDotNet.Model.Actions;
using TrelloDotNet.Model.Options;
using TrelloDotNet.Model.Webhook;

namespace TrelloDotNet.AutomationEngine.Model.Actions
Expand Down Expand Up @@ -41,7 +43,7 @@ public async Task PerformActionAsync(WebhookAction webhookAction, ProcessingResu
throw new AutomationException("Could not perform RemoveCardDataAction as WebhookAction did not involve a Card");
}
var card = await webhookAction.Data.Card.GetAsync();
bool updateNeeded = false;
var queryParametersToUpdate = new List<QueryParameter>();
foreach (var dataType in DataToRemove)
{
switch (dataType)
Expand All @@ -50,49 +52,49 @@ public async Task PerformActionAsync(WebhookAction webhookAction, ProcessingResu
if (card.Start != null)
{
card.Start = null;
updateNeeded = true;
queryParametersToUpdate.Add(new QueryParameter(CardFieldsType.Start.GetJsonPropertyName(), (DateTimeOffset?)null));
}
break;
case RemoveCardDataType.DueDate:
if (card.Due != null)
{
card.Due = null;
updateNeeded = true;
queryParametersToUpdate.Add(new QueryParameter(CardFieldsType.Due.GetJsonPropertyName(), (DateTimeOffset?)null));
}
break;
case RemoveCardDataType.DueComplete:
if (card.DueComplete)
{
card.DueComplete = false;
updateNeeded = true;
queryParametersToUpdate.Add(new QueryParameter(CardFieldsType.DueComplete.GetJsonPropertyName(), false));
}
break;
case RemoveCardDataType.Description:
if (!string.IsNullOrWhiteSpace(card.Description))
{
card.Description = null;
updateNeeded = true;
queryParametersToUpdate.Add(new QueryParameter(CardFieldsType.Description.GetJsonPropertyName(), string.Empty));
}
break;
case RemoveCardDataType.AllLabels:
if (card.LabelIds.Any())
{
card.LabelIds = new List<string>();
updateNeeded = true;
queryParametersToUpdate.Add(new QueryParameter(CardFieldsType.LabelIds.GetJsonPropertyName(), new List<string>()));
}
break;
case RemoveCardDataType.AllMembers:
if (card.MemberIds.Any())
{
card.MemberIds = new List<string>();
updateNeeded = true;
queryParametersToUpdate.Add(new QueryParameter(CardFieldsType.MemberIds.GetJsonPropertyName(), new List<string>()));
}
break;
case RemoveCardDataType.Cover:
if (card.Cover != null && (card.Cover.Color != null || card.Cover.BackgroundImageId != null))
{
card.Cover = null;
updateNeeded = true;
queryParametersToUpdate.Add(new QueryParameter(CardFieldsType.Cover.GetJsonPropertyName(), (string)null));
}
break;
case RemoveCardDataType.AllChecklists:
Expand Down Expand Up @@ -128,10 +130,10 @@ public async Task PerformActionAsync(WebhookAction webhookAction, ProcessingResu
}
}

if (updateNeeded)
if (queryParametersToUpdate.Any())
{
processingResult.ActionsExecuted++;
await webhookAction.TrelloClient.UpdateCardAsync(card);
await webhookAction.TrelloClient.UpdateCardAsync(card.Id, queryParametersToUpdate);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Threading.Tasks;
using TrelloDotNet.AutomationEngine.Interface;
using TrelloDotNet.Control;
using TrelloDotNet.Model;
using TrelloDotNet.Model.Options;
using TrelloDotNet.Model.Webhook;

namespace TrelloDotNet.AutomationEngine.Model.Actions
Expand All @@ -25,9 +29,10 @@ public async Task PerformActionAsync(WebhookAction webhookAction, ProcessingResu
throw new AutomationException("Could not perform RemoveCoverFromCardAction as WebhookAction did not involve a Card");
}
var trelloClient = webhookAction.TrelloClient;
var card = await webhookAction.Data.Card.GetAsync();
card.Cover = null;
await trelloClient.UpdateCardAsync(card);
await trelloClient.UpdateCardAsync(webhookAction.Data.Card.Id, new List<QueryParameter>
{
new QueryParameter(CardFieldsType.Cover.GetJsonPropertyName(), (string)null)
});
processingResult.AddToLog($"Removed Cover from Card '{webhookAction.Data.Card.Name}'");
processingResult.ActionsExecuted++;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using TrelloDotNet.Control;
using TrelloDotNet.Model;
using TrelloDotNet.Model.Options;

namespace TrelloDotNet.AutomationEngine.Model.Actions
{
Expand Down Expand Up @@ -42,6 +44,12 @@ public bool SetIfNeeded(Card card)
return false;
}

/// <inheritdoc />
public QueryParameter GetQueryParameter(Card card)
{
return SetIfNeeded(card) ? new QueryParameter(CardFieldsType.Description.GetJsonPropertyName(), card.Description) : null;
}

/// <summary>
/// Constructor
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using TrelloDotNet.Model;
using TrelloDotNet.Control;
using TrelloDotNet.Model;
using TrelloDotNet.Model.Options;

namespace TrelloDotNet.AutomationEngine.Model.Actions
{
Expand All @@ -23,6 +25,12 @@ public bool SetIfNeeded(Card card)
return true;
}

/// <inheritdoc />
public QueryParameter GetQueryParameter(Card card)
{
return SetIfNeeded(card) ? new QueryParameter(CardFieldsType.DueComplete.GetJsonPropertyName(), card.DueComplete) : null;
}

/// <summary>
/// Constructor
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using TrelloDotNet.Control;
using TrelloDotNet.Model;
using TrelloDotNet.Model.Options;

namespace TrelloDotNet.AutomationEngine.Model.Actions
{
Expand Down Expand Up @@ -44,6 +46,12 @@ public bool SetIfNeeded(Card card)
return false;
}

/// <inheritdoc />
public QueryParameter GetQueryParameter(Card card)
{
return SetIfNeeded(card) ? new QueryParameter(CardFieldsType.Due.GetJsonPropertyName(), card.Due) : null;
}

/// <summary>
/// Constructor
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using TrelloDotNet.Control;
using TrelloDotNet.Model;
using TrelloDotNet.Model.Options;

namespace TrelloDotNet.AutomationEngine.Model.Actions
{
Expand Down Expand Up @@ -44,6 +46,12 @@ public bool SetIfNeeded(Card card)
return false;
}

/// <inheritdoc />
public QueryParameter GetQueryParameter(Card card)
{
return SetIfNeeded(card) ? new QueryParameter(CardFieldsType.Name.GetJsonPropertyName(), card.Name) : null;
}

/// <summary>
/// Constructor
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using TrelloDotNet.Control;
using TrelloDotNet.Model;
using TrelloDotNet.Model.Options;

namespace TrelloDotNet.AutomationEngine.Model.Actions
{
Expand Down Expand Up @@ -43,6 +45,12 @@ public bool SetIfNeeded(Card card)
return false;
}

/// <inheritdoc />
public QueryParameter GetQueryParameter(Card card)
{
return SetIfNeeded(card) ? new QueryParameter(CardFieldsType.Start.GetJsonPropertyName(), card.Start) : null;
}

/// <summary>
/// Constructor
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TrelloDotNet.AutomationEngine.Interface;
using TrelloDotNet.Model;
using TrelloDotNet.Model.Webhook;

namespace TrelloDotNet.AutomationEngine.Model.Actions
Expand Down Expand Up @@ -35,19 +38,21 @@ public async Task PerformActionAsync(WebhookAction webhookAction, ProcessingResu
throw new AutomationException("Could not perform SetFieldsOnCardAction as WebhookAction did not involve a Card");
}
var card = await webhookAction.Data.Card.GetAsync();
bool updateNeeded = false;
var queryParametersToAdd = new List<QueryParameter>();
foreach (var fieldValue in FieldValues)
{
if (fieldValue.SetIfNeeded(card))
QueryParameter queryParameter = fieldValue.GetQueryParameter(card);
if (queryParameter != null)
{
updateNeeded = true;
queryParametersToAdd.Add(queryParameter);
}

}

if (updateNeeded)
if (queryParametersToAdd.Any())
{
processingResult.ActionsExecuted++;
await webhookAction.TrelloClient.UpdateCardAsync(card);
await webhookAction.TrelloClient.UpdateCardAsync(card.Id, queryParametersToAdd);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal QueryParameter[] GetViaQueryParameterAttributes<T>(T instance)
else if (updateablePropertyType == typeof(List<string>))
{
var list = (List<string>)rawValue;
parameters.Add(list == null ? new QueryParameter(jsonPropertyName.Name, string.Empty) : new QueryParameter(jsonPropertyName.Name, string.Join(",", list)));
parameters.Add(list == null ? new QueryParameter(jsonPropertyName.Name, string.Empty) : new QueryParameter(jsonPropertyName.Name, list));
}
else if (updateablePropertyType.BaseType == typeof(Enum))
{
Expand Down
Loading

0 comments on commit c1717e1

Please sign in to comment.