enhance crud jenis pengadaan
This commit is contained in:
@ -5,9 +5,7 @@ import com.iconplus.smartproc.helper.model.EmptyResponse;
|
|||||||
import com.iconplus.smartproc.model.request.JenisAnggaranRequest;
|
import com.iconplus.smartproc.model.request.JenisAnggaranRequest;
|
||||||
import com.iconplus.smartproc.model.response.GetListJenisAnggaranResponse;
|
import com.iconplus.smartproc.model.response.GetListJenisAnggaranResponse;
|
||||||
import com.iconplus.smartproc.model.response.JenisAnggaranResponse;
|
import com.iconplus.smartproc.model.response.JenisAnggaranResponse;
|
||||||
import com.iconplus.smartproc.repository.JenisAnggaranRepository;
|
|
||||||
import com.iconplus.smartproc.service.jenisanggaran.*;
|
import com.iconplus.smartproc.service.jenisanggaran.*;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@ -17,9 +15,6 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
@RequestMapping("/api/jenisanggaran")
|
@RequestMapping("/api/jenisanggaran")
|
||||||
public class JenisAnggaranController {
|
public class JenisAnggaranController {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JenisAnggaranRepository jenisanggaranRepository;
|
|
||||||
|
|
||||||
private final GetListJenisAnggaranService getListJenisAnggaranService;
|
private final GetListJenisAnggaranService getListJenisAnggaranService;
|
||||||
private final GetJenisAnggaranByIdService getJenisAnggaranByIdService;
|
private final GetJenisAnggaranByIdService getJenisAnggaranByIdService;
|
||||||
private final PostCreateJenisAnggaranService postCreateJenisAnggaranService;
|
private final PostCreateJenisAnggaranService postCreateJenisAnggaranService;
|
||||||
|
@ -1,65 +1,75 @@
|
|||||||
package com.iconplus.smartproc.controller;
|
package com.iconplus.smartproc.controller;
|
||||||
|
|
||||||
import com.iconplus.smartproc.model.entity.JenisPengadaan;
|
import com.iconplus.smartproc.helper.model.EmptyResponse;
|
||||||
import com.iconplus.smartproc.exception.ResourceNotFoundException;
|
import com.iconplus.smartproc.model.request.JenisPengadaanRequest;
|
||||||
import com.iconplus.smartproc.repository.JenisPengadaanRepository;
|
import com.iconplus.smartproc.model.response.GetListJenisPengadaanResponse;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import com.iconplus.smartproc.model.response.JenisPengadaanResponse;
|
||||||
import org.springframework.http.ResponseEntity;
|
import com.iconplus.smartproc.service.jenispengadaan.*;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@CrossOrigin(origins = "http://localhost:8080", allowCredentials = "true")
|
@CrossOrigin(origins = "http://localhost:8080", allowCredentials = "true")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/jenispengadaan")
|
@RequestMapping("/api/jenispengadaan")
|
||||||
public class JenisPengadaanController {
|
public class JenisPengadaanController {
|
||||||
@Autowired
|
|
||||||
private JenisPengadaanRepository jenispengadaanRepository;
|
|
||||||
|
|
||||||
//get all data
|
private final GetListJenisPengadaanService getListJenisPengadaanService;
|
||||||
|
private final GetJenisPengadaanService getJenisPengadaanService;
|
||||||
|
private final PostCreateJenisPengadaanService postCreateJenisPengadaanService;
|
||||||
|
private final DeleteJenisPengadaanService deleteJenisPengadaanService;
|
||||||
|
private final PutUpdateJenisPengadaanService putUpdateJenisPengadaanService;
|
||||||
|
|
||||||
|
public JenisPengadaanController(GetListJenisPengadaanService getListJenisPengadaanService,
|
||||||
|
GetJenisPengadaanService getJenisPengadaanService,
|
||||||
|
PostCreateJenisPengadaanService postCreateJenisPengadaanService,
|
||||||
|
DeleteJenisPengadaanService deleteJenisPengadaanService,
|
||||||
|
PutUpdateJenisPengadaanService putUpdateJenisPengadaanService) {
|
||||||
|
this.getListJenisPengadaanService = getListJenisPengadaanService;
|
||||||
|
this.getJenisPengadaanService = getJenisPengadaanService;
|
||||||
|
this.postCreateJenisPengadaanService = postCreateJenisPengadaanService;
|
||||||
|
this.deleteJenisPengadaanService = deleteJenisPengadaanService;
|
||||||
|
this.putUpdateJenisPengadaanService = putUpdateJenisPengadaanService;
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public List<JenisPengadaan> getAllJenispengadaans(){
|
public GetListJenisPengadaanResponse getListJenisPengadaan(@RequestParam(name = "search", required = false) String search,
|
||||||
return jenispengadaanRepository.findAll();
|
@RequestParam(name = "page", defaultValue = "1") Integer page,
|
||||||
|
@RequestParam(name = "size", defaultValue = "5") Integer size){
|
||||||
|
|
||||||
|
Pageable pageable = PageRequest.of((page - 1), size);
|
||||||
|
JenisPengadaanRequest jenisPengadaanRequest = JenisPengadaanRequest.builder()
|
||||||
|
.search(search)
|
||||||
|
.pageable(pageable)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return getListJenisPengadaanService.execute(jenisPengadaanRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public JenisPengadaan createJenispengadaan(@RequestBody JenisPengadaan jenispengadaan) {
|
public JenisPengadaanResponse createJenisPengadaan(@RequestBody JenisPengadaanRequest jenisPengadaanRequest) {
|
||||||
return jenispengadaanRepository.save(jenispengadaan);
|
return postCreateJenisPengadaanService.execute(jenisPengadaanRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get jenispengadaan by id rest api
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
public ResponseEntity<JenisPengadaan> getJenispengadaanById(@PathVariable Long id) {
|
public JenisPengadaanResponse getJenisPengadaannById(@PathVariable Long id) {
|
||||||
JenisPengadaan jenispengadaan = jenispengadaanRepository.findById(id)
|
return getJenisPengadaanService.execute(JenisPengadaanRequest.builder()
|
||||||
.orElseThrow(() -> new ResourceNotFoundException("Jenispengadaan not exist with id :" + id));
|
.id(id)
|
||||||
return ResponseEntity.ok(jenispengadaan);
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
// update jenispengadaan rest api
|
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
public ResponseEntity<JenisPengadaan> updateJenispengadaan(@PathVariable Long id, @RequestBody JenisPengadaan jenisPengadaanDetails){
|
public JenisPengadaanResponse updateJenisPengadaan(@PathVariable Long id,
|
||||||
JenisPengadaan jenispengadaan = jenispengadaanRepository.findById(id)
|
@RequestBody JenisPengadaanRequest jenisPengadaanRequest){
|
||||||
.orElseThrow(() -> new ResourceNotFoundException("Jenispengadaan not exist with id :" + id));
|
jenisPengadaanRequest.setId(id);
|
||||||
|
return putUpdateJenisPengadaanService.execute(jenisPengadaanRequest);
|
||||||
jenispengadaan.setJenisPengadaan(jenisPengadaanDetails.getJenisPengadaan());
|
|
||||||
jenispengadaan.setKeterangan(jenisPengadaanDetails.getKeterangan());
|
|
||||||
|
|
||||||
JenisPengadaan updatedJenisPengadaan = jenispengadaanRepository.save(jenispengadaan);
|
|
||||||
return ResponseEntity.ok(updatedJenisPengadaan);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete jenispengadaan rest api
|
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
public ResponseEntity<Map<String, Boolean>> deleteJenispengadaan(@PathVariable Long id){
|
public EmptyResponse deleteJenisAnggaran(@PathVariable Long id) {
|
||||||
JenisPengadaan jenispengadaan = jenispengadaanRepository.findById(id)
|
return deleteJenisPengadaanService.execute(JenisPengadaanRequest.builder()
|
||||||
.orElseThrow(() -> new ResourceNotFoundException("Supposmatrix not exist with id :" + id));
|
.id(id)
|
||||||
|
.build());
|
||||||
jenispengadaanRepository.delete(jenispengadaan);
|
|
||||||
Map<String, Boolean> response = new HashMap<>();
|
|
||||||
response.put("deleted", Boolean.TRUE);
|
|
||||||
return ResponseEntity.ok(response);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.iconplus.smartproc.model.projection;
|
||||||
|
|
||||||
|
public interface JenisPengadaanView {
|
||||||
|
|
||||||
|
Long getId();
|
||||||
|
void setId(Long id);
|
||||||
|
|
||||||
|
String getJenisPengadaan();
|
||||||
|
void setJenisPengadaan(String jenisPengadaan);
|
||||||
|
|
||||||
|
String getKeterangan();
|
||||||
|
void setKeterangan(String keterangan);
|
||||||
|
|
||||||
|
Boolean getIsActive();
|
||||||
|
void setIsActive(Boolean isActive);
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.iconplus.smartproc.model.request;
|
||||||
|
|
||||||
|
import com.iconplus.smartproc.helper.base.BaseRequest;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class JenisPengadaanRequest extends BaseRequest {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private String jenisPengadaan;
|
||||||
|
private String keterangan;
|
||||||
|
private Boolean isActive;
|
||||||
|
private String search;
|
||||||
|
private transient Pageable pageable;
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.iconplus.smartproc.model.response;
|
||||||
|
|
||||||
|
import com.iconplus.smartproc.helper.base.BaseResponse;
|
||||||
|
import com.iconplus.smartproc.helper.model.Pagination;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class GetListJenisPengadaanResponse extends BaseResponse {
|
||||||
|
|
||||||
|
private List<JenisPengadaanResponse> data;
|
||||||
|
private Pagination pagination;
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.iconplus.smartproc.model.response;
|
||||||
|
|
||||||
|
import com.iconplus.smartproc.helper.base.BaseResponse;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class JenisPengadaanResponse extends BaseResponse {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private String jenisPengadaan;
|
||||||
|
private String keterangan;
|
||||||
|
private Boolean isActive;
|
||||||
|
private Boolean isDelete;
|
||||||
|
|
||||||
|
}
|
@ -1,10 +1,29 @@
|
|||||||
package com.iconplus.smartproc.repository;
|
package com.iconplus.smartproc.repository;
|
||||||
|
|
||||||
import com.iconplus.smartproc.model.entity.JenisPengadaan;
|
import com.iconplus.smartproc.model.entity.JenisPengadaan;
|
||||||
|
import com.iconplus.smartproc.model.projection.JenisPengadaanView;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface JenisPengadaanRepository extends JpaRepository<JenisPengadaan, Long> {
|
public interface JenisPengadaanRepository extends JpaRepository<JenisPengadaan, Long> {
|
||||||
|
|
||||||
|
Optional<JenisPengadaan> findByIdAndIsDeleteFalse(Long id);
|
||||||
|
Optional<JenisPengadaan> findByJenisPengadaanAndIsDeleteFalse(String jenisPengadaan);
|
||||||
|
|
||||||
|
@Query(value = "SELECT jp.id as id, " +
|
||||||
|
"jp.jenisPengadaan as jenisPengadaan, " +
|
||||||
|
"jp.keterangan as keterangan, " +
|
||||||
|
"jp.isActive as isActive " +
|
||||||
|
"FROM JenisPengadaan jp " +
|
||||||
|
"WHERE jp.isDelete = false " +
|
||||||
|
"AND (:search='' OR UPPER(jp.jenisPengadaan) like :search) " +
|
||||||
|
"ORDER BY jp.id")
|
||||||
|
Page<JenisPengadaanView> getListJenisPengadaan(String search, Pageable pageable);
|
||||||
|
|
||||||
}
|
}
|
@ -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