package org.c4sg.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import org.c4sg.dto.SkillDTO;
import org.c4sg.dto.SkillUserCountDTO;
import org.c4sg.exception.BadRequestException;
import org.c4sg.exception.NotFoundException;
import org.c4sg.exception.SkillException;
import org.c4sg.service.SkillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/api/skills")
@Api(description = "Operations about Skills", tags = "skill")
public class SkillController {

    @Autowired
    private SkillService skillService;

    @CrossOrigin
    @RequestMapping(produces = {"application/json"}, method = RequestMethod.GET)
    @ApiOperation(value = "Get all skills", notes = "Returns a collection of skills (alphabetical)")
    public List<SkillDTO> getSkills() {
        return skillService.findSkills();
    }
    
    @CrossOrigin
    @RequestMapping(value="/userCount",produces = {"application/json"}, method = RequestMethod.GET)
    @ApiOperation(value = "Get skills grouped by user count", notes = "Returns a collection of skills with user count")
    public List<SkillUserCountDTO> getSkillsWithUserCount() {
        return skillService.findSkillsWithUserCount();
    }
    
    @CrossOrigin
    @RequestMapping(value="/user",produces = {"application/json"}, method = RequestMethod.GET)
    @ApiOperation(value = "Get skills for an user by id", notes = "Returns a collection of skills for an user by id")
    public List<String> getSkillsForUser(@ApiParam(value = "ID of user to return", required = true)
    									 @RequestParam Integer id) {
        return skillService.findSkillsForUser(id);
    }
    
    @CrossOrigin
    @RequestMapping(value="/project",produces = {"application/json"}, method = RequestMethod.GET)
    @ApiOperation(value = "Get skills for a project by id", notes = "Returns a collection of skills for a project")
    public List<String> getSkillsForProject(@ApiParam(value = "ID of project to return", required = true)
    									 	@RequestParam Integer id) {
        return skillService.findSkillsForProject(id);
    }
    
    @CrossOrigin
    @RequestMapping(value="/user/save", method = RequestMethod.POST)
    @ApiOperation(value = "Add skills for a user", notes = "Adds skills for the user with display order")
    public void createSkillsForUser(@ApiParam(value = "ID of user to add skills",name="id", required = true)
			 						@RequestParam Integer id,
    								@ApiParam(value = "Skills in display order",name="skillsList", required = true)
									@RequestParam List<String> skillsList)	{
		try {
			skillService.saveSkillsForUser(id,skillsList);
		} catch (NullPointerException e) {
            throw new NotFoundException(e.getMessage());
        } catch (SkillException e) {
			throw new BadRequestException(e.getMessage());
		}
	}
    
    @CrossOrigin
    @RequestMapping(value="/project/save", method = RequestMethod.POST)
    @ApiOperation(value = "Add skills for a project", notes = "Adds skills for the project with display order")
    public void createSkillsForProject(@ApiParam(value = "ID of project to add skills", required = true)
			 								@RequestParam Integer id,
    										@ApiParam(value = "Skills in display order", required = true)
											@RequestParam List<String> skillsList)	{
		try {
			skillService.saveSkillsForProject(id,skillsList);
		} catch (NullPointerException e) {
            throw new NotFoundException(e.getMessage());
        } catch (SkillException e) {
        	throw new BadRequestException(e.getMessage());
		}
	}
}
@@ -1727,20 +1727,16 @@
    %09%09%09%09%09
-%09%09%09%09
  @Reques
@@ -2168,14 +2168,12 @@
 %09%09%09%09
-%09%09%09%09 %09
+    
 @Req
@@ -2311,20 +2311,25 @@
 =%22/user/
-save
+addSkills
 %22, metho
@@ -2572,21 +2572,20 @@
 e)%0A%09%09%09 %09
-%09%09%09%09%09
+    
 @Request
@@ -2606,28 +2606,28 @@
 id,%0A    %09%09%09%09
-%09%09%09%09
+    
 @ApiParam(va
@@ -2694,29 +2694,28 @@
 = true)%0A%09%09%09%09
-%09%09%09%09%09
+    
 @RequestPara
@@ -2736,36 +2736,34 @@
  skillsList)
-%09
+ 
 %7B%0A
-%09
 %09try %7B%0A
-%09
 %09%09skillServi
@@ -2791,33 +2791,32 @@
 id,skillsList);%0A
-%09
 %09%7D catch (NullPo
@@ -2835,36 +2835,33 @@
 on e) %7B%0A        
-    
+%09
 throw new NotFou
@@ -2928,17 +2928,16 @@
  e) %7B%0A%09%09
-%09
 throw ne
@@ -2975,21 +2975,23 @@
 age());%0A
-%09
 %09%7D%0A
-%09
+    
 %7D%0A    %0A 
@@ -3042,20 +3042,25 @@
 project/
-save
+addSkills
 %22, metho
@@ -3305,23 +3305,23 @@
 e)%0A%09%09%09 %09
-%09%09%09%09%09%09%09
+       
 @Request
@@ -3346,22 +3346,23 @@
     %09%09%09%09
-%09%09%09%09%09%09
+       
 @ApiPara
@@ -3419,23 +3419,23 @@
 ue)%0A%09%09%09%09
-%09%09%09%09%09%09%09
+       
 @Request
@@ -3468,12 +3468,15 @@
 ist)
-%09%7B%0A%09
+ %7B%0A    
 %09try
@@ -3480,17 +3480,16 @@
 try %7B%0A%09%09
-%09
 skillSer
@@ -3530,17 +3530,16 @@
 sList);%0A
-%09
 %09%7D catch
@@ -3578,16 +3578,17 @@
         
+%09
 throw ne
@@ -3721,12 +3721,15 @@
 ));%0A
-%09
 %09%7D%0A
-%09
+    
 %7D%0A%7D
+%0A

Update SkillController.java