prueba tecnica

This commit is contained in:
Alejandro
2025-06-15 18:29:25 +02:00
parent 9758ee0bc6
commit d97e55a83f
127 changed files with 6488 additions and 1 deletions

View File

@@ -0,0 +1,56 @@
using AutoMapper;
using ProximaContracts.Application.Rates.Services;
using ProximaContracts.Domain.Contracts.DTOs.Request;
using ProximaContracts.Domain.Contracts.DTOs.Response;
using ProximaContracts.Infrastructure.Rpositories.Contracts;
using ProximaContracts.Shared.Exceptions.Repositories.Contract;
namespace ProximaContracts.Application.Contracts.Services
{
public class ContractService(IContractRepository repository, IMapper mapper, IRateService rateService) : IContractService
{
private readonly IContractRepository _repository = repository;
private readonly IMapper _mapper = mapper;
private readonly IRateService _rateService = rateService;
public async Task<ContractByIdResponseDto> GetContractById(ContractByIdRequestDto dto)
{
var result = await _repository.GetContractById(dto);
return _mapper.Map< ContractByIdResponseDto>(result);
}
public async Task<IEnumerable<GetContractsResponseDto>> GetContracts()
{
var result = await _repository.GetContracts();
return _mapper.Map<List<GetContractsResponseDto>>(result);
}
public async Task<CreateContractResponseDto> CreateContract(CreateContractRequestDto dto)
{
var rateExists = await _rateService.CheckIfExists(dto.RateId);
if (!rateExists)
{
throw new CreateContractRateNotFoundException($"No rate found with id: {dto.RateId}, Contract can't be created.");
}
var result = await _repository.CreateContract(dto);
return new CreateContractResponseDto()
{
IsCreated = result.HasValue ? true : false,
Message = result.HasValue ? "Created" : "Error creating contract",
NewContractId = result.HasValue ? result.Value : 0
};
}
public async Task<UpdateContractResponseDto> UpdateContract(UpdateContractRequestDto dto)
{
var result = await _repository.UpdateContract(dto);
return new UpdateContractResponseDto()
{
IsUpdated = result.HasValue ? true : false,
Message = result.HasValue ? "Updated" : "Error updating contract",
ContractId = result.HasValue ? result.Value : 0
};
}
}
}