package io.github.web.rest.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
public class MyRestController {

    @Autowired
    private MyService teamsService;

    @RequestMapping(value = "/teams", method = RequestMethod.GET)
    public List<Team> getTeams() {
        return teamsService.getTeams();
    }

    @RequestMapping(value = "/team", method = RequestMethod.GET)
    public Team getTeamByQuery(@RequestParam("index") int index) {
        return teamsService.getTeam(index);
    }

    @RequestMapping(value = "/team/{index}", method = RequestMethod.GET)
    public Team getTeamByPath(@PathVariable("index") int index) {
        return teamsService.getTeam(index);
    }

    @RequestMapping(value = "/teams", method = RequestMethod.POST)
    public ResponseEntity<Integer> addTeam(@RequestBody Team team) {
        teamsService.addTeam(team);
        return new ResponseEntity<Integer>(teamsService.size(),
                HttpStatus.CREATED);
    }

}

@@ -831,16 +831,31 @@
  public 
+ResponseEntity%3C
 List%3CTea
@@ -856,16 +856,17 @@
 st%3CTeam%3E
+%3E
  getTeam
@@ -871,38 +871,50 @@
 ams() %7B%0A        
-return
+List%3CTeam%3E teams =
  teamsService.ge
@@ -922,16 +922,184 @@
 Teams();
+%0A%0A        HttpStatus status = HttpStatus.OK;%0A        ResponseEntity%3CList%3CTeam%3E%3E response = new ResponseEntity%3C%3E(teams,%0A                status);%0A        return response;
 %0A    %7D%0A%0A
@@ -1166,36 +1166,52 @@
 GET)%0A    public 
+ResponseEntity%3C
 Team
+%3E
  getTeamByQuery(
@@ -1210,16 +1210,29 @@
 ByQuery(
+%0A            
 @Request
@@ -1270,37 +1270,24 @@
      return 
-teamsService.
 getTeam(inde
@@ -1381,20 +1381,36 @@
  public 
+ResponseEntity%3C
 Team
+%3E
  getTeam
@@ -1416,16 +1416,29 @@
 mByPath(
+%0A            
 @PathVar
@@ -1480,29 +1480,16 @@
  return 
-teamsService.
 getTeam(
@@ -1687,99 +1687,470 @@
     
-return new ResponseEntity%3CInteger%3E(teamsService.size(),%0A                HttpStatus.CREATED)
+int teamSize = teamsService.size();%0A%0A        HttpStatus status = HttpStatus.CREATED;%0A        ResponseEntity%3CInteger%3E response = new ResponseEntity%3C%3E(teamSize,%0A                status);%0A        return response;%0A    %7D%0A%0A    private ResponseEntity%3CTeam%3E getTeam(int index) %7B%0A        Team team = teamsService.getTeam(index);%0A%0A        HttpStatus status = HttpStatus.OK;%0A        ResponseEntity%3CTeam%3E response = new ResponseEntity%3C%3E(team, status);%0A        return response
 ;%0A  

Use always ResponseEntity in REST service responses