57 lines
2.1 KiB
Java
57 lines
2.1 KiB
Java
package com.iconplus.smartproc.controller;
|
|
|
|
import com.iconplus.smartproc.model.request.DrpRequest;
|
|
import com.iconplus.smartproc.model.response.DrpResponse;
|
|
import com.iconplus.smartproc.model.response.GetListDrpResponse;
|
|
import com.iconplus.smartproc.service.drp.GetDrpService;
|
|
import com.iconplus.smartproc.service.drp.GetListDrpService;
|
|
import com.iconplus.smartproc.service.drp.PostCreateDrpService;
|
|
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/drp")
|
|
public class DrpController {
|
|
|
|
private final GetDrpService getDrpService;
|
|
private final GetListDrpService getListDrpService;
|
|
private final PostCreateDrpService postCreateDrpService;
|
|
|
|
public DrpController(GetDrpService getDrpService,
|
|
GetListDrpService getListDrpService,
|
|
PostCreateDrpService postCreateDrpService) {
|
|
this.getDrpService = getDrpService;
|
|
this.getListDrpService = getListDrpService;
|
|
this.postCreateDrpService = postCreateDrpService;
|
|
}
|
|
|
|
@GetMapping
|
|
public GetListDrpResponse getListDrp(@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);
|
|
DrpRequest drpRequest = DrpRequest.builder()
|
|
.search(search)
|
|
.pageable(pageable)
|
|
.build();
|
|
|
|
return getListDrpService.execute(drpRequest);
|
|
}
|
|
|
|
@GetMapping("/{id}")
|
|
public DrpResponse getDrp(@PathVariable Long id) {
|
|
return getDrpService.execute(DrpRequest.builder()
|
|
.id(id)
|
|
.build());
|
|
}
|
|
|
|
@PostMapping
|
|
public DrpResponse createDrp(@RequestBody DrpRequest drpRequest) {
|
|
return postCreateDrpService.execute(drpRequest);
|
|
}
|
|
|
|
}
|