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

Include project notes in the NotesService Get response. #53

Merged
merged 2 commits into from
Jun 1, 2024
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
4 changes: 2 additions & 2 deletions src/Todoist.Net.Tests/Services/NotesServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public async Task AddNoteGetAndDelete_Success()
var note = new Note("Hello");
await todoistClient.Notes.AddToProjectAsync(note, project.Id.PersistentId);

var notes = await todoistClient.Notes.GetAsync();
Assert.Contains(notes, n => n.Id == note.Id);
var notesInfo = await todoistClient.Notes.GetAsync();
Assert.Contains(notesInfo.ProjectNotes, n => n.Id == note.Id);

await todoistClient.Projects.DeleteAsync(project.Id);
}
Expand Down
26 changes: 26 additions & 0 deletions src/Todoist.Net/Models/NotesInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections.Generic;

namespace Todoist.Net.Models
{
/// <summary>
/// Represents collections of item and project notes.
/// </summary>
public class NotesInfo
{
/// <summary>
/// Gets the item notes.
/// </summary>
/// <value>
/// The item notes.
/// </value>
public IReadOnlyCollection<Note> ItemNotes { get; internal set; }

/// <summary>
/// Gets the project notes.
/// </summary>
/// <value>
/// The project notes.
/// </value>
public IReadOnlyCollection<Note> ProjectNotes { get; internal set; }
}
}
3 changes: 1 addition & 2 deletions src/Todoist.Net/Services/INotesServices.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -19,6 +18,6 @@ public interface INotesServices : INotesCommandServices
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>The notes.</returns>
/// <exception cref="HttpRequestException">API exception.</exception>
Task<IEnumerable<Note>> GetAsync(CancellationToken cancellationToken = default);
Task<NotesInfo> GetAsync(CancellationToken cancellationToken = default);
}
}
9 changes: 6 additions & 3 deletions src/Todoist.Net/Services/NotesService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -19,11 +18,15 @@ internal NotesService(IAdvancedTodoistClient todoistClient)
}

/// <inheritdoc/>
public async Task<IEnumerable<Note>> GetAsync(CancellationToken cancellationToken = default)
public async Task<NotesInfo> GetAsync(CancellationToken cancellationToken = default)
{
var response = await TodoistClient.GetResourcesAsync(cancellationToken, ResourceType.Notes).ConfigureAwait(false);

return response.Notes;
return new NotesInfo
{
ItemNotes = response.Notes,
ProjectNotes = response.ProjectNotes
};
}
}
}