Skip to content

Commit

Permalink
fix(todos): add ids to response models and query filter
Browse files Browse the repository at this point in the history
  • Loading branch information
EnisMulic committed Nov 17, 2023
1 parent 9d57c3d commit 8b01b58
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
12 changes: 5 additions & 7 deletions src/Application/Features/Todos/CompleteTodoItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ public async Task<Unit> Handle(CompleteTodoCommand request, CancellationToken ca
var item = await _context.TodoItems.FindAsync(new object?[] { request.Id }, cancellationToken: cancellationToken)
?? throw new NotFoundException(nameof(TodoItem), request.Id);

//if (!item.Done)
//{

//}

item.Complete();
await _context.SaveChangesAsync(cancellationToken);
if (!item.Done)
{
item.Complete();
await _context.SaveChangesAsync(cancellationToken);
}

return Unit.Value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Features/Todos/GetTodos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void AddRoutes(IEndpointRouteBuilder app)
return response;
})
.RequireAuthorization()
.Produces<int>(StatusCodes.Status201Created)
.Produces<List<TodoListResponse>>(StatusCodes.Status200OK)
.Produces(StatusCodes.Status400BadRequest)
.WithOpenApi(operation => new(operation)
{
Expand Down
12 changes: 7 additions & 5 deletions src/Application/Features/Todos/TodoListResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ namespace Application.Features.Todos;
#nullable disable
public class TodoListResponse : IMapFrom<TodoList>
{
public int Id { get; set; }
public string Title { get; set; }
public string Colour { get; set; }
public IList<TodoItemResponse> Items { get; set; }
}

public class TodoItemResponse : IMapFrom<TodoItem>
{
public string Title { get; private set; }
public string Note { get; private set; }
public PriorityLevel PriorityLevel { get; private set; }
public bool Done { get; private set; }
public DateTime? Reminder { get; private set; }
public int Id { get; set; }
public string Title { get; set; }
public string Note { get; set; }
public PriorityLevel PriorityLevel { get; set; }
public bool Done { get; set; }
public DateTime? Reminder { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class TodoItemConfiguration : IEntityTypeConfiguration<TodoItem>
{
public void Configure(EntityTypeBuilder<TodoItem> builder)
{
builder.HasQueryFilter(i => !i.IsDeleted);

builder.Property(t => t.Title)
.HasMaxLength(200)
.IsRequired();
Expand Down

0 comments on commit 8b01b58

Please sign in to comment.