package org.enricogiurin.sushibar.controller;

import org.enricogiurin.sushibar.model.User;
import org.enricogiurin.sushibar.model.UserRepository;
import org.enricogiurin.sushibar.po.UserDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * Created by enrico on 2/27/17.
 */

@RestController
public class UserController {

    @Autowired
    private UserRepository userRepository;

    @GetMapping(value = "/user")
    @Secured(value = {"ROLE_USER"})
    public  @ResponseBody List<UserDTO> activeUsers() {
        List<User> activeUsers = userRepository.activeUsers();
        return activeUsers.stream()
                .map(user -> new UserDTO(user.getUsername(), user.getEmail()))
                .collect(Collectors.toList());
    }

}

@@ -36,24 +36,69 @@
 ontroller;%0A%0A
+import org.enricogiurin.sushibar.model.Role;%0A
 import org.e
@@ -803,17 +803,21 @@
 alue = %7B
-%22
+Role.
 ROLE_USE
@@ -817,17 +817,16 @@
 OLE_USER
-%22
 %7D)%0A    p

Use of constant