Test all Java
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package com.iconplus.smartproc.service.jenispengadaan;
|
||||
|
||||
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.entity.JenisPengadaan;
|
||||
import com.iconplus.smartproc.model.request.JenisPengadaanRequest;
|
||||
import com.iconplus.smartproc.repository.JenisPengadaanRepository;
|
||||
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 DeleteJenisPengadaanService implements BaseService<JenisPengadaanRequest, EmptyResponse> {
|
||||
|
||||
private JenisPengadaanRepository jenisPengadaanRepository;
|
||||
|
||||
public DeleteJenisPengadaanService(JenisPengadaanRepository jenisPengadaanRepository) {
|
||||
this.jenisPengadaanRepository = jenisPengadaanRepository;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public EmptyResponse execute(JenisPengadaanRequest input) {
|
||||
|
||||
var jenisPengadaan = jenisPengadaanRepository.findByIdAndDeletedFalse(input.getId())
|
||||
.orElseThrow(() -> new BusinessException(HttpStatus.CONFLICT,
|
||||
Constants.ERR_CODE_10001,
|
||||
Constants.ERR_TTL_10001,
|
||||
String.format(Constants.ERR_MSG_10001, input.getId())));
|
||||
|
||||
jenisPengadaan.setIsDelete(true);
|
||||
jenisPengadaanRepository.save(jenisPengadaan);
|
||||
log.info("success delete jenis pengadaan id {}", jenisPengadaan.getIsDelete());
|
||||
return new EmptyResponse();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.iconplus.smartproc.service.jenispengadaan;
|
||||
|
||||
import com.iconplus.smartproc.exception.BusinessException;
|
||||
import com.iconplus.smartproc.helper.service.BaseService;
|
||||
import com.iconplus.smartproc.model.request.JenisPengadaanRequest;
|
||||
import com.iconplus.smartproc.model.response.JenisPengadaanResponse;
|
||||
import com.iconplus.smartproc.repository.JenisPengadaanRepository;
|
||||
import com.iconplus.smartproc.util.Constants;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
@Service
|
||||
public class GetJenisPengadaanByIdService implements BaseService<JenisPengadaanRequest, JenisPengadaanResponse> {
|
||||
|
||||
private final JenisPengadaanRepository jenisPengadaanRepository;
|
||||
|
||||
public GetJenisPengadaanByIdService(JenisPengadaanRepository jenisPengadaanRepository) {
|
||||
this.jenisPengadaanRepository = jenisPengadaanRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JenisPengadaanResponse execute(JenisPengadaanRequest input) {
|
||||
JenisPengadaanResponse jenisPengadaanResponse = new JenisPengadaanResponse();
|
||||
var jenisPengadaanView = jenisPengadaanRepository.findByIdAndDeletedFalse(input.getId());
|
||||
if (jenisPengadaanView.isEmpty()) {
|
||||
throw new BusinessException(HttpStatus.CONFLICT,
|
||||
Constants.ERR_CODE_10001,
|
||||
Constants.ERR_TTL_10001,
|
||||
String.format(Constants.ERR_MSG_10001, input.getId()));
|
||||
}
|
||||
|
||||
jenisPengadaanResponse.setJenisPengadaan(jenisPengadaanView.get().getJenisPengadaan());
|
||||
jenisPengadaanResponse.setKeterangan(jenisPengadaanView.get().getKeterangan());
|
||||
jenisPengadaanResponse.setIsDelete(jenisPengadaanView.get().getIsDelete());
|
||||
|
||||
return JenisPengadaanResponse.builder()
|
||||
.id(jenisPengadaanView.get().getId())
|
||||
.jenisPengadaan(jenisPengadaanView.get().getJenisPengadaan())
|
||||
.keterangan(jenisPengadaanView.get().getKeterangan())
|
||||
.isDelete(jenisPengadaanView.get().getIsDelete())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.iconplus.smartproc.service.jenispengadaan;
|
||||
|
||||
import com.iconplus.smartproc.helper.model.Pagination;
|
||||
import com.iconplus.smartproc.helper.service.BaseService;
|
||||
import com.iconplus.smartproc.model.projection.JenisPengadaanView;
|
||||
import com.iconplus.smartproc.model.request.JenisPengadaanRequest;
|
||||
import com.iconplus.smartproc.model.response.GetListJenisPengadaanResponse;
|
||||
import com.iconplus.smartproc.model.response.JenisPengadaanResponse;
|
||||
import com.iconplus.smartproc.repository.JenisPengadaanRepository;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
// kontrak
|
||||
@Service
|
||||
public class GetListJenisPengadaanService implements BaseService<JenisPengadaanRequest, GetListJenisPengadaanResponse> {
|
||||
|
||||
private JenisPengadaanRepository jenisPengadaanRepository;
|
||||
|
||||
public GetListJenisPengadaanService(JenisPengadaanRepository jenisPengadaanRepository) {
|
||||
this.jenisPengadaanRepository = jenisPengadaanRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetListJenisPengadaanResponse execute(JenisPengadaanRequest input) {
|
||||
validateRequest(input);
|
||||
List<JenisPengadaanResponse> jenisPengadaanResponseList = new ArrayList<>();
|
||||
var jenisPengadaanViews = jenisPengadaanRepository.getAllJenisPengadaan(input.getSearch(), input.getPageable());
|
||||
|
||||
for (JenisPengadaanView jenisPengadaanView : jenisPengadaanViews) {
|
||||
JenisPengadaanResponse jenisPengadaanResponse = JenisPengadaanResponse.builder()
|
||||
.id(jenisPengadaanView.getId())
|
||||
.jenisPengadaan(jenisPengadaanView.getJenisPengadaan())
|
||||
.keterangan(jenisPengadaanView.getKeterangan())
|
||||
.isDelete(jenisPengadaanView.getIsDelete())
|
||||
.build();
|
||||
jenisPengadaanResponseList.add(jenisPengadaanResponse);
|
||||
}
|
||||
|
||||
return GetListJenisPengadaanResponse.builder()
|
||||
.data(jenisPengadaanResponseList)
|
||||
.pagination(Pagination.builder()
|
||||
.pageSize(input.getPageable().getPageSize())
|
||||
.currentPage(input.getPageable().getPageNumber())
|
||||
.totalPages(jenisPengadaanViews.getTotalPages())
|
||||
.totalRecords(jenisPengadaanViews.getTotalElements())
|
||||
.isFirstPage(jenisPengadaanViews.isFirst())
|
||||
.isLastPage(jenisPengadaanViews.isLast())
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
private void validateRequest(JenisPengadaanRequest input) {
|
||||
if (StringUtils.isNotBlank(input.getSearch())) {
|
||||
input.setSearch('%'+ input.getSearch().toUpperCase()+'%');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.iconplus.smartproc.service.jenispengadaan;
|
||||
|
||||
import com.iconplus.smartproc.exception.BusinessException;
|
||||
import com.iconplus.smartproc.helper.service.BaseService;
|
||||
import com.iconplus.smartproc.model.entity.JenisPengadaan;
|
||||
import com.iconplus.smartproc.model.request.JenisPengadaanRequest;
|
||||
import com.iconplus.smartproc.model.response.JenisPengadaanResponse;
|
||||
import com.iconplus.smartproc.repository.JenisPengadaanRepository;
|
||||
import com.iconplus.smartproc.util.Constants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PostCreateJenisPengadaanService implements BaseService<JenisPengadaanRequest, JenisPengadaanResponse> {
|
||||
|
||||
private final JenisPengadaanRepository jenisPengadaanRepository;
|
||||
|
||||
public PostCreateJenisPengadaanService(JenisPengadaanRepository jenisPengadaanRepository) {
|
||||
this.jenisPengadaanRepository = jenisPengadaanRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JenisPengadaanResponse execute(JenisPengadaanRequest input) {
|
||||
|
||||
var existJenisPengadaan = jenisPengadaanRepository.findByJenisPengadaanAndDeletedFalse(input.getJenisPengadaan());
|
||||
if (existJenisPengadaan.isPresent()) {
|
||||
throw new BusinessException(HttpStatus.CONFLICT,
|
||||
Constants.ERR_CODE_10002,
|
||||
Constants.ERR_TTL_10002,
|
||||
String.format(Constants.ERR_MSG_10002, existJenisPengadaan.get().getId()));
|
||||
}
|
||||
|
||||
JenisPengadaan jenisPengadaan = JenisPengadaan.builder()
|
||||
.jenisPengadaan(input.getJenisPengadaan())
|
||||
.keterangan(input.getKeterangan())
|
||||
.isDelete(false)
|
||||
.build();
|
||||
// jenisKontrak.setCreatedTime(new Timestamp(System.currentTimeMillis()));
|
||||
|
||||
var result = jenisPengadaanRepository.save(jenisPengadaan);
|
||||
log.info("success insert jenis kontrak id : {}", result.getId());
|
||||
return JenisPengadaanResponse.builder()
|
||||
.id(result.getId())
|
||||
.build();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.iconplus.smartproc.service.jenispengadaan;
|
||||
|
||||
import com.iconplus.smartproc.exception.BusinessException;
|
||||
import com.iconplus.smartproc.helper.service.BaseService;
|
||||
import com.iconplus.smartproc.model.request.JenisPengadaanRequest;
|
||||
import com.iconplus.smartproc.model.response.JenisPengadaanResponse;
|
||||
import com.iconplus.smartproc.repository.JenisPengadaanRepository;
|
||||
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 PutUpdateJenisPengadaanService implements BaseService<JenisPengadaanRequest, JenisPengadaanResponse> {
|
||||
|
||||
private JenisPengadaanRepository jenisPengadaanRepository;
|
||||
|
||||
public PutUpdateJenisPengadaanService(JenisPengadaanRepository jenisPengadaanRepository) {
|
||||
this.jenisPengadaanRepository = jenisPengadaanRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JenisPengadaanResponse execute(JenisPengadaanRequest input) {
|
||||
|
||||
var jenisPengadaan = jenisPengadaanRepository.findByIdAndDeletedFalse(input.getId())
|
||||
.orElseThrow(() -> new BusinessException(HttpStatus.CONFLICT,
|
||||
Constants.ERR_CODE_10001,
|
||||
Constants.ERR_TTL_10001,
|
||||
String.format(Constants.ERR_MSG_10001, input.getId())));
|
||||
|
||||
jenisPengadaan.setJenisPengadaan(input.getJenisPengadaan());
|
||||
jenisPengadaan.setKeterangan(input.getKeterangan());
|
||||
jenisPengadaan.setIsDelete(BooleanUtils.isTrue(input.getDeleted()));
|
||||
jenisPengadaan.setLastUpdate(new Timestamp(System.currentTimeMillis()));
|
||||
jenisPengadaanRepository.save(jenisPengadaan);
|
||||
log.info("Success edit jenis pengadaan id {}", jenisPengadaan.getId());
|
||||
return JenisPengadaanResponse.builder()
|
||||
.id(jenisPengadaan.getId())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user