package com.lesingle.creation.controller; import com.lesingle.creation.common.core.Result; import com.lesingle.creation.common.security.UserPrincipal; import com.lesingle.creation.dto.presetcomment.CreatePresetCommentDTO; import com.lesingle.creation.service.ContestPresetCommentService; import com.lesingle.creation.service.ContestReviewService; import com.lesingle.creation.vo.presetcomment.PresetCommentVO; import com.lesingle.creation.vo.review.JudgeContestVO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.List; /** * 竞赛预设评语管理控制器 */ @Tag(name = "竞赛预设评语管理") @RestController @RequestMapping("/api/contests/preset-comments") @RequiredArgsConstructor public class ContestPresetCommentController { private final ContestPresetCommentService presetCommentService; private final ContestReviewService reviewService; @PostMapping @Operation(summary = "创建预设评语") @PreAuthorize("hasAuthority('contest:preset-comment:create')") public Result create( @AuthenticationPrincipal UserPrincipal userPrincipal, @RequestBody @Validated CreatePresetCommentDTO dto) { Long tenantId = userPrincipal.getTenantId(); PresetCommentVO result = presetCommentService.create(dto, tenantId); return Result.success(result); } @DeleteMapping("/{id}") @Operation(summary = "删除预设评语") @PreAuthorize("hasAuthority('contest:preset-comment:delete')") public Result delete(@PathVariable Long id) { presetCommentService.delete(id); return Result.success(null); } @GetMapping("/{id}") @Operation(summary = "获取预设评语详情") @PreAuthorize("hasAuthority('contest:read')") public Result getDetail(@PathVariable Long id) { PresetCommentVO result = presetCommentService.getDetail(id); return Result.success(result); } @GetMapping("/contest/{contestId}") @Operation(summary = "查询活动的预设评语列表") @PreAuthorize("hasAuthority('contest:read')") public Result> listByContest( @AuthenticationPrincipal UserPrincipal userPrincipal, @PathVariable Long contestId) { Long tenantId = userPrincipal.getTenantId(); List result = presetCommentService.listByContest(contestId, tenantId); return Result.success(result); } @GetMapping("/common") @Operation(summary = "查询通用评语列表") @PreAuthorize("hasAuthority('contest:read')") public Result> listCommon( @AuthenticationPrincipal UserPrincipal userPrincipal) { Long tenantId = userPrincipal.getTenantId(); List result = presetCommentService.listCommon(tenantId); return Result.success(result); } /** * 与 {@code GET /api/contests/reviews/judge/contests} 一致,供前端在预设评语模块复用 */ @GetMapping("/judge/contests") @Operation(summary = "评委参与的活动列表") @PreAuthorize("hasAnyAuthority('review:score','contest:review:score')") public Result> getJudgeContests( @AuthenticationPrincipal UserPrincipal userPrincipal) { Long judgeId = userPrincipal.getUserId(); Long tenantId = userPrincipal.getTenantId(); return Result.success(reviewService.getJudgeContests(judgeId, tenantId)); } }