package fr.ekito.example.web.rest; import com.codahale.metrics.annotation.Timed; import fr.ekito.example.domain.User; import fr.ekito.example.repository.UserRepository; import fr.ekito.example.security.AuthoritiesConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.annotation.security.RolesAllowed; import javax.inject.Inject; import java.util.Optional; /** * REST controller for managing users. */ @RestController @RequestMapping("/app") public class UserResource { private final Logger log = LoggerFactory.getLogger(UserResource.class); @Inject private UserRepository userRepository; /** * GET /rest/users/:login -> get the "login" user. */ @RequestMapping(value = "/rest/users/{login}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @Timed @RolesAllowed(AuthoritiesConstants.ADMIN) ResponseEntity<User> getUser(@PathVariable String login) { log.debug("REST request to get User : {}", login); return Optional.ofNullable(userRepository.findOne(login)) .map(user -> new ResponseEntity<>(user, HttpStatus.OK)) .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND)); } }