更新+mock部分

This commit is contained in:
2026-04-16 18:12:09 +08:00
parent d5c06eca28
commit adadb3bf1d
40 changed files with 884 additions and 174 deletions

View File

@@ -2,15 +2,16 @@ package com.k12study.auth.controller;
import com.k12study.api.auth.dto.CurrentUserResponse;
import com.k12study.api.auth.dto.LoginRequest;
import com.k12study.api.auth.dto.RefreshTokenRequest;
import com.k12study.api.auth.dto.TokenResponse;
import com.k12study.auth.service.AuthService;
import com.k12study.common.api.response.ApiResponse;
import com.k12study.common.web.exception.BizException;
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.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@@ -22,17 +23,21 @@ public class AuthController {
this.authService = authService;
}
@PostMapping("/login")
@PostMapping("/tokens")
public ApiResponse<TokenResponse> login(@RequestBody LoginRequest request) {
return ApiResponse.success("登录成功", authService.login(request));
}
@PostMapping("/refresh")
public ApiResponse<TokenResponse> refresh(@RequestParam("refreshToken") String refreshToken) {
@PostMapping("/tokens/refresh")
public ApiResponse<TokenResponse> refresh(@RequestBody RefreshTokenRequest request) {
String refreshToken = request == null ? null : request.refreshToken();
if (refreshToken == null || refreshToken.isBlank()) {
throw new BizException(400, "refreshToken 不能为空");
}
return ApiResponse.success("刷新成功", authService.refresh(refreshToken));
}
@GetMapping("/current-user")
@GetMapping("/users/current")
public ApiResponse<CurrentUserResponse> currentUser(
@RequestHeader(value = "Authorization", required = false) String authorizationHeader) {
return ApiResponse.success(authService.currentUser(authorizationHeader));

View File

@@ -23,6 +23,6 @@ auth:
enabled: true
gateway-mode: true
whitelist:
- /auth/login
- /auth/refresh
- /auth/tokens
- /auth/tokens/refresh
- /actuator/**