Deprecate controllers/services; simplify generics
Added `[Obsolete("Use MediatR")]` attributes to various controller and service classes to indicate deprecation in favor of MediatR. Simplified generic type constraints in `CRUDControllerBase` and related files by removing `IUnique<TId>`. Improved structure and documentation in `CSPMiddleware.cs`. Introduced new extension methods in `EntityExtensions.cs` for safer retrieval of 'Id' properties. Removed `IUnique.cs` interface and updated project dependencies in `DigitalData.Core.Application.csproj` for caching. Overall, these changes enhance code maintainability and clarity.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using AutoMapper;
|
||||
using DigitalData.Core.Abstractions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DigitalData.Core.Application.Interfaces.Repository;
|
||||
using DigitalData.Core.Application.Interfaces;
|
||||
@@ -14,8 +13,10 @@ namespace DigitalData.Core.Application
|
||||
/// <typeparam name="TReadDto">The DTO type for read operations.</typeparam>
|
||||
/// <typeparam name="TEntity">The entity type.</typeparam>
|
||||
/// <typeparam name="TId">The type of the identifier for the entity.</typeparam>
|
||||
///
|
||||
[Obsolete("Use MediatR")]
|
||||
public class CRUDService<TCRUDRepository, TCreateDto, TReadDto, TEntity, TId> : ReadService<TCRUDRepository, TReadDto, TEntity, TId>, ICRUDService<TCreateDto, TReadDto, TEntity, TId>
|
||||
where TCRUDRepository : ICRUDRepository<TEntity, TId> where TCreateDto : class where TReadDto : class where TEntity : class, IUnique<TId>
|
||||
where TCRUDRepository : ICRUDRepository<TEntity, TId> where TCreateDto : class where TReadDto : class where TEntity : class
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
@@ -36,7 +37,7 @@ namespace DigitalData.Core.Application
|
||||
{
|
||||
var entity = _mapper.Map<TEntity>(createDto);
|
||||
var createdEntity = await _repository.CreateAsync(entity);
|
||||
return createdEntity is null ? Result.Fail<TId>() : Result.Success(createdEntity.Id);
|
||||
return createdEntity is null ? Result.Fail<TId>() : Result.Success(createdEntity.GetIdOrDefault<TId>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -44,12 +45,12 @@ namespace DigitalData.Core.Application
|
||||
/// </summary>
|
||||
/// <param name="updateDto">The DTO to update an entity from.</param>
|
||||
/// <returns>A service message indicating success or failure.</returns>
|
||||
public virtual async Task<Result> UpdateAsync<TUpdateDto>(TUpdateDto updateDto) where TUpdateDto : IUnique<TId>
|
||||
public virtual async Task<Result> UpdateAsync<TUpdateDto>(TUpdateDto updateDto)
|
||||
{
|
||||
var currentEntitiy = await _repository.ReadByIdAsync(updateDto.Id);
|
||||
var currentEntitiy = await _repository.ReadByIdAsync(updateDto.GetIdOrDefault<TId>());
|
||||
|
||||
if (currentEntitiy is null)
|
||||
return Result.Fail().Notice(LogLevel.Warning, Flag.NotFound, $"{updateDto.Id} is not found in update process of {GetType()} entity.");
|
||||
return Result.Fail().Notice(LogLevel.Warning, Flag.NotFound, $"{updateDto.GetIdOrDefault<TId>()} is not found in update process of {GetType()} entity.");
|
||||
|
||||
var entity = _mapper.Map(updateDto, currentEntitiy);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user