smartproc-be/src/main/java/com/iconplus/smartproc/controller/AuthenticationController.java
dirgantarasiahaan a32d5a499f change password
2023-05-28 17:48:37 +07:00

58 lines
2.4 KiB
Java

package com.iconplus.smartproc.controller;
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.LoginRequest;
import com.iconplus.smartproc.model.request.RefreshTokenRequest;
import com.iconplus.smartproc.model.response.LoginResponse;
import com.iconplus.smartproc.model.response.RefreshTokenResponse;
import com.iconplus.smartproc.service.authentication.ChangePasswordService;
import com.iconplus.smartproc.service.authentication.LoginService;
import com.iconplus.smartproc.service.authentication.LogoutService;
import com.iconplus.smartproc.service.authentication.TokenManagementService;
import org.springframework.web.bind.annotation.*;
@CrossOrigin(origins = "http://localhost:8080", allowCredentials = "true")
@RestController
@RequestMapping("/api/authentication")
public class AuthenticationController {
private LoginService loginService;
private TokenManagementService tokenManagementService;
private LogoutService logoutService;
private ChangePasswordService changePasswordService;
public AuthenticationController(LoginService loginService,
TokenManagementService tokenManagementService,
LogoutService logoutService,
ChangePasswordService changePasswordService) {
this.loginService = loginService;
this.tokenManagementService = tokenManagementService;
this.logoutService = logoutService;
this.changePasswordService = changePasswordService;
}
@PostMapping("/login")
public LoginResponse getLoginResponse(@RequestBody LoginRequest loginRequest) {
return loginService.execute(loginRequest);
}
@PostMapping("/refresh-token")
public RefreshTokenResponse getRefreshToken(@RequestBody RefreshTokenRequest refreshTokenRequest) {
return tokenManagementService.execute(refreshTokenRequest);
}
@PostMapping("/logout")
public EmptyResponse logoutUser(EmptyRequest request) {
return logoutService.execute(request);
}
@PostMapping("/change-password")
public EmptyResponse changePassword(@RequestBody ChangePasswordRequest changePasswordRequest) {
return changePasswordService.execute(changePasswordRequest);
}
}