blob: 89208c68ab2605cada5a0351aeb105a653e77766 [file] [log] [blame]
夜雨声烦451d71c2025-05-20 00:58:36 +08001package com.example.g8backend.controller;
2
3import com.example.g8backend.service.AdminService;
4import org.springframework.beans.factory.annotation.Autowired;
5import org.springframework.security.access.prepost.PreAuthorize;
6import org.springframework.web.bind.annotation.PathVariable;
7import org.springframework.web.bind.annotation.PostMapping;
8import org.springframework.web.bind.annotation.RequestMapping;
9import org.springframework.web.bind.annotation.RestController;
10
11@RestController
12@RequestMapping("/admin")
13public class AdminController {
14 @Autowired
15 private AdminService adminService;
16
17 @PostMapping("/grant-vip/{userId}")
18 @PreAuthorize("hasRole('ADMIN')") // 仅允许管理员访问
19 public String grantVip(@PathVariable Long userId) {
20 boolean success = adminService.grantVip(userId);
21 return success ? "VIP授予成功" : "操作失败(用户不存在)";
22 }
23}