-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/delete catalogs #22
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
Open
KopfSzmercen
wants to merge
17
commits into
main
Choose a base branch
from
feat/delete-catalogs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6656c99
core
iAttaquer dcf68d3
added Creating Catalog
iAttaquer c0c0e0d
Update catalog, fix create catalog
iAttaquer c92c820
Get browse catalogs
iAttaquer 9b59ff6
Delete catalog
iAttaquer 14b5db9
add book to catalog
iAttaquer 5558d25
core
iAttaquer 078e2af
added Creating Catalog
iAttaquer 9918b1f
Update catalog, fix create catalog
iAttaquer e6ddf50
Get browse catalogs
iAttaquer 4a59b1b
Delete catalog
iAttaquer ed8695f
add book to catalog
iAttaquer 1bb6984
catalog
iAttaquer bb04bff
feat: add book to catalog, Browse books in catalog, Remove book from …
iAttaquer e07c847
resolved some conflicts
iAttaquer 7d07b3f
resolved some conflicts
iAttaquer 87bf911
feat: added migration for catalogs
iAttaquer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
37 changes: 37 additions & 0 deletions
37
src/DotNetBoilerplate.Api/Catalogs/AddBookToCatalogEndpoint.cs
This file contains hidden or 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,37 @@ | ||
| using DotNetBoilerplate.Application.Catalogs.AddBook; | ||
| using DotNetBoilerplate.Shared.Abstractions.Commands; | ||
| using Microsoft.AspNetCore.Http.HttpResults; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace DotNetBoilerplate.Api.Catalogs; | ||
|
|
||
| public class AddBookToCatalogEndpoint : IEndpoint | ||
| { | ||
| public static void Map(IEndpointRouteBuilder app) | ||
| { | ||
| app.MapPost("{catalogId:guid}/books", Handle) | ||
| .RequireAuthorization() | ||
| .WithSummary("Add book to catalog"); | ||
| } | ||
|
|
||
| private static async Task<Ok<Response>> Handle( | ||
| [FromRoute] Guid catalogId, | ||
| [FromBody] Request request, | ||
| [FromServices] ICommandDispatcher commandDispatcher, | ||
| CancellationToken ct | ||
| ) | ||
| { | ||
| var command = new AddBookToCatalogCommand(catalogId, request.BookId); | ||
| var result = await commandDispatcher.DispatchAsync<AddBookToCatalogCommand, Guid>(command, ct); | ||
|
|
||
| return TypedResults.Ok(new Response(result)); | ||
| } | ||
| internal sealed record Response( | ||
| Guid Id | ||
| ); | ||
|
|
||
| private class Request | ||
| { | ||
| public Guid BookId { get; init; } | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
src/DotNetBoilerplate.Api/Catalogs/BrowseBooksInCatalogEndpoint.cs
This file contains hidden or 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 DotNetBoilerplate.Application.Catalogs.BrowseBooks; | ||
| using DotNetBoilerplate.Application.Books.DTO; | ||
| using DotNetBoilerplate.Shared.Abstractions.Queries; | ||
| using Microsoft.AspNetCore.Http.HttpResults; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace DotNetBoilerplate.Api.Catalogs; | ||
|
|
||
| public class BrowseBooksInCatalogEndpoint : IEndpoint | ||
| { | ||
| public static void Map(IEndpointRouteBuilder app) | ||
| { | ||
| app.MapGet("{catalogId:guid}/books", Handle) | ||
| .WithSummary("Browse books with CatalogId parameter"); | ||
| } | ||
|
|
||
| private static async Task<Results<Ok<IEnumerable<BookDto>>, NotFound>> Handle( | ||
| [FromRoute] Guid catalogId, | ||
| [FromServices] IQueryDispatcher queryDispatcher, | ||
| CancellationToken ct | ||
| ) | ||
| { | ||
| var query = new BrowseBooksInCatalogQuery(catalogId); | ||
| var result = await queryDispatcher.QueryAsync(query, ct); | ||
|
|
||
| return result is null | ||
| ? TypedResults.NotFound() | ||
| : TypedResults.Ok(result); | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
src/DotNetBoilerplate.Api/Catalogs/BrowseCatalogsEndpoint.cs
This file contains hidden or 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 DotNetBoilerplate.Application.Catalogs.Browse; | ||
| using DotNetBoilerplate.Application.Catalogs.DTO; | ||
| using DotNetBoilerplate.Shared.Abstractions.Queries; | ||
| using Microsoft.AspNetCore.Http.HttpResults; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace DotNetBoilerplate.Api.Catalogs; | ||
|
|
||
| public class BrowseCatalogsEndpoint : IEndpoint | ||
| { | ||
| public static void Map(IEndpointRouteBuilder app) | ||
| { | ||
| app.MapGet("", Handle) | ||
| .WithSummary("Browse catalogs with optional BookStoreId parameter"); | ||
| } | ||
|
|
||
| private static async Task<Results<Ok<IEnumerable<CatalogDto>>, NotFound>> Handle( | ||
| [FromQuery] Guid? bookStoreId, | ||
| [FromServices] IQueryDispatcher queryDispatcher, | ||
| CancellationToken ct | ||
| ) | ||
| { | ||
| var query = new BrowseCatalogsQuery(bookStoreId); | ||
| var result = await queryDispatcher.QueryAsync(query, ct); | ||
|
|
||
| return result is null | ||
| ? TypedResults.NotFound() | ||
| : TypedResults.Ok(result); | ||
| } | ||
| } |
This file contains hidden or 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,26 @@ | ||
| using DotNetBoilerplate.Api.Catalogs; | ||
|
|
||
| namespace DotNetBoilerplate.Api.Catalogs; | ||
|
|
||
| internal static class CatalogsEndpoints | ||
| { | ||
| public const string BasePath = "catalogs"; | ||
| public const string Tags = "Catalogs"; | ||
|
|
||
| public static void MapCatalogsEndpoints(this WebApplication app) | ||
| { | ||
| var group = app.MapGroup(BasePath) | ||
| .WithTags(Tags); | ||
|
|
||
| group | ||
| .MapEndpoint<CreateCatalogEndpoint>() | ||
| .MapEndpoint<UpdateCatalogEndpoint>() | ||
| .MapEndpoint<BrowseCatalogsEndpoint>() | ||
| .MapEndpoint<GetCatalogByIdEndpoint>() | ||
| .MapEndpoint<DeleteCatalogEndpoint>() | ||
| .MapEndpoint<AddBookToCatalogEndpoint>() | ||
| .MapEndpoint<BrowseBooksInCatalogEndpoint>() | ||
| .MapEndpoint<RemoveBookFromCatalogEndpoint>(); | ||
| } | ||
| } | ||
|
|
46 changes: 46 additions & 0 deletions
46
src/DotNetBoilerplate.Api/Catalogs/CreateCatalogEndpoint.cs
This file contains hidden or 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,46 @@ | ||
| using System.ComponentModel.DataAnnotations; | ||
| using DotNetBoilerplate.Application.Catalogs.Create; | ||
| using DotNetBoilerplate.Shared.Abstractions.Commands; | ||
| using Microsoft.AspNetCore.Http.HttpResults; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace DotNetBoilerplate.Api.Catalogs; | ||
|
|
||
| internal sealed class CreateCatalogEndpoint : IEndpoint | ||
| { | ||
| public static void Map(IEndpointRouteBuilder app) | ||
| { | ||
| app.MapPost("", Handle) | ||
| .RequireAuthorization() | ||
| .WithSummary("Create catalog"); | ||
| } | ||
| private static async Task<Ok<Response>> Handle( | ||
| [FromBody] Request request, | ||
| [FromServices] ICommandDispatcher commandDispatcher, | ||
| CancellationToken ct | ||
| ) | ||
| { | ||
| var command = new CreateCatalogCommand( | ||
| request.Name, | ||
| request.Genre, | ||
| request.Description | ||
| ); | ||
|
|
||
| var result = await commandDispatcher.DispatchAsync<CreateCatalogCommand, Guid>(command, ct); | ||
|
|
||
| return TypedResults.Ok(new Response(result)); | ||
| } | ||
|
|
||
| internal sealed record Response( | ||
| Guid Id | ||
| ); | ||
|
|
||
| private sealed class Request | ||
| { | ||
| [Required] public string Name { get; init; } | ||
|
|
||
| [Required] public string Genre { get; init; } | ||
|
|
||
| [Required] public string Description { get; init; } | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
src/DotNetBoilerplate.Api/Catalogs/DeleteCatalogEndpoint.cs
This file contains hidden or 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,29 @@ | ||
| using DotNetBoilerplate.Application.Catalogs.Delete; | ||
| using DotNetBoilerplate.Shared.Abstractions.Commands; | ||
| using Microsoft.AspNetCore.Http.HttpResults; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace DotNetBoilerplate.Api.Catalogs; | ||
|
|
||
| internal sealed class DeleteCatalogEndpoint : IEndpoint | ||
| { | ||
| public static void Map(IEndpointRouteBuilder app) | ||
| { | ||
| app.MapDelete("{id:guid}", Handle) | ||
| .RequireAuthorization() | ||
| .WithSummary("Delete catalog by Id"); | ||
| } | ||
|
|
||
| private static async Task<IResult> Handle( | ||
| Guid id, | ||
| [FromServices] ICommandDispatcher commandDispatcher, | ||
| CancellationToken ct | ||
| ) | ||
| { | ||
| var command = new DeleteCatalogCommand(id); | ||
|
|
||
| await commandDispatcher.DispatchAsync<DeleteCatalogCommand>(command, ct); | ||
|
|
||
| return TypedResults.NoContent(); | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
src/DotNetBoilerplate.Api/Catalogs/GetCatalogByIdEndpoint.cs
This file contains hidden or 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,31 @@ | ||
| using DotNetBoilerplate.Application.Catalogs.Get; | ||
| using DotNetBoilerplate.Application.Catalogs.DTO; | ||
| using DotNetBoilerplate.Shared.Abstractions.Queries; | ||
| using Microsoft.AspNetCore.Http.HttpResults; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace DotNetBoilerplate.Api.Catalogs; | ||
|
|
||
| public class GetCatalogByIdEndpoint : IEndpoint | ||
| { | ||
| public static void Map(IEndpointRouteBuilder app) | ||
| { | ||
| app.MapGet("{id:guid}", Handle) | ||
| .WithSummary("Browse catalog by Id"); | ||
| } | ||
|
|
||
| private static async Task<Results<Ok<CatalogDto>, NotFound>> Handle( | ||
| [FromRoute] Guid id, | ||
| [FromServices] IQueryDispatcher queryDispatcher, | ||
| CancellationToken ct | ||
| ) | ||
| { | ||
| var query = new GetCatalogByIdQuery(id); | ||
|
|
||
| var result = await queryDispatcher.QueryAsync(query, ct); | ||
|
|
||
| if (result is null) return TypedResults.NotFound(); | ||
|
|
||
| return TypedResults.Ok(result); | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
src/DotNetBoilerplate.Api/Catalogs/RemoveBookFromCatalogEndpoint.cs
This file contains hidden or 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,35 @@ | ||
| using System.ComponentModel.DataAnnotations; | ||
| using DotNetBoilerplate.Application.Catalogs.Delete; | ||
| using DotNetBoilerplate.Application.Catalogs.RemoveBook; | ||
| using DotNetBoilerplate.Shared.Abstractions.Commands; | ||
| using Microsoft.AspNetCore.Http.HttpResults; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace DotNetBoilerplate.Api.Catalogs; | ||
|
|
||
| internal sealed class RemoveBookFromCatalogEndpoint : IEndpoint | ||
| { | ||
| public static void Map(IEndpointRouteBuilder app) | ||
| { | ||
| app.MapDelete("{catalogId:guid}/books/{bookId:guid}", Handle) | ||
| .RequireAuthorization() | ||
| .WithSummary("Remove book from catalog by Id"); | ||
| } | ||
|
|
||
| private static async Task<IResult> Handle( | ||
| Guid catalogId, Guid bookId, | ||
| [FromServices] ICommandDispatcher commandDispatcher, | ||
| CancellationToken ct | ||
| ) | ||
| { | ||
| var command = new RemoveBookFromCatalogCommand(catalogId, bookId); | ||
|
|
||
| await commandDispatcher.DispatchAsync<RemoveBookFromCatalogCommand>(command, ct); | ||
|
|
||
| return TypedResults.NoContent(); | ||
| } | ||
| private sealed class Request | ||
| { | ||
| [Required] public Guid BookId { get; init; } | ||
| } | ||
| } |
52 changes: 52 additions & 0 deletions
52
src/DotNetBoilerplate.Api/Catalogs/UpdateCatalogEndpoint.cs
This file contains hidden or 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,52 @@ | ||
| using System.ComponentModel.DataAnnotations; | ||
| using DotNetBoilerplate.Application.Catalogs.Update; | ||
| using DotNetBoilerplate.Shared.Abstractions.Commands; | ||
| using Microsoft.AspNetCore.Http.HttpResults; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace DotNetBoilerplate.Api.Catalogs; | ||
|
|
||
| public class UpdateCatalogEndpoint : IEndpoint | ||
| { | ||
| public static void Map(IEndpointRouteBuilder app) | ||
| { | ||
| app.MapPut("{id:guid}", Handle) | ||
| .RequireAuthorization() | ||
| .WithSummary("Update a catalog"); | ||
| } | ||
|
|
||
| private static async Task<Ok<Response>> Handle( | ||
| [FromRoute] Guid id, | ||
| [FromBody] Request request, | ||
| [FromServices] ICommandDispatcher commandDispatcher, | ||
| CancellationToken ct | ||
| ) | ||
| { | ||
| var command = new UpdateCatalogCommand( | ||
| id, | ||
| request.Name, | ||
| request.Genre, | ||
| request.Description | ||
| ); | ||
|
|
||
| var result = await commandDispatcher.DispatchAsync<UpdateCatalogCommand, Guid>(command, ct); | ||
|
|
||
| return TypedResults.Ok(new Response(result)); | ||
| } | ||
|
|
||
| internal sealed record Response( | ||
| Guid Id | ||
| ); | ||
|
|
||
| private sealed class Request | ||
| { | ||
| // ReSharper disable once UnusedAutoPropertyAccessor.Local | ||
| [Required] public string Name { get; init; } | ||
|
|
||
| // ReSharper disable once UnusedAutoPropertyAccessor.Local | ||
| [Required] public string Genre { get; init; } | ||
|
|
||
| // ReSharper disable once UnusedAutoPropertyAccessor.Local | ||
| [Required] public string Description { get; init; } | ||
| } | ||
| } |
This file contains hidden or 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
5 changes: 5 additions & 0 deletions
5
src/DotNetBoilerplate.Application/Catalogs/AddBook/AddBookToCatalogCommand.cs
This file contains hidden or 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,5 @@ | ||
| using DotNetBoilerplate.Shared.Abstractions.Commands; | ||
|
|
||
| namespace DotNetBoilerplate.Application.Catalogs.AddBook; | ||
|
|
||
| public sealed record AddBookToCatalogCommand(Guid CatalogId, Guid BookId) : ICommand<Guid>; |
26 changes: 26 additions & 0 deletions
26
src/DotNetBoilerplate.Application/Catalogs/AddBook/AddBookToCatalogHandler.cs
This file contains hidden or 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,26 @@ | ||
| using DotNetBoilerplate.Core.Catalogs; | ||
| using DotNetBoilerplate.Core.Books; | ||
| using DotNetBoilerplate.Shared.Abstractions.Commands; | ||
| using DotNetBoilerplate.Application.Exceptions; | ||
|
|
||
| namespace DotNetBoilerplate.Application.Catalogs.AddBook; | ||
|
|
||
| internal sealed class AddBookToCatalogHandler( | ||
| ICatalogRepository catalogRepository, | ||
| IBookRepository bookRepository | ||
| ) : ICommandHandler<AddBookToCatalogCommand, Guid> | ||
| { | ||
| public async Task<Guid> HandleAsync(AddBookToCatalogCommand command) | ||
| { | ||
| var catalog = await catalogRepository.GetByIdAsync(command.CatalogId); | ||
| if (catalog is null) | ||
| throw new CatalogNotFoundException(); | ||
| var book = await bookRepository.GetByIdAsync(command.BookId); | ||
| if (book is null) | ||
| throw new BookNotFoundException(); | ||
|
|
||
| await catalogRepository.AddBookToCatalogAsync(book, catalog); | ||
|
|
||
| return catalog.Id; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
albo catalog.AddBook(book) albo book.SetCatalog(catalog)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nie powinniśmy przekładać odpowiedzialności za procesy biznesowe na repozytorium
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do przemyślenia czy czasem nie zwrobić tak że Book ma public Catalog, a katalog nie ma List - bo za każdym update byśmy musieli to zaciągać z bazy