add master data api
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package com.iconplus.smartproc.service.jeniskontrak;
|
||||
|
||||
import com.iconplus.smartproc.exception.BusinessException;
|
||||
import com.iconplus.smartproc.helper.model.EmptyResponse;
|
||||
import com.iconplus.smartproc.helper.service.BaseService;
|
||||
import com.iconplus.smartproc.model.request.JenisKontrakRequest;
|
||||
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 DeleteJenisKontrakService implements BaseService<JenisKontrakRequest, EmptyResponse> {
|
||||
|
||||
private JenisKontrakRepository jenisKontrakRepository;
|
||||
|
||||
public DeleteJenisKontrakService(JenisKontrakRepository jenisKontrakRepository) {
|
||||
this.jenisKontrakRepository = jenisKontrakRepository;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public EmptyResponse execute(JenisKontrakRequest input) {
|
||||
|
||||
var jenisKontrak = jenisKontrakRepository.findByIdAndIsDeleteFalse(input.getId())
|
||||
.orElseThrow(() -> new BusinessException(HttpStatus.CONFLICT,
|
||||
Constants.ERR_CODE_10001,
|
||||
Constants.ERR_TTL_10001,
|
||||
String.format(Constants.ERR_MSG_10001, input.getId())));
|
||||
|
||||
jenisKontrak.setIsDelete(true);
|
||||
jenisKontrakRepository.save(jenisKontrak);
|
||||
log.info("success delete jenis kontrak id {}", jenisKontrak.getIsDelete());
|
||||
return new EmptyResponse();
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
package com.iconplus.smartproc.service.jeniskontrak;
|
||||
|
||||
import com.iconplus.smartproc.exception.BusinessException;
|
||||
import com.iconplus.smartproc.helper.service.BaseService;
|
||||
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 org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
@Service
|
||||
public class GetJenisKontrakByIdService implements BaseService<JenisKontrakRequest, JenisKontrakResponse> {
|
||||
|
||||
private final JenisKontrakRepository jenisKontrakRepository;
|
||||
|
||||
public GetJenisKontrakByIdService(JenisKontrakRepository jenisKontrakRepository) {
|
||||
this.jenisKontrakRepository = jenisKontrakRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JenisKontrakResponse execute(JenisKontrakRequest input) {
|
||||
var jenisKontrakView = jenisKontrakRepository.findByIdAndIsDeleteFalse(input.getId());
|
||||
if (jenisKontrakView.isEmpty()) {
|
||||
throw new BusinessException(HttpStatus.CONFLICT,
|
||||
Constants.ERR_CODE_10001,
|
||||
Constants.ERR_TTL_10001,
|
||||
String.format(Constants.ERR_MSG_10001, input.getId()));
|
||||
}
|
||||
|
||||
return JenisKontrakResponse.builder()
|
||||
.id(jenisKontrakView.get().getId())
|
||||
.jenisKontrak(jenisKontrakView.get().getJenisKontrak())
|
||||
.keterangan(jenisKontrakView.get().getKeterangan())
|
||||
.isActive(jenisKontrakView.get().getIsActive())
|
||||
.isDelete(jenisKontrakView.get().getIsDelete())
|
||||
.build();
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
package com.iconplus.smartproc.service.jeniskontrak;
|
||||
|
||||
import com.iconplus.smartproc.helper.model.Pagination;
|
||||
import com.iconplus.smartproc.helper.service.BaseService;
|
||||
import com.iconplus.smartproc.model.projection.JenisKontrakView;
|
||||
import com.iconplus.smartproc.model.request.JenisKontrakRequest;
|
||||
import com.iconplus.smartproc.model.response.GetListJenisKontrakResponse;
|
||||
import com.iconplus.smartproc.model.response.JenisKontrakResponse;
|
||||
import com.iconplus.smartproc.repository.JenisKontrakRepository;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Service
|
||||
public class GetListJenisKontrakService implements BaseService<JenisKontrakRequest, GetListJenisKontrakResponse> {
|
||||
|
||||
private JenisKontrakRepository jenisKontrakRepository;
|
||||
|
||||
public GetListJenisKontrakService(JenisKontrakRepository jenisKontrakRepository) {
|
||||
this.jenisKontrakRepository = jenisKontrakRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetListJenisKontrakResponse execute(JenisKontrakRequest input) {
|
||||
validateRequest(input);
|
||||
List<JenisKontrakResponse> jenisKontrakResponseList = new ArrayList<>();
|
||||
var jenisKontrakViews = jenisKontrakRepository.getAllJenisKontrak(input.getSearch(), input.getPageable());
|
||||
|
||||
for (JenisKontrakView jenisKontrakView : jenisKontrakViews) {
|
||||
JenisKontrakResponse jenisKontrakResponse = JenisKontrakResponse.builder()
|
||||
.id(jenisKontrakView.getId())
|
||||
.jenisKontrak(jenisKontrakView.getJenisKontrak())
|
||||
.keterangan(jenisKontrakView.getKeterangan())
|
||||
.isActive(jenisKontrakView.getIsActive())
|
||||
.isDelete(jenisKontrakView.getIsDelete())
|
||||
.build();
|
||||
jenisKontrakResponseList.add(jenisKontrakResponse);
|
||||
}
|
||||
|
||||
return GetListJenisKontrakResponse.builder()
|
||||
.data(jenisKontrakResponseList)
|
||||
.pagination(Pagination.builder()
|
||||
.pageSize(input.getPageable().getPageSize())
|
||||
.currentPage(input.getPageable().getPageNumber())
|
||||
.totalPages(jenisKontrakViews.getTotalPages())
|
||||
.totalRecords(jenisKontrakViews.getTotalElements())
|
||||
.isFirstPage(jenisKontrakViews.isFirst())
|
||||
.isLastPage(jenisKontrakViews.isLast())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
private void validateRequest(JenisKontrakRequest input) {
|
||||
if (StringUtils.isNotBlank(input.getSearch())) {
|
||||
input.setSearch('%'+ input.getSearch().toUpperCase()+'%');
|
||||
}
|
||||
}
|
||||
}
|
@@ -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();
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
package com.iconplus.smartproc.service.jeniskontrak;
|
||||
|
||||
import com.iconplus.smartproc.exception.BusinessException;
|
||||
import com.iconplus.smartproc.helper.service.BaseService;
|
||||
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.apache.commons.lang3.BooleanUtils;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PutUpdateJenisKontrakService implements BaseService<JenisKontrakRequest, JenisKontrakResponse> {
|
||||
|
||||
private JenisKontrakRepository jenisKontrakRepository;
|
||||
|
||||
public PutUpdateJenisKontrakService(JenisKontrakRepository jenisKontrakRepository) {
|
||||
this.jenisKontrakRepository = jenisKontrakRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JenisKontrakResponse execute(JenisKontrakRequest input) {
|
||||
|
||||
var jenisKontrak = jenisKontrakRepository.findByIdAndIsDeleteFalse(input.getId())
|
||||
.orElseThrow(() -> new BusinessException(HttpStatus.CONFLICT,
|
||||
Constants.ERR_CODE_10001,
|
||||
Constants.ERR_TTL_10001,
|
||||
String.format(Constants.ERR_MSG_10001, input.getId())));
|
||||
|
||||
jenisKontrak.setJenisKontrak(input.getJenisKontrak());
|
||||
jenisKontrak.setKeterangan(input.getKeterangan());
|
||||
jenisKontrak.setIsActive(input.getIsActive());
|
||||
jenisKontrakRepository.save(jenisKontrak);
|
||||
log.info("Success edit jenis kontrak id {}", jenisKontrak.getId());
|
||||
return JenisKontrakResponse.builder()
|
||||
.id(jenisKontrak.getId())
|
||||
.build();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user