package li.l1t.sic.rest;

import li.l1t.sic.model.GuestUser;
import li.l1t.sic.model.dto.PersonDto;
import li.l1t.sic.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;

import java.security.Principal;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

/**
 * REST controller providing an API for getting information about people and modifying it.
 *
 * @author <a href="http://xxyy.github.io/">xxyy</a>
 * @since 2016-02-14
 */
@RestController
public class PersonController {
    private final PersonService personService;

    @Autowired
    PersonController(PersonService personService) {
        this.personService = personService;
    }


    @RequestMapping("/api/person/list")
    public List<PersonDto> personList() {
        return StreamSupport.stream(personService.getAllPeople().spliterator(), false)
                .map(personService::toDto)
                .collect(Collectors.toList());
    }

    @RequestMapping("/api/person/by/id/{id}")
    public PersonDto singlePerson(@PathVariable("id") int id) {
        return personService.toDto(personService.getById(id));
    }

    @RequestMapping(value = "/api/person/new", method = RequestMethod.POST)
    public PersonDto newPerson(@RequestBody PersonDto personDto, Principal user) {
        GuestUser.validateNotGuest(user);
        return personService.toDto(personService.newPerson(personDto));
    }
}

@@ -197,16 +197,80 @@
 owired;%0A
+import org.springframework.boot.actuate.metrics.CounterService;%0A
 import o
@@ -926,16 +926,31 @@
 oller %7B%0A
+    @Autowired%0A
     priv
@@ -957,14 +957,8 @@
 ate 
-final 
 Pers
@@ -982,17 +982,16 @@
 ervice;%0A
-%0A
     @Aut
@@ -1005,91 +1005,38 @@
     
-Person
+private 
 Co
+u
 nt
-roller(PersonService personService) %7B%0A        this.personService = person
+erService counter
 Serv
@@ -1040,22 +1040,16 @@
 ervice;%0A
-    %7D%0A
 %0A%0A    @R
@@ -1120,24 +1120,91 @@
 sonList() %7B%0A
+        counterService.increment(%22controllers.person.listAccess%22);%0A
         retu

Add people list access counter