Update CreateAsync to return DataResult<TReadDto>
Modified the CreateAsync method in CRUDService.cs and ICRUDService.cs to change the return type from DataResult<TId> to DataResult<TReadDto>. The implementation now maps the created entity to a read DTO, providing the caller with the complete entity representation instead of just its ID.
This commit is contained in:
parent
b95baaef5f
commit
d49aaf61dc
@ -33,11 +33,12 @@ namespace DigitalData.Core.Application
|
||||
/// </summary>
|
||||
/// <param name="createDto">The DTO to create an entity from.</param>
|
||||
/// <returns>A service result indicating success or failure, including the entity DTO.</returns>
|
||||
public virtual async Task<DataResult<TId>> CreateAsync(TCreateDto createDto)
|
||||
public virtual async Task<DataResult<TReadDto>> CreateAsync(TCreateDto createDto)
|
||||
{
|
||||
var entity = _mapper.Map<TEntity>(createDto);
|
||||
var createdEntity = await _repository.CreateAsync(entity);
|
||||
return createdEntity is null ? Result.Fail<TId>() : Result.Success(createdEntity.GetIdOrDefault<TId>());
|
||||
var dto = _mapper.Map<TReadDto>(createdEntity);
|
||||
return createdEntity is null ? Result.Fail<TReadDto>() : Result.Success(dto);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -12,7 +12,7 @@ namespace DigitalData.Core.Application.Interfaces
|
||||
/// </summary>
|
||||
/// <param name="createDto">The data transfer object containing the information for the new entity.</param>
|
||||
/// <returns>A task representing the asynchronous operation, with a <see cref="DataResult{TId}"/> containing the identifier of the created entity or an error message.</returns>
|
||||
Task<DataResult<TId>> CreateAsync(TCreateDto createDto);
|
||||
Task<DataResult<TReadDto>> CreateAsync(TCreateDto createDto);
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing entity based on the provided updateDTO and returns the result wrapped in an IServiceMessage,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user