|
@@ -2,6 +2,10 @@ package space.anyi.serve.controller;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.Parameter;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import jakarta.annotation.Resource;
|
|
import jakarta.annotation.Resource;
|
|
|
import jakarta.validation.Valid;
|
|
import jakarta.validation.Valid;
|
|
@@ -18,6 +22,11 @@ import space.anyi.serve.util.SecurityUtils;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@Tag(name = "ContestController", description = "比赛相关接口")
|
|
@Tag(name = "ContestController", description = "比赛相关接口")
|
|
|
|
|
+@ApiResponses(value = {
|
|
|
|
|
+ @ApiResponse(responseCode = "400", description = "参数校验失败,返回体 code=400"),
|
|
|
|
|
+ @ApiResponse(responseCode = "401", description = "未认证或认证已过期"),
|
|
|
|
|
+ @ApiResponse(responseCode = "403", description = "无权限访问")
|
|
|
|
|
+})
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("contest")
|
|
@RequestMapping("contest")
|
|
|
public class ContestController {
|
|
public class ContestController {
|
|
@@ -28,9 +37,13 @@ public class ContestController {
|
|
|
@Operation(summary = "分页查询比赛列表")
|
|
@Operation(summary = "分页查询比赛列表")
|
|
|
@GetMapping
|
|
@GetMapping
|
|
|
public Response<PageVo<List<ContestVo>>> queryByPage(
|
|
public Response<PageVo<List<ContestVo>>> queryByPage(
|
|
|
|
|
+ @Parameter(description = "比赛标题,模糊查询")
|
|
|
@RequestParam(defaultValue = "") String title,
|
|
@RequestParam(defaultValue = "") String title,
|
|
|
|
|
+ @Parameter(description = "状态:pending-未开始,running-进行中,ended-已结束")
|
|
|
@RequestParam(defaultValue = "") String status,
|
|
@RequestParam(defaultValue = "") String status,
|
|
|
|
|
+ @Parameter(description = "页码")
|
|
|
@NotNull(message = "页码不能为null") @RequestParam(defaultValue = "1") Integer pageNum,
|
|
@NotNull(message = "页码不能为null") @RequestParam(defaultValue = "1") Integer pageNum,
|
|
|
|
|
+ @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.isAnonymous();
|
|
|
Page<Contest> page = Page.of(pageNum, pageSize);
|
|
Page<Contest> page = Page.of(pageNum, pageSize);
|
|
@@ -38,10 +51,10 @@ public class ContestController {
|
|
|
return Response.ok(new PageVo<>(result.getTotal(), result.getRecords()));
|
|
return Response.ok(new PageVo<>(result.getTotal(), result.getRecords()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Operation(summary = "查询比赛详情")
|
|
|
|
|
|
|
+ @Operation(summary = "查询比赛详情", security = @SecurityRequirement(name = "openApiSecurityScheme"))
|
|
|
@GetMapping("{id}")
|
|
@GetMapping("{id}")
|
|
|
- public Response<ContestVo> getDetail(@PathVariable Long id,
|
|
|
|
|
- @RequestParam(required = false) String password) {
|
|
|
|
|
|
|
+ public Response<ContestVo> getDetail(@Parameter(description = "比赛ID") @PathVariable Long id,
|
|
|
|
|
+ @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 ("password".equals(base.getType())) {
|
|
if ("password".equals(base.getType())) {
|
|
@@ -59,68 +72,68 @@ public class ContestController {
|
|
|
return Response.ok(contestService.getDetail(id, userId));
|
|
return Response.ok(contestService.getDetail(id, userId));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Operation(summary = "查询比赛排行榜")
|
|
|
|
|
|
|
+ @Operation(summary = "查询比赛排行榜", security = @SecurityRequirement(name = "openApiSecurityScheme"))
|
|
|
@GetMapping("{id}/ranking")
|
|
@GetMapping("{id}/ranking")
|
|
|
- public Response<List<RankVo>> getRanking(@PathVariable Long id) {
|
|
|
|
|
|
|
+ public Response<List<RankVo>> getRanking(@Parameter(description = "比赛ID") @PathVariable Long id) {
|
|
|
return Response.ok(contestService.getRanking(id));
|
|
return Response.ok(contestService.getRanking(id));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Operation(summary = "新增比赛")
|
|
|
|
|
|
|
+ @Operation(summary = "新增比赛", security = @SecurityRequirement(name = "openApiSecurityScheme"))
|
|
|
@PreAuthorize("hasAnyRole('ROLE_coach', 'ROLE_admin')")
|
|
@PreAuthorize("hasAnyRole('ROLE_coach', 'ROLE_admin')")
|
|
|
@PostMapping
|
|
@PostMapping
|
|
|
public Response<Boolean> add(@Valid @RequestBody ContestDto dto) {
|
|
public Response<Boolean> add(@Valid @RequestBody ContestDto dto) {
|
|
|
return Response.ok(contestService.insert(dto, SecurityUtils.getCurrentUserId()));
|
|
return Response.ok(contestService.insert(dto, SecurityUtils.getCurrentUserId()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Operation(summary = "修改比赛")
|
|
|
|
|
|
|
+ @Operation(summary = "修改比赛", security = @SecurityRequirement(name = "openApiSecurityScheme"))
|
|
|
@PreAuthorize("hasAnyRole('ROLE_coach', 'ROLE_admin')")
|
|
@PreAuthorize("hasAnyRole('ROLE_coach', 'ROLE_admin')")
|
|
|
@PutMapping
|
|
@PutMapping
|
|
|
public Response<Boolean> edit(@Valid @RequestBody ContestDto dto) {
|
|
public Response<Boolean> edit(@Valid @RequestBody ContestDto dto) {
|
|
|
return Response.ok(contestService.update(dto));
|
|
return Response.ok(contestService.update(dto));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Operation(summary = "批量删除比赛")
|
|
|
|
|
|
|
+ @Operation(summary = "批量删除比赛", security = @SecurityRequirement(name = "openApiSecurityScheme"))
|
|
|
@PreAuthorize("hasRole('ROLE_admin')")
|
|
@PreAuthorize("hasRole('ROLE_admin')")
|
|
|
@DeleteMapping
|
|
@DeleteMapping
|
|
|
public Response<Boolean> deleteByIds(@NotEmpty(message = "ID列表不能为空") @RequestParam List<Long> ids) {
|
|
public Response<Boolean> deleteByIds(@NotEmpty(message = "ID列表不能为空") @RequestParam List<Long> ids) {
|
|
|
return Response.ok(contestService.deleteByIds(ids));
|
|
return Response.ok(contestService.deleteByIds(ids));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Operation(summary = "比赛添加题目")
|
|
|
|
|
|
|
+ @Operation(summary = "比赛添加题目", security = @SecurityRequirement(name = "openApiSecurityScheme"))
|
|
|
@PreAuthorize("hasAnyRole('ROLE_coach', 'ROLE_admin')")
|
|
@PreAuthorize("hasAnyRole('ROLE_coach', 'ROLE_admin')")
|
|
|
@PostMapping("{id}/problem")
|
|
@PostMapping("{id}/problem")
|
|
|
- public Response<Boolean> addProblem(@PathVariable Long id, @Valid @RequestBody ContestProblemDto dto) {
|
|
|
|
|
|
|
+ public Response<Boolean> addProblem(@Parameter(description = "比赛ID") @PathVariable Long id, @Valid @RequestBody ContestProblemDto dto) {
|
|
|
return Response.ok(contestService.addProblem(id, dto));
|
|
return Response.ok(contestService.addProblem(id, dto));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Operation(summary = "修改比赛题目")
|
|
|
|
|
|
|
+ @Operation(summary = "修改比赛题目", security = @SecurityRequirement(name = "openApiSecurityScheme"))
|
|
|
@PreAuthorize("hasAnyRole('ROLE_coach', 'ROLE_admin')")
|
|
@PreAuthorize("hasAnyRole('ROLE_coach', 'ROLE_admin')")
|
|
|
@PutMapping("{id}/problem")
|
|
@PutMapping("{id}/problem")
|
|
|
- public Response<Boolean> updateProblem(@PathVariable Long id, @Valid @RequestBody ContestProblemDto dto) {
|
|
|
|
|
|
|
+ public Response<Boolean> updateProblem(@Parameter(description = "比赛ID") @PathVariable Long id, @Valid @RequestBody ContestProblemDto dto) {
|
|
|
return Response.ok(contestService.updateProblem(id, dto));
|
|
return Response.ok(contestService.updateProblem(id, dto));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Operation(summary = "比赛移除题目")
|
|
|
|
|
|
|
+ @Operation(summary = "比赛移除题目", security = @SecurityRequirement(name = "openApiSecurityScheme"))
|
|
|
@PreAuthorize("hasAnyRole('ROLE_coach', 'ROLE_admin')")
|
|
@PreAuthorize("hasAnyRole('ROLE_coach', 'ROLE_admin')")
|
|
|
@DeleteMapping("{id}/problem")
|
|
@DeleteMapping("{id}/problem")
|
|
|
- public Response<Boolean> removeProblem(@PathVariable Long id,
|
|
|
|
|
- @NotNull(message = "题目ID不能为空") @RequestParam Long problemId) {
|
|
|
|
|
|
|
+ public Response<Boolean> removeProblem(@Parameter(description = "比赛ID") @PathVariable Long id,
|
|
|
|
|
+ @Parameter(description = "题目ID") @NotNull(message = "题目ID不能为空") @RequestParam Long problemId) {
|
|
|
return Response.ok(contestService.removeProblem(id, problemId));
|
|
return Response.ok(contestService.removeProblem(id, problemId));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Operation(summary = "报名比赛")
|
|
|
|
|
|
|
+ @Operation(summary = "报名比赛", security = @SecurityRequirement(name = "openApiSecurityScheme"))
|
|
|
@PostMapping("{id}/register")
|
|
@PostMapping("{id}/register")
|
|
|
- public Response<Boolean> register(@PathVariable Long id, @Valid @RequestBody ContestRegisterDto dto) {
|
|
|
|
|
|
|
+ public Response<Boolean> register(@Parameter(description = "比赛ID") @PathVariable Long id, @Valid @RequestBody ContestRegisterDto dto) {
|
|
|
if (!contestService.checkPassword(id, dto.getPassword())) {
|
|
if (!contestService.checkPassword(id, dto.getPassword())) {
|
|
|
return Response.error("比赛密码错误");
|
|
return Response.error("比赛密码错误");
|
|
|
}
|
|
}
|
|
|
return Response.ok(contestService.register(id, SecurityUtils.getCurrentUserId()));
|
|
return Response.ok(contestService.register(id, SecurityUtils.getCurrentUserId()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Operation(summary = "查询比赛报名名单")
|
|
|
|
|
|
|
+ @Operation(summary = "查询比赛报名名单", security = @SecurityRequirement(name = "openApiSecurityScheme"))
|
|
|
@PreAuthorize("hasAnyRole('ROLE_coach', 'ROLE_admin')")
|
|
@PreAuthorize("hasAnyRole('ROLE_coach', 'ROLE_admin')")
|
|
|
@GetMapping("{id}/registrations")
|
|
@GetMapping("{id}/registrations")
|
|
|
- public Response<List<ContestRegistrationVo>> queryRegistrations(@PathVariable Long id) {
|
|
|
|
|
|
|
+ public Response<List<ContestRegistrationVo>> queryRegistrations(@Parameter(description = "比赛ID") @PathVariable Long id) {
|
|
|
return Response.ok(contestService.queryRegistrations(id));
|
|
return Response.ok(contestService.queryRegistrations(id));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|