|
@@ -52,36 +52,51 @@ public class ContestController {
|
|
|
@NotNull(message = "页码不能为null") @RequestParam(defaultValue = "1") Integer pageNum,
|
|
@NotNull(message = "页码不能为null") @RequestParam(defaultValue = "1") Integer pageNum,
|
|
|
@Parameter(description = "分页大小")
|
|
@Parameter(description = "分页大小")
|
|
|
@NotNull(message = "分页大小不能为null") @RequestParam(defaultValue = "10") Integer pageSize) {
|
|
@NotNull(message = "分页大小不能为null") @RequestParam(defaultValue = "10") Integer pageSize) {
|
|
|
- boolean onlyPublic = SecurityUtils.isAnonymous();
|
|
|
|
|
|
|
+ boolean onlyPublic = !SecurityUtils.isStaff();
|
|
|
Page<Contest> page = Page.of(pageNum, pageSize);
|
|
Page<Contest> page = Page.of(pageNum, pageSize);
|
|
|
Page<ContestVo> result = contestService.queryByPage(title, status, onlyPublic, page);
|
|
Page<ContestVo> result = contestService.queryByPage(title, status, onlyPublic, page);
|
|
|
return Response.ok(new PageVo<>(result.getTotal(), result.getRecords()));
|
|
return Response.ok(new PageVo<>(result.getTotal(), result.getRecords()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Operation(summary = "查询比赛详情", security = @SecurityRequirement(name = "openApiSecurityScheme"))
|
|
|
|
|
|
|
+ @Operation(summary = "查询比赛详情")
|
|
|
@GetMapping("{id}")
|
|
@GetMapping("{id}")
|
|
|
public Response<ContestDetailVo> getDetail(@Parameter(description = "比赛ID") @PathVariable Long id,
|
|
public Response<ContestDetailVo> getDetail(@Parameter(description = "比赛ID") @PathVariable Long id,
|
|
|
@Parameter(description = "访问密码(密码型比赛需传入)") @RequestParam(required = false) String password) {
|
|
@Parameter(description = "访问密码(密码型比赛需传入)") @RequestParam(required = false) String password) {
|
|
|
Long userId = SecurityUtils.getCurrentUserId();
|
|
Long userId = SecurityUtils.getCurrentUserId();
|
|
|
ContestVo base = contestService.getBaseInfo(id);
|
|
ContestVo base = contestService.getBaseInfo(id);
|
|
|
|
|
+ if (User.ROLE_ADMIN.equals(SecurityUtils.getCurrentRole())) {
|
|
|
|
|
+ return Response.ok(contestService.getDetail(id, userId));
|
|
|
|
|
+ }
|
|
|
if (Contest.TYPE_PASSWORD.equals(base.getType())) {
|
|
if (Contest.TYPE_PASSWORD.equals(base.getType())) {
|
|
|
- if (!contestService.checkPassword(id, password)) {
|
|
|
|
|
|
|
+ if (userId == null || !contestService.checkPassword(id, password)) {
|
|
|
return Response.ok(ContestDetailVo.from(base));
|
|
return Response.ok(ContestDetailVo.from(base));
|
|
|
}
|
|
}
|
|
|
} else if (Contest.TYPE_PRIVATE.equals(base.getType())) {
|
|
} else if (Contest.TYPE_PRIVATE.equals(base.getType())) {
|
|
|
- String role = SecurityUtils.getCurrentRole();
|
|
|
|
|
- boolean staff = User.ROLE_COACH.equals(role) || User.ROLE_ADMIN.equals(role);
|
|
|
|
|
- if (!contestService.isRegistered(id, userId)
|
|
|
|
|
- && !contestService.isCreator(id, userId) && !staff) {
|
|
|
|
|
|
|
+ if (!contestService.isCreator(id, userId)) {
|
|
|
return Response.error("无权限查看该比赛");
|
|
return Response.error("无权限查看该比赛");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return Response.ok(contestService.getDetail(id, userId));
|
|
return Response.ok(contestService.getDetail(id, userId));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Operation(summary = "查询比赛排行榜", security = @SecurityRequirement(name = "openApiSecurityScheme"))
|
|
|
|
|
|
|
+ @Operation(summary = "查询比赛排行榜")
|
|
|
@GetMapping("{id}/ranking")
|
|
@GetMapping("{id}/ranking")
|
|
|
- public Response<List<RankVo>> getRanking(@Parameter(description = "比赛ID") @PathVariable Long id) {
|
|
|
|
|
|
|
+ public Response<List<RankVo>> getRanking(@Parameter(description = "比赛ID") @PathVariable Long id,
|
|
|
|
|
+ @Parameter(description = "访问密码(密码型比赛需传入)") @RequestParam(required = false) String password) {
|
|
|
|
|
+ Long userId = SecurityUtils.getCurrentUserId();
|
|
|
|
|
+ ContestVo base = contestService.getBaseInfo(id);
|
|
|
|
|
+ if (User.ROLE_ADMIN.equals(SecurityUtils.getCurrentRole())) {
|
|
|
|
|
+ return Response.ok(contestService.getRanking(id));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Contest.TYPE_PASSWORD.equals(base.getType())) {
|
|
|
|
|
+ if (userId == null || !contestService.checkPassword(id, password)) {
|
|
|
|
|
+ return Response.error("无权限查看该比赛排行榜");
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (Contest.TYPE_PRIVATE.equals(base.getType())) {
|
|
|
|
|
+ if (!contestService.isCreator(id, userId)) {
|
|
|
|
|
+ return Response.error("无权限查看该比赛排行榜");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
return Response.ok(contestService.getRanking(id));
|
|
return Response.ok(contestService.getRanking(id));
|
|
|
}
|
|
}
|
|
|
|
|
|