add bidang api
This commit is contained in:
@ -0,0 +1,74 @@
|
||||
package com.iconplus.smartproc.controller;
|
||||
|
||||
import com.iconplus.smartproc.helper.model.EmptyResponse;
|
||||
import com.iconplus.smartproc.model.request.BidangRequest;
|
||||
import com.iconplus.smartproc.model.response.BidangResponse;
|
||||
import com.iconplus.smartproc.model.response.GetListBidangResponse;
|
||||
import com.iconplus.smartproc.service.bidang.*;
|
||||
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/bidang")
|
||||
public class BidangController {
|
||||
|
||||
private GetBidangService getBidangService;
|
||||
private DeleteBidangService deleteBidangService;
|
||||
private GetListBidangService getListBidangService;
|
||||
private PostCreateBidangService postCreateBidangService;
|
||||
private PutUpdateBidangService putUpdateBidangService;
|
||||
|
||||
public BidangController(GetBidangService getBidangService,
|
||||
DeleteBidangService deleteBidangService,
|
||||
GetListBidangService getListBidangService,
|
||||
PostCreateBidangService postCreateBidangService,
|
||||
PutUpdateBidangService putUpdateBidangService) {
|
||||
this.getBidangService = getBidangService;
|
||||
this.deleteBidangService = deleteBidangService;
|
||||
this.getListBidangService = getListBidangService;
|
||||
this.postCreateBidangService = postCreateBidangService;
|
||||
this.putUpdateBidangService = putUpdateBidangService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public GetListBidangResponse getListInstansi(@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);
|
||||
BidangRequest bidangRequest = BidangRequest.builder()
|
||||
.search(search)
|
||||
.pageable(pageable)
|
||||
.build();
|
||||
|
||||
return getListBidangService.execute(bidangRequest);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public BidangResponse createBidang(@RequestBody BidangRequest request) {
|
||||
return postCreateBidangService.execute(request);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public BidangResponse getBidangById(@PathVariable Long id) {
|
||||
return getBidangService.execute(BidangRequest.builder()
|
||||
.id(id)
|
||||
.build());
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public BidangResponse updateBidang(@PathVariable Long id, @RequestBody BidangRequest request){
|
||||
request.setId(id);
|
||||
return putUpdateBidangService.execute(request);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public EmptyResponse deleteBidang(@PathVariable Long id){
|
||||
return deleteBidangService.execute(BidangRequest.builder()
|
||||
.id(id)
|
||||
.build());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user