Skip to content

Commit 0628d0c

Browse files
Merge branch 'release/v1.0.4'
2 parents 0acc752 + a660ab5 commit 0628d0c

23 files changed

+149
-180
lines changed

docker-compose.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ services:
66
- urls=http://0.0.0.0:8080
77
- S3AwsSettings__AccessKey=${S3_ACCESS_KEY}
88
- S3AwsSettings__SecretKey=${S3_SECRET_KEY}
9-
expose:
9+
- RedisDatabaseSettings__Password=${REDIS_PASSWORD}
10+
- ElasticsearchSettings__Password=${ELASTICSEARCH_PASSWORD}
11+
- DatabaseSettings__DatabaseConnection=${DATABASE_CONNECTION}
12+
- HangfireSettings__Storage__ConnectionString=${DATABASE_CONNECTION}
13+
- HangfireSettings__Credentials__Username=${HANGFIRE_USERNAME}
14+
- HangfireSettings__Credentials__Password=${HANGFIRE_PASSWORD}
15+
- SecuritySettings__JwtSettings__SecretKey=${JWT_SECRET_KEY}
16+
ports:
1017
- "8081:8080"
1118
networks:
1219
- the-template-network

src/Api/appsettings.Production.json

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
},
3131
"SecuritySettings": {
3232
"JwtSettings": {
33-
"SecretKey": "ERcSDBHO2LfN6aSJgvVhUwdSG9j99JbrvDQh9oCAwaOG/gdy8UTiBY+yiHFBJ/Ky",
3433
"ExpireTimeAccessToken": 1,
3534
"ExpireTimeRefreshToken": 1
3635
}
@@ -44,7 +43,7 @@
4443
"IsEnabled": true
4544
},
4645
"SerilogSettings": {
47-
"IsDistributeLog": true,
46+
"IsDistributeLog": false,
4847
"SeqUrl": "seq:5341"
4948
},
5049
"EmailSettings": {
@@ -66,7 +65,6 @@
6665
"RedisDatabaseSettings": {
6766
"Host": "redis",
6867
"Port": 6379,
69-
"Password": "123456",
7068
"IsEnbaled": false
7169
},
7270
"QueueSettings": {
@@ -79,12 +77,8 @@
7977
"DefaultSize": 9999,
8078
"IsEnbaled": false,
8179
"DefaultIndex": "default_index",
82-
"Password": "Admin@123",
8380
"Username": "elastic"
8481
},
85-
"DatabaseSettings": {
86-
"DatabaseConnection": "Host=database;Port=5432;Username=theusername;Password=123456;Database=the_database"
87-
},
8882
"HangfireSettings": {
8983
"Enable": false,
9084
"Route": "/jobs",
@@ -104,18 +98,13 @@
10498
"WorkerCount": 5
10599
},
106100
"Storage": {
107-
"ConnectionString": "Host=database;Port=5432;Username=theusername;Password=123456;Database=the_database;Include Error Detail=true;",
108101
"Options": {
109102
"CommandBatchMaxTimeout": "00:05:00",
110103
"QueuePollInterval": "00:00:01",
111104
"UseRecommendedIsolationLevel": true,
112105
"SlidingInvisibilityTimeout": "00:05:00",
113106
"DisableGlobalLocks": true
114107
}
115-
},
116-
"Credentials": {
117-
"Username": "admin",
118-
"Password": "Admin@123"
119108
}
120109
},
121110
"CacheSettings": {

src/Application/Common/Behaviors/ProcessImagePathBehavior.cs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Reflection;
33
using Application.Common.Interfaces.Services.Storage;
44
using Application.Common.Security;
5+
using Contracts.ApiWrapper;
56
using Contracts.Dtos.Responses;
67
using Mediator;
78
using Serilog;
@@ -13,35 +14,51 @@ public class ProcessImagePathBehavior<TMessage, TResponse>(
1314
IStorageService storageService
1415
) : MessagePostProcessor<TMessage, TResponse>
1516
where TMessage : notnull, IMessage
17+
where TResponse : notnull
1618
{
1719
protected override ValueTask Handle(
1820
TMessage message,
1921
TResponse response,
2022
CancellationToken cancellationToken
2123
)
2224
{
25+
Type responseType = typeof(TResponse);
26+
if (
27+
!responseType.IsGenericType
28+
|| responseType.GetGenericTypeDefinition() != typeof(Result<>)
29+
)
30+
{
31+
return default!;
32+
}
33+
34+
object? value = ResultTypeHelper.ExtractValue(response);
35+
if (value == null)
36+
{
37+
return default!;
38+
}
39+
2340
// Check if the response is a PaginationResponse and handle accordingly
41+
Type resultType = responseType.GetGenericArguments()[0];
2442
if (
25-
typeof(TResponse).IsGenericType
26-
&& typeof(TResponse).GetGenericTypeDefinition() == typeof(PaginationResponse<>)
43+
resultType.IsGenericType
44+
&& resultType.GetGenericTypeDefinition() == typeof(PaginationResponse<>)
2745
)
2846
{
29-
ProcessPaginationResponse(response);
47+
ProcessPaginationResponse(value);
3048
return default!;
3149
}
3250

3351
// Handle non-pagination responses
34-
ProcessSingleResponse(response);
35-
52+
ProcessSingleResponse(value);
3653
return default!;
3754
}
3855

3956
// Processes responses of type PaginationResponse<>
40-
private void ProcessPaginationResponse(TResponse response)
57+
private void ProcessPaginationResponse(object response)
4158
{
42-
PropertyInfo? dataProperty = typeof(TResponse).GetProperty(
43-
nameof(PaginationResponse<object>.Data)
44-
);
59+
PropertyInfo? dataProperty = response
60+
.GetType()
61+
.GetProperty(nameof(PaginationResponse<object>.Data));
4562
if (dataProperty == null)
4663
{
4764
return;
@@ -58,8 +75,8 @@ private void ProcessPaginationResponse(TResponse response)
5875
}
5976

6077
// Processes individual response properties with the [File] attribute
61-
private void ProcessSingleResponse(TResponse response) =>
62-
ProcessDataPropertiesWithFileAttribute(response!);
78+
private void ProcessSingleResponse(object response) =>
79+
ProcessDataPropertiesWithFileAttribute(response);
6380

6481
// Processes the properties of a data object within a pagination response
6582
private void ProcessDataPropertiesWithFileAttribute(object data)

src/Application/Common/Extensions/PaginationExtension.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Microsoft.EntityFrameworkCore;
77
using Newtonsoft.Json;
88
using SharedKernel.Extensions;
9-
using SharedKernel.Extensions.Encryption;
109
using SharedKernel.Extensions.Expressions;
1110
using SharedKernel.Extensions.QueryExtensions;
1211
using SharedKernel.Extensions.Reflections;

src/Application/Common/Interfaces/Services/IActionAccessorService.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Microsoft.AspNetCore.Http;
2+
3+
namespace Application.Common.Interfaces.Services;
4+
5+
public interface IHttpContextAccessorService
6+
{
7+
HttpContext? HttpContext { get; }
8+
string? GetRouteValue(string key);
9+
string? GetHttpMethod();
10+
string? GetRequestPath();
11+
string? GetId();
12+
}

src/Application/Features/Common/Mapping/Roles/RoleMapping.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,6 @@
33

44
namespace Application.Features.Common.Mapping.Roles;
55

6-
// public class RoleMapping : Profile
7-
// {
8-
// public RoleMapping()
9-
// {
10-
// CreateMap<RoleModel, Role>()
11-
// .ForMember(
12-
// dest => dest.Name,
13-
// opt => opt.MapFrom(src => src.Name.ToSnakeCase().ToUpper())
14-
// );
15-
16-
// CreateMap<RoleClaimModel, RoleClaim>()
17-
// .ForMember(dest => dest.Id, opt => opt.Ignore())
18-
// .AfterMap(
19-
// (src, dest) =>
20-
// {
21-
// if (src.Id != null)
22-
// {
23-
// dest.Id = src.Id.Value;
24-
// }
25-
// }
26-
// );
27-
// CreateMap<RoleClaim, RoleClaimDetailProjection>();
28-
// }
29-
// }
30-
316
public static class RoleMapping
327
{
338
public static List<RoleClaim>? ToListRoleClaim(this List<RoleClaimModel>? roleClaims) =>

src/Application/Features/Common/Mapping/Users/UserMapping.cs

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,6 @@
33

44
namespace Application.Features.Common.Mapping.Users;
55

6-
// public class UserMapping : Profile
7-
// {
8-
// public UserMapping()
9-
// {
10-
// CreateMap<User, UserProjection>().IncludeMembers(x => x.Address);
11-
12-
// CreateMap<User, UserDetailProjection>()
13-
// .IncludeMembers(x => x.Address)
14-
// .ForMember(
15-
// dest => dest.Roles,
16-
// opt => opt.MapFrom(src => src.UserRoles!.Select(x => x.Role))
17-
// );
18-
// CreateMap<Address, UserProjection>();
19-
// CreateMap<Address, UserDetailProjection>();
20-
21-
// CreateMap<Role, RoleDetailProjection>();
22-
// CreateMap<RoleClaim, RoleClaimDetailProjection>();
23-
// CreateMap<UserClaim, UserClaimDetailProjection>();
24-
25-
// CreateMap<UserClaimModel, UserClaim>()
26-
// .AfterMap(
27-
// (src, dest, context) =>
28-
// {
29-
// if (
30-
// Enum.TryParse(
31-
// context.Items[nameof(UserClaim.Type)]?.ToString(),
32-
// out KindaUserClaimType type
33-
// )
34-
// )
35-
// {
36-
// dest.Type = type;
37-
// }
38-
39-
// if (
40-
// Ulid.TryParse(
41-
// context.Items[nameof(UserClaim.UserId)]?.ToString(),
42-
// out Ulid id
43-
// )
44-
// )
45-
// {
46-
// dest.UserId = id;
47-
// }
48-
49-
// if (src.Id == null || src.Id == Ulid.Empty)
50-
// {
51-
// dest.Id = Ulid.NewUlid();
52-
// }
53-
// }
54-
// );
55-
// }
56-
// }
57-
586
public static class UserMapping
597
{
608
public static UserClaimDetailProjection ToRoleClaimDetailProjection(this UserClaim userClaim)

src/Application/Features/Common/Validators/Roles/RoleValidator.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ namespace Application.Features.Common.Validators.Roles;
1212
public class RoleValidator : AbstractValidator<RoleModel>
1313
{
1414
private readonly IRoleManagerService roleManagerService;
15-
private readonly IActionAccessorService actionAccessorService;
15+
private readonly IHttpContextAccessorService httpContextAccessorService;
1616

1717
public RoleValidator(
1818
IRoleManagerService roleManagerService,
19-
IActionAccessorService actionAccessorService
19+
IHttpContextAccessorService httpContextAccessorService
2020
)
2121
{
2222
this.roleManagerService = roleManagerService;
23-
this.actionAccessorService = actionAccessorService;
23+
this.httpContextAccessorService = httpContextAccessorService;
2424
ApplyRules();
2525
}
2626

2727
private void ApplyRules()
2828
{
29-
_ = Ulid.TryParse(actionAccessorService.Id, out Ulid id);
29+
_ = Ulid.TryParse(httpContextAccessorService.GetId(), out Ulid id);
3030

3131
RuleFor(x => x.Name)
3232
.NotEmpty()
@@ -51,7 +51,7 @@ private void ApplyRules()
5151
IsNameAvailableAsync(name, cancellationToken: cancellationToken)
5252
)
5353
.When(
54-
_ => actionAccessorService.GetHttpMethod() == HttpMethod.Post.ToString(),
54+
_ => httpContextAccessorService.GetHttpMethod() == HttpMethod.Post.ToString(),
5555
ApplyConditionTo.CurrentValidator
5656
)
5757
.WithState(x =>
@@ -65,7 +65,7 @@ private void ApplyRules()
6565
(name, cancellationToken) => IsNameAvailableAsync(name, id, cancellationToken)
6666
)
6767
.When(
68-
_ => actionAccessorService.GetHttpMethod() == HttpMethod.Put.ToString(),
68+
_ => httpContextAccessorService.GetHttpMethod() == HttpMethod.Put.ToString(),
6969
ApplyConditionTo.CurrentValidator
7070
)
7171
.WithState(x =>

src/Application/Features/Common/Validators/Users/UserValidator.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ namespace Application.Features.Common.Validators.Users;
1111

1212
public partial class UserValidator : AbstractValidator<UserModel>
1313
{
14-
private readonly IActionAccessorService accessorService;
14+
private readonly IHttpContextAccessorService httpContextAccessorService;
1515
private readonly IUserManagerService userManagerService;
1616

1717
public UserValidator(
1818
IUserManagerService userManagerService,
19-
IActionAccessorService accessorService
19+
IHttpContextAccessorService httpContextAccessorService
2020
)
2121
{
22-
this.accessorService = accessorService;
22+
this.httpContextAccessorService = httpContextAccessorService;
2323
this.userManagerService = userManagerService;
2424
ApplyRules();
2525
}
2626

2727
private void ApplyRules()
2828
{
29-
_ = Ulid.TryParse(accessorService.Id, out Ulid id);
29+
_ = Ulid.TryParse(httpContextAccessorService.GetId(), out Ulid id);
3030

3131
RuleFor(x => x.LastName)
3232
.NotEmpty()
@@ -94,7 +94,7 @@ private void ApplyRules()
9494
(email, cancellationToken) => IsEmailAvailableAsync(email!, id, cancellationToken)
9595
)
9696
.When(
97-
_ => accessorService.GetHttpMethod() == HttpMethod.Put.ToString(),
97+
_ => httpContextAccessorService.GetHttpMethod() == HttpMethod.Put.ToString(),
9898
ApplyConditionTo.CurrentValidator
9999
)
100100
.WithState(x =>
@@ -109,7 +109,7 @@ private void ApplyRules()
109109
IsEmailAvailableAsync(email!, cancellationToken: cancellationToken)
110110
)
111111
.When(
112-
_ => accessorService.GetHttpMethod() == HttpMethod.Post.ToString(),
112+
_ => httpContextAccessorService.GetHttpMethod() == HttpMethod.Post.ToString(),
113113
ApplyConditionTo.CurrentValidator
114114
)
115115
.WithState(x =>

src/Application/Features/Roles/Commands/Create/CreateRoleCommandValidator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ public class CreateRoleCommandValidator : AbstractValidator<CreateRoleCommand>
99
{
1010
public CreateRoleCommandValidator(
1111
IRoleManagerService roleManagerService,
12-
IActionAccessorService actionAccessorService
12+
IHttpContextAccessorService httpContextAccessorService
1313
)
1414
{
15-
Include(new RoleValidator(roleManagerService, actionAccessorService));
15+
Include(new RoleValidator(roleManagerService, httpContextAccessorService));
1616
}
1717
}

src/Application/Features/Roles/Commands/Update/UpdateRoleCommandValidator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ public class UpdateRoleCommandValidator : AbstractValidator<RoleUpdateRequest>
99
{
1010
public UpdateRoleCommandValidator(
1111
IRoleManagerService roleManagerService,
12-
IActionAccessorService actionAccessorService
12+
IHttpContextAccessorService httpContextAccessorService
1313
)
1414
{
15-
Include(new RoleValidator(roleManagerService, actionAccessorService));
15+
Include(new RoleValidator(roleManagerService, httpContextAccessorService));
1616
}
1717
}

0 commit comments

Comments
 (0)