package com.nju.edu.eval.web.controller; import com.nju.edu.eval.aspect.auth.Authorized; import com.nju.edu.eval.data.entity.User; import com.nju.edu.eval.publicdatas.enums.UserRole; import com.nju.edu.eval.service.UserService; import com.nju.edu.eval.web.Response; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import springfox.documentation.annotations.ApiIgnore; /** * @author mars */ @RestController @RequestMapping(path = "/api/user") @Api(tags = {"用户信息"}) public class UserController { private final UserService userService; @Autowired public UserController(UserService userService) { this.userService = userService; } @ApiOperation("获得当前用户信息") @GetMapping("") @Authorized() public Response getCurrentUser(@ApiIgnore User user) { return Response.buildSuccess(userService.getUserById(user.getId())); } @ApiOperation("获得报名某次考试的所有学生") @GetMapping("/{examId}") @Authorized(roles = {UserRole.ADMIN, UserRole.HR, UserRole.TEACHER}) public Response getUsersByExamId(@PathVariable Integer examId) { return Response.buildSuccess(userService.getUsersByExamId(examId)); } @GetMapping("/test") @Authorized() public String test(){ return "hello"; } }