76 lines
3.6 KiB
Java
76 lines
3.6 KiB
Java
package com.iconplus.smartproc.controller;
|
|
|
|
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.*;
|
|
|
|
@CrossOrigin(origins = "http://localhost:8080", allowCredentials = "true")
|
|
@RestController
|
|
@RequestMapping("/api/jenispengadaan")
|
|
public class JenisPengadaanController {
|
|
|
|
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
|
|
public GetListJenisPengadaanResponse getListJenisPengadaan(@RequestParam(name = "search", required = false) String search,
|
|
@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);
|
|
}
|
|
|
|
@PostMapping
|
|
public JenisPengadaanResponse createJenisPengadaan(@RequestBody JenisPengadaanRequest jenisPengadaanRequest) {
|
|
return postCreateJenisPengadaanService.execute(jenisPengadaanRequest);
|
|
}
|
|
|
|
@GetMapping("/{id}")
|
|
public JenisPengadaanResponse getJenisPengadaannById(@PathVariable Long id) {
|
|
return getJenisPengadaanService.execute(JenisPengadaanRequest.builder()
|
|
.id(id)
|
|
.build());
|
|
}
|
|
|
|
|
|
@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());
|
|
}
|
|
}
|