init drp
This commit is contained in:
@ -1,12 +1,13 @@
|
||||
package com.iconplus.smartproc.controller;
|
||||
|
||||
import com.iconplus.smartproc.exception.BusinessException;
|
||||
import com.iconplus.smartproc.helper.model.EmptyRequest;
|
||||
import com.iconplus.smartproc.helper.model.EmptyResponse;
|
||||
import com.iconplus.smartproc.model.request.ChangePasswordRequest;
|
||||
import com.iconplus.smartproc.model.request.ForgotPasswordRequest;
|
||||
import com.iconplus.smartproc.model.request.LoginRequest;
|
||||
import com.iconplus.smartproc.model.request.RefreshTokenRequest;
|
||||
import com.iconplus.smartproc.model.response.LoginResponse;
|
||||
import com.iconplus.smartproc.model.response.GlobalResponse;
|
||||
import com.iconplus.smartproc.model.response.RefreshTokenResponse;
|
||||
import com.iconplus.smartproc.service.authentication.*;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -35,8 +36,20 @@ public class AuthenticationController {
|
||||
}
|
||||
|
||||
@PostMapping("/login")
|
||||
public LoginResponse getLoginResponse(@RequestBody LoginRequest loginRequest) {
|
||||
return loginService.execute(loginRequest);
|
||||
public GlobalResponse getLoginResponse(@RequestBody LoginRequest loginRequest) {
|
||||
try {
|
||||
var loginResponse = loginService.execute(loginRequest);
|
||||
return GlobalResponse.builder()
|
||||
.isOk(true)
|
||||
.message("Succes")
|
||||
.data(loginResponse)
|
||||
.build();
|
||||
} catch (BusinessException exception) {
|
||||
return GlobalResponse.builder()
|
||||
.isOk(false)
|
||||
.message(exception.getErrorMessage())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/refresh-token")
|
||||
|
@ -1,11 +1,59 @@
|
||||
package com.iconplus.smartproc.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.iconplus.smartproc.model.request.DrpRequest;
|
||||
import com.iconplus.smartproc.model.request.InstansiRequest;
|
||||
import com.iconplus.smartproc.model.response.DrpResponse;
|
||||
import com.iconplus.smartproc.model.response.GetListDrpResponse;
|
||||
import com.iconplus.smartproc.model.response.InstansiResponse;
|
||||
import com.iconplus.smartproc.service.drp.GetDrpService;
|
||||
import com.iconplus.smartproc.service.drp.GetListDrpService;
|
||||
import com.iconplus.smartproc.service.drp.PostCreateDrpService;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@CrossOrigin(origins = "http://localhost:8080", allowCredentials = "true")
|
||||
@CrossOrigin(origins = "${fe.server}", allowCredentials = "true")
|
||||
@RestController
|
||||
@RequestMapping("/api/drp")
|
||||
public class DrpController {
|
||||
|
||||
private final GetDrpService getDrpService;
|
||||
private final GetListDrpService getListDrpService;
|
||||
private final PostCreateDrpService postCreateDrpService;
|
||||
|
||||
public DrpController(GetDrpService getDrpService,
|
||||
GetListDrpService getListDrpService,
|
||||
PostCreateDrpService postCreateDrpService) {
|
||||
this.getDrpService = getDrpService;
|
||||
this.getListDrpService = getListDrpService;
|
||||
this.postCreateDrpService = postCreateDrpService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public GetListDrpResponse getListDrp(@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);
|
||||
DrpRequest drpRequest = DrpRequest.builder()
|
||||
.search(search)
|
||||
.pageable(pageable)
|
||||
.build();
|
||||
|
||||
return getListDrpService.execute(drpRequest);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public DrpResponse getDrp(@PathVariable Long id) {
|
||||
return getDrpService.execute(DrpRequest.builder()
|
||||
.id(id)
|
||||
.build());
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public DrpResponse createDrp(@RequestBody DrpRequest drpRequest) {
|
||||
return postCreateDrpService.execute(drpRequest);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user