-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from romandykyi/basic-todo-list-management
Basic To-do List Management
- Loading branch information
Showing
37 changed files
with
2,311 additions
and
453 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
namespace AdvancedTodoList.Core.Dtos; | ||
|
||
public record TodoListItemView(int Id); | ||
/// <summary> | ||
/// DTO for creating/editing a to-do list. | ||
/// </summary> | ||
public record TodoListCreateDto(string Name, string Description); | ||
|
||
public record TodoListCreateDto(string Name); | ||
|
||
public record TodoListGetByIdDto(string Id, string Name, TodoListItemView[] TodoItems); | ||
/// <summary> | ||
/// DTO for a full view of a to-do list. | ||
/// </summary> | ||
public record TodoListGetByIdDto(string Id, string Name, string Description); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using AdvancedTodoList.Core.Models.TodoLists; | ||
|
||
namespace AdvancedTodoList.Core.Dtos; | ||
|
||
/// <summary> | ||
/// DTO for creating/editing a to-do list item. | ||
/// </summary> | ||
public record TodoItemCreateDto(string Name, string Description, DateTime? DeadlineDate); | ||
|
||
/// <summary> | ||
/// DTO for changing the state of a to-do list item. | ||
/// </summary> | ||
public record TodoItemUpdateStateDto(TodoItemState State); | ||
|
||
/// <summary> | ||
/// DTO for a full view of a to-do list item. | ||
/// </summary> | ||
public record TodoItemGetByIdDto( | ||
int Id, string TodoListId, string Name, | ||
string Description, DateTime? DeadlineDate, | ||
TodoItemState State | ||
); | ||
|
||
/// <summary> | ||
/// DTO for a partial view of a to-do list item. | ||
/// </summary> | ||
public record TodoItemPreviewDto( | ||
int Id, string TodoListId, string Name, | ||
DateTime? DeadlineDate, TodoItemState State | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Mapster; | ||
|
||
namespace AdvancedTodoList.Core.Mapping; | ||
|
||
/// <summary> | ||
/// Class that defines global mapping settings. | ||
/// </summary> | ||
public static class MappingGlobalSettings | ||
{ | ||
/// <summary> | ||
/// Apply global mapping settings. | ||
/// </summary> | ||
public static void Apply() | ||
{ | ||
// Convert null strings into empty strings and trim strings | ||
TypeAdapterConfig.GlobalSettings.Default | ||
.AddDestinationTransform((string? dest) => dest != null ? dest.Trim() : string.Empty); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace AdvancedTodoList.Core.Models; | ||
|
||
/// <summary> | ||
/// An interface that represents an entity with an ID property. | ||
/// </summary> | ||
/// <typeparam name="TId">Type of the entity ID.</typeparam> | ||
public interface IEntity<TId> where TId : IEquatable<TId> | ||
{ | ||
TId Id { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using AdvancedTodoList.Core.Models; | ||
|
||
namespace AdvancedTodoList.Core.Services; | ||
|
||
/// <summary> | ||
/// An interface for the service that checks whether an entity with an ID exists. | ||
/// </summary> | ||
public interface IEntityExistenceChecker | ||
{ | ||
/// <summary> | ||
/// Asynchronously checks whether an entity of type <typeparamref name="TEntity"/> with an ID | ||
/// <paramref name="id"/> of type <typeparamref name="TId"/> exists. | ||
/// </summary> | ||
/// <typeparam name="TEntity">Type of the entity.</typeparam> | ||
/// <typeparam name="TId">Type which ID of the entity has.</typeparam> | ||
/// <param name="id">ID of the entity which existence is checked.</param> | ||
/// <returns> | ||
/// A task representing the asynchronous operation. The task result contains | ||
/// <see langword="true"/> if entity with the given ID exists; otherwise | ||
/// <see langword="false"/>. | ||
/// </returns> | ||
Task<bool> ExistsAsync<TEntity, TId>(TId id) | ||
where TEntity : class, IEntity<TId> | ||
where TId : IEquatable<TId>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using AdvancedTodoList.Core.Dtos; | ||
using AdvancedTodoList.Core.Models.TodoLists; | ||
|
||
namespace AdvancedTodoList.Core.Services; | ||
|
||
/// <summary> | ||
/// Interface for a service that manages to-do list items. | ||
/// </summary> | ||
public interface ITodoItemsService | ||
{ | ||
/// <summary> | ||
/// Retrieves to-do list items of the list with the specified ID. | ||
/// </summary> | ||
/// <remarks> | ||
/// Does not throw exceptions if ID is invalid. | ||
/// </remarks> | ||
/// <param name="id">The ID of the to-do list which items will be retrieved.</param> | ||
/// <returns> | ||
/// A task representing the asynchronous operation. | ||
/// The task result contains a collection of <see cref="TodoItemPreviewDto"/> objects. | ||
/// </returns> | ||
public Task<IEnumerable<TodoItemPreviewDto>> GetItemsOfListAsync(string id); | ||
|
||
/// <summary> | ||
/// Retrieves a to-do list ID of the to-do list item. | ||
/// </summary> | ||
/// <param name="id">ID of the to-do list item.</param> | ||
/// <returns> | ||
/// A task representing the asynchronous operation. The task result contains | ||
/// an ID of the to-do list which owns a to-do list item with the specified ID if it's found; | ||
/// otherwise, returns <see langword="null"/>. | ||
/// </returns> | ||
public Task<string?> GetTodoListByIdAsync(int id); | ||
|
||
/// <summary> | ||
/// Retrieves a to-do list item by its ID asynchronously. | ||
/// </summary> | ||
/// <param name="id">The ID of the to-do list item to retrieve.</param> | ||
/// <returns> | ||
/// A task representing the asynchronous operation. The task result contains | ||
/// a <see cref="TodoItemGetByIdDto"/> object if the specified ID is found; | ||
/// otherwise, returns <see langword="null"/>. | ||
/// </returns> | ||
public Task<TodoItemGetByIdDto?> GetByIdAsync(int id); | ||
|
||
/// <summary> | ||
/// Creates a new to-do list item asynchronously. | ||
/// </summary> | ||
/// <param name="todoListId">The ID of the to-do list to associate the item with.</param> | ||
/// <param name="dto">The DTO containing information for creating the to-do list item.</param> | ||
/// <returns> | ||
/// A task representing the asynchronous operation. | ||
/// The task result contains the created <see cref="TodoItem"/>. | ||
/// </returns> | ||
public Task<TodoItem> CreateAsync(string todoListId, TodoItemCreateDto dto); | ||
|
||
/// <summary> | ||
/// Edits a to-do list item asynchronously. | ||
/// </summary> | ||
/// <param name="id">The ID of the to-do list item to edit.</param> | ||
/// <param name="dto">The DTO containing information for editing the to-do list item.</param> | ||
/// <returns> | ||
/// A task representing the asynchronous operation. | ||
/// The task result contains <see langword="true"/> on success; | ||
/// otherwise <see langword="false"/> if the entity was not found. | ||
/// </returns> | ||
public Task<bool> EditAsync(int id, TodoItemCreateDto dto); | ||
|
||
/// <summary> | ||
/// Updates the state of a to-do list item asynchronously. | ||
/// </summary> | ||
/// <param name="id">The ID of the to-do list item to update the state.</param> | ||
/// <param name="dto">The DTO containing information for updating the state of the to-do list item.</param> | ||
/// <returns> | ||
/// A task representing the asynchronous operation. | ||
/// The task result contains <see langword="true"/> on success; | ||
/// otherwise <see langword="false"/> if the entity was not found. | ||
/// </returns> | ||
public Task<bool> UpdateStateAsync(int id, TodoItemUpdateStateDto dto); | ||
|
||
/// <summary> | ||
/// Deletes a to-do list item asynchronously. | ||
/// </summary> | ||
/// <param name="id">The ID of the to-do list item to delete.</param> | ||
/// <returns> | ||
/// A task representing the asynchronous operation. | ||
/// The task result contains <see langword="true"/> on success; | ||
/// otherwise <see langword="false"/> if the entity was not found. | ||
/// </returns> | ||
public Task<bool> DeleteAsync(int id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
AdvancedTodoList.Core/Validation/TodoItemCreateDtoValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using AdvancedTodoList.Core.Dtos; | ||
using FluentValidation; | ||
|
||
namespace AdvancedTodoList.Core.Validation; | ||
|
||
/// <summary> | ||
/// Validator class for <see cref="TodoItemCreateDto" /> | ||
/// </summary> | ||
public class TodoItemCreateDtoValidator : AbstractValidator<TodoItemCreateDto> | ||
{ | ||
public TodoItemCreateDtoValidator() | ||
{ | ||
// Name is required | ||
RuleFor(x => x.Name) | ||
.NotEmpty() | ||
.WithErrorCode(ValidationErrorCodes.PropertyRequired); | ||
|
||
// Description is not null | ||
RuleFor(x => x.Description) | ||
.NotNull() | ||
.WithErrorCode(ValidationErrorCodes.PropertyRequired); | ||
|
||
// Deadline date should be after the current date | ||
RuleFor(x => x.DeadlineDate) | ||
.GreaterThan(DateTime.UtcNow) | ||
.WithErrorCode(ValidationErrorCodes.PropertyOutOfRange); | ||
} | ||
} |
Oops, something went wrong.