Skip to content

Commit

Permalink
minimal api upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
HaikAsatryan committed May 11, 2024
1 parent ba0c157 commit 6368750
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,17 @@ public void AddRoutes(IEndpointRouteBuilder app)

if (clientType != ClientType.Browser)
{
return Results.Ok(response);
return TypedResults.Ok(response);
}

var domain = configuration["Security:CookieDomain"]!;
httpContextAccessor.HttpContext!.PrepareAndSetCookies(response, environment, domain);

return Results.Ok(response);
return TypedResults.Ok(response);
})
.WithSummary(" \ud83c\udf6a Cookies for the browser and token for the rest of the clients. \ud83c\udf6a")
.WithDescription(
"This endpoint is used to authenticate a user. Be aware that the response will be different depending on the client type.")
.Produces<LoginV1CommandResponse>()
.Produces<ErrorResponse>(400);


Expand All @@ -65,13 +64,13 @@ public void AddRoutes(IEndpointRouteBuilder app)

if (clientType != ClientType.Browser)
{
return Results.Ok(response);
return TypedResults.Ok(response);
}

var domain = configuration["Security:CookieDomain"]!;
httpContextAccessor.HttpContext!.PrepareAndSetCookies(response, environment, domain);

return Results.Ok(response);
return TypedResults.Ok(response);
})
.WithSummary(" \ud83c\udf6a Cookies for the browser and token for the rest of the clients. \ud83c\udf6a")
.WithDescription("This endpoint is used to refresh the user token.")
Expand All @@ -81,11 +80,10 @@ public void AddRoutes(IEndpointRouteBuilder app)
groupApp.MapGet("/state", async (ISender sender) =>
{
var identity = await sender.Send(new GetIdentityStateV1Query());
return Results.Ok(identity);
return TypedResults.Ok(identity);
})
.Authorize(UserRole.User)
.WithDescription("This endpoint is used to get the current user state.")
.Produces<IdentityStateV1CommandResponse>();
.WithDescription("This endpoint is used to get the current user state.");


groupApp.MapPost("/logout",
Expand All @@ -95,7 +93,7 @@ public void AddRoutes(IEndpointRouteBuilder app)
var domain = configuration["Security:CookieDomain"]!;
await sender.Send(new RevokeCurrentTokenV1Command());
httpContextAccessor.HttpContext!.DeleteAllCookies(environment, domain);
return Results.Ok();
return TypedResults.Ok();
})
.Authorize(UserRole.User)
.WithDescription("This endpoint is used to logout the user and delete cookies. \ud83c\udf6a")
Expand All @@ -105,7 +103,7 @@ public void AddRoutes(IEndpointRouteBuilder app)
async (ISender sender, UpdatePasswordForcedV1Command command) =>
{
await sender.Send(command);
return Results.Ok();
return TypedResults.Ok();
})
.Authorize(UserRole.User, false, true)
.WithDescription("This endpoint is used to update the user password when it is forced.")
Expand All @@ -114,7 +112,7 @@ public void AddRoutes(IEndpointRouteBuilder app)
groupApp.MapPatch("/password/own", async (ISender sender, UpdateOwnPasswordV1Command command) =>
{
await sender.Send(command);
return Results.Ok();
return TypedResults.Ok();
})
.Authorize(UserRole.User)
.WithDescription("This endpoint is used to update the user password from its own profile.")
Expand Down
18 changes: 6 additions & 12 deletions src/Pandatech.VerticalSlices/Features/User/Api/UserV1Endpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,17 @@ public void AddRoutes(IEndpointRouteBuilder app)
groupApp.MapPost("", async (ISender mediator, [FromBody] CreateUserV1Command command) =>
{
await mediator.Send(command);
return Results.Ok();
return TypedResults.Ok();
})
.Authorize()
.Produces(200)
.Produces<ErrorResponse>(400);

groupApp.MapGet("/{id}", async (ISender mediator, [PandaParameterBaseConverter] long id) =>
{
var user = await mediator.Send(new GetUserByIdV1Query(id));
return Results.Ok(user);
return TypedResults.Ok(user);
})
.Authorize()
.Produces<GetUserByIdV1QueryResponse>()
.Produces<ErrorResponse>(404);


Expand All @@ -53,10 +51,9 @@ public void AddRoutes(IEndpointRouteBuilder app)
{
command.Id = id;
await mediator.Send(command);
return Results.Ok();
return TypedResults.Ok();
})
.Authorize()
.Produces(200)
.Produces<ErrorResponse>(400)
.Produces<ErrorResponse>(409);

Expand All @@ -67,10 +64,9 @@ public void AddRoutes(IEndpointRouteBuilder app)
{
command.Id = id;
await mediator.Send(command);
return Results.Ok();
return TypedResults.Ok();
})
.Authorize()
.Produces(200)
.Produces<ErrorResponse>(400)
.Produces<ErrorResponse>(404);

Expand All @@ -80,21 +76,19 @@ public void AddRoutes(IEndpointRouteBuilder app)
{
command.Id = id;
await mediator.Send(command);
return Results.Ok();
return TypedResults.Ok();
})
.Authorize()
.Produces(200)
.Produces<ErrorResponse>(400)
.Produces<ErrorResponse>(404);

groupApp.MapDelete("",
async (ISender mediator, [FromBody] DeleteUsersV1Command command) =>
{
await mediator.Send(command);
return Results.Ok();
return TypedResults.Ok();
})
.Authorize()
.Produces(200)
.Produces<ErrorResponse>(400);
}
}

0 comments on commit 6368750

Please sign in to comment.