mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-20 14:00:56 +08:00
Revert "feat: add admin point grants and history UI"
This reverts commit adfc05b9b2.
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
package com.openisle.controller;
|
||||
|
||||
import com.openisle.dto.AdminGrantPointRequest;
|
||||
import com.openisle.service.PointService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.core.Authentication;
|
||||
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;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/admin/points")
|
||||
@RequiredArgsConstructor
|
||||
public class AdminPointController {
|
||||
|
||||
private final PointService pointService;
|
||||
|
||||
@PostMapping("/grant")
|
||||
@SecurityRequirement(name = "JWT")
|
||||
@Operation(summary = "Grant points", description = "Grant points to a user as administrator")
|
||||
@ApiResponse(responseCode = "200", description = "Points granted")
|
||||
public Map<String, Object> grant(
|
||||
@RequestBody AdminGrantPointRequest request,
|
||||
Authentication auth
|
||||
) {
|
||||
String username = request.getUsername();
|
||||
int balance = pointService.grantPointByAdmin(auth.getName(), username, request.getAmount());
|
||||
return Map.of("username", username.trim(), "point", balance);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.openisle.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class AdminGrantPointRequest {
|
||||
|
||||
private String username;
|
||||
private int amount;
|
||||
}
|
||||
@@ -13,5 +13,4 @@ public enum PointHistoryType {
|
||||
REDEEM,
|
||||
LOTTERY_JOIN,
|
||||
LOTTERY_REWARD,
|
||||
ADMIN_GRANT,
|
||||
}
|
||||
|
||||
@@ -43,22 +43,6 @@ public class PointService {
|
||||
return addPoint(user, 500, PointHistoryType.FEATURE, post, null, null);
|
||||
}
|
||||
|
||||
public int grantPointByAdmin(String adminName, String targetUsername, int amount) {
|
||||
if (amount <= 0) {
|
||||
throw new FieldException("amount", "积分必须为正数");
|
||||
}
|
||||
if (targetUsername == null || targetUsername.isBlank()) {
|
||||
throw new FieldException("username", "用户名不能为空");
|
||||
}
|
||||
String normalizedUsername = targetUsername.trim();
|
||||
User admin = userRepository.findByUsername(adminName).orElseThrow();
|
||||
User target = userRepository
|
||||
.findByUsername(normalizedUsername)
|
||||
.orElseThrow(() -> new FieldException("username", "用户不存在"));
|
||||
addPoint(target, amount, PointHistoryType.ADMIN_GRANT, null, null, admin);
|
||||
return target.getPoint();
|
||||
}
|
||||
|
||||
public void processLotteryJoin(User participant, LotteryPost post) {
|
||||
int cost = post.getPointCost();
|
||||
if (cost > 0) {
|
||||
|
||||
Reference in New Issue
Block a user