package org.synyx.urlaubsverwaltung.person.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.synyx.urlaubsverwaltung.api.ResponseWrapper;
import org.synyx.urlaubsverwaltung.person.Person;
import org.synyx.urlaubsverwaltung.person.PersonService;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;


@Api("Persons: Get information about the persons of the application")
@RestController("restApiPersonController")
@RequestMapping("/api")
public class PersonApiController {

    private static final String ROOT_URL = "/persons";

    private final PersonService personService;

    @Autowired
    PersonApiController(PersonService personService) {

        this.personService = personService;
    }

    @ApiOperation(
        value = "Get all active persons of the application", notes = "Get all active persons of the application"
    )
    @GetMapping(ROOT_URL)
    public List<PersonResponse> persons() {

        return personService.getActivePersons().stream().map(PersonResponse::new).collect(Collectors.toList());
    }
}

@@ -255,162 +255,71 @@
 ork.
-web.bind.annotation.GetMapping;%0Aimport org.springframework.web.bind.annotation.RequestMapping;%0Aimport org.springframework.web.bind.annotation.RequestParam
+http.HttpStatus;%0Aimport org.springframework.http.ResponseEntity
 ;%0Aim
@@ -363,30 +363,17 @@
 otation.
-RestController
+*
 ;%0Aimport
@@ -873,16 +873,81 @@
 ersons%22;
+%0A    private static final String PERSON_URL = ROOT_URL + %22/%7Bid%7D%22;
 %0A%0A    pr
@@ -1285,16 +1285,31 @@
  public 
+ResponseEntity%3C
 List%3CPer
@@ -1320,16 +1320,17 @@
 esponse%3E
+%3E
  persons
@@ -1347,14 +1347,38 @@
     
-return
+List%3CPersonResponse%3E persons =
  per
@@ -1415,16 +1415,29 @@
 stream()
+%0A            
 .map(Per
@@ -1453,16 +1453,29 @@
 se::new)
+%0A            
 .collect
@@ -1496,16 +1496,586 @@
 List());
+%0A%0A        return new ResponseEntity%3C%3E(persons, HttpStatus.OK);%0A    %7D%0A%0A    @ApiOperation(%0A        value = %22Get one active person by id%22, notes = %22Get one active person by id%22%0A    )%0A    @GetMapping(PERSON_URL)%0A    public ResponseEntity%3CPersonResponse%3E getPerson(@PathVariable Integer id) %7B%0A%0A        Optional%3CPerson%3E person = personService.getPersonByID(id);%0A        if(person.isPresent()) %7B%0A            return new ResponseEntity%3C%3E(new PersonResponse(person.get()), HttpStatus.OK);%0A        %7D else %7B%0A            return new ResponseEntity%3C%3E(HttpStatus.NOT_FOUND);%0A        %7D%0A%0A
 %0A    %7D%0A%7D

create API to get one person by id