package com.royalrangers.controller.achievement;

import com.royalrangers.bean.ResponseResult;
import com.royalrangers.bean.UserBean;
import com.royalrangers.model.achievement.*;
import com.royalrangers.service.achievement.*;
import com.royalrangers.utils.ResponseBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.royalrangers.service.achievement.UserAchievementService.getUsersFromUserAchievements;

@RestController
@RequestMapping("/achievements/userAchievement")
public class UserAchievementController {

    @Autowired
    private UserTaskService userTaskService;
    @Autowired
    private UserTestService userTestService;
    @Autowired
    private UserQuarterAchievementService userQuarterAchievementService;
    @Autowired
    private UserYearAchievementService userYearAchievementService;
    @Autowired
    private UserThreeYearAchievementService userThreeYearAchievementService;
    @Autowired
    private UserTwelveYearAchievementService userTwelveYearAchievementService;



    @GetMapping("/task")
    public ResponseResult getUsersListForTask(Long platoonId, Long taskId, String achievementState){
        List<UserTask> userAchievementList = userTaskService.getUserTasksByTaskId(taskId);
        List<UserBean> result = getUsersFromUserAchievements(userAchievementList, platoonId,achievementState);
        return ResponseBuilder.success(result);
    }

    @GetMapping("/test")
    public ResponseResult getUsersListForTest(Long platoonId, Long testId, String achievementState){
        List<UserTest> userAchievementList = userTestService.getUserTestsByTestId(testId);
        List<UserBean> result = getUsersFromUserAchievements(userAchievementList, platoonId,achievementState);
        return ResponseBuilder.success(result);
    }

    @GetMapping("/quarterAchievement")
    public ResponseResult getUsersListForQuarterAchievement(Long platoonId, Long achievementId, String achievementState){
        List<UserQuarterAchievement> userAchievementList = userQuarterAchievementService.getUserQuarterAchievementByAchievementId(achievementId);
        List<UserBean> result = getUsersFromUserAchievements(userAchievementList, platoonId,achievementState);
        return ResponseBuilder.success(result);
    }

    @GetMapping("/yearAchievement")
    public ResponseResult getUsersListForYearAchievement(Long platoonId, Long achievementId, String achievementState){
        List<UserYearAchievement> userAchievementList = userYearAchievementService.getUserYearAchievementByAchievementId(achievementId);
        List<UserBean> result = getUsersFromUserAchievements(userAchievementList, platoonId,achievementState);
        return ResponseBuilder.success(result);
    }

    @GetMapping("/threeYearAchievement")
    public ResponseResult getUsersListForThreeYearAchievement(Long platoonId, Long achievementId, String achievementState){
        List<UserThreeYearAchievement> userAchievementList = userThreeYearAchievementService.getUserThreeYearAchievementByAchievementId(achievementId);
        List<UserBean> result = getUsersFromUserAchievements(userAchievementList, platoonId,achievementState);
        return ResponseBuilder.success(result);
    }

    @GetMapping("/twelveYearAchievement")
    public ResponseResult getUsersListForTwelveYearAchievement(Long platoonId, Long achievementId, String achievementState){
        List<UserTwelveYearAchievement> userAchievementList = userTwelveYearAchievementService.getUserTwelveYearAchievementByAchievementId(achievementId);
        List<UserBean> result = getUsersFromUserAchievements(userAchievementList, platoonId,achievementState);
        return ResponseBuilder.success(result);
    }
}

@@ -329,16 +329,81 @@
 owired;%0A
+import org.springframework.security.access.prepost.PreAuthorize;%0A
 import o
@@ -445,32 +445,32 @@
 ion.GetMapping;%0A
-
 import org.sprin
@@ -508,32 +508,93 @@
 RequestMapping;%0A
+import org.springframework.web.bind.annotation.RequestParam;%0A
 import org.sprin
@@ -1381,16 +1381,54 @@
 /task%22)%0A
+    @PreAuthorize(%22hasRole('ADMIN')%22)%0A
     publ
@@ -1465,16 +1465,30 @@
 ForTask(
+@RequestParam 
 Long pla
@@ -1498,21 +1498,141 @@
 nId,
- Long taskId,
+%0A                                              @RequestParam Long taskId,%0A                                              @RequestParam
  Str
@@ -1932,24 +1932,62 @@
 ng(%22/test%22)%0A
+    @PreAuthorize(%22hasRole('ADMIN')%22)%0A
     public R
@@ -2020,16 +2020,30 @@
 ForTest(
+@RequestParam 
 Long pla
@@ -2053,21 +2053,141 @@
 nId,
- Long testId,
+%0A                                              @RequestParam Long testId,%0A                                              @RequestParam
  Str
@@ -2497,32 +2497,70 @@
 erAchievement%22)%0A
+    @PreAuthorize(%22hasRole('ADMIN')%22)%0A
     public Respo
@@ -2595,32 +2595,46 @@
 rterAchievement(
+@RequestParam 
 Long platoonId, 
@@ -2632,36 +2632,184 @@
 atoonId,
- Long achievementId,
+%0A                                                            @RequestParam Long achievementId,%0A                                                            @RequestParam
  String 
@@ -3167,32 +3167,70 @@
 arAchievement%22)%0A
+    @PreAuthorize(%22hasRole('ADMIN')%22)%0A
     public Respo
@@ -3262,32 +3262,46 @@
 YearAchievement(
+@RequestParam 
 Long platoonId, 
@@ -3299,36 +3299,178 @@
 atoonId,
- Long achievementId,
+%0A                                                         @RequestParam Long achievementId,%0A                                                         @RequestParam
  String 
@@ -3824,32 +3824,70 @@
 arAchievement%22)%0A
+    @PreAuthorize(%22hasRole('ADMIN')%22)%0A
     public Respo
@@ -3924,32 +3924,46 @@
 YearAchievement(
+@RequestParam 
 Long platoonId, 
@@ -3961,36 +3961,188 @@
 atoonId,
- Long achievementId,
+%0A                                                              @RequestParam Long achievementId,%0A                                                              @RequestParam
  String 
@@ -4516,24 +4516,62 @@
 hievement%22)%0A
+    @PreAuthorize(%22hasRole('ADMIN')%22)%0A
     public R
@@ -4621,16 +4621,30 @@
 evement(
+@RequestParam 
 Long pla
@@ -4650,36 +4650,190 @@
 atoonId,
- Long achievementId,
+%0A                                                               @RequestParam Long achievementId,%0A                                                               @RequestParam
  String 

Add @RequestParam to controller arguments.