add crud jabatan
This commit is contained in:
@ -0,0 +1,73 @@
|
||||
package com.iconplus.smartproc.controller;
|
||||
|
||||
import com.iconplus.smartproc.helper.model.EmptyResponse;
|
||||
import com.iconplus.smartproc.model.request.JabatanRequest;
|
||||
import com.iconplus.smartproc.model.response.GetListJabatanResponse;
|
||||
import com.iconplus.smartproc.model.response.JabatanResponse;
|
||||
import com.iconplus.smartproc.service.jabatan.*;
|
||||
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/jabatan")
|
||||
public class JabatanController {
|
||||
|
||||
private DeleteJabatanService deleteJabatanService;
|
||||
private GetJabatanService getJabatanService;
|
||||
private GetListJabatanService getListJabatanService;
|
||||
private PostCreateJabatanService postCreateJabatanService;
|
||||
private PutUpdateJabatanService putUpdateJabatanService;
|
||||
|
||||
public JabatanController(DeleteJabatanService deleteJabatanService,
|
||||
GetJabatanService getJabatanService,
|
||||
GetListJabatanService getListJabatanService,
|
||||
PostCreateJabatanService postCreateJabatanService,
|
||||
PutUpdateJabatanService putUpdateJabatanService) {
|
||||
this.deleteJabatanService = deleteJabatanService;
|
||||
this.getJabatanService = getJabatanService;
|
||||
this.getListJabatanService = getListJabatanService;
|
||||
this.postCreateJabatanService = postCreateJabatanService;
|
||||
this.putUpdateJabatanService = putUpdateJabatanService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public GetListJabatanResponse getListJabatan(@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);
|
||||
JabatanRequest bidangRequest = JabatanRequest.builder()
|
||||
.search(search)
|
||||
.pageable(pageable)
|
||||
.build();
|
||||
|
||||
return getListJabatanService.execute(bidangRequest);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public JabatanResponse createJabatan(@RequestBody JabatanRequest request) {
|
||||
return postCreateJabatanService.execute(request);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public JabatanResponse getJabatanById(@PathVariable Long id) {
|
||||
return getJabatanService.execute(JabatanRequest.builder()
|
||||
.id(id)
|
||||
.build());
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public JabatanResponse updateBidang(@PathVariable Long id, @RequestBody JabatanRequest request){
|
||||
request.setId(id);
|
||||
return putUpdateJabatanService.execute(request);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public EmptyResponse deleteJabatan(@PathVariable Long id){
|
||||
return deleteJabatanService.execute(JabatanRequest.builder()
|
||||
.id(id)
|
||||
.build());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user