/** * A controller method for assigning an item to a guest. * * @param id Id of the guest to assign the item to. * @param title Title of the item. * @return {@code BaseResponse} Stating the result of the process. */ @RequestMapping(value = "/assign", method = RequestMethod.GET) public BaseResponse assignItem(@RequestParam("id") long id, @RequestParam("title") String title) { mLogger.info("Assigning item '{}' for guest with id #{}", title, id); try { Guest guest = mEventService.assignItem(id, title); return new BaseResponse<>(guest.createRepresentationalObject()); } catch (ServiceException e) { mLogger.error(e.getMessage()); return new BaseResponse<>(e.getMessage(), BaseResponse.INTERNAL_ERROR); } }
/** * A controller method for deleting a guest. * * @param id Id of the guest to delete. * @return {@code BaseResponse} Stating the result of process. */ @RequestMapping(value = "/guest", method = RequestMethod.DELETE) public BaseResponse deleteGuest(@RequestParam("id") long id) { mLogger.info("Deleting guest with id #{}", id); try { Guest guest = mEventService.deleteGuest(id); return new BaseResponse<>(guest.createRepresentationalObject()); } catch (ServiceException e) { mLogger.error(e.getMessage()); return new BaseResponse<>(e.getMessage(), BaseResponse.INTERNAL_ERROR); } }
/** * A controller method for updating an item with the given id. * * @param id Id of the item to delete. * @param isBringing Whether the guest is bringing the item. * @return {@code BaseResponse} Stating the result of the process. */ @RequestMapping(value = "/item", method = RequestMethod.PUT) public BaseResponse updateItem( @RequestParam("id") long id, @RequestParam("bringing") boolean isBringing) { mLogger.info("Updating item with id #{}", id); try { Item item = mEventService.updateItem(id, isBringing); return new BaseResponse<>(item.createRepresentationalObject()); } catch (ServiceException e) { mLogger.error(e.getMessage()); return new BaseResponse<>(e.getMessage(), BaseResponse.INTERNAL_ERROR); } }
/** * A controller method for updating an {@link Guest}. * * @param id The id of the invited user, we wish to update. * @param updateRequest The new details of the invited user. * @return {@code BaseResponse} representing the updated invited user, or the error occurred. */ @RequestMapping(value = "/updateGuest", method = RequestMethod.PUT) public BaseResponse updateGuest( @RequestParam("id") long id, @RequestBody UpdateGuestRequest updateRequest) { try { mLogger.info("Updating guest with id #{}", id); GuestRO guest = mEventService.updateGuest(id, updateRequest).createRepresentationalObject(); return new BaseResponse<>(guest); } catch (ServiceException e) { mLogger.error(e.getMessage()); return new BaseResponse<>(e.getMessage(), BaseResponse.INTERNAL_ERROR); } }
/** * A controller method for creating a new event, given the saveEventRequest details. In case of * {@code ServiceException}, return the error. * * @param saveEventRequest The details of the event - given in JSON. * @return {@code BaseResponse} stating the result of the process. */ @RequestMapping(method = RequestMethod.POST) public BaseResponse createEvent(@RequestBody SaveEventRequest saveEventRequest) { try { mLogger.info("Create Event Request {}", saveEventRequest); EventRO createdEvent = mEventService.createEvent(saveEventRequest).createRepresentationalObject(); return new BaseResponse<>(createdEvent); } catch (ServiceException e) { mLogger.error(e.getMessage()); return new BaseResponse<>(e.getMessage(), BaseResponse.INTERNAL_ERROR); } }
/** * A controller method for requesting the user events, given the user id. * * @param id Of the user to get events for. * @return {@link BaseResponse} stating the result of the process. */ @RequestMapping(value = "/getUserEvents", method = RequestMethod.GET) public BaseResponse getUserEvents(@RequestParam("id") long id) { try { mLogger.info("Getting user events for user with id #{}", id); List<EventRO> events = Converter.convertList( mEventService.getUserEvents(id), Event::createRepresentationalObject); return new BaseResponse<>(events); } catch (ServiceException e) { mLogger.error(e.getMessage()); return new BaseResponse<>(e.getMessage(), BaseResponse.INTERNAL_ERROR); } }
/** * A controller method for updating an existing event, given the saveEventRequest details. In case * of {@link ServiceException}, return the error. * * @param saveEventRequest The details of the event - given in JSON. * @return {@link BaseResponse} stating the result of the process. */ @RequestMapping(method = RequestMethod.PUT) public BaseResponse updateEvent( @RequestParam("id") long id, @RequestBody SaveEventRequest saveEventRequest) { try { mLogger.info("Update Event Request, for event with id #" + id + ": " + saveEventRequest); EventRO updatedEvent = mEventService.updateEvent(id, saveEventRequest).createRepresentationalObject(); return new BaseResponse<>(updatedEvent); } catch (ServiceException e) { mLogger.error(e.getMessage()); return new BaseResponse<>(e.getMessage(), BaseResponse.INTERNAL_ERROR); } }