54 lines
1.8 KiB
Java
54 lines
1.8 KiB
Java
package com.designhub.controller;
|
|
|
|
import com.designhub.common.Result;
|
|
import com.designhub.entity.Achievement;
|
|
import com.designhub.entity.UserAchievement;
|
|
import com.designhub.service.AchievementService;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 成就系统Controller
|
|
*/
|
|
@Tag(name = "成就系统", description = "成就徽章相关API")
|
|
@RestController
|
|
@RequestMapping("/api/achievements")
|
|
@RequiredArgsConstructor
|
|
public class AchievementController {
|
|
|
|
private final AchievementService achievementService;
|
|
|
|
@Operation(summary = "获取所有成就列表")
|
|
@GetMapping
|
|
public Result<List<Achievement>> getAllAchievements() {
|
|
List<Achievement> achievements = achievementService.getAllAchievements();
|
|
return Result.success(achievements);
|
|
}
|
|
|
|
@Operation(summary = "获取用户已达成的成就")
|
|
@GetMapping("/user/{userId}")
|
|
public Result<List<UserAchievement>> getUserAchievements(@PathVariable Long userId) {
|
|
List<UserAchievement> achievements = achievementService.getUserAchievements(userId);
|
|
return Result.success(achievements);
|
|
}
|
|
|
|
@Operation(summary = "领取成就奖励")
|
|
@PostMapping("/{achievementId}/claim")
|
|
public Result<Boolean> claimReward(@PathVariable Long achievementId, @RequestParam Long userId) {
|
|
boolean success = achievementService.claimAchievementReward(userId, achievementId);
|
|
return Result.success(success);
|
|
}
|
|
|
|
@Operation(summary = "初始化默认成就")
|
|
@PostMapping("/init")
|
|
public Result<Void> initDefaultAchievements() {
|
|
achievementService.initDefaultAchievements();
|
|
return Result.success(null);
|
|
}
|
|
}
|
|
|