Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 0 additions & 69 deletions Src/Core/F11/BusinessLogic/F10Service.cs

This file was deleted.

56 changes: 56 additions & 0 deletions Src/Core/F11/BusinessLogic/F11Service.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using F11.Common;
using F11.DataAccess;
using F11.Models;
using FCommon.FeatureService;
using FCommon.IdGeneration;

namespace F11.BusinessLogic;

public sealed class F11Service : IServiceHandler<F11AppRequestModel, F11AppResponseModel>
{
private readonly Lazy<IF11Repository> _repository;
private readonly Lazy<IAppIdGenerator> _idGenerator;

public F11Service(Lazy<IF11Repository> repository, Lazy<IAppIdGenerator> idGenerator)
{
_repository = repository;
_idGenerator = idGenerator;
}

public async Task<F11AppResponseModel> ExecuteAsync(
F11AppRequestModel request,
CancellationToken ct
)
{
var doesListExist = await _repository.Value.DoesTodoTaskListExistAsync(
request.TodoTaskListId,
ct
);
if (!doesListExist)
{
return F11Constant.DefaultResponse.App.TODO_TASK_LIST_NOT_FOUND;
}

var todoTask = new F11TaskTodoModel
{
Id = _idGenerator.Value.NextId(),
Content = request.Content,
CreatedDate = DateTime.UtcNow,
TodoTaskListId = request.TodoTaskListId,
};
var isTodoTaskCreated = await _repository.Value.CreateTodoTaskAsync(todoTask, ct);
if (!isTodoTaskCreated)
{
return F11Constant.DefaultResponse.App.SERVER_ERROR;
}

return new()
{
AppCode = F11Constant.AppCode.SUCCESS,
Body = new() { TodoTaskId = todoTask.Id },
};
}
}
39 changes: 0 additions & 39 deletions Src/Core/F11/Common/F10Constant.cs

This file was deleted.

60 changes: 60 additions & 0 deletions Src/Core/F11/Common/F11Constant.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using F11.Models;
using F11.Presentation;
using Microsoft.AspNetCore.Http;

namespace F11.Common;

public static class F11Constant
{
public const string ENDPOINT_PATH = "f11";

public const string REQUEST_ARGUMENT_NAME = "request";

public static class DefaultResponse
{
public static class App
{
public static readonly F11AppResponseModel SERVER_ERROR = new()
{
AppCode = AppCode.SERVER_ERROR,
};

public static readonly F11AppResponseModel TODO_TASK_LIST_NOT_FOUND = new()
{
AppCode = AppCode.TODO_TASK_LIST_NOT_FOUND,
};
}

public static class Http
{
public static readonly F11Response VALIDATION_FAILED = new()
{
AppCode = (int)AppCode.VALIDATION_FAILED,
HttpCode = StatusCodes.Status400BadRequest,
};

public static readonly F11Response SERVER_ERROR = new()
{
AppCode = (int)AppCode.SERVER_ERROR,
HttpCode = StatusCodes.Status500InternalServerError,
};

public static readonly F11Response TODO_TASK_LIST_NOT_FOUND = new()
{
AppCode = (int)AppCode.TODO_TASK_LIST_NOT_FOUND,
HttpCode = StatusCodes.Status404NotFound,
};
}
}

public enum AppCode
{
SUCCESS = 1,

VALIDATION_FAILED,

SERVER_ERROR,

TODO_TASK_LIST_NOT_FOUND,
}
}
36 changes: 0 additions & 36 deletions Src/Core/F11/DataAccess/F10Repository.cs

This file was deleted.

54 changes: 54 additions & 0 deletions Src/Core/F11/DataAccess/F11Repository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using F11.Models;
using FA1.DbContext;
using FA1.Entities;
using Microsoft.EntityFrameworkCore;

namespace F11.DataAccess;

public sealed class F11Repository : IF11Repository
{
private readonly AppDbContext _appContext;

public F11Repository(AppDbContext context)
{
_appContext = context;
}

public async Task<bool> CreateTodoTaskAsync(F11TaskTodoModel todoTask, CancellationToken ct)
{
var newEntity = new TodoTaskEntity
{
Id = todoTask.Id,
Content = todoTask.Content,
CreatedDate = todoTask.CreatedDate,
TodoTaskListId = todoTask.TodoTaskListId,
DueDate = DateTime.MinValue.ToUniversalTime(),
IsFinished = false,
IsImportant = false,
IsInMyDay = false,
Note = string.Empty,
RecurringExpression = string.Empty,
};

try
{
await _appContext.Set<TodoTaskEntity>().AddAsync(newEntity, ct);

await _appContext.SaveChangesAsync(ct);

return true;
}
catch (DbUpdateException)
{
return false;
}
}

public Task<bool> DoesTodoTaskListExistAsync(long listId, CancellationToken ct)
{
return _appContext.Set<TodoTaskListEntity>().AnyAsync(entity => entity.Id == listId, ct);
}
}
15 changes: 0 additions & 15 deletions Src/Core/F11/DataAccess/IF10Repository.cs

This file was deleted.

12 changes: 12 additions & 0 deletions Src/Core/F11/DataAccess/IF11Repository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Threading;
using System.Threading.Tasks;
using F11.Models;

namespace F11.DataAccess;

public interface IF11Repository
{
Task<bool> CreateTodoTaskAsync(F11TaskTodoModel todoTask, CancellationToken ct);

Task<bool> DoesTodoTaskListExistAsync(long listId, CancellationToken ct);
}
16 changes: 8 additions & 8 deletions Src/Core/F11/F10Register.cs → Src/Core/F11/F11Register.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using F10.BusinessLogic;
using F10.DataAccess;
using F11.BusinessLogic;
using F11.DataAccess;
using FACommon.DependencyInjection;
using FluentValidation;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace F10;
namespace F11;

public sealed class F10Register : IServiceRegister
public sealed class F11Register : IServiceRegister
{
public IServiceCollection Register(IServiceCollection services, IConfiguration configuration)
{
var currentAssembly = typeof(F10Register).Assembly;
var currentAssembly = typeof(F11Register).Assembly;

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

#region Core
services
.AddScoped<IF10Repository, F10Repository>()
.MakeScopedLazy<IF10Repository>()
.AddScoped<F10Service>();
.AddScoped<IF11Repository, F11Repository>()
.MakeScopedLazy<IF11Repository>()
.AddScoped<F11Service>();
#endregion

return services;
Expand Down
Loading
Loading