夜雨声烦 | 451d71c | 2025-05-20 00:58:36 +0800 | [diff] [blame^] | 1 | package com.example.g8backend.controller; |
| 2 | |
| 3 | import com.example.g8backend.service.AdminService; |
| 4 | import org.springframework.beans.factory.annotation.Autowired; |
| 5 | import org.springframework.security.access.prepost.PreAuthorize; |
| 6 | import org.springframework.web.bind.annotation.PathVariable; |
| 7 | import org.springframework.web.bind.annotation.PostMapping; |
| 8 | import org.springframework.web.bind.annotation.RequestMapping; |
| 9 | import org.springframework.web.bind.annotation.RestController; |
| 10 | |
| 11 | @RestController |
| 12 | @RequestMapping("/admin") |
| 13 | public 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 | } |