|
|
@@ -0,0 +1,84 @@
|
|
|
+package space.anyi.serve.controller;
|
|
|
+
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.Parameter;
|
|
|
+import io.swagger.v3.oas.annotations.media.Content;
|
|
|
+import io.swagger.v3.oas.annotations.media.Schema;
|
|
|
+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 jakarta.annotation.Resource;
|
|
|
+import jakarta.validation.Valid;
|
|
|
+import jakarta.validation.constraints.NotNull;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import space.anyi.serve.entity.PageVo;
|
|
|
+import space.anyi.serve.entity.Response;
|
|
|
+import space.anyi.serve.entity.contest.SubmissionVo;
|
|
|
+import space.anyi.serve.entity.contest.SubmitDto;
|
|
|
+import space.anyi.serve.service.SubmissionService;
|
|
|
+import space.anyi.serve.util.SecurityUtils;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Tag(name = "SubmissionController", description = "代码提交与判题相关接口")
|
|
|
+@ApiResponses(value = {
|
|
|
+ @ApiResponse(responseCode = "200", description = "成功", useReturnTypeSchema = true),
|
|
|
+ @ApiResponse(responseCode = "400", description = "参数校验失败,返回体 code=400",
|
|
|
+ content = @Content(schema = @Schema(implementation = Response.class))),
|
|
|
+ @ApiResponse(responseCode = "401", description = "未认证或认证已过期",
|
|
|
+ content = @Content(schema = @Schema(implementation = Response.class))),
|
|
|
+ @ApiResponse(responseCode = "403", description = "无权限访问",
|
|
|
+ content = @Content(schema = @Schema(implementation = Response.class)))
|
|
|
+})
|
|
|
+@RestController
|
|
|
+public class SubmissionController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private SubmissionService submissionService;
|
|
|
+
|
|
|
+ @Operation(summary = "提交代码并判题", description = "同步返回判题结果,contestId为空表示日常练习提交",
|
|
|
+ security = @SecurityRequirement(name = "openApiSecurityScheme"))
|
|
|
+ @PostMapping("submit")
|
|
|
+ public Response<SubmissionVo> submit(@Valid @RequestBody SubmitDto dto) {
|
|
|
+ return Response.ok(submissionService.submit(dto, SecurityUtils.getCurrentUserId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "查询提交记录详情", security = @SecurityRequirement(name = "openApiSecurityScheme"))
|
|
|
+ @GetMapping("submission/{id}")
|
|
|
+ public Response<SubmissionVo> getDetail(@Parameter(description = "提交ID") @PathVariable Long id) {
|
|
|
+ return Response.ok(submissionService.getDetail(id, SecurityUtils.getCurrentUserId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "查询我的提交记录", description = "分页查询当前用户的提交记录,按提交时间倒序",
|
|
|
+ security = @SecurityRequirement(name = "openApiSecurityScheme"))
|
|
|
+ @GetMapping("submission/my")
|
|
|
+ public Response<PageVo<List<SubmissionVo>>> queryMy(
|
|
|
+ @Parameter(description = "页码")
|
|
|
+ @NotNull(message = "页码不能为null") @RequestParam(defaultValue = "1") Integer pageNum,
|
|
|
+ @Parameter(description = "分页大小")
|
|
|
+ @NotNull(message = "分页大小不能为null") @RequestParam(defaultValue = "10") Integer pageSize) {
|
|
|
+ var page = submissionService.queryMySubmissions(SecurityUtils.getCurrentUserId(), pageNum, pageSize);
|
|
|
+ return Response.ok(new PageVo<>(page.getTotal(), page.getRecords()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "查询题目的提交记录", description = "coach/admin 查看某题的全部提交记录",
|
|
|
+ security = @SecurityRequirement(name = "openApiSecurityScheme"))
|
|
|
+ @PreAuthorize("hasAnyRole('ROLE_coach', 'ROLE_admin')")
|
|
|
+ @GetMapping("problem/{id}/submission")
|
|
|
+ public Response<PageVo<List<SubmissionVo>>> queryByProblemId(
|
|
|
+ @Parameter(description = "题目ID") @PathVariable Long id,
|
|
|
+ @Parameter(description = "页码")
|
|
|
+ @NotNull(message = "页码不能为null") @RequestParam(defaultValue = "1") Integer pageNum,
|
|
|
+ @Parameter(description = "分页大小")
|
|
|
+ @NotNull(message = "分页大小不能为null") @RequestParam(defaultValue = "10") Integer pageSize) {
|
|
|
+ var page = submissionService.queryByProblemId(id, pageNum, pageSize);
|
|
|
+ return Response.ok(new PageVo<>(page.getTotal(), page.getRecords()));
|
|
|
+ }
|
|
|
+}
|