package fr.insa.lyon.ot.sims.centralserver.ws;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import fr.insa.lyon.ot.sims.centralserver.model.Profile;
import fr.insa.lyon.ot.sims.centralserver.model.User;
import fr.insa.lyon.ot.sims.centralserver.service.user.UserDoesNotExistException;
import fr.insa.lyon.ot.sims.centralserver.service.user.UserService;
import fr.insa.lyon.ot.sims.centralserver.ws.response.UserProfileResponse;
@Path("/profile/get/")
@Stateless
public class GetUserProfileRS {
@EJB
private UserService userService;
@GET
@Produces(MediaType.APPLICATION_JSON)
public UserProfileResponse getUserProfile(@QueryParam("login") String login) {
try {
User user = userService.findByLogin(login);
Profile profile = user.getProfile();
return UserProfileResponse.userProfileResponse(login, profile);
} catch (UserDoesNotExistException ex) {
return UserProfileResponse.userDoesNotExistResponse(login);
}
}
}
|