Skip to content

Commit 86b0b21

Browse files
committed
refactor(F3): Refactor
Remove all f3 prefix of all class and change register name to registration center
1 parent 2ec18ba commit 86b0b21

File tree

17 files changed

+85
-93
lines changed

17 files changed

+85
-93
lines changed
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,23 @@
99

1010
namespace F3.BusinessLogic;
1111

12-
public sealed class F3Service : IServiceHandler<F3AppRequestModel, F3AppResponseModel>
12+
public sealed class Service : IServiceHandler<AppRequestModel, AppResponseModel>
1313
{
14-
private readonly Lazy<IF3Repository> _repository;
14+
private readonly Lazy<IRepository> _repository;
1515
private readonly Lazy<IAppIdGenerator> _idGenerator;
1616

17-
public F3Service(Lazy<IF3Repository> repository, Lazy<IAppIdGenerator> idGenerator)
17+
public Service(Lazy<IRepository> repository, Lazy<IAppIdGenerator> idGenerator)
1818
{
1919
_repository = repository;
2020
_idGenerator = idGenerator;
2121
}
2222

23-
public async Task<F3AppResponseModel> ExecuteAsync(
24-
F3AppRequestModel request,
25-
CancellationToken ct
26-
)
23+
public async Task<AppResponseModel> ExecuteAsync(AppRequestModel request, CancellationToken ct)
2724
{
2825
var isEmailFound = await _repository.Value.DoesEmailExistsAsync(request.Email, ct);
2926
if (isEmailFound)
3027
{
31-
return F3Constant.DefaultResponse.App.EMAIL_ALREADY_EXISTS;
28+
return Constant.DefaultResponse.App.EMAIL_ALREADY_EXISTS;
3229
}
3330

3431
var isPasswordValid = await _repository.Value.IsPasswordValidAsync(
@@ -38,20 +35,20 @@ CancellationToken ct
3835
);
3936
if (!isPasswordValid)
4037
{
41-
return F3Constant.DefaultResponse.App.PASSWORD_IS_INVALID;
38+
return Constant.DefaultResponse.App.PASSWORD_IS_INVALID;
4239
}
4340

4441
var user = CreateNewUser(request);
4542
var result = await _repository.Value.CreateUserAsync(user, ct);
4643
if (!result)
4744
{
48-
return F3Constant.DefaultResponse.App.SERVER_ERROR;
45+
return Constant.DefaultResponse.App.SERVER_ERROR;
4946
}
5047

51-
return new() { AppCode = F3Constant.AppCode.SUCCESS };
48+
return new() { AppCode = Constant.AppCode.SUCCESS };
5249
}
5350

54-
private F3UserInfoModel CreateNewUser(F3AppRequestModel appRequest)
51+
private UserInfoModel CreateNewUser(AppRequestModel appRequest)
5552
{
5653
return new()
5754
{
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
namespace F3.Common;
66

7-
public static class F3Constant
7+
public static class Constant
88
{
9+
public const string CONTROLLER_NAME = "F3Endpoint";
10+
911
public const string ENDPOINT_PATH = "f3";
1012

1113
public const string REQUEST_ARGUMENT_NAME = "request";
@@ -14,48 +16,48 @@ public static class DefaultResponse
1416
{
1517
public static class App
1618
{
17-
public static readonly F3AppResponseModel EMAIL_ALREADY_EXISTS = new()
19+
public static readonly AppResponseModel EMAIL_ALREADY_EXISTS = new()
1820
{
1921
AppCode = AppCode.EMAIL_ALREADY_EXISTS,
2022
};
2123

22-
public static readonly F3AppResponseModel PASSWORD_IS_INVALID = new()
24+
public static readonly AppResponseModel PASSWORD_IS_INVALID = new()
2325
{
2426
AppCode = AppCode.PASSWORD_IS_INVALID,
2527
};
2628

27-
public static readonly F3AppResponseModel VALIDATION_FAILED = new()
29+
public static readonly AppResponseModel VALIDATION_FAILED = new()
2830
{
2931
AppCode = AppCode.VALIDATION_FAILED,
3032
};
3133

32-
public static readonly F3AppResponseModel SERVER_ERROR = new()
34+
public static readonly AppResponseModel SERVER_ERROR = new()
3335
{
3436
AppCode = AppCode.SERVER_ERROR,
3537
};
3638
}
3739

3840
public static class Http
3941
{
40-
public static readonly F3Response PASSWORD_IS_INVALID = new()
42+
public static readonly Response PASSWORD_IS_INVALID = new()
4143
{
4244
HttpCode = StatusCodes.Status422UnprocessableEntity,
4345
AppCode = (int)AppCode.PASSWORD_IS_INVALID,
4446
};
4547

46-
public static readonly F3Response EMAIL_ALREADY_EXISTS = new()
48+
public static readonly Response EMAIL_ALREADY_EXISTS = new()
4749
{
4850
HttpCode = StatusCodes.Status409Conflict,
4951
AppCode = (int)AppCode.EMAIL_ALREADY_EXISTS,
5052
};
5153

52-
public static readonly F3Response VALIDATION_FAILED = new()
54+
public static readonly Response VALIDATION_FAILED = new()
5355
{
5456
HttpCode = StatusCodes.Status400BadRequest,
5557
AppCode = (int)AppCode.VALIDATION_FAILED,
5658
};
5759

58-
public static readonly F3Response SERVER_ERROR = new()
60+
public static readonly Response SERVER_ERROR = new()
5961
{
6062
HttpCode = StatusCodes.Status500InternalServerError,
6163
AppCode = (int)AppCode.SERVER_ERROR,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
namespace F3.DataAccess;
66

7-
public interface IF3Repository
7+
public interface IRepository
88
{
99
Task<bool> DoesEmailExistsAsync(string email, CancellationToken ct);
1010

1111
Task<bool> IsPasswordValidAsync(string email, string password, CancellationToken ct);
1212

13-
Task<bool> CreateUserAsync(F3UserInfoModel user, CancellationToken ct);
13+
Task<bool> CreateUserAsync(UserInfoModel user, CancellationToken ct);
1414
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010

1111
namespace F3.DataAccess;
1212

13-
public sealed class F3Repository : IF3Repository
13+
public sealed class Repository : IRepository
1414
{
1515
private readonly AppDbContext _appContext;
1616
private readonly Lazy<UserManager<IdentityUserEntity>> _userManager;
1717

18-
public F3Repository(AppDbContext context, Lazy<UserManager<IdentityUserEntity>> userManager)
18+
public Repository(AppDbContext context, Lazy<UserManager<IdentityUserEntity>> userManager)
1919
{
2020
_appContext = context;
2121
_userManager = userManager;
2222
}
2323

24-
public async Task<bool> CreateUserAsync(F3UserInfoModel user, CancellationToken ct)
24+
public async Task<bool> CreateUserAsync(UserInfoModel user, CancellationToken ct)
2525
{
2626
var dbResult = true;
2727

Src/Core/F3/Mapper/F3HttpResponseMapper.cs renamed to Src/Core/F3/Mapper/HttpResponseMapper.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
namespace F3.Mapper;
1010

11-
public static class F3HttpResponseMapper
11+
public static class HttpResponseMapper
1212
{
1313
private static ConcurrentDictionary<
14-
F3Constant.AppCode,
15-
Func<F3AppRequestModel, F3AppResponseModel, HttpContext, F3Response>
14+
Constant.AppCode,
15+
Func<AppRequestModel, AppResponseModel, HttpContext, Response>
1616
> _httpResponseMapper;
1717

1818
private static void Init()
@@ -22,52 +22,52 @@ private static void Init()
2222
_httpResponseMapper = new();
2323

2424
_httpResponseMapper.TryAdd(
25-
F3Constant.AppCode.EMAIL_ALREADY_EXISTS,
25+
Constant.AppCode.EMAIL_ALREADY_EXISTS,
2626
(appRequest, appResponse, httpContext) =>
2727
{
28-
return F3Constant.DefaultResponse.Http.EMAIL_ALREADY_EXISTS;
28+
return Constant.DefaultResponse.Http.EMAIL_ALREADY_EXISTS;
2929
}
3030
);
3131

3232
_httpResponseMapper.TryAdd(
33-
F3Constant.AppCode.PASSWORD_IS_INVALID,
33+
Constant.AppCode.PASSWORD_IS_INVALID,
3434
(appRequest, appResponse, httpContext) =>
3535
{
36-
return F3Constant.DefaultResponse.Http.PASSWORD_IS_INVALID;
36+
return Constant.DefaultResponse.Http.PASSWORD_IS_INVALID;
3737
}
3838
);
3939

4040
_httpResponseMapper.TryAdd(
41-
F3Constant.AppCode.SUCCESS,
41+
Constant.AppCode.SUCCESS,
4242
(appRequest, appResponse, httpContext) =>
4343
{
4444
return new()
4545
{
4646
HttpCode = StatusCodes.Status200OK,
47-
AppCode = (int)F3Constant.AppCode.SUCCESS,
47+
AppCode = (int)Constant.AppCode.SUCCESS,
4848
};
4949
}
5050
);
5151

5252
_httpResponseMapper.TryAdd(
53-
F3Constant.AppCode.SERVER_ERROR,
53+
Constant.AppCode.SERVER_ERROR,
5454
(appRequest, appResponse, httpContext) =>
5555
{
56-
return F3Constant.DefaultResponse.Http.SERVER_ERROR;
56+
return Constant.DefaultResponse.Http.SERVER_ERROR;
5757
}
5858
);
5959
}
6060
}
6161

62-
public static F3Response Get(
63-
F3AppRequestModel appRequest,
64-
F3AppResponseModel appResponse,
62+
public static Response Get(
63+
AppRequestModel appRequest,
64+
AppResponseModel appResponse,
6565
HttpContext httpContext
6666
)
6767
{
6868
Init();
6969

70-
var stateBag = httpContext.Items[nameof(F3StateBag)] as F3StateBag;
70+
var stateBag = httpContext.Items[nameof(StateBag)] as StateBag;
7171

7272
var httpResponse = _httpResponseMapper[appResponse.AppCode]
7373
(appRequest, appResponse, httpContext);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace F3.Models;
44

5-
public sealed class F3AppRequestModel : IServiceRequest<F3AppResponseModel>
5+
public sealed class AppRequestModel : IServiceRequest<AppResponseModel>
66
{
77
public string Email { get; set; }
88

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
namespace F3.Models;
55

6-
public sealed class F3AppResponseModel : IServiceResponse
6+
public sealed class AppResponseModel : IServiceResponse
77
{
8-
public F3Constant.AppCode AppCode { get; set; }
8+
public Constant.AppCode AppCode { get; set; }
99

1010
public BodyModel Body { get; set; }
1111

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace F3.Models;
22

3-
public sealed class F3UserInfoModel
3+
public sealed class UserInfoModel
44
{
55
public long Id { get; set; }
66

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313

1414
namespace F3.Presentation;
1515

16-
public sealed class F3Endpoint : ControllerBase
16+
[Tags(Constant.CONTROLLER_NAME)]
17+
public sealed class Endpoint : ControllerBase
1718
{
18-
private readonly F3Service _service;
19+
private readonly Service _service;
1920

20-
public F3Endpoint(F3Service service)
21+
public Endpoint(Service service)
2122
{
2223
_service = service;
2324
}
@@ -39,26 +40,22 @@ public F3Endpoint(F3Service service)
3940
[ProducesResponseType(StatusCodes.Status400BadRequest)]
4041
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
4142
[ProducesResponseType(StatusCodes.Status200OK)]
42-
[ProducesResponseType(1, Type = typeof(F3Response))]
43+
[ProducesResponseType(1, Type = typeof(Response))]
4344
[Produces(MediaTypeNames.Application.Json)]
4445
[Consumes(MediaTypeNames.Application.Json)]
4546
// =============================================================
46-
[HttpPost(F3Constant.ENDPOINT_PATH)]
47-
[ServiceFilter<F3SetStateBagFilter>]
48-
[ServiceFilter<F3ValidationFilter>]
47+
[HttpPost(Constant.ENDPOINT_PATH)]
48+
[ServiceFilter<SetStateBagFilter>]
49+
[ServiceFilter<ValidationFilter>]
4950
public async Task<IActionResult> ExecuteF3Async(
50-
[FromBody] [Required] F3Request request,
51+
[FromBody] [Required] Request request,
5152
CancellationToken ct
5253
)
5354
{
54-
var appRequest = new F3AppRequestModel
55-
{
56-
Email = request.Email,
57-
Password = request.Password,
58-
};
55+
var appRequest = new AppRequestModel { Email = request.Email, Password = request.Password };
5956
var appResponse = await _service.ExecuteAsync(appRequest, ct);
6057

61-
var httpResponse = F3HttpResponseMapper.Get(appRequest, appResponse, HttpContext);
58+
var httpResponse = HttpResponseMapper.Get(appRequest, appResponse, HttpContext);
6259

6360
return StatusCode(httpResponse.HttpCode, httpResponse);
6461
}

Src/Core/F3/Presentation/Filters/SetStateBag/F3StateBag.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)