50 lines
1.9 KiB
Java
50 lines
1.9 KiB
Java
package com.iconplus.smartproc.service.jeniskontrak;
|
|
|
|
import com.iconplus.smartproc.exception.BusinessException;
|
|
import com.iconplus.smartproc.helper.service.BaseService;
|
|
import com.iconplus.smartproc.model.entity.JenisKontrak;
|
|
import com.iconplus.smartproc.model.request.JenisKontrakRequest;
|
|
import com.iconplus.smartproc.model.response.JenisKontrakResponse;
|
|
import com.iconplus.smartproc.repository.JenisKontrakRepository;
|
|
import com.iconplus.smartproc.util.Constants;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
@Service
|
|
@Slf4j
|
|
public class PostCreateJenisKontrakService implements BaseService<JenisKontrakRequest, JenisKontrakResponse> {
|
|
|
|
private final JenisKontrakRepository jenisKontrakRepository;
|
|
|
|
public PostCreateJenisKontrakService(JenisKontrakRepository jenisKontrakRepository) {
|
|
this.jenisKontrakRepository = jenisKontrakRepository;
|
|
}
|
|
|
|
@Override
|
|
public JenisKontrakResponse execute(JenisKontrakRequest input) {
|
|
|
|
var existJenisKontrak = jenisKontrakRepository.findByJenisKontrakAndIsDeleteFalse(input.getJenisKontrak());
|
|
if (existJenisKontrak.isPresent()) {
|
|
throw new BusinessException(HttpStatus.CONFLICT,
|
|
Constants.ERR_CODE_10002,
|
|
Constants.ERR_TTL_10002,
|
|
String.format(Constants.ERR_MSG_10002, "Jenis Kontrak", input.getJenisKontrak()));
|
|
}
|
|
|
|
JenisKontrak jenisKontrak = JenisKontrak.builder()
|
|
.jenisKontrak(input.getJenisKontrak())
|
|
.isActive(input.getIsActive())
|
|
.keterangan(input.getKeterangan())
|
|
.isDelete(false)
|
|
.build();
|
|
|
|
var result = jenisKontrakRepository.save(jenisKontrak);
|
|
log.info("success insert jenis kontrak id : {}", result.getId());
|
|
return JenisKontrakResponse.builder()
|
|
.id(result.getId())
|
|
.build();
|
|
|
|
}
|
|
}
|