Commit 3e8ab32c by Tuomas Riihimäki

Add rest for fetching user and users places with barcode

1 parent baf69018
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>moya-restpojo</artifactId> <artifactId>moya-restpojo</artifactId>
<groupId>fi.codecrew.moya</groupId> <groupId>fi.codecrew.moya</groupId>
<version>1.0.3</version> <version>1.0.4</version>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
......
...@@ -26,6 +26,7 @@ import javax.xml.bind.annotation.XmlRootElement; ...@@ -26,6 +26,7 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement() @XmlRootElement()
public class UserReservationRoot { public class UserReservationRoot {
private EventUserRestPojo user;
private List<UserReservationPlacePojo> reservations = new ArrayList<UserReservationPlacePojo>(); private List<UserReservationPlacePojo> reservations = new ArrayList<UserReservationPlacePojo>();
public UserReservationRoot() { public UserReservationRoot() {
...@@ -40,6 +41,12 @@ public class UserReservationRoot { ...@@ -40,6 +41,12 @@ public class UserReservationRoot {
this.reservations = reservations; this.reservations = reservations;
} }
public EventUserRestPojo getUser() {
return user;
}
public void setUser(EventUserRestPojo user) {
this.user = user;
}
} }
...@@ -51,11 +51,12 @@ import fi.codecrew.moya.beans.CardTemplateBeanLocal; ...@@ -51,11 +51,12 @@ import fi.codecrew.moya.beans.CardTemplateBeanLocal;
import fi.codecrew.moya.beans.EventBeanLocal; import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal; import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.PlaceGroupBeanLocal; import fi.codecrew.moya.beans.PlaceGroupBeanLocal;
import fi.codecrew.moya.beans.ReaderBeanLocal;
import fi.codecrew.moya.beans.TicketBeanLocal; import fi.codecrew.moya.beans.TicketBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal; import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.GroupMembership; import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.LanEventPropertyKey; import fi.codecrew.moya.model.ReaderEvent;
import fi.codecrew.moya.rest.pojo.userinfo.v1.EventUserRestPojo; import fi.codecrew.moya.rest.pojo.userinfo.v1.EventUserRestPojo;
import fi.codecrew.moya.rest.pojo.userinfo.v1.PrintedCardRestPojo; import fi.codecrew.moya.rest.pojo.userinfo.v1.PrintedCardRestPojo;
import fi.codecrew.moya.rest.pojo.userinfo.v1.SimpleEventuserRoot; import fi.codecrew.moya.rest.pojo.userinfo.v1.SimpleEventuserRoot;
...@@ -90,22 +91,47 @@ public class UserRestView { ...@@ -90,22 +91,47 @@ public class UserRestView {
private PlaceGroupBeanLocal placegroupbean; private PlaceGroupBeanLocal placegroupbean;
@EJB @EJB
private ReaderBeanLocal readerbean;
@EJB
private TicketBeanLocal ticketbean; private TicketBeanLocal ticketbean;
@POST @GET
@Path("/reservationswithcode/{code}")
public Response getPlacesWithCode(@PathParam("code") String code) {
EventUser curruser = permbean.getCurrentUser();
ReaderEvent revent = readerbean.checkCode("restapi: " + curruser.getLogin(), code);
if (revent != null && revent.getUser() != null) {
EventUser eu = revent.getUser();
List<GroupMembership> gms = ticketbean.findMembershipPrintlistForUser(eu);
UserReservationRoot ret = new UserReservationRoot();
ret.setUser(PojoUtils.initEventUserRestPojo(eu));
for (GroupMembership g : gms) {
UserReservationPlacePojo ur = new UserReservationPlacePojo();
ur.setPlaceid(g.getPlaceReservation().getId());
ur.setPlacegiven(g.getEnteredEvent() != null);
ur.setPlacename(g.getPlaceReservation().getName());
ret.getReservations().add(ur);
}
return Response.ok(ret).build();
}
return Response.status(Status.NOT_FOUND).build();
}
@GET @GET
@Path("/{userid}/reservations") @Path("/{userid}/reservations")
public Response usersPlaces(@PathParam("userid") Integer userid) { public Response usersPlaces(@PathParam("userid") Integer userid) {
logger.info("user {} is trying to fetch user {}", permbean.getCurrentUser().getLogin(), userid);
EventUser eu = userbean.findByUserId(userid, false); EventUser eu = userbean.findByUserId(userid, false);
logger.info("Trying to fetch reservations for user {}, with useid {}", eu, userid);
if (eu != null) { if (eu != null) {
List<GroupMembership> gms = ticketbean.findMembershipPrintlistForUser(eu); List<GroupMembership> gms = ticketbean.findMembershipPrintlistForUser(eu);
UserReservationRoot ret = new UserReservationRoot(); UserReservationRoot ret = new UserReservationRoot();
logger.info("Got membersips {}", gms); ret.setUser(PojoUtils.initEventUserRestPojo(eu));
for (GroupMembership g : gms) { for (GroupMembership g : gms) {
UserReservationPlacePojo ur = new UserReservationPlacePojo(); UserReservationPlacePojo ur = new UserReservationPlacePojo();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!