Skip to content

Commit

Permalink
Merge pull request #16 from Tim-Maes/feature/updates
Browse files Browse the repository at this point in the history
Update template config
  • Loading branch information
Tim-Maes committed Apr 8, 2024
2 parents 7b3bba8 + 9daad93 commit 711603c
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"exclude": [
".template.config/**/*",
"*.nuspec",
"readme.md",
"README.md",
"template.json"
],
"rename": {
Expand Down
4 changes: 2 additions & 2 deletions src/GraphR.API/GraphR.API.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand All @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HotChocolate.AspNetCore" Version="14.0.0-p.22" />
<PackageReference Include="HotChocolate.AspNetCore" Version="13.9.0" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions src/GraphR.Application/Books/BooksQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ public sealed class BooksQuery
{
public async Task<BookDto> Book([Service] IGetBookByIdHandler handler, GetBookByIdParameters parameters)
=> await handler.Handle(parameters);

public async Task<BookDto[]> BooksForAuthor([Service] IGetBooksForAuthorQueryHandler handler, GetBooksForAuthorParameters parameters)
=> await handler.Handle(parameters);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using FluentValidation;
using GraphR.Application.Books.Types.Input;
using GraphR.Application.Books.Types.Mappings;
using GraphR.Application.Books.Types.Output;
using GraphR.Domain.Interfaces.Repositories;
using GrapR.Core.Handlers;

namespace GraphR.Application.Books.Handlers.Query;
internal sealed class GetBooksForAuthorQueryHandler
: Handler<GetBooksForAuthorParameters, BookDto[]>, IGetBooksForAuthorQueryHandler
{
private readonly IBookRepository _bookRepository;

public GetBooksForAuthorQueryHandler(IBookRepository bookRepository)
{
_bookRepository = bookRepository;
}

protected override void DefineRules()
{
RuleFor(x => x.AuthorId).GreaterThan(0);
}

protected override async Task<BookDto[]> HandleValidatedRequest(GetBooksForAuthorParameters request)
=> (await _bookRepository.GetByAuthorId(request.AuthorId)).ToOutput();
}

public interface IGetBooksForAuthorQueryHandler : IHandler<GetBooksForAuthorParameters, BookDto[]> { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace GraphR.Application.Books.Types.Input;

public sealed class GetBooksForAuthorParameters
{
public int AuthorId { get; set; }
}
3 changes: 3 additions & 0 deletions src/GraphR.Application/Books/Types/Mappings/BookMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ internal static BookDto ToOutput(this Book book)
Description = book.Description,
Category = book.Category.ToString(),
};

internal static BookDto[] ToOutput(this Book[] books)
=> books.Select(ToOutput).ToArray();
}
2 changes: 1 addition & 1 deletion src/GraphR.Application/GraphR.Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

</ItemGroup>
<ItemGroup>
<PackageReference Include="HotChocolate.Abstractions" Version="14.0.0-p.22" />
<PackageReference Include="HotChocolate.Abstractions" Version="13.9.0" />
</ItemGroup>

</Project>

0 comments on commit 711603c

Please sign in to comment.