Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d02a6b0

Browse files
feat: adição do arquivo ContaineresEndpoints.cs
1 parent 1b91b13 commit d02a6b0

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using ContainRs.Api.Contracts;
2+
using ContainRs.Api.Domain;
3+
using Microsoft.AspNetCore.Mvc;
4+
5+
namespace ContainRs.Api.Conteineres;
6+
7+
public static class ContaineresEndpoints
8+
{
9+
public const string ENDPOINT_NAME_GET_CONTEINER = "GetConteiner";
10+
11+
public static IEndpointRouteBuilder MapConteineresEndpoints(this IEndpointRouteBuilder builder)
12+
{
13+
var group = builder
14+
.MapGroup(EndpointConstants.ROUTE_CONTEINERES)
15+
.RequireAuthorization(builder => builder.RequireRole("Cliente"))
16+
.WithTags(EndpointConstants.TAG_CONTEINERES)
17+
.WithOpenApi();
18+
19+
group
20+
.MapGetConteinerById();
21+
22+
return builder;
23+
}
24+
25+
public static RouteGroupBuilder MapGetConteinerById(this RouteGroupBuilder builder)
26+
{
27+
builder.MapGet("{id:guid}", async (
28+
[FromRoute] Guid id,
29+
[FromServices] IRepository<Conteiner> repository) =>
30+
{
31+
32+
var conteiner = await repository
33+
.GetFirstAsync(
34+
c => c.Id == id,
35+
p => p.Id);
36+
if (conteiner is null) return Results.NotFound();
37+
38+
return Results.Ok(ConteinerResponse.From(conteiner));
39+
})
40+
.WithName(ENDPOINT_NAME_GET_CONTEINER)
41+
.WithSummary("Cliente consulta informações sobre o contêiner")
42+
.Produces(StatusCodes.Status404NotFound)
43+
.Produces<ConteinerResponse>(StatusCodes.Status200OK);
44+
45+
return builder;
46+
}
47+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /