78 lines
3.9 KiB
Java
78 lines
3.9 KiB
Java
package com.iconplus.smartproc.controller;
|
|
|
|
|
|
import com.iconplus.smartproc.helper.model.EmptyResponse;
|
|
import com.iconplus.smartproc.model.request.MetodePengadaanRequest;
|
|
import com.iconplus.smartproc.model.response.GetListMetodePengadaanResponse;
|
|
import com.iconplus.smartproc.model.response.MetodePengadaanResponse;
|
|
import com.iconplus.smartproc.service.metodepengadaan.*;
|
|
import org.springframework.data.domain.PageRequest;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
@CrossOrigin(origins = "${fe.server}", allowCredentials = "true")
|
|
@RestController
|
|
@RequestMapping("/api/metodepengadaan")
|
|
public class MetodePengadaanController {
|
|
|
|
private final GetListMetodePengadaanService getListMetodePengadaanService;
|
|
private final GetMetodePengadaanByIdService getMetodePengadaanByIdService;
|
|
private final PostCreateMetodePengadaanService postCreateMetodePengadaanService;
|
|
private final PutUpdateMetodePengadaanService putUpdateMetodePengadaanService;
|
|
private final DeleteMetodePengadaanService deleteMetodePengadaanService;
|
|
|
|
public MetodePengadaanController(GetListMetodePengadaanService getListMetodePengadaanService,
|
|
GetMetodePengadaanByIdService getMetodePengadaanByIdService,
|
|
PostCreateMetodePengadaanService postCreateMetodePengadaanService,
|
|
PutUpdateMetodePengadaanService putUpdateMetodePengadaanService,
|
|
DeleteMetodePengadaanService deleteMetodePengadaanService) {
|
|
this.getListMetodePengadaanService = getListMetodePengadaanService;
|
|
this.getMetodePengadaanByIdService = getMetodePengadaanByIdService;
|
|
this.postCreateMetodePengadaanService = postCreateMetodePengadaanService;
|
|
this.putUpdateMetodePengadaanService = putUpdateMetodePengadaanService;
|
|
this.deleteMetodePengadaanService = deleteMetodePengadaanService;
|
|
}
|
|
|
|
|
|
@GetMapping
|
|
public GetListMetodePengadaanResponse getListMetodePengadaan(@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);
|
|
MetodePengadaanRequest metodePengadaanRequest = MetodePengadaanRequest.builder()
|
|
.search(search)
|
|
.pageable(pageable)
|
|
.build();
|
|
|
|
return getListMetodePengadaanService.execute(metodePengadaanRequest);
|
|
}
|
|
|
|
@PostMapping
|
|
public MetodePengadaanResponse createMetodePengadaan(@RequestBody MetodePengadaanRequest metodePengadaanRequest) {
|
|
return postCreateMetodePengadaanService.execute(metodePengadaanRequest);
|
|
}
|
|
|
|
@GetMapping("/{id}")
|
|
public MetodePengadaanResponse getMetodePengadaanById(@PathVariable Long id) {
|
|
return getMetodePengadaanByIdService.execute(MetodePengadaanRequest.builder()
|
|
.id(id)
|
|
.build());
|
|
}
|
|
|
|
|
|
@PutMapping("/{id}")
|
|
public MetodePengadaanResponse updateMetodepengadaan(@PathVariable Long id,
|
|
@RequestBody MetodePengadaanRequest metodePengadaanRequest){
|
|
metodePengadaanRequest.setId(id);
|
|
return putUpdateMetodePengadaanService.execute(metodePengadaanRequest);
|
|
}
|
|
|
|
@DeleteMapping("/{id}")
|
|
public EmptyResponse deleteMetodePengadaan(@PathVariable Long id) {
|
|
return deleteMetodePengadaanService.execute(MetodePengadaanRequest.builder()
|
|
.id(id)
|
|
.build());
|
|
}
|
|
}
|