Ejemplo n.º 1
0
 /**
  * Remove user from room's users
  *
  * @param roomId
  * @param userId
  * @return HttpEntity<Room> - HttpStatus.NO_CONTENT when all is ok
  */
 @RequestMapping(value = "/leave/{id}", method = RequestMethod.POST)
 public HttpEntity<Room> leaveRoom(@PathVariable("id") int roomId, @RequestBody int userId)
     throws ObjectNotFoundException {
   User user = userService.findOne(userId);
   roomService.removeUserFromRoom(roomId, user);
   return new ResponseEntity(HttpStatus.NO_CONTENT);
 }
Ejemplo n.º 2
0
 /**
  * Add user to room's users
  *
  * @param roomId
  * @param userId
  * @return HttpEntity<Room> - room that user joined to
  */
 @RequestMapping(value = "/join/{id}", method = RequestMethod.POST)
 public HttpEntity<Room> joinRoom(@PathVariable("id") int roomId, @RequestBody int userId)
     throws AlreadyExistsException {
   Room room = roomService.findOne(roomId);
   User user = userService.findOne(userId);
   if (user == null || room == null || room.getType() == Room.CLOSE_TYPE) {
     return new ResponseEntity(HttpStatus.BAD_REQUEST);
   }
   room = roomService.joinRoom(roomId, user);
   return new ResponseEntity(room, HttpStatus.OK);
 }