Skip to content

Commit c7cddee

Browse files
authored
Merge pull request #105 from Jackpieking/setup
refactor(F14): Refactor
2 parents 6785af1 + 17f6e25 commit c7cddee

File tree

18 files changed

+88
-92
lines changed

18 files changed

+88
-92
lines changed
Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,24 @@
1010

1111
namespace F14.BusinessLogic;
1212

13-
public sealed class F14Service : IServiceHandler<F14AppRequestModel, F14AppResponseModel>
13+
public sealed class Service : IServiceHandler<AppRequestModel, AppResponseModel>
1414
{
15-
private readonly Lazy<IF14Repository> _repository;
15+
private readonly Lazy<IRepository> _repository;
1616

17-
public F14Service(Lazy<IF14Repository> repository)
17+
public Service(Lazy<IRepository> repository)
1818
{
1919
_repository = repository;
2020
}
2121

22-
public async Task<F14AppResponseModel> ExecuteAsync(
23-
F14AppRequestModel request,
24-
CancellationToken ct
25-
)
22+
public async Task<AppResponseModel> ExecuteAsync(AppRequestModel request, CancellationToken ct)
2623
{
2724
var doesListExist = await _repository.Value.DoesTodoTaskListExistAsync(
2825
request.TodoTaskListId,
2926
ct
3027
);
3128
if (!doesListExist)
3229
{
33-
return F14Constant.DefaultResponse.App.TODO_TASK_LIST_NOT_FOUND;
30+
return Constant.DefaultResponse.App.TODO_TASK_LIST_NOT_FOUND;
3431
}
3532

3633
if (request.TodoTaskId != 0)
@@ -42,11 +39,11 @@ CancellationToken ct
4239
);
4340
if (!doesTaskExist)
4441
{
45-
return F14Constant.DefaultResponse.App.TASK_NOT_FOUND;
42+
return Constant.DefaultResponse.App.TASK_NOT_FOUND;
4643
}
4744
}
4845

49-
var input = new F14GetTodoTasksInputModel
46+
var input = new GetTodoTasksInputModel
5047
{
5148
TodoTaskId = request.TodoTaskId,
5249
TodoTaskListId = request.TodoTaskListId,
@@ -59,11 +56,11 @@ CancellationToken ct
5956
{
6057
return new()
6158
{
62-
AppCode = F14Constant.AppCode.SUCCESS,
59+
AppCode = Constant.AppCode.SUCCESS,
6360
Body = new()
6461
{
6562
TodoTasks = foundTodoTasks.Select(
66-
taskDetail => new F14AppResponseModel.BodyModel.TodoTaskModel
63+
taskDetail => new AppResponseModel.BodyModel.TodoTaskModel
6764
{
6865
Id = taskDetail.Id,
6966
Content = taskDetail.Content,
@@ -80,7 +77,7 @@ CancellationToken ct
8077
};
8178
}
8279

83-
var appResponseTodoTasks = new List<F14AppResponseModel.BodyModel.TodoTaskModel>();
80+
var appResponseTodoTasks = new List<AppResponseModel.BodyModel.TodoTaskModel>();
8481
for (var i = 0; i < taskCount; i++)
8582
{
8683
var taskDetail = foundTodoTasks.ElementAt(i);
@@ -104,7 +101,7 @@ CancellationToken ct
104101

105102
return new()
106103
{
107-
AppCode = F14Constant.AppCode.SUCCESS,
104+
AppCode = Constant.AppCode.SUCCESS,
108105
Body = new() { TodoTasks = appResponseTodoTasks, NextCursor = nextCursor },
109106
};
110107
}
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
namespace F14.Common;
66

7-
public static class F14Constant
7+
public static class Constant
88
{
9+
public const string CONTROLLER_NAME = "F14Endpoint";
10+
911
public const string ENDPOINT_PATH =
1012
"f14/list/{TodoTaskListId:required}/task/cursor/{TodoTaskId:required}";
1113

@@ -23,32 +25,32 @@ public static class DefaultResponse
2325
{
2426
public static class App
2527
{
26-
public static readonly F14AppResponseModel TASK_NOT_FOUND = new()
28+
public static readonly AppResponseModel TASK_NOT_FOUND = new()
2729
{
2830
AppCode = AppCode.TASK_NOT_FOUND,
2931
};
3032

31-
public static readonly F14AppResponseModel TODO_TASK_LIST_NOT_FOUND = new()
33+
public static readonly AppResponseModel TODO_TASK_LIST_NOT_FOUND = new()
3234
{
3335
AppCode = AppCode.TODO_TASK_LIST_NOT_FOUND,
3436
};
3537
}
3638

3739
public static class Http
3840
{
39-
public static readonly F14Response VALIDATION_FAILED = new()
41+
public static readonly Response VALIDATION_FAILED = new()
4042
{
4143
AppCode = (int)AppCode.VALIDATION_FAILED,
4244
HttpCode = StatusCodes.Status400BadRequest,
4345
};
4446

45-
public static readonly F14Response TASK_NOT_FOUND = new()
47+
public static readonly Response TASK_NOT_FOUND = new()
4648
{
4749
AppCode = (int)AppCode.TASK_NOT_FOUND,
4850
HttpCode = StatusCodes.Status404NotFound,
4951
};
5052

51-
public static readonly F14Response TODO_TASK_LIST_NOT_FOUND = new()
53+
public static readonly Response TODO_TASK_LIST_NOT_FOUND = new()
5254
{
5355
AppCode = (int)AppCode.TODO_TASK_LIST_NOT_FOUND,
5456
HttpCode = StatusCodes.Status404NotFound,
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
namespace F14.DataAccess;
77

8-
public interface IF14Repository
8+
public interface IRepository
99
{
10-
Task<IEnumerable<F14TodoTaskModel>> GetCompletedTodoTasksAsync(
11-
F14GetTodoTasksInputModel input,
10+
Task<IEnumerable<TodoTaskModel>> GetCompletedTodoTasksAsync(
11+
GetTodoTasksInputModel input,
1212
CancellationToken ct
1313
);
1414

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
namespace F14.DataAccess;
1212

13-
public sealed class F14Repository : IF14Repository
13+
public sealed class Repository : IRepository
1414
{
1515
private readonly AppDbContext _appContext;
1616

17-
public F14Repository(AppDbContext context)
17+
public Repository(AppDbContext context)
1818
{
1919
_appContext = context;
2020
}
@@ -31,8 +31,8 @@ public Task<bool> DoesTodoTaskListExistAsync(long listId, CancellationToken ct)
3131
return _appContext.Set<TodoTaskListEntity>().AnyAsync(entity => entity.Id == listId, ct);
3232
}
3333

34-
public async Task<IEnumerable<F14TodoTaskModel>> GetCompletedTodoTasksAsync(
35-
F14GetTodoTasksInputModel input,
34+
public async Task<IEnumerable<TodoTaskModel>> GetCompletedTodoTasksAsync(
35+
GetTodoTasksInputModel input,
3636
CancellationToken ct
3737
)
3838
{
@@ -43,7 +43,7 @@ CancellationToken ct
4343
&& entity.TodoTaskListId == input.TodoTaskListId
4444
&& entity.IsFinished == true
4545
)
46-
.Select(entity => new F14TodoTaskModel
46+
.Select(entity => new TodoTaskModel
4747
{
4848
Id = entity.Id,
4949
Content = entity.Content,

Src/Core/F14/Mapper/F14HttpResponseMapper.cs renamed to Src/Core/F14/Mapper/HttpResponseMapper.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
namespace F14.Mapper;
1111

12-
public static class F14HttpResponseMapper
12+
public static class HttpResponseMapper
1313
{
1414
private static ConcurrentDictionary<
15-
F14Constant.AppCode,
16-
Func<F14AppRequestModel, F14AppResponseModel, HttpContext, F14Response>
15+
Constant.AppCode,
16+
Func<AppRequestModel, AppResponseModel, HttpContext, Response>
1717
> _httpResponseMapper;
1818

1919
private static void Init()
@@ -24,17 +24,17 @@ private static void Init()
2424
}
2525

2626
_httpResponseMapper.TryAdd(
27-
F14Constant.AppCode.SUCCESS,
27+
Constant.AppCode.SUCCESS,
2828
(appRequest, appResponse, httpContext) =>
2929
{
3030
return new()
3131
{
32-
AppCode = (int)F14Constant.AppCode.SUCCESS,
32+
AppCode = (int)Constant.AppCode.SUCCESS,
3333
HttpCode = StatusCodes.Status200OK,
3434
Body = new()
3535
{
3636
TodoTasks = appResponse.Body.TodoTasks.Select(
37-
taskDetail => new F14Response.BodyDto.TodoTaskDto
37+
taskDetail => new Response.BodyDto.TodoTaskDto
3838
{
3939
Id = taskDetail.Id,
4040
Content = taskDetail.Content,
@@ -53,31 +53,31 @@ private static void Init()
5353
);
5454

5555
_httpResponseMapper.TryAdd(
56-
F14Constant.AppCode.TASK_NOT_FOUND,
56+
Constant.AppCode.TASK_NOT_FOUND,
5757
(appRequest, appResponse, httpContext) =>
5858
{
59-
return F14Constant.DefaultResponse.Http.TASK_NOT_FOUND;
59+
return Constant.DefaultResponse.Http.TASK_NOT_FOUND;
6060
}
6161
);
6262

6363
_httpResponseMapper.TryAdd(
64-
F14Constant.AppCode.TODO_TASK_LIST_NOT_FOUND,
64+
Constant.AppCode.TODO_TASK_LIST_NOT_FOUND,
6565
(appRequest, appResponse, httpContext) =>
6666
{
67-
return F14Constant.DefaultResponse.Http.TODO_TASK_LIST_NOT_FOUND;
67+
return Constant.DefaultResponse.Http.TODO_TASK_LIST_NOT_FOUND;
6868
}
6969
);
7070
}
7171

72-
public static F14Response Get(
73-
F14AppRequestModel appRequest,
74-
F14AppResponseModel appResponse,
72+
public static Response Get(
73+
AppRequestModel appRequest,
74+
AppResponseModel appResponse,
7575
HttpContext httpContext
7676
)
7777
{
7878
Init();
7979

80-
var stateBag = httpContext.Items[nameof(F14StateBag)] as F14StateBag;
80+
var stateBag = httpContext.Items[nameof(StateBag)] as StateBag;
8181

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

33
namespace F14.Models;
44

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

Src/Core/F14/Models/F14AppResponseModel.cs renamed to Src/Core/F14/Models/AppResponseModel.cs

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

66
namespace F14.Models;
77

8-
public sealed class F14AppResponseModel : IServiceResponse
8+
public sealed class AppResponseModel : IServiceResponse
99
{
10-
public F14Constant.AppCode AppCode { get; set; }
10+
public Constant.AppCode AppCode { get; set; }
1111

1212
public BodyModel Body { get; set; }
1313

Src/Core/F14/Models/F14GetTodoTasksInputModel.cs renamed to Src/Core/F14/Models/GetTodoTasksInputModel.cs

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

3-
public sealed class F14GetTodoTasksInputModel
3+
public sealed class GetTodoTasksInputModel
44
{
55
public long TodoTaskId { get; set; }
66

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace F14.Models;
44

5-
public sealed class F14TodoTaskModel
5+
public sealed class TodoTaskModel
66
{
77
public long Id { get; set; }
88

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

1616
namespace F14.Presentation;
1717

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

22-
public F14Endpoint(F14Service service)
23+
public Endpoint(Service service)
2324
{
2425
_service = service;
2526
}
@@ -41,27 +42,27 @@ public F14Endpoint(F14Service service)
4142
[ProducesResponseType(StatusCodes.Status200OK)]
4243
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
4344
[ProducesResponseType(StatusCodes.Status403Forbidden)]
44-
[ProducesResponseType(1, Type = typeof(F14Response))]
45+
[ProducesResponseType(1, Type = typeof(Response))]
4546
[Produces(MediaTypeNames.Application.Json)]
4647
// =============================================================
47-
[HttpGet(F14Constant.ENDPOINT_PATH)]
48+
[HttpGet(Constant.ENDPOINT_PATH)]
4849
[Authorize(Policy = nameof(DefaultAuthorizationRequirement))]
49-
[ServiceFilter<F14SetStateBagFilter>]
50-
[ServiceFilter<F14ValidationFilter>]
50+
[ServiceFilter<SetStateBagFilter>]
51+
[ServiceFilter<ValidationFilter>]
5152
public async Task<IActionResult> ExecuteF14Async(
52-
[Required] F14Request request,
53+
[Required] Request request,
5354
CancellationToken ct
5455
)
5556
{
56-
var appRequest = new F14AppRequestModel
57+
var appRequest = new AppRequestModel
5758
{
5859
TodoTaskId = request.TodoTaskId,
5960
TodoTaskListId = request.TodoTaskListId,
6061
NumberOfRecord = request.NumberOfRecord,
6162
};
6263
var appResponse = await _service.ExecuteAsync(appRequest, ct);
6364

64-
var httpResponse = F14HttpResponseMapper.Get(appRequest, appResponse, HttpContext);
65+
var httpResponse = HttpResponseMapper.Get(appRequest, appResponse, HttpContext);
6566

6667
return StatusCode(httpResponse.HttpCode, httpResponse);
6768
}

0 commit comments

Comments
 (0)