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 { 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 drpOptional = drpRepository.findByTahunAndIsDeleteFalse(input.getTahun()); if (drpOptional.isPresent()) { throw new BusinessException(Constants.ERR_CODE_10010, Constants.ERR_TTL_10010, Constants.ERR_MSG_10010); } } }