Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for returning sync token values after committing transactions. #30

Merged
merged 2 commits into from
Aug 31, 2023
Merged
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
3 changes: 2 additions & 1 deletion src/Todoist.Net.Tests/Services/TransactionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public void CreateProjectAndCreateNote_Success()
var note = new Note("Demo note");
transaction.Notes.AddToProjectAsync(note, projectId).Wait();

transaction.CommitAsync().Wait();
var syncToken = transaction.CommitAsync().Result;

var projectInfo = client.Projects.GetAsync(project.Id).Result;

Assert.True(projectInfo.Notes.Count > 0);
Assert.NotNull(syncToken);

var deleteTransaction = client.CreateTransaction();

Expand Down
9 changes: 6 additions & 3 deletions src/Todoist.Net/IAdvancedTodoistClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;

Expand All @@ -12,11 +12,14 @@ internal interface IAdvancedTodoistClient : ITodoistClient
/// Executes the commands asynchronous.
/// </summary>
/// <param name="commands">The commands.</param>
/// <returns>Returns <see cref="T:System.Threading.Tasks.Task" />.The task object representing the asynchronous operation.</returns>
/// <returns>
/// Returns <see cref="Task{TResult}" />. The task object representing the asynchronous operation
/// that at completion returns the commands execution sync_token.
/// </returns>
/// <exception cref="System.ArgumentNullException">Value cannot be null - commands.</exception>
/// <exception cref="System.AggregateException">Command execution exception.</exception>
/// <exception cref="HttpRequestException">API exception.</exception>
Task ExecuteCommandsAsync(params Command[] commands);
Task<string> ExecuteCommandsAsync(params Command[] commands);

/// <summary>
/// Posts the request asynchronous.
Expand Down
3 changes: 3 additions & 0 deletions src/Todoist.Net/Models/SyncResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ internal class SyncResponse

[JsonProperty("temp_id_mapping")]
public Dictionary<Guid, string> TempIdMappings { get; set; }

[JsonProperty("sync_token")]
public string SyncToken { get; set; }
}
}
9 changes: 6 additions & 3 deletions src/Todoist.Net/Services/ITransaction.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Net.Http;
using System.Threading.Tasks;

Expand Down Expand Up @@ -70,9 +70,12 @@ public interface ITransaction
/// <summary>
/// Commits the transaction asynchronous.
/// </summary>
/// <returns>Returns <see cref="T:System.Threading.Tasks.Task" />.The task object representing the asynchronous operation.</returns>
/// <returns>
/// Returns <see cref="Task{TResult}" />. The task object representing the asynchronous operation
/// that at completion returns the transaction sync_token.
/// </returns>
/// <exception cref="AggregateException">Command execution exception.</exception>
/// <exception cref="HttpRequestException">API exception.</exception>
Task CommitAsync();
Task<string> CommitAsync();
}
}
11 changes: 7 additions & 4 deletions src/Todoist.Net/Services/Transaction.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
Expand Down Expand Up @@ -59,14 +59,17 @@ internal Transaction(IAdvancedTodoistClient todoistClient)
/// <summary>
/// Commits the transaction asynchronous.
/// </summary>
/// <returns>Returns <see cref="T:System.Threading.Tasks.Task" />.The task object representing the asynchronous operation.</returns>
/// <returns>
/// Returns <see cref="Task{TResult}" />. The task object representing the asynchronous operation
/// that at completion returns the transaction sync_token.
/// </returns>
/// <exception cref="AggregateException">Command execution exception.</exception>
/// <exception cref="HttpRequestException">API exception.</exception>
public async Task CommitAsync()
public async Task<string> CommitAsync()
{
try
{
await _todoistClient.ExecuteCommandsAsync(_commands.ToArray()).ConfigureAwait(false);
return await _todoistClient.ExecuteCommandsAsync(_commands.ToArray()).ConfigureAwait(false);
}
finally
{
Expand Down
8 changes: 6 additions & 2 deletions src/Todoist.Net/TodoistClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,15 @@ public Task<T> PostFormAsync<T>(
/// Executes the commands asynchronous.
/// </summary>
/// <param name="commands">The commands.</param>
/// <returns>Returns <see cref="T:System.Threading.Tasks.Task" />.The task object representing the asynchronous operation.</returns>
/// <returns>
/// Returns <see cref="Task{TResult}" />. The task object representing the asynchronous operation
/// that at completion returns the commands execution sync_token.
/// </returns>
/// <exception cref="System.ArgumentNullException">Value cannot be null - commands.</exception>
/// <exception cref="System.AggregateException">Command execution exception.</exception>
/// <exception cref="ArgumentException">Value cannot be an empty collection.</exception>
/// <exception cref="HttpRequestException">API exception.</exception>
async Task IAdvancedTodoistClient.ExecuteCommandsAsync(params Command[] commands)
async Task<string> IAdvancedTodoistClient.ExecuteCommandsAsync(params Command[] commands)
{
if (commands == null)
{
Expand All @@ -294,6 +297,7 @@ async Task IAdvancedTodoistClient.ExecuteCommandsAsync(params Command[] commands
{
UpdateTempIds(commands, syncResponse.TempIdMappings);
}
return syncResponse.SyncToken;
}

/// <summary>
Expand Down