-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEAT: Minimal APIs implementation (#63)
## Description The classic Controllers implementation is replaced by the new, more modern and performant Minimal APIs implementation. ## Related Issue Closes #56. ## Motivation and Context As explained in #56, the Minimal APIs implementation brings improved performance to the request execution because of the reduced amount of dependencies they provide. They are also more flexible to make this a better fit even for smaller projects as they are easy to compose and have a better system to document them in Swagger. ## How Has This Been Tested? This should be transparent and the endpoints respond exactly as the ones provided by the Controllers. ## Types of changes - [ ] Bug fix (non-breaking change which fixes an issue) - [X] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Checklist: - [X] My code follows the code style of this project. - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly. - [X] I have read the **CONTRIBUTING** document. - [ ] I have added tests to cover my changes. - [X] All new and existing tests passed.
- Loading branch information
Showing
37 changed files
with
661 additions
and
544 deletions.
There are no files selected for viewing
97 changes: 0 additions & 97 deletions
97
src/Content/Backend/Solution/Monaco.Template.Backend.Api/Controllers/CompaniesController.cs
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
src/Content/Backend/Solution/Monaco.Template.Backend.Api/Controllers/CountriesController.cs
This file was deleted.
Oops, something went wrong.
43 changes: 0 additions & 43 deletions
43
src/Content/Backend/Solution/Monaco.Template.Backend.Api/Controllers/FilesController.cs
This file was deleted.
Oops, something went wrong.
103 changes: 0 additions & 103 deletions
103
src/Content/Backend/Solution/Monaco.Template.Backend.Api/Controllers/ProductsController.cs
This file was deleted.
Oops, something went wrong.
88 changes: 88 additions & 0 deletions
88
src/Content/Backend/Solution/Monaco.Template.Backend.Api/Endpoints/Companies.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,88 @@ | ||
using Asp.Versioning.Builder; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Http.HttpResults; | ||
using Microsoft.AspNetCore.Mvc; | ||
#if (!disableAuth) | ||
using Monaco.Template.Backend.Api.Auth; | ||
#endif | ||
using Monaco.Template.Backend.Api.DTOs; | ||
using Monaco.Template.Backend.Api.DTOs.Extensions; | ||
using Monaco.Template.Backend.Application.DTOs; | ||
using Monaco.Template.Backend.Application.Features.Company; | ||
using Monaco.Template.Backend.Common.Api.Application; | ||
using Monaco.Template.Backend.Common.Api.MinimalApi; | ||
using Monaco.Template.Backend.Common.Domain.Model; | ||
|
||
namespace Monaco.Template.Backend.Api.Endpoints; | ||
|
||
public static class Companies | ||
{ | ||
public static IEndpointRouteBuilder AddCompanies(this IEndpointRouteBuilder builder, ApiVersionSet versionSet) | ||
{ | ||
var companies = builder.CreateApiGroupBuilder(versionSet, "Companies"); | ||
|
||
companies.MapGet("", | ||
Task<Results<Ok<Page<CompanyDto>>, NotFound>> ([FromServices] ISender sender, | ||
HttpRequest request) => | ||
sender.ExecuteQueryAsync(new GetCompanyPage.Query(request.Query)), | ||
"GetCompanies", | ||
#if (disableAuth) | ||
"Gets a page of companies"); | ||
#else | ||
"Gets a page of companies") | ||
.RequireAuthorization(Scopes.CompaniesRead); | ||
#endif | ||
|
||
companies.MapGet("{id:guid}", | ||
Task<Results<Ok<CompanyDto?>, NotFound>> ([FromServices] ISender sender, | ||
[FromRoute] Guid id) => | ||
sender.ExecuteQueryAsync(new GetCompanyById.Query(id)), | ||
"GetCompany", | ||
#if (disableAuth) | ||
"Gets a company by Id"); | ||
#else | ||
"Gets a company by Id") | ||
.RequireAuthorization(Scopes.CompaniesRead); | ||
#endif | ||
|
||
companies.MapPost("", | ||
Task<Results<Created<Guid>, NotFound, ValidationProblem>> ([FromServices] ISender sender, | ||
[FromBody] CompanyCreateEditDto dto, | ||
HttpContext context) => | ||
sender.ExecuteCommandAsync(dto.MapCreateCommand(), "api/v{0}/Companies/{1}", context.GetRequestedApiVersion()!), | ||
"CreateCompany", | ||
#if (disableAuth) | ||
"Create a new company"); | ||
#else | ||
"Create a new company") | ||
.RequireAuthorization(Scopes.CompaniesWrite); | ||
#endif | ||
|
||
companies.MapPut("{id:guid}", | ||
Task<Results<NoContent, NotFound, ValidationProblem>> ([FromServices] ISender sender, | ||
[FromRoute] Guid id, | ||
[FromBody] CompanyCreateEditDto dto) => | ||
sender.ExecuteCommandEditAsync(dto.MapEditCommand(id)), | ||
"EditCompany", | ||
#if (disableAuth) | ||
"Edit an existing company by Id"); | ||
#else | ||
"Edit an existing company by Id") | ||
.RequireAuthorization(Scopes.CompaniesWrite); | ||
#endif | ||
|
||
companies.MapDelete("{id:guid}", | ||
Task<Results<Ok, NotFound, ValidationProblem>> ([FromServices] ISender sender, | ||
[FromRoute] Guid id) => | ||
sender.ExecuteCommandDeleteAsync(new DeleteCompany.Command(id)), | ||
"DeleteCompany", | ||
#if (disableAuth) | ||
"Delete an existing company by Id"); | ||
#else | ||
"Delete an existing company by Id") | ||
.RequireAuthorization(Scopes.CompaniesWrite); | ||
#endif | ||
|
||
return builder; | ||
} | ||
} |
Oops, something went wrong.