upload dokumen

This commit is contained in:
dirgantarasiahaan
2023-05-30 11:12:25 +07:00
parent 746d7ec4ae
commit 06058d279e
14 changed files with 381 additions and 47 deletions

View File

@@ -0,0 +1,45 @@
package com.iconplus.smartproc.service.drp;
import com.iconplus.smartproc.exception.BusinessException;
import com.iconplus.smartproc.helper.service.BaseService;
import com.iconplus.smartproc.model.entity.Drp;
import com.iconplus.smartproc.model.request.DrpRequest;
import com.iconplus.smartproc.model.response.DrpResponse;
import com.iconplus.smartproc.repository.DrpRepository;
import com.iconplus.smartproc.util.Constants;
import org.springframework.stereotype.Service;
import java.util.Optional;
@Service
public class PostCreateTahunDrpService implements BaseService<DrpRequest, DrpResponse> {
private DrpRepository drpRepository;
public PostCreateTahunDrpService(DrpRepository drpRepository) {
this.drpRepository = drpRepository;
}
@Override
public DrpResponse execute(DrpRequest input) {
validateTahunDrp(input);
Drp drp = Drp.builder()
.tahun(input.getTahun())
.isDelete(false)
.build();
var result = drpRepository.save(drp);
return DrpResponse.builder()
.id(result.getId())
.build();
}
private void validateTahunDrp(DrpRequest input) {
Optional<Drp> drpOptional = drpRepository.findByTahunAndIsDeleteFalse(input.getTahun());
if (drpOptional.isPresent()) {
throw new BusinessException(Constants.ERR_CODE_10010,
Constants.ERR_TTL_10010,
Constants.ERR_MSG_10010);
}
}
}