package com.iconplus.smartproc.controller; import com.iconplus.smartproc.helper.model.EmptyResponse; import com.iconplus.smartproc.model.request.MetodePenyampaianRequest; import com.iconplus.smartproc.model.response.GetListMetodePenyampaianResponse; import com.iconplus.smartproc.model.response.MetodePenyampaianResponse; import com.iconplus.smartproc.repository.MetodePenyampaianRepository; import com.iconplus.smartproc.service.metodepenyampaian.*; 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.*; @CrossOrigin(origins = "${fe.server}", allowCredentials = "true") @RestController @RequestMapping("/api/metodepenyampaian") public class MetodePenyampaianController { @Autowired private MetodePenyampaianRepository metodepenyampaianRepository; private final GetListMetodePenyampaianService getListMetodePenyampaianService; private final GetMetodePenyampaianByIdService getMetodePenyampaianByIdService; private final PostCreateMetodePenyampaianService postCreateMetodePenyampaianService; private final PutUpdateMetodePenyampaianService putUpdateMetodePenyampaianService; private final DeleteMetodePenyampaianService deleteMetodePenyampaianService; public MetodePenyampaianController(GetListMetodePenyampaianService getListMetodePenyampaianService, GetMetodePenyampaianByIdService getMetodePenyampaianByIdService, PostCreateMetodePenyampaianService postCreateMetodePenyampaianService, PutUpdateMetodePenyampaianService putUpdateMetodePenyampaianService, DeleteMetodePenyampaianService deleteMetodePenyampaianService) { this.getListMetodePenyampaianService = getListMetodePenyampaianService; this.getMetodePenyampaianByIdService = getMetodePenyampaianByIdService; this.postCreateMetodePenyampaianService = postCreateMetodePenyampaianService; this.putUpdateMetodePenyampaianService = putUpdateMetodePenyampaianService; this.deleteMetodePenyampaianService = deleteMetodePenyampaianService; } @GetMapping public GetListMetodePenyampaianResponse getListMetodePenyampaian(@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); MetodePenyampaianRequest metodePenyampaianRequest = MetodePenyampaianRequest.builder() .search(search) .pageable(pageable) .build(); return getListMetodePenyampaianService.execute(metodePenyampaianRequest); } @PostMapping public MetodePenyampaianResponse createMetodePenyampaian(@RequestBody MetodePenyampaianRequest metodePenyampaianRequest) { return postCreateMetodePenyampaianService.execute(metodePenyampaianRequest); } @GetMapping("/{id}") public MetodePenyampaianResponse getMetodePenyampaianById(@PathVariable Long id) { return getMetodePenyampaianByIdService.execute(MetodePenyampaianRequest.builder() .id(id) .build()); } @PutMapping("/{id}") public MetodePenyampaianResponse updateMetodepenyampaian(@PathVariable Long id, @RequestBody MetodePenyampaianRequest metodePenyampaianRequest){ metodePenyampaianRequest.setId(id); return putUpdateMetodePenyampaianService.execute(metodePenyampaianRequest); } @DeleteMapping("/{id}") public EmptyResponse deleteMetodePenyampaian(@PathVariable Long id) { return deleteMetodePenyampaianService.execute(MetodePenyampaianRequest.builder() .id(id) .build()); } }