85 lines
3.1 KiB
Java
85 lines
3.1 KiB
Java
package com.iconplus.smartproc.controller;
|
|
|
|
import com.iconplus.smartproc.helper.model.EmptyResponse;
|
|
import com.iconplus.smartproc.model.request.UsersRequest;
|
|
import com.iconplus.smartproc.model.response.GetUsersResponse;
|
|
import com.iconplus.smartproc.model.response.UsersResponse;
|
|
import com.iconplus.smartproc.service.manajemenuser.*;
|
|
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/users")
|
|
public class UsersController {
|
|
|
|
private final GetListUserService getListUserService;
|
|
private final PostCreateUserService postCreateUserService;
|
|
private final PutUpdateUserService putUpdateUserService;
|
|
private final GetUserByIdService getUserByIdService;
|
|
private final DeleteUserService deleteUserService;
|
|
public UsersController(GetListUserService getListUserService,
|
|
PostCreateUserService postCreateUserService,
|
|
PutUpdateUserService putUpdateUserService,
|
|
GetUserByIdService getUserByIdService,
|
|
DeleteUserService deleteUserService) {
|
|
this.getListUserService = getListUserService;
|
|
this.postCreateUserService = postCreateUserService;
|
|
this.putUpdateUserService = putUpdateUserService;
|
|
this.getUserByIdService = getUserByIdService;
|
|
this.deleteUserService = deleteUserService;
|
|
}
|
|
|
|
|
|
@GetMapping
|
|
public GetUsersResponse getUsers(@RequestParam(name = "search", required = false) String search,
|
|
@RequestParam(name = "instansi", required = false) String instansi,
|
|
@RequestParam(name = "bidang", required = false) String bidang,
|
|
@RequestParam(name = "nama", required = false) String nama,
|
|
@RequestParam(name = "jabatan", required = false) String jabatan,
|
|
@RequestParam(name = "role", required = false) String role,
|
|
@RequestParam(name = "email", required = false) String email,
|
|
@RequestParam(name = "page", defaultValue = "1") Integer page,
|
|
@RequestParam(name = "size", defaultValue = "5") Integer size){
|
|
|
|
Pageable pageable = PageRequest.of((page - 1), size);
|
|
UsersRequest usersRequest = UsersRequest.builder()
|
|
.search(search)
|
|
.instansi(instansi)
|
|
.bidang(bidang)
|
|
.nama(nama)
|
|
.jabatan(jabatan)
|
|
.role(role)
|
|
.email(email)
|
|
.pageable(pageable)
|
|
.build();
|
|
|
|
return getListUserService.execute(usersRequest);
|
|
}
|
|
|
|
@PostMapping
|
|
public UsersResponse createUsers(@RequestBody UsersRequest request) {
|
|
return postCreateUserService.execute(request);
|
|
}
|
|
|
|
@GetMapping("/{id}")
|
|
public UsersResponse getUsersById(@PathVariable Long id) {
|
|
return getUserByIdService.execute(UsersRequest.builder()
|
|
.id(id)
|
|
.build());
|
|
}
|
|
|
|
@PutMapping("/{id}")
|
|
public UsersResponse updateUsers(@PathVariable Long id, @RequestBody UsersRequest request){
|
|
request.setId(id);
|
|
return putUpdateUserService.execute(request);
|
|
}
|
|
|
|
@DeleteMapping("/{id}")
|
|
public EmptyResponse deleteUsers(@PathVariable Long id){
|
|
return deleteUserService.execute(UsersRequest.builder()
|
|
.id(id)
|
|
.build());
|
|
}
|
|
} |