package com.royalrangers.controller.achievement;

import com.fasterxml.jackson.annotation.JsonView;
import com.royalrangers.dto.ResponseResult;
import com.royalrangers.dto.achievement.UserAchievementRequestDto;
import com.royalrangers.model.Views;
import com.royalrangers.service.achievement.UserYearAchievementService;
import com.royalrangers.utils.ResponseBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/achievements/userYear")
public class UserYearAchievementController {

    @Autowired
    private UserYearAchievementService userYearAchievementService;

    @JsonView(Views.Achievement.class)
    @GetMapping
    public ResponseResult getAllUserYearAchievement() {
        try {
            return ResponseBuilder.success(userYearAchievementService.findAllForUser());
        } catch (Exception ex) {
            log.error(ex.getMessage());
            return ResponseBuilder.fail("Failed get all user achievement");
        }
    }

    @PostMapping
    public ResponseResult addUserYearAchievement(@RequestBody UserAchievementRequestDto params) {
        try {
            userYearAchievementService.addUserYearAchievement(params);
            return ResponseBuilder.success("Successfully added userYearAchievement");
        } catch (Exception ex) {
            log.error(ex.getMessage());
            return ResponseBuilder.fail("Failed add userAchievement");
        }
    }

    @JsonView(Views.Achievement.class)
    @GetMapping("/{userAchievementId}")
    public ResponseResult getUserYearAchievementById(@PathVariable Long userAchievementId) {
        try {
            return ResponseBuilder.success(userYearAchievementService.getUserYearAchievementById(userAchievementId));
        } catch (Exception ex) {
            log.error(ex.getMessage());
            return ResponseBuilder.fail("Failed get userAchievement by id");
        }
    }

    @DeleteMapping("/{userAchievementId}")
    public ResponseResult deleteUserYearAchievement(@PathVariable Long userAchievementId) {
        try {
            userYearAchievementService.deleteUserYearAchievement(userAchievementId);
            return ResponseBuilder.success("UserAchievement was success delete");
        } catch (Exception ex) {
            log.error(ex.getMessage());
            return ResponseBuilder.fail("Failed delete userAchievement");
        }
    }

    @PutMapping("/{userAchievementId}")
    public ResponseResult editUserYearAchievement(@RequestBody UserAchievementRequestDto params, @PathVariable Long userAchievementId) {
        try {
            userYearAchievementService.editUserYearAchievement(params, userAchievementId);
            return ResponseBuilder.success("Successfully editing UserYearAchievement");
        } catch (Exception ex) {
            log.error(ex.getMessage());
            return ResponseBuilder.fail("Failed edit userAchievement");
        }
    }
}

@@ -360,16 +360,60 @@
 uilder;%0A
+import io.swagger.annotations.ApiOperation;%0A
 import l
@@ -438,16 +438,16 @@
 .Slf4j;%0A
-
 import o
@@ -793,32 +793,110 @@
     @GetMapping%0A
+    @ApiOperation(value = %22Get a list of year achievements for current user%22)%0A
     public Respo
@@ -1217,24 +1217,95 @@
 PostMapping%0A
+    @ApiOperation(value = %22Add the year achievement for current user%22)%0A
     public R
@@ -1793,32 +1793,87 @@
 chievementId%7D%22)%0A
+    @ApiOperation(value = %22Get year achievement info%22)%0A
     public Respo
@@ -2283,32 +2283,98 @@
 chievementId%7D%22)%0A
+    @ApiOperation(value = %22Delete current user year achievement%22)%0A
     public Respo
@@ -2790,24 +2790,24 @@
    %7D%0A    %7D%0A%0A
-
     @PutMapp
@@ -2830,24 +2830,90 @@
 vementId%7D%22)%0A
+    @ApiOperation(value = %22Update current user year achievement%22)%0A
     public R

Add API descriptions