package ca.intelliware.ihtsdo.mlds.web.rest;
import javax.annotation.security.RolesAllowed;
import javax.inject.Inject;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import ca.intelliware.ihtsdo.mlds.domain.User;
import ca.intelliware.ihtsdo.mlds.repository.UserRepository;
import ca.intelliware.ihtsdo.mlds.security.AuthoritiesConstants;
import com.codahale.metrics.annotation.Timed;
/**
* REST controller for managing users.
*/
@RestController
@RequestMapping("/api")
public class UserResource {
private final Logger log = LoggerFactory.getLogger(UserResource.class);
@Inject
private UserRepository userRepository;
@RequestMapping(value = "/users",
method = RequestMethod.GET,
produces = "application/json")
@RolesAllowed({ AuthoritiesConstants.STAFF, AuthoritiesConstants.ADMIN })
@Timed
public @ResponseBody Iterable<User> getUsers() {
log.debug("Rest request to get all Users");
return userRepository.findAll();
}
/**
* GET /rest/users/:login -> get the "login" user.
*/
@RequestMapping(value = "/users/{login}",
method = RequestMethod.GET,
produces = "application/json")
@Timed
@RolesAllowed({ AuthoritiesConstants.STAFF, AuthoritiesConstants.ADMIN })
public User getUser(@PathVariable String login, HttpServletResponse response) {
log.debug("REST request to get User : {}", login);
User user = userRepository.findByLoginIgnoreCase(login);
if (user == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
}
return user;
}
}