package com.tcm.training.admin.auth.controller;
|
|
import com.tcm.training.admin.auth.dto.ChangePasswordRequest;
|
import com.tcm.training.admin.auth.dto.LoginRequest;
|
import com.tcm.training.admin.auth.dto.ProfileUpdateRequest;
|
import com.tcm.training.admin.auth.service.AuthService;
|
import com.tcm.training.admin.auth.service.CaptchaService;
|
import com.tcm.training.admin.auth.vo.CaptchaResponse;
|
import com.tcm.training.admin.auth.vo.LoginResponse;
|
import com.tcm.training.admin.auth.vo.UserVO;
|
import com.tcm.training.admin.common.ApiResponse;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PutMapping;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.validation.Valid;
|
|
@Validated
|
@RestController
|
@RequestMapping("/api/auth")
|
public class AuthController {
|
|
private final AuthService authService;
|
private final CaptchaService captchaService;
|
|
public AuthController(AuthService authService, CaptchaService captchaService) {
|
this.authService = authService;
|
this.captchaService = captchaService;
|
}
|
|
@PostMapping("/login")
|
public ApiResponse<LoginResponse> login(@Valid @RequestBody LoginRequest req) {
|
return ApiResponse.ok(authService.login(req));
|
}
|
|
@PostMapping("/logout")
|
public ApiResponse<Void> logout() {
|
authService.logout();
|
return ApiResponse.ok(null);
|
}
|
|
@GetMapping("/captcha")
|
public ApiResponse<CaptchaResponse> captcha() {
|
return ApiResponse.ok(captchaService.createCaptcha());
|
}
|
|
@GetMapping("/me")
|
public ApiResponse<UserVO> me() {
|
return ApiResponse.ok(authService.me());
|
}
|
|
@PutMapping("/profile")
|
public ApiResponse<UserVO> updateProfile(@Valid @RequestBody ProfileUpdateRequest req) {
|
return ApiResponse.ok(authService.updateProfile(req));
|
}
|
|
@PostMapping("/change-password")
|
public ApiResponse<Void> changePassword(@Valid @RequestBody ChangePasswordRequest req) {
|
authService.changePassword(req);
|
return ApiResponse.ok(null);
|
}
|
}
|