add master data api

This commit is contained in:
dirgantarasiahaan
2023-05-26 10:39:31 +07:00
parent c573eb2fb3
commit fe72608465
67 changed files with 2376 additions and 307 deletions

View File

@@ -0,0 +1,49 @@
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, existJenisKontrak.get().getId()));
}
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();
}
}