diff --git a/README.md b/README.md index 1ba9d2f..cd9bf35 100644 --- a/README.md +++ b/README.md @@ -83,44 +83,46 @@ public override async Task> HandleAsync([FromBo Option to use service dependency injection instead of constructor ``` csharp // File: sample/SampleEndpointApp/AuthorEndpoints/List.cs - public class List : BaseAsyncEndpoints.WithRequest.WithResponse> - { - private readonly IAsyncRepository repository; - private readonly IMapper mapper; +public class List : BaseAsyncEndpoint + .WithRequest + .WithResponse> +{ + private readonly IAsyncRepository repository; + private readonly IMapper mapper; - public List( - IAsyncRepository repository, - IMapper mapper) + public List( + IAsyncRepository repository, + IMapper mapper) + { + this.repository = repository; + this.mapper = mapper; + } + [HttpGet("/authors")] + [SwaggerOperation( + Summary = "List all Authors", + Description = "List all Authors", + OperationId = "Author.List", + Tags = new[] { "AuthorEndpoint" }) + ] + public override async Task>> HandleAsync( + + [FromQuery] AuthorListRequest request, + CancellationToken cancellationToken = default) + { + if (request.PerPage == 0) { - this.repository = repository; - this.mapper = mapper; + request.PerPage = 10; } - [HttpGet("/authors")] - [SwaggerOperation( - Summary = "List all Authors", - Description = "List all Authors", - OperationId = "Author.List", - Tags = new[] { "AuthorEndpoint" }) - ] - public override async Task>> HandleAsync( - - [FromQuery] AuthorListRequest request, - CancellationToken cancellationToken = default) + if (request.Page == 0) { - if (request.PerPage == 0) - { - request.PerPage = 10; - } - if (request.Page == 0) - { - request.Page = 1; - } - var result = (await repository.ListAllAsync(request.PerPage, request.Page, cancellationToken)) - .Select(i => mapper.Map(i)); - - return Ok(result); + request.Page = 1; } + var result = (await repository.ListAllAsync(request.PerPage, request.Page, cancellationToken)) + .Select(i => mapper.Map(i)); + + return Ok(result); } +} ``` Examples of the configuration can be found in the sample API project @@ -129,7 +131,7 @@ Examples of the configuration can be found in the sample API project ### Working with Endpoints, Requests, and Results in Visual Studio -![api-endpoints](https://user-images.githubusercontent.com/782127/80016785-9bfef580-84a1-11ea-8b9f-58e37fd52d3b.gif) +![api-endpoints-2](https://user-images.githubusercontent.com/782127/107803375-7e509480-6d30-11eb-97bc-45da8396e8e8.gif) ## Open Questions