“mitao”
2026-03-24 e7f9345c528ab4d6f18d8e450d8178845989d5e1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.tcm.training.admin.auth.controller;
 
import com.tcm.training.admin.auth.dto.LoginRequest;
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.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());
    }
}