Skip to content

Commit 88e7c4a

Browse files
authored
Merge pull request #43 from Jackpieking/F11
fix(F11): Finish F11 and make small change to F2
2 parents 6befc9a + 49d0be2 commit 88e7c4a

28 files changed

+385
-371
lines changed

Src/Core/F11/BusinessLogic/F10Service.cs

Lines changed: 0 additions & 69 deletions
This file was deleted.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using F11.Common;
5+
using F11.DataAccess;
6+
using F11.Models;
7+
using FCommon.FeatureService;
8+
using FCommon.IdGeneration;
9+
10+
namespace F11.BusinessLogic;
11+
12+
public sealed class F11Service : IServiceHandler<F11AppRequestModel, F11AppResponseModel>
13+
{
14+
private readonly Lazy<IF11Repository> _repository;
15+
private readonly Lazy<IAppIdGenerator> _idGenerator;
16+
17+
public F11Service(Lazy<IF11Repository> repository, Lazy<IAppIdGenerator> idGenerator)
18+
{
19+
_repository = repository;
20+
_idGenerator = idGenerator;
21+
}
22+
23+
public async Task<F11AppResponseModel> ExecuteAsync(
24+
F11AppRequestModel request,
25+
CancellationToken ct
26+
)
27+
{
28+
var doesListExist = await _repository.Value.DoesTodoTaskListExistAsync(
29+
request.TodoTaskListId,
30+
ct
31+
);
32+
if (!doesListExist)
33+
{
34+
return F11Constant.DefaultResponse.App.TODO_TASK_LIST_NOT_FOUND;
35+
}
36+
37+
var todoTask = new F11TaskTodoModel
38+
{
39+
Id = _idGenerator.Value.NextId(),
40+
Content = request.Content,
41+
CreatedDate = DateTime.UtcNow,
42+
TodoTaskListId = request.TodoTaskListId,
43+
};
44+
var isTodoTaskCreated = await _repository.Value.CreateTodoTaskAsync(todoTask, ct);
45+
if (!isTodoTaskCreated)
46+
{
47+
return F11Constant.DefaultResponse.App.SERVER_ERROR;
48+
}
49+
50+
return new()
51+
{
52+
AppCode = F11Constant.AppCode.SUCCESS,
53+
Body = new() { TodoTaskId = todoTask.Id },
54+
};
55+
}
56+
}

Src/Core/F11/Common/F10Constant.cs

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

Src/Core/F11/Common/F11Constant.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using F11.Models;
2+
using F11.Presentation;
3+
using Microsoft.AspNetCore.Http;
4+
5+
namespace F11.Common;
6+
7+
public static class F11Constant
8+
{
9+
public const string ENDPOINT_PATH = "f11";
10+
11+
public const string REQUEST_ARGUMENT_NAME = "request";
12+
13+
public static class DefaultResponse
14+
{
15+
public static class App
16+
{
17+
public static readonly F11AppResponseModel SERVER_ERROR = new()
18+
{
19+
AppCode = AppCode.SERVER_ERROR,
20+
};
21+
22+
public static readonly F11AppResponseModel TODO_TASK_LIST_NOT_FOUND = new()
23+
{
24+
AppCode = AppCode.TODO_TASK_LIST_NOT_FOUND,
25+
};
26+
}
27+
28+
public static class Http
29+
{
30+
public static readonly F11Response VALIDATION_FAILED = new()
31+
{
32+
AppCode = (int)AppCode.VALIDATION_FAILED,
33+
HttpCode = StatusCodes.Status400BadRequest,
34+
};
35+
36+
public static readonly F11Response SERVER_ERROR = new()
37+
{
38+
AppCode = (int)AppCode.SERVER_ERROR,
39+
HttpCode = StatusCodes.Status500InternalServerError,
40+
};
41+
42+
public static readonly F11Response TODO_TASK_LIST_NOT_FOUND = new()
43+
{
44+
AppCode = (int)AppCode.TODO_TASK_LIST_NOT_FOUND,
45+
HttpCode = StatusCodes.Status404NotFound,
46+
};
47+
}
48+
}
49+
50+
public enum AppCode
51+
{
52+
SUCCESS = 1,
53+
54+
VALIDATION_FAILED,
55+
56+
SERVER_ERROR,
57+
58+
TODO_TASK_LIST_NOT_FOUND,
59+
}
60+
}

Src/Core/F11/DataAccess/F10Repository.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using F11.Models;
5+
using FA1.DbContext;
6+
using FA1.Entities;
7+
using Microsoft.EntityFrameworkCore;
8+
9+
namespace F11.DataAccess;
10+
11+
public sealed class F11Repository : IF11Repository
12+
{
13+
private readonly AppDbContext _appContext;
14+
15+
public F11Repository(AppDbContext context)
16+
{
17+
_appContext = context;
18+
}
19+
20+
public async Task<bool> CreateTodoTaskAsync(F11TaskTodoModel todoTask, CancellationToken ct)
21+
{
22+
var newEntity = new TodoTaskEntity
23+
{
24+
Id = todoTask.Id,
25+
Content = todoTask.Content,
26+
CreatedDate = todoTask.CreatedDate,
27+
TodoTaskListId = todoTask.TodoTaskListId,
28+
DueDate = DateTime.MinValue.ToUniversalTime(),
29+
IsFinished = false,
30+
IsImportant = false,
31+
IsInMyDay = false,
32+
Note = string.Empty,
33+
RecurringExpression = string.Empty,
34+
};
35+
36+
try
37+
{
38+
await _appContext.Set<TodoTaskEntity>().AddAsync(newEntity, ct);
39+
40+
await _appContext.SaveChangesAsync(ct);
41+
42+
return true;
43+
}
44+
catch (DbUpdateException)
45+
{
46+
return false;
47+
}
48+
}
49+
50+
public Task<bool> DoesTodoTaskListExistAsync(long listId, CancellationToken ct)
51+
{
52+
return _appContext.Set<TodoTaskListEntity>().AnyAsync(entity => entity.Id == listId, ct);
53+
}
54+
}

Src/Core/F11/DataAccess/IF10Repository.cs

Lines changed: 0 additions & 15 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 System.Threading;
2+
using System.Threading.Tasks;
3+
using F11.Models;
4+
5+
namespace F11.DataAccess;
6+
7+
public interface IF11Repository
8+
{
9+
Task<bool> CreateTodoTaskAsync(F11TaskTodoModel todoTask, CancellationToken ct);
10+
11+
Task<bool> DoesTodoTaskListExistAsync(long listId, CancellationToken ct);
12+
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
using F10.BusinessLogic;
2-
using F10.DataAccess;
1+
using F11.BusinessLogic;
2+
using F11.DataAccess;
33
using FACommon.DependencyInjection;
44
using FluentValidation;
55
using Microsoft.Extensions.Configuration;
66
using Microsoft.Extensions.DependencyInjection;
77

8-
namespace F10;
8+
namespace F11;
99

10-
public sealed class F10Register : IServiceRegister
10+
public sealed class F11Register : IServiceRegister
1111
{
1212
public IServiceCollection Register(IServiceCollection services, IConfiguration configuration)
1313
{
14-
var currentAssembly = typeof(F10Register).Assembly;
14+
var currentAssembly = typeof(F11Register).Assembly;
1515

1616
#region Filters
1717
services.RegisterFiltersFromAssembly(currentAssembly);
@@ -23,9 +23,9 @@ public IServiceCollection Register(IServiceCollection services, IConfiguration c
2323

2424
#region Core
2525
services
26-
.AddScoped<IF10Repository, F10Repository>()
27-
.MakeScopedLazy<IF10Repository>()
28-
.AddScoped<F10Service>();
26+
.AddScoped<IF11Repository, F11Repository>()
27+
.MakeScopedLazy<IF11Repository>()
28+
.AddScoped<F11Service>();
2929
#endregion
3030

3131
return services;

0 commit comments

Comments
 (0)