86 lines
2.8 KiB
Java
86 lines
2.8 KiB
Java
package com.designhub.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.designhub.common.Result;
|
|
import com.designhub.entity.TeamPK;
|
|
import com.designhub.service.TeamPKService;
|
|
import com.designhub.util.JwtUtil;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
/**
|
|
* 团队PK Controller
|
|
*/
|
|
@Tag(name = "团队PK", description = "团队PK管理相关API")
|
|
@RestController
|
|
@RequestMapping("/api/team-pk")
|
|
@RequiredArgsConstructor
|
|
public class TeamPKController {
|
|
|
|
private final TeamPKService teamPKService;
|
|
private final JwtUtil jwtUtil;
|
|
|
|
@Operation(summary = "创建团队PK")
|
|
@PostMapping
|
|
public Result<TeamPK> createTeamPK(
|
|
@RequestBody TeamPK teamPK,
|
|
@RequestHeader("Authorization") String authHeader) {
|
|
String token = jwtUtil.extractTokenFromHeader(authHeader);
|
|
Long userId = jwtUtil.getUserIdFromToken(token);
|
|
teamPK.setCreatorId(userId);
|
|
return Result.success(teamPKService.createTeamPK(teamPK));
|
|
}
|
|
|
|
@Operation(summary = "发布团队PK")
|
|
@PostMapping("/{id}/publish")
|
|
public Result<TeamPK> publishTeamPK(@PathVariable Long id) {
|
|
return Result.success(teamPKService.publishTeamPK(id));
|
|
}
|
|
|
|
@Operation(summary = "结束团队PK")
|
|
@PostMapping("/{id}/end")
|
|
public Result<Void> endTeamPK(@PathVariable Long id) {
|
|
teamPKService.endTeamPK(id);
|
|
return Result.success();
|
|
}
|
|
|
|
@Operation(summary = "取消团队PK")
|
|
@PostMapping("/{id}/cancel")
|
|
public Result<Void> cancelTeamPK(@PathVariable Long id) {
|
|
teamPKService.cancelTeamPK(id);
|
|
return Result.success();
|
|
}
|
|
|
|
@Operation(summary = "删除团队PK")
|
|
@DeleteMapping("/{id}")
|
|
public Result<Void> deleteTeamPK(@PathVariable Long id) {
|
|
teamPKService.deleteTeamPK(id);
|
|
return Result.success();
|
|
}
|
|
|
|
@Operation(summary = "获取团队PK列表")
|
|
@GetMapping
|
|
public Result<IPage<TeamPK>> getPKList(
|
|
@RequestParam(defaultValue = "1") Integer page,
|
|
@RequestParam(defaultValue = "10") Integer pageSize,
|
|
@RequestParam(required = false) String status) {
|
|
return Result.success(teamPKService.getPKList(page, pageSize, status));
|
|
}
|
|
|
|
@Operation(summary = "获取团队PK详情")
|
|
@GetMapping("/{id}")
|
|
public Result<TeamPK> getPKById(@PathVariable Long id) {
|
|
return Result.success(teamPKService.getPKById(id));
|
|
}
|
|
|
|
@Operation(summary = "刷新PK数据")
|
|
@PostMapping("/{id}/refresh")
|
|
public Result<TeamPK> refreshPKStats(@PathVariable Long id) {
|
|
TeamPK pk = teamPKService.getPKById(id);
|
|
teamPKService.refreshPKStats(pk);
|
|
return Result.success(teamPKService.getPKById(id));
|
|
}
|
|
}
|