enhance crud jenis pengadaan
This commit is contained in:
@ -0,0 +1,26 @@
|
||||
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.request.JenisPengadaanRequest;
|
||||
import com.iconplus.smartproc.repository.JenisPengadaanRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
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.findByIdAndIsDeleteFalse(input.getId())
|
||||
.orElseThrow(() -> new BusinessException("err", "err", "err"));
|
||||
jenisPengadaan.setIsDelete(true);
|
||||
jenisPengadaanRepository.save(jenisPengadaan);
|
||||
return new EmptyResponse();
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
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 org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class GetJenisPengadaanService implements BaseService<JenisPengadaanRequest, JenisPengadaanResponse> {
|
||||
|
||||
private JenisPengadaanRepository jenisPengadaanRepository;
|
||||
public GetJenisPengadaanService(JenisPengadaanRepository jenisPengadaanRepository) {
|
||||
this.jenisPengadaanRepository = jenisPengadaanRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JenisPengadaanResponse execute(JenisPengadaanRequest input) {
|
||||
|
||||
var jenisPengadaan = jenisPengadaanRepository.findByIdAndIsDeleteFalse(input.getId())
|
||||
.orElseThrow(() -> new BusinessException("err", "err", "err"));
|
||||
|
||||
return JenisPengadaanResponse.builder()
|
||||
.id(jenisPengadaan.getId())
|
||||
.jenisPengadaan(jenisPengadaan.getJenisPengadaan())
|
||||
.keterangan(jenisPengadaan.getKeterangan())
|
||||
.isActive(jenisPengadaan.getIsActive())
|
||||
.isDelete(jenisPengadaan.getIsDelete())
|
||||
.build();
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
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;
|
||||
|
||||
@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.getListJenisPengadaan(input.getSearch(), input.getPageable());
|
||||
|
||||
for (JenisPengadaanView jenisPengadaanView : jenisPengadaanViews) {
|
||||
JenisPengadaanResponse jenisPengadaanResponse = JenisPengadaanResponse.builder()
|
||||
.id(jenisPengadaanView.getId())
|
||||
.jenisPengadaan(jenisPengadaanView.getJenisPengadaan())
|
||||
.keterangan(jenisPengadaanView.getKeterangan())
|
||||
.isActive(jenisPengadaanView.getIsActive())
|
||||
.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,37 @@
|
||||
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 org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class PostCreateJenisPengadaanService implements BaseService<JenisPengadaanRequest, JenisPengadaanResponse> {
|
||||
|
||||
private JenisPengadaanRepository jenisPengadaanRepository;
|
||||
public PostCreateJenisPengadaanService(JenisPengadaanRepository jenisPengadaanRepository) {
|
||||
this.jenisPengadaanRepository = jenisPengadaanRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JenisPengadaanResponse execute(JenisPengadaanRequest input) {
|
||||
var jenisPengadaan = jenisPengadaanRepository.findByJenisPengadaanAndIsDeleteFalse(input.getJenisPengadaan());
|
||||
if (jenisPengadaan.isPresent()) {
|
||||
throw new BusinessException("err", "err", "err");
|
||||
}
|
||||
|
||||
JenisPengadaan jenisPengadaanEntity = JenisPengadaan.builder()
|
||||
.jenisPengadaan(input.getJenisPengadaan())
|
||||
.keterangan(input.getKeterangan())
|
||||
.isActive(input.getIsActive())
|
||||
.isDelete(false)
|
||||
.build();
|
||||
var result = jenisPengadaanRepository.save(jenisPengadaanEntity);
|
||||
return JenisPengadaanResponse.builder()
|
||||
.id(result.getId())
|
||||
.build();
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
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 org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
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.findByIdAndIsDeleteFalse(input.getId())
|
||||
.orElseThrow(() -> new BusinessException("err", "err", "err"));
|
||||
jenisPengadaan.setJenisPengadaan(input.getJenisPengadaan());
|
||||
jenisPengadaan.setKeterangan(input.getKeterangan());
|
||||
jenisPengadaan.setIsActive(input.getIsActive());
|
||||
jenisPengadaanRepository.save(jenisPengadaan);
|
||||
return JenisPengadaanResponse.builder()
|
||||
.id(jenisPengadaan.getId())
|
||||
.build();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user