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.response.GetListJenisAnggaranResponse;
|
||||
import com.iconplus.smartproc.model.response.JenisAnggaranResponse;
|
||||
import com.iconplus.smartproc.repository.JenisAnggaranRepository;
|
||||
import com.iconplus.smartproc.service.jenisanggaran.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -17,9 +15,6 @@ import org.springframework.web.bind.annotation.*;
|
||||
@RequestMapping("/api/jenisanggaran")
|
||||
public class JenisAnggaranController {
|
||||
|
||||
@Autowired
|
||||
private JenisAnggaranRepository jenisanggaranRepository;
|
||||
|
||||
private final GetListJenisAnggaranService getListJenisAnggaranService;
|
||||
private final GetJenisAnggaranByIdService getJenisAnggaranByIdService;
|
||||
private final PostCreateJenisAnggaranService postCreateJenisAnggaranService;
|
||||
|
@ -1,65 +1,75 @@
|
||||
package com.iconplus.smartproc.controller;
|
||||
|
||||
import com.iconplus.smartproc.model.entity.JenisPengadaan;
|
||||
import com.iconplus.smartproc.exception.ResourceNotFoundException;
|
||||
import com.iconplus.smartproc.repository.JenisPengadaanRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import com.iconplus.smartproc.helper.model.EmptyResponse;
|
||||
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.service.jenispengadaan.*;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
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")
|
||||
@RestController
|
||||
@RequestMapping("/api/jenispengadaan")
|
||||
public class JenisPengadaanController {
|
||||
@Autowired
|
||||
private JenisPengadaanRepository jenispengadaanRepository;
|
||||
|
||||
//get all data
|
||||
@GetMapping
|
||||
public List<JenisPengadaan> getAllJenispengadaans(){
|
||||
return jenispengadaanRepository.findAll();
|
||||
}
|
||||
private final GetListJenisPengadaanService getListJenisPengadaanService;
|
||||
private final GetJenisPengadaanService getJenisPengadaanService;
|
||||
private final PostCreateJenisPengadaanService postCreateJenisPengadaanService;
|
||||
private final DeleteJenisPengadaanService deleteJenisPengadaanService;
|
||||
private final PutUpdateJenisPengadaanService putUpdateJenisPengadaanService;
|
||||
|
||||
// create
|
||||
@PostMapping
|
||||
public JenisPengadaan createJenispengadaan(@RequestBody JenisPengadaan jenispengadaan) {
|
||||
return jenispengadaanRepository.save(jenispengadaan);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
// get jenispengadaan by id rest api
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<JenisPengadaan> getJenispengadaanById(@PathVariable Long id) {
|
||||
JenisPengadaan jenispengadaan = jenispengadaanRepository.findById(id)
|
||||
.orElseThrow(() -> new ResourceNotFoundException("Jenispengadaan not exist with id :" + id));
|
||||
return ResponseEntity.ok(jenispengadaan);
|
||||
}
|
||||
@GetMapping
|
||||
public GetListJenisPengadaanResponse getListJenisPengadaan(@RequestParam(name = "search", required = false) String search,
|
||||
@RequestParam(name = "page", defaultValue = "1") Integer page,
|
||||
@RequestParam(name = "size", defaultValue = "5") Integer size){
|
||||
|
||||
// update jenispengadaan rest api
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<JenisPengadaan> updateJenispengadaan(@PathVariable Long id, @RequestBody JenisPengadaan jenisPengadaanDetails){
|
||||
JenisPengadaan jenispengadaan = jenispengadaanRepository.findById(id)
|
||||
.orElseThrow(() -> new ResourceNotFoundException("Jenispengadaan not exist with id :" + id));
|
||||
Pageable pageable = PageRequest.of((page - 1), size);
|
||||
JenisPengadaanRequest jenisPengadaanRequest = JenisPengadaanRequest.builder()
|
||||
.search(search)
|
||||
.pageable(pageable)
|
||||
.build();
|
||||
|
||||
jenispengadaan.setJenisPengadaan(jenisPengadaanDetails.getJenisPengadaan());
|
||||
jenispengadaan.setKeterangan(jenisPengadaanDetails.getKeterangan());
|
||||
return getListJenisPengadaanService.execute(jenisPengadaanRequest);
|
||||
}
|
||||
|
||||
JenisPengadaan updatedJenisPengadaan = jenispengadaanRepository.save(jenispengadaan);
|
||||
return ResponseEntity.ok(updatedJenisPengadaan);
|
||||
}
|
||||
@PostMapping
|
||||
public JenisPengadaanResponse createJenisPengadaan(@RequestBody JenisPengadaanRequest jenisPengadaanRequest) {
|
||||
return postCreateJenisPengadaanService.execute(jenisPengadaanRequest);
|
||||
}
|
||||
|
||||
// delete jenispengadaan rest api
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Map<String, Boolean>> deleteJenispengadaan(@PathVariable Long id){
|
||||
JenisPengadaan jenispengadaan = jenispengadaanRepository.findById(id)
|
||||
.orElseThrow(() -> new ResourceNotFoundException("Supposmatrix not exist with id :" + id));
|
||||
@GetMapping("/{id}")
|
||||
public JenisPengadaanResponse getJenisPengadaannById(@PathVariable Long id) {
|
||||
return getJenisPengadaanService.execute(JenisPengadaanRequest.builder()
|
||||
.id(id)
|
||||
.build());
|
||||
}
|
||||
|
||||
jenispengadaanRepository.delete(jenispengadaan);
|
||||
Map<String, Boolean> response = new HashMap<>();
|
||||
response.put("deleted", Boolean.TRUE);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public JenisPengadaanResponse updateJenisPengadaan(@PathVariable Long id,
|
||||
@RequestBody JenisPengadaanRequest jenisPengadaanRequest){
|
||||
jenisPengadaanRequest.setId(id);
|
||||
return putUpdateJenisPengadaanService.execute(jenisPengadaanRequest);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public EmptyResponse deleteJenisAnggaran(@PathVariable Long id) {
|
||||
return deleteJenisPengadaanService.execute(JenisPengadaanRequest.builder()
|
||||
.id(id)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user