Files
smartproc-be/src/main/java/com/iconplus/smartproc/controller/RksDaftarIsiController.java
dirgantarasiahaan 4877b84de0 add rks isi
2023-06-06 09:31:11 +07:00

123 lines
5.5 KiB
Java

package com.iconplus.smartproc.controller;
import com.iconplus.smartproc.helper.model.EmptyResponse;
import com.iconplus.smartproc.model.request.RksDaftarIsiRequest;
import com.iconplus.smartproc.model.request.RksIsiRequest;
import com.iconplus.smartproc.model.response.*;
import com.iconplus.smartproc.service.rksdaftarisi.*;
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/rks/daftar-isi")
public class RksDaftarIsiController {
private final GetListRksDaftarIsiService getListRksDaftarIsiService;
private final PostCreateRksDaftarIsiService postCreateRksDaftarIsiService;
private final GetListRksIsiService getListRksIsiService;
private final DeleteRksDaftarIsiService deleteRksDaftarIsiService;
private final PutUpdateRksDaftarIsiService putUpdateRksDaftarIsiService;
private final GetListRksParentService getListRksParentService;
private final PostCreateRksIsiService postCreateRksIsiService;
private final DeleteRksIsiService deleteRksIsiService;
private final PutEditRksIsiService putEditRksIsiService;
public RksDaftarIsiController(GetListRksDaftarIsiService getListRksDaftarIsiService,
PostCreateRksDaftarIsiService postCreateRksDaftarIsiService,
GetListRksIsiService getListRksIsiService,
DeleteRksDaftarIsiService deleteRksDaftarIsiService,
PutUpdateRksDaftarIsiService putUpdateRksDaftarIsiService,
GetListRksParentService getListRksParentService,
PostCreateRksIsiService postCreateRksIsiService,
DeleteRksIsiService deleteRksIsiService,
PutEditRksIsiService putEditRksIsiService) {
this.getListRksDaftarIsiService = getListRksDaftarIsiService;
this.postCreateRksDaftarIsiService = postCreateRksDaftarIsiService;
this.getListRksIsiService = getListRksIsiService;
this.deleteRksDaftarIsiService = deleteRksDaftarIsiService;
this.putUpdateRksDaftarIsiService = putUpdateRksDaftarIsiService;
this.getListRksParentService = getListRksParentService;
this.postCreateRksIsiService = postCreateRksIsiService;
this.deleteRksIsiService = deleteRksIsiService;
this.putEditRksIsiService = putEditRksIsiService;
}
@GetMapping()
public ListRksDaftarIsiResponse getAllRksDaftarIsi(@RequestParam(name = "page", defaultValue = "1") Integer page,
@RequestParam(name = "size", defaultValue = "5") Integer size){
Pageable pageable = PageRequest.of((page - 1), size);
RksDaftarIsiRequest rksDaftarIsiRequest = RksDaftarIsiRequest.builder()
.pageable(pageable)
.build();
return getListRksDaftarIsiService.execute(rksDaftarIsiRequest);
}
@PostMapping()
public RksDaftarIsiResponse createRksDaftarIsi(@RequestBody RksDaftarIsiRequest rksDaftarIsiRequest) {
return postCreateRksDaftarIsiService.execute(rksDaftarIsiRequest);
}
@PutMapping("/{id}")
public RksDaftarIsiResponse editRksDaftarIsi(@PathVariable(name = "id") Long id,
@RequestBody RksDaftarIsiRequest rksDaftarIsiRequest) {
rksDaftarIsiRequest.setId(id);
return putUpdateRksDaftarIsiService.execute(rksDaftarIsiRequest);
}
@DeleteMapping("/{id}")
public EmptyResponse deleteRksDaftarIsi(@PathVariable(name = "id") Long id) {
return deleteRksDaftarIsiService.execute(RksDaftarIsiRequest.builder()
.id(id)
.build());
}
// perlu enhance
@GetMapping("/{id}/isi")
public ListRksIsiResponse getListRksIsi(@PathVariable(name = "id") Long id,
@RequestParam(name = "page", defaultValue = "1") Integer page,
@RequestParam(name = "size", defaultValue = "5") Integer size) {
Pageable pageable = PageRequest.of((page - 1), size);
RksIsiRequest rksIsiRequest = RksIsiRequest.builder()
.rksDaftarIsiId(id)
.pageable(pageable)
.build();
return getListRksIsiService.execute(rksIsiRequest);
}
@GetMapping("/{id}/parent")
public ListRksIsiResponse getParentRksIsi(@PathVariable(name = "id") Long id) {
return getListRksParentService.execute(RksIsiRequest.builder()
.rksDaftarIsiId(id)
.build());
}
@PostMapping("/{id}/isi")
public RksIsiResponse createRksIsi(@PathVariable(name = "id") Long id,
@RequestBody RksIsiRequest rksIsiRequest) {
rksIsiRequest.setRksDaftarIsiId(id);
return postCreateRksIsiService.execute(rksIsiRequest);
}
@PutMapping("/isi/{id}")
public RksIsiResponse editRksIsi(@PathVariable(name = "id") Long id,
@RequestBody RksIsiRequest rksIsiRequest) {
rksIsiRequest.setId(id);
return putEditRksIsiService.execute(rksIsiRequest);
}
@DeleteMapping("/isi/{id}")
public EmptyResponse deleteRksIsi(@PathVariable(name = "id") Long id) {
return deleteRksIsiService.execute(RksIsiRequest.builder()
.id(id)
.build());
}
}