feat: 添加获取当前用户积分余额的接口
This commit is contained in:
@@ -3,6 +3,7 @@ package com.gameplatform.server.controller.admin;
|
||||
import com.gameplatform.server.model.dto.account.*;
|
||||
import com.gameplatform.server.model.dto.common.PageResult;
|
||||
import com.gameplatform.server.service.account.AccountService;
|
||||
import com.gameplatform.server.security.JwtService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -16,9 +17,11 @@ import reactor.core.publisher.Mono;
|
||||
@Tag(name = "管理员账户管理", description = "管理员账户的增删改查操作")
|
||||
public class AccountController {
|
||||
private final AccountService accountService;
|
||||
private final JwtService jwtService;
|
||||
|
||||
public AccountController(AccountService accountService) {
|
||||
public AccountController(AccountService accountService, JwtService jwtService) {
|
||||
this.accountService = accountService;
|
||||
this.jwtService = jwtService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@@ -72,5 +75,27 @@ public class AccountController {
|
||||
public Mono<Void> resetPassword(@Parameter(description = "账户ID") @PathVariable Long id, @Valid @RequestBody ResetPasswordRequest req) {
|
||||
return accountService.resetPassword(id, req.getNewPassword(), Boolean.TRUE.equals(req.getForceLogout()));
|
||||
}
|
||||
|
||||
@GetMapping("/me/points-balance")
|
||||
@Operation(summary = "获取当前用户积分余额", description = "根据token解析用户ID并获取当前用户的积分余额")
|
||||
public Mono<PointsBalanceResponse> getCurrentUserPointsBalance(
|
||||
@Parameter(hidden = true) @RequestHeader("Authorization") String authHeader) {
|
||||
return Mono.fromCallable(() -> {
|
||||
if (authHeader == null || !authHeader.startsWith("Bearer ")) {
|
||||
throw new IllegalArgumentException("Authorization header is required");
|
||||
}
|
||||
|
||||
String token = authHeader.substring(7);
|
||||
io.jsonwebtoken.Claims claims = jwtService.parse(token);
|
||||
Long userId = claims.get("userId", Long.class);
|
||||
|
||||
if (userId == null) {
|
||||
throw new IllegalArgumentException("Invalid token: userId not found");
|
||||
}
|
||||
|
||||
return userId;
|
||||
})
|
||||
.flatMap(accountService::getCurrentUserPointsBalance);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user