Skip to content

Commit 3c986ff

Browse files
committed
updated style
1 parent 476fca8 commit 3c986ff

File tree

54 files changed

+581
-176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+581
-176
lines changed

Directory.Packages.props

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
<PackageVersion Include="Hangfire" Version="1.8.14" />
1313
<PackageVersion Include="Hangfire.Dashboard.Basic.Authentication" Version="7.0.1" />
1414
<PackageVersion Include="Hangfire.EntityFrameworkCore" Version="0.6.0" />
15-
<PackageVersion Include="Hangfire.PostgreSql" Version="1.20.8" />
15+
<PackageVersion Include="Hangfire.PostgreSql" Version="1.20.9" />
1616
<PackageVersion Include="MassTransit.RabbitMQ" Version="8.2.3" />
1717
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.6" />
1818
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
19-
<PackageVersion Include="MediatR" />
19+
<PackageVersion Include="MediatR" Version="12.3.0" />
2020
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.6">
2121
<PrivateAssets>all</PrivateAssets>
2222
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -39,19 +39,20 @@
3939
<PackageVersion Include="PandaTech.BaseConverter" Version="4.0.4" />
4040
<PackageVersion Include="Pandatech.DistributedCache" Version="1.1.0" />
4141
<PackageVersion Include="Pandatech.EFCore.AuditBase" Version="1.0.3" />
42+
<PackageVersion Include="PandaTech.FileExporter" Version="3.1.1" />
4243
<PackageVersion Include="Pandatech.FluentMinimalApiMapper" Version="1.1.0" />
4344
<PackageVersion Include="Pandatech.CommissionCalculator" Version="3.3.0" />
4445
<PackageVersion Include="Pandatech.Communicator" Version="1.0.5" />
4546
<PackageVersion Include="Pandatech.Crypto" Version="2.5.0" />
46-
<PackageVersion Include="Pandatech.GridifyExtensions" Version="1.3.6" />
47+
<PackageVersion Include="Pandatech.GridifyExtensions" Version="1.4.0" />
4748
<PackageVersion Include="Pandatech.MassTransit.PostgresOutbox" Version="1.0.7" />
4849
<PackageVersion Include="Pandatech.PandaVaultClient" Version="3.1.0" />
4950
<PackageVersion Include="Pandatech.RegexBox" Version="1.2.4" />
50-
<PackageVersion Include="Pandatech.ResponseCrafter" Version="2.1.3" />
51+
<PackageVersion Include="Pandatech.ResponseCrafter" Version="2.2.2" />
5152
<PackageVersion Include="Serilog.AspNetCore" Version="8.0.1" />
5253
<PackageVersion Include="Serilog.Enrichers.Environment" Version="3.0.1" />
5354
<PackageVersion Include="Serilog.Sinks.Elasticsearch" Version="10.0.0" />
54-
<PackageVersion Include="SonarAnalyzer.CSharp" Version="9.27.0.93347">
55+
<PackageVersion Include="SonarAnalyzer.CSharp" Version="9.28.0.94264">
5556
<PrivateAssets>all</PrivateAssets>
5657
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
5758
</PackageVersion>

src/Pandatech.CleanArchitecture.Api/Endpoints/Auth/AuthenticationEndpoints.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Pandatech.CleanArchitecture.Application.Features.Auth.Application.UpdatePasswordForced;
99
using Pandatech.CleanArchitecture.Application.Features.Auth.Helpers;
1010
using Pandatech.CleanArchitecture.Application.Features.Auth.Helpers.ApiAuth.MinimalApiExtensions;
11-
using Pandatech.CleanArchitecture.Application.Features.MyAccount.Application.RevokeCurrentToken;
1211
using Pandatech.CleanArchitecture.Application.Features.MyAccount.Application.UpdateOwnPassword;
1312
using Pandatech.CleanArchitecture.Core.Enums;
1413
using ResponseCrafter.Extensions;
@@ -50,7 +49,7 @@ public void AddRoutes(IEndpointRouteBuilder app)
5049
.WithSummary(" \ud83c\udf6a Cookies for the browser and token for the rest of the clients. \ud83c\udf6a")
5150
.WithDescription(
5251
"This endpoint is used to authenticate a user. Be aware that the response will be different depending on the client type.")
53-
.ProducesErrorResponse(400);
52+
.ProducesBadRequest();
5453

5554

5655
groupApp.MapPost("/refresh-token",
@@ -73,7 +72,7 @@ public void AddRoutes(IEndpointRouteBuilder app)
7372
})
7473
.WithSummary(" \ud83c\udf6a Cookies for the browser and token for the rest of the clients. \ud83c\udf6a")
7574
.WithDescription("This endpoint is used to refresh the user token.")
76-
.ProducesErrorResponse(400);
75+
.ProducesBadRequest();
7776

7877

7978
groupApp.MapGet("/state", async (ISender sender, CancellationToken token) =>
@@ -95,6 +94,6 @@ public void AddRoutes(IEndpointRouteBuilder app)
9594
.Authorize(UserRole.User)
9695
.ForcedPasswordChange()
9796
.WithDescription("This endpoint is used to update the user password when it is forced.")
98-
.ProducesErrorResponse(400);
97+
.ProducesBadRequest();
9998
}
10099
}

src/Pandatech.CleanArchitecture.Api/Endpoints/MyAccount/MyAccountEndpoints.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
using Pandatech.CleanArchitecture.Api.Helpers;
55
using Pandatech.CleanArchitecture.Application.Features.Auth.Helpers;
66
using Pandatech.CleanArchitecture.Application.Features.Auth.Helpers.ApiAuth.MinimalApiExtensions;
7+
using Pandatech.CleanArchitecture.Application.Features.MyAccount.Application.Logout;
78
using Pandatech.CleanArchitecture.Application.Features.MyAccount.Application.PersonalInformation;
8-
using Pandatech.CleanArchitecture.Application.Features.MyAccount.Application.RevokeCurrentToken;
99
using Pandatech.CleanArchitecture.Application.Features.MyAccount.Application.UpdateOwnPassword;
1010
using Pandatech.CleanArchitecture.Core.Enums;
1111
using ResponseCrafter.Extensions;
@@ -24,6 +24,7 @@ public void AddRoutes(IEndpointRouteBuilder app)
2424
.MapGroup(RoutePrefix)
2525
.WithTags(TagName)
2626
.WithGroupName(ApiHelper.GroupNameClean)
27+
.DisableAntiforgery()
2728
.WithOpenApi();
2829

2930
groupApp.MapGet("/personal-information", async (ISender sender, CancellationToken token) =>
@@ -42,7 +43,7 @@ public void AddRoutes(IEndpointRouteBuilder app)
4243
})
4344
.Authorize(UserRole.User)
4445
.WithDescription("This endpoint is used to update the user password from its own profile.")
45-
.ProducesErrorResponse(400);
46+
.ProducesBadRequest();
4647

4748

4849
groupApp.MapPost("/logout",
@@ -56,6 +57,6 @@ public void AddRoutes(IEndpointRouteBuilder app)
5657
})
5758
.Authorize(UserRole.User)
5859
.WithDescription("This endpoint is used to logout the user and delete cookies. \ud83c\udf6a")
59-
.ProducesErrorResponse(404);
60+
.ProducesNotFound();
6061
}
6162
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using FluentMinimalApiMapper;
2+
using MediatR;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Pandatech.CleanArchitecture.Api.Helpers;
5+
using Pandatech.CleanArchitecture.Application.Features.Auth.Helpers.ApiAuth.MinimalApiExtensions;
6+
using Pandatech.CleanArchitecture.Application.Features.UserConfig.CreateOrUpdate;
7+
using Pandatech.CleanArchitecture.Application.Features.UserConfig.Delete;
8+
using Pandatech.CleanArchitecture.Application.Features.UserConfig.Get;
9+
using Pandatech.CleanArchitecture.Core.Enums;
10+
using ResponseCrafter.Extensions;
11+
12+
namespace Pandatech.CleanArchitecture.Api.Endpoints.UserConfig;
13+
14+
public class UserConfigEndpoints : IEndpoint
15+
{
16+
private const string BaseRoute = "/user";
17+
private const string TagName = "user-configs";
18+
private static string RoutePrefix => ApiHelper.GetRoutePrefix(1, BaseRoute);
19+
20+
public void AddRoutes(IEndpointRouteBuilder app)
21+
{
22+
var groupApp = app
23+
.MapGroup(RoutePrefix)
24+
.WithTags(TagName)
25+
.WithGroupName(ApiHelper.GroupNameClean)
26+
.DisableAntiforgery()
27+
.WithOpenApi();
28+
29+
groupApp.MapPost("/frontend/configs",
30+
async ([FromBody] CreateOrUpdateUserConfigCommand request, [FromServices] ISender sender,
31+
CancellationToken token) =>
32+
{
33+
await sender.Send(request, token);
34+
return TypedResults.Ok();
35+
})
36+
.WithSummary("Create or update user frontend configs")
37+
.Authorize(UserRole.User)
38+
.ProducesBadRequest();
39+
40+
groupApp.MapGet("/frontend/configs",
41+
async ([AsParameters] GetUserConfigsQuery query, [FromServices] ISender sender, CancellationToken token) =>
42+
{
43+
var configs = await sender.Send(query, token);
44+
return TypedResults.Ok(configs);
45+
})
46+
.WithSummary("Get user frontend configs")
47+
.Authorize(UserRole.User)
48+
.ProducesBadRequest();
49+
50+
groupApp.MapDelete("/frontend/configs",
51+
async ([FromBody] DeleteUserConfigsCommand request, [FromServices] ISender sender,
52+
CancellationToken token) =>
53+
{
54+
await sender.Send(request, token);
55+
return TypedResults.Ok();
56+
})
57+
.WithSummary("Delete user frontend configs")
58+
.Authorize(UserRole.User)
59+
.ProducesBadRequest();
60+
}
61+
}

src/Pandatech.CleanArchitecture.Api/Endpoints/Users/UserEndpoints.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ public void AddRoutes(IEndpointRouteBuilder app)
3232
.MapGroup(RoutePrefix)
3333
.WithTags(TagName)
3434
.WithGroupName(ApiHelper.GroupNameClean)
35+
.DisableAntiforgery()
3536
.WithOpenApi();
3637

37-
groupApp.MapPost("", async (ISender sender, [FromForm] CreateUserCommand command, CancellationToken token) =>
38+
groupApp.MapPost("", async (ISender sender, [FromBody] CreateUserCommand command, CancellationToken token) =>
3839
{
3940
await sender.Send(command, token);
4041
return TypedResults.Ok();
4142
})
4243
.Authorize()
43-
.ProducesErrorResponse(400);
44+
.ProducesBadRequest();
4445

4546
groupApp.MapGet("/{id}", async (ISender sender, long id, CancellationToken token) =>
4647
{
@@ -49,45 +50,45 @@ public void AddRoutes(IEndpointRouteBuilder app)
4950
})
5051
.Authorize()
5152
.RouteBaseConverter()
52-
.ProducesErrorResponse(404);
53+
.ProducesNotFound();
5354

5455

5556
groupApp.MapPut("/{id}",
56-
async (ISender sender, long id, [FromForm] UpdateUserCommand command, CancellationToken token) =>
57+
async (ISender sender, long id, [FromBody] UpdateUserCommand command, CancellationToken token) =>
5758
{
5859
command.Id = id;
5960
await sender.Send(command, token);
6061
return TypedResults.Ok();
6162
})
6263
.Authorize()
6364
.RouteBaseConverter()
64-
.ProducesErrorResponse(400)
65-
.ProducesErrorResponse(409);
65+
.ProducesBadRequest()
66+
.ProducesConflict();
6667

6768

6869
groupApp.MapPatch("/{id}/password",
69-
async (ISender sender, long id, [FromForm] UpdateUserPasswordCommand command, CancellationToken token) =>
70+
async (ISender sender, long id, [FromBody] UpdateUserPasswordCommand command, CancellationToken token) =>
7071
{
7172
command.Id = id;
7273
await sender.Send(command, token);
7374
return TypedResults.Ok();
7475
})
7576
.Authorize()
7677
.RouteBaseConverter()
77-
.ProducesErrorResponse(400)
78-
.ProducesErrorResponse(404);
78+
.ProducesBadRequest()
79+
.ProducesNotFound();
7980

8081
groupApp.MapPatch("/{id}/status",
81-
async (ISender sender, long id, [FromForm] UpdateUserStatusCommand command, CancellationToken token) =>
82+
async (ISender sender, long id, [FromBody] UpdateUserStatusCommand command, CancellationToken token) =>
8283
{
8384
command.Id = id;
8485
await sender.Send(command, token);
8586
return TypedResults.Ok();
8687
})
8788
.Authorize()
8889
.RouteBaseConverter()
89-
.ProducesErrorResponse(400)
90-
.ProducesErrorResponse(404);
90+
.ProducesBadRequest()
91+
.ProducesNotFound();
9192

9293
groupApp.MapDelete("",
9394
async (ISender sender, [FromBody] DeleteUsersCommand command, CancellationToken token) =>
@@ -96,15 +97,15 @@ public void AddRoutes(IEndpointRouteBuilder app)
9697
return TypedResults.Ok();
9798
})
9899
.Authorize()
99-
.ProducesErrorResponse(400);
100+
.ProducesBadRequest();
100101

101102
groupApp.MapGet("", async ([AsParameters] GetUsersQuery request, ISender sender, CancellationToken token) =>
102103
{
103104
var users = await sender.Send(request, token);
104105
return TypedResults.Ok(users);
105106
})
106107
.Authorize()
107-
.ProducesErrorResponse(400);
108+
.ProducesBadRequest();
108109

109110
groupApp.MapGet("/column/distinct",
110111
async ([AsParameters] GetUserColumnDistinctValuesQuery query, ISender sender, CancellationToken token) =>
@@ -113,11 +114,11 @@ public void AddRoutes(IEndpointRouteBuilder app)
113114
return TypedResults.Ok(distinctValues);
114115
})
115116
.Authorize()
116-
.ProducesErrorResponse(400);
117+
.ProducesBadRequest();
117118

118119
groupApp.MapGet("/filters", () => TypedResults.Ok(QueryableExtensions.GetMappings<User>()))
119120
.Authorize()
120121
.WithSummary("Get filter technical information")
121-
.ProducesErrorResponse(400);
122+
.ProducesBadRequest();
122123
}
123124
}

src/Pandatech.CleanArchitecture.Api/appsettings.Local.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"Security": {
2626
"SuperUser": {
2727
"Username": "admin@admin.com",
28-
"Password": "Qwerty123"
28+
"Password": "Qwertyui123@"
2929
},
3030
"Hangfire": {
3131
"Username": "test",

src/Pandatech.CleanArchitecture.Application/Features/Auth/Application/Auth/AuthQueryHandler.cs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,17 @@ public async Task Handle(AuthQuery request, CancellationToken cancellationToken)
3030
return;
3131
}
3232

33-
if (string.IsNullOrWhiteSpace(accessTokenSignature))
34-
{
35-
throw new UnauthorizedException(ErrorMessages.AccessTokenIsRequired);
36-
}
33+
UnauthorizedException.ThrowIfNullOrWhiteSpace(accessTokenSignature, ErrorMessages.AccessTokenIsRequired);
3734

38-
var accessTokenHash = Sha3.Hash(accessTokenSignature);
3935

40-
var tokenEntity = await unitOfWork.UserTokens.GetUserTokenByAccessTokenAsync(accessTokenHash, cancellationToken);
36+
var accessTokenHash = Sha3.Hash(accessTokenSignature);
4137

42-
if (tokenEntity is null || tokenEntity.User.Status is not UserStatus.Active)
43-
{
44-
throw new UnauthorizedException();
45-
}
38+
var tokenEntity = await unitOfWork.Tokens.GetTokenByAccessTokenAsync(accessTokenHash, cancellationToken);
4639

47-
if (tokenEntity.AccessTokenExpiresAt <= DateTime.UtcNow)
48-
{
49-
throw new UnauthorizedException(ErrorMessages.AccessTokenIsExpired);
50-
}
40+
UnauthorizedException.ThrowIfNull(tokenEntity);
41+
UnauthorizedException.ThrowIf(tokenEntity.User.Status is not UserStatus.Active);
42+
UnauthorizedException.ThrowIf(tokenEntity.AccessTokenExpiresAt <= DateTime.UtcNow,
43+
ErrorMessages.AccessTokenIsExpired);
5144

5245
var identity = new Identity
5346
{
@@ -59,7 +52,7 @@ public async Task Handle(AuthQuery request, CancellationToken cancellationToken)
5952
UserRole = tokenEntity.User.Role,
6053
CreatedAt = tokenEntity.User.CreatedAt,
6154
UpdatedAt = tokenEntity.User.UpdatedAt,
62-
UserTokenId = tokenEntity.Id,
55+
TokenId = tokenEntity.Id,
6356
AccessTokenSignature = accessTokenSignature,
6457
AccessTokenExpiration = tokenEntity.AccessTokenExpiresAt
6558
};

src/Pandatech.CleanArchitecture.Application/Features/Auth/Application/CreateToken/CreateTokenCommandHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public async Task<CreateTokenCommandResponse> Handle(CreateTokenCommand request,
3636
UpdatedAt = now
3737
};
3838

39-
unitOfWork.UserTokens.Add(token);
39+
unitOfWork.Tokens.Add(token);
4040
await unitOfWork.SaveChangesAsync(cancellationToken);
4141

4242
return CreateTokenCommandResponse.MapFromEntity(token, accessTokenSignature, refreshTokenSignature);

src/Pandatech.CleanArchitecture.Application/Features/Auth/Application/Login/LoginCommandHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ public async Task<LoginCommandResponse> Handle(LoginCommand request, Cancellatio
2020
if (user is null || user.Status != UserStatus.Active ||
2121
!argon2Id.VerifyHash(request.Password, user.PasswordHash))
2222
{
23-
throw new BadRequestException(ErrorMessages.InvalidUsernameOrPassword);
23+
throw new BadRequestException(ErrorMessages.InvalidCredentials);
2424
}
2525

26-
var userToken = await sender.Send(new CreateTokenCommand(user.Id), cancellationToken);
26+
var token = await sender.Send(new CreateTokenCommand(user.Id), cancellationToken);
2727

28-
return LoginCommandResponse.MapFromEntity(userToken, user.Role, user.ForcePasswordChange);
28+
return LoginCommandResponse.MapFromEntity(token, user.Role, user.ForcePasswordChange);
2929
}
3030
}

0 commit comments

Comments
 (0)