Skip to content

Commit 865d6ed

Browse files
committed
refactor(F16): Refactor
Remove all f16 prefix of all class and change register name to registration center
1 parent 0d18a54 commit 865d6ed

File tree

16 files changed

+75
-79
lines changed

16 files changed

+75
-79
lines changed
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,21 @@
88

99
namespace F16.BusinessLogic;
1010

11-
public sealed class F16Service : IServiceHandler<F16AppRequestModel, F16AppResponseModel>
11+
public sealed class Service : IServiceHandler<AppRequestModel, AppResponseModel>
1212
{
13-
private readonly Lazy<IF16Repository> _repository;
13+
private readonly Lazy<IRepository> _repository;
1414

15-
public F16Service(Lazy<IF16Repository> repository)
15+
public Service(Lazy<IRepository> repository)
1616
{
1717
_repository = repository;
1818
}
1919

20-
public async Task<F16AppResponseModel> ExecuteAsync(
21-
F16AppRequestModel request,
22-
CancellationToken ct
23-
)
20+
public async Task<AppResponseModel> ExecuteAsync(AppRequestModel request, CancellationToken ct)
2421
{
2522
var doesTaskExist = await _repository.Value.DoesTodoTaskExistAsync(request.TodoTaskId, ct);
2623
if (!doesTaskExist)
2724
{
28-
return F16Constant.DefaultResponse.App.TASK_NOT_FOUND;
25+
return Constant.DefaultResponse.App.TASK_NOT_FOUND;
2926
}
3027

3128
var isSuccess = await _repository.Value.ModifyIsInMyDayStatusAsync(
@@ -35,9 +32,9 @@ CancellationToken ct
3532
);
3633
if (!isSuccess)
3734
{
38-
return F16Constant.DefaultResponse.App.SERVER_ERROR;
35+
return Constant.DefaultResponse.App.SERVER_ERROR;
3936
}
4037

41-
return new() { AppCode = F16Constant.AppCode.SUCCESS };
38+
return new() { AppCode = Constant.AppCode.SUCCESS };
4239
}
4340
}
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
namespace F16.Common;
66

7-
public static class F16Constant
7+
public static class Constant
88
{
9+
public const string CONTROLLER_NAME = "F16Endpoint";
10+
911
public const string ENDPOINT_PATH = "f16";
1012

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

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

2830
public static class Http
2931
{
30-
public static readonly F16Response VALIDATION_FAILED = new()
32+
public static readonly Response VALIDATION_FAILED = new()
3133
{
3234
AppCode = (int)AppCode.VALIDATION_FAILED,
3335
HttpCode = StatusCodes.Status400BadRequest,
3436
};
3537

36-
public static readonly F16Response TASK_NOT_FOUND = new()
38+
public static readonly Response TASK_NOT_FOUND = new()
3739
{
3840
AppCode = (int)AppCode.TASK_NOT_FOUND,
3941
HttpCode = StatusCodes.Status404NotFound,
4042
};
4143

42-
public static readonly F16Response SERVER_ERROR = new()
44+
public static readonly Response SERVER_ERROR = new()
4345
{
4446
AppCode = (int)AppCode.SERVER_ERROR,
4547
HttpCode = StatusCodes.Status500InternalServerError,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace F16.DataAccess;
55

6-
public interface IF16Repository
6+
public interface IRepository
77
{
88
Task<bool> DoesTodoTaskExistAsync(long taskId, CancellationToken ct);
99

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

99
namespace F16.DataAccess;
1010

11-
public sealed class F16Repository : IF16Repository
11+
public sealed class Repository : IRepository
1212
{
1313
private readonly AppDbContext _appContext;
1414

15-
public F16Repository(AppDbContext context)
15+
public Repository(AppDbContext context)
1616
{
1717
_appContext = context;
1818
}

Src/Core/F16/Mapper/F16HttpResponseMapper.cs renamed to Src/Core/F16/Mapper/HttpResponseMapper.cs

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

99
namespace F16.Mapper;
1010

11-
public static class F16HttpResponseMapper
11+
public static class HttpResponseMapper
1212
{
1313
private static ConcurrentDictionary<
14-
F16Constant.AppCode,
15-
Func<F16AppRequestModel, F16AppResponseModel, HttpContext, F16Response>
14+
Constant.AppCode,
15+
Func<AppRequestModel, AppResponseModel, HttpContext, Response>
1616
> _httpResponseMapper;
1717

1818
private static void Init()
@@ -23,43 +23,43 @@ private static void Init()
2323
}
2424

2525
_httpResponseMapper.TryAdd(
26-
F16Constant.AppCode.SUCCESS,
26+
Constant.AppCode.SUCCESS,
2727
(appRequest, appResponse, httpContext) =>
2828
{
2929
return new()
3030
{
31-
AppCode = (int)F16Constant.AppCode.SUCCESS,
31+
AppCode = (int)Constant.AppCode.SUCCESS,
3232
HttpCode = StatusCodes.Status200OK,
3333
};
3434
}
3535
);
3636

3737
_httpResponseMapper.TryAdd(
38-
F16Constant.AppCode.TASK_NOT_FOUND,
38+
Constant.AppCode.TASK_NOT_FOUND,
3939
(appRequest, appResponse, httpContext) =>
4040
{
41-
return F16Constant.DefaultResponse.Http.TASK_NOT_FOUND;
41+
return Constant.DefaultResponse.Http.TASK_NOT_FOUND;
4242
}
4343
);
4444

4545
_httpResponseMapper.TryAdd(
46-
F16Constant.AppCode.SERVER_ERROR,
46+
Constant.AppCode.SERVER_ERROR,
4747
(appRequest, appResponse, httpContext) =>
4848
{
49-
return F16Constant.DefaultResponse.Http.SERVER_ERROR;
49+
return Constant.DefaultResponse.Http.SERVER_ERROR;
5050
}
5151
);
5252
}
5353

54-
public static F16Response Get(
55-
F16AppRequestModel appRequest,
56-
F16AppResponseModel appResponse,
54+
public static Response Get(
55+
AppRequestModel appRequest,
56+
AppResponseModel appResponse,
5757
HttpContext httpContext
5858
)
5959
{
6060
Init();
6161

62-
var stateBag = httpContext.Items[nameof(F16StateBag)] as F16StateBag;
62+
var stateBag = httpContext.Items[nameof(StateBag)] as StateBag;
6363

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

33
namespace F16.Models;
44

5-
public sealed class F16AppRequestModel : IServiceRequest<F16AppResponseModel>
5+
public sealed class AppRequestModel : IServiceRequest<AppResponseModel>
66
{
77
public long TodoTaskId { get; set; }
88

Src/Core/F16/Models/F16AppResponseModel.cs renamed to Src/Core/F16/Models/AppResponseModel.cs

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

44
namespace F16.Models;
55

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

1010
public BodyModel Body { get; set; }
1111

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515

1616
namespace F16.Presentation;
1717

18-
public sealed class F16Endpoint : ControllerBase
18+
[Tags(Constant.CONTROLLER_NAME)]
19+
public sealed class Endpoint : ControllerBase
1920
{
20-
private readonly F16Service _service;
21+
private readonly Service _service;
2122

22-
public F16Endpoint(F16Service service)
23+
public Endpoint(Service service)
2324
{
2425
_service = service;
2526
}
@@ -43,27 +44,27 @@ public F16Endpoint(F16Service service)
4344
[ProducesResponseType(StatusCodes.Status200OK)]
4445
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
4546
[ProducesResponseType(StatusCodes.Status403Forbidden)]
46-
[ProducesResponseType(1, Type = typeof(F16Response))]
47+
[ProducesResponseType(1, Type = typeof(Response))]
4748
[Produces(MediaTypeNames.Application.Json)]
4849
[Consumes(MediaTypeNames.Application.Json)]
4950
// =============================================================
50-
[HttpPost(F16Constant.ENDPOINT_PATH)]
51+
[HttpPost(Constant.ENDPOINT_PATH)]
5152
[Authorize(Policy = nameof(DefaultAuthorizationRequirement))]
52-
[ServiceFilter<F16SetStateBagFilter>]
53-
[ServiceFilter<F16ValidationFilter>]
53+
[ServiceFilter<SetStateBagFilter>]
54+
[ServiceFilter<ValidationFilter>]
5455
public async Task<IActionResult> ExecuteF16Async(
55-
[FromBody] [Required] F16Request request,
56+
[FromBody] [Required] Request request,
5657
CancellationToken ct
5758
)
5859
{
59-
var appRequest = new F16AppRequestModel
60+
var appRequest = new AppRequestModel
6061
{
6162
TodoTaskId = request.TodoTaskId,
6263
IsInMyDay = request.IsInMyDay,
6364
};
6465
var appResponse = await _service.ExecuteAsync(appRequest, ct);
6566

66-
var httpResponse = F16HttpResponseMapper.Get(appRequest, appResponse, HttpContext);
67+
var httpResponse = HttpResponseMapper.Get(appRequest, appResponse, HttpContext);
6768

6869
return StatusCode(httpResponse.HttpCode, httpResponse);
6970
}

Src/Core/F16/Presentation/Filters/SetStateBag/F16StateBag.cs

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

Src/Core/F16/Presentation/Filters/SetStateBag/F16SetStateBagFilter.cs renamed to Src/Core/F16/Presentation/Filters/SetStateBag/SetStateBagFilter.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,35 @@
88

99
namespace F16.Presentation.Filters.SetStateBag;
1010

11-
public sealed class F16SetStateBagFilter : IAsyncActionFilter
11+
public sealed class SetStateBagFilter : IAsyncActionFilter
1212
{
1313
public async Task OnActionExecutionAsync(
1414
ActionExecutingContext context,
1515
ActionExecutionDelegate next
1616
)
1717
{
1818
var doesRequestExist = context.ActionArguments.Any(argument =>
19-
argument.Key.Equals(F16Constant.REQUEST_ARGUMENT_NAME)
19+
argument.Key.Equals(Constant.REQUEST_ARGUMENT_NAME)
2020
);
2121

2222
if (!doesRequestExist)
2323
{
2424
context.Result = new ContentResult
2525
{
26-
StatusCode = F16Constant.DefaultResponse.Http.VALIDATION_FAILED.HttpCode,
27-
Content = JsonSerializer.Serialize(
28-
F16Constant.DefaultResponse.Http.VALIDATION_FAILED
29-
),
26+
StatusCode = Constant.DefaultResponse.Http.VALIDATION_FAILED.HttpCode,
27+
Content = JsonSerializer.Serialize(Constant.DefaultResponse.Http.VALIDATION_FAILED),
3028
ContentType = MediaTypeNames.Application.Json,
3129
};
3230

3331
return;
3432
}
3533

36-
var stateBag = new F16StateBag
34+
var stateBag = new StateBag
3735
{
38-
HttpRequest = context.ActionArguments[F16Constant.REQUEST_ARGUMENT_NAME] as F16Request,
36+
HttpRequest = context.ActionArguments[Constant.REQUEST_ARGUMENT_NAME] as Request,
3937
};
4038

41-
context.HttpContext.Items.Add(nameof(F16StateBag), stateBag);
39+
context.HttpContext.Items.Add(nameof(StateBag), stateBag);
4240

4341
await next();
4442
}

0 commit comments

Comments
 (0)