blob: 394e44549868109dc993281b10339650c1df69c4 [file] [log] [blame]
夜雨声烦451d71c2025-05-20 00:58:36 +08001package com.example.g8backend.controller;
2
夜雨声烦70f4c652025-05-20 01:52:41 +08003import com.example.g8backend.dto.ApiResponse;
4import com.example.g8backend.entity.Report;
夜雨声烦451d71c2025-05-20 00:58:36 +08005import com.example.g8backend.service.AdminService;
夜雨声烦70f4c652025-05-20 01:52:41 +08006import com.example.g8backend.service.IReportService;
夜雨声烦451d71c2025-05-20 00:58:36 +08007import org.springframework.beans.factory.annotation.Autowired;
8import org.springframework.security.access.prepost.PreAuthorize;
夜雨声烦70f4c652025-05-20 01:52:41 +08009import org.springframework.security.core.context.SecurityContextHolder;
10import org.springframework.web.bind.annotation.*;
11
12import java.util.List;
夜雨声烦451d71c2025-05-20 00:58:36 +080013
14@RestController
15@RequestMapping("/admin")
16public class AdminController {
17 @Autowired
18 private AdminService adminService;
夜雨声烦70f4c652025-05-20 01:52:41 +080019 private IReportService reportService;
夜雨声烦451d71c2025-05-20 00:58:36 +080020 @PostMapping("/grant-vip/{userId}")
21 @PreAuthorize("hasRole('ADMIN')") // 仅允许管理员访问
22 public String grantVip(@PathVariable Long userId) {
23 boolean success = adminService.grantVip(userId);
24 return success ? "VIP授予成功" : "操作失败(用户不存在)";
25 }
夜雨声烦70f4c652025-05-20 01:52:41 +080026 // 获取举报记录(支持按状态过滤)
27 @GetMapping("/reports")
28 @PreAuthorize("hasRole('ADMIN')")
29 public ApiResponse<List<Report>> getReports(
30 @RequestParam(required = false) String status) {
夜雨声烦70f4c652025-05-20 01:52:41 +080031 Long adminId = (Long) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
32 return ApiResponse.success(reportService.getReports(status, adminId));
33 }
34 // 处理举报
35 @PutMapping("/reports/{reportId}")
36 @PreAuthorize("hasRole('ADMIN')")
37 public ApiResponse<String> resolveReport(
38 @PathVariable Long reportId,
39 @RequestParam String status,
40 @RequestParam(required = false) String notes) {
夜雨声烦45c25dd2025-05-20 11:59:03 +080041 Long adminId = (Long) SecurityContextHolder.getContext().getAuthentication().getPrincipal();//这里之前不太对,service改了
夜雨声烦363e5362025-05-20 02:01:13 +080042 reportService.resolveReport(reportId, adminId, status, notes);
夜雨声烦70f4c652025-05-20 01:52:41 +080043 return ApiResponse.success("举报处理完成");
44 }
45
夜雨声烦451d71c2025-05-20 00:58:36 +080046}