Refactored ICRUDService interface to remove the generic TCRUDRepository parameter for simplification and improved readability.

This commit is contained in:
Developer 02
2024-06-15 00:41:24 +02:00
parent 0697f5ff58
commit 3844f9d8d8
8 changed files with 29 additions and 32 deletions

View File

@@ -1,5 +1,5 @@
using DigitalData.Core.Contracts.Application;
using DigitalData.Core.Contracts.Infrastructure;
using DigitalData.Core.DTO;
using Microsoft.AspNetCore.Mvc;
namespace DigitalData.Core.API
@@ -12,9 +12,8 @@ namespace DigitalData.Core.API
/// <typeparam name="TId">The type of the entity's identifier.</typeparam>
[ApiController]
[Route("api/[controller]")]
public class ReadControllerBase<TBasicCRUDService, TCRUDRepository, TReadDto, TEntity, TId> : ControllerBase
where TBasicCRUDService : IBasicCRUDService<TCRUDRepository, TReadDto, TEntity, TId>
where TCRUDRepository : ICRUDRepository<TEntity, TId>
public class ReadControllerBase<TBasicCRUDService, TReadDto, TEntity, TId> : ControllerBase
where TBasicCRUDService : IBasicCRUDService<TReadDto, TEntity, TId>
where TReadDto : class
where TEntity : class
{
@@ -42,12 +41,13 @@ namespace DigitalData.Core.API
[HttpGet("{id}")]
public virtual async Task<IActionResult> GetById([FromRoute] TId id)
{
var result = await _service.ReadByIdAsync(id);
if (result.IsSuccess)
{
return Ok(result);
}
return NotFound(result);
return await _service.ReadByIdAsync(id).ThenAsync(
Success: Ok,
Fail: IActionResult (messages, notices) =>
{
_logger.LogNotice(notices);
return NotFound(messages);
});
}
/// <summary>
@@ -57,12 +57,13 @@ namespace DigitalData.Core.API
[HttpGet]
public virtual async Task<IActionResult> GetAll()
{
var result = await _service.ReadAllAsync();
if (result.IsSuccess)
{
return Ok(result);
}
return NotFound(result);
return await _service.ReadAllAsync().ThenAsync(
Success: Ok,
Fail: IActionResult (messages, notices) =>
{
_logger.LogNotice(notices);
return NotFound(messages);
});
}
}
}