Ejemplo n.º 1
0
 def __get_all_users_in_room(self, room_id):
     if not is_valid_uuid(room_id) or Room.query.get(room_id) is None:
         raise LookupError("Room not found")
     room_users = RoomUser.query.filter_by(room_id=room_id).all()
     users = User.query.filter(User.id.in_([x.user_id
                                            for x in room_users])).all()
     return [user.to_json() for user in users]
Ejemplo n.º 2
0
 def __get_room(self, room_id):
     if not is_valid_uuid(room_id):
         raise LookupError("Room not found")
     room = Room.query.get(room_id)
     if room is None:
         raise LookupError("Room not found")
     return room.to_json()
Ejemplo n.º 3
0
 def __delete_room(self, room_id):
     if not is_valid_uuid(room_id):
         raise LookupError("Room not found")
     room = Room.query.get(room_id)
     if room is None:
         raise LookupError("Room not found")
     db.session.delete(room)
     db.session.commit()
     return
Ejemplo n.º 4
0
 def __add_user_to_room(self, user_id, room_id):
     if not is_valid_uuid(room_id) or Room.query.get(room_id) is None:
         raise LookupError("Room not found")
     elif User.query.get(user_id) is None:
         raise LookupError("User not found")
     room_user = RoomUser(room_id=room_id, user_id=user_id)
     db.session.add(room_user)
     db.session.commit()
     return
Ejemplo n.º 5
0
 def __update_room(self, room_id, args):
     if not is_valid_uuid(room_id):
         raise LookupError("Room not found")
     room = Room.query.get(room_id)
     if room is None:
         raise LookupError("Room not found")
     for k, v in args.items():
         setattr(room, k, v)
     db.session.commit()
     return room.to_json()
    def __add_video_to_playlist(self, room_id, video_id):
        if not is_valid_uuid(room_id) or Room.query.get(room_id) is None:
            raise LookupError("Room not found")
        elif Video.query.get(video_id) is None:
            raise LookupError("Video not found")
        playlist = Playlist(room_id=room_id, video_id=video_id)
        db.session.add(playlist)
        db.session.commit()

        return playlist.video_id
 def __delete_video_from_playlist(self, room_id, video_id):
     if not is_valid_uuid(room_id) or Room.query.get(room_id) is None:
         raise LookupError("Room not found")
     video = Playlist.query.filter_by(room_id=room_id,
                                      video_id=video_id).first()
     if video is None:
         raise LookupError("Video not found")
     db.session.delete(video)
     db.session.commit()
     return
Ejemplo n.º 8
0
 def __remove_user_from_room(self, user_id, room_id):
     if not is_valid_uuid(room_id):
         raise LookupError("Room not found")
     room_user = RoomUser.query.filter_by(room_id=room_id,
                                          user_id=user_id).first()
     if room_user is None:
         raise LookupError("RoomUser not found")
     db.session.delete(room_user)
     db.session.commit()
     return
 def __get_playlist(self, room_id):
     if not is_valid_uuid(room_id) or Room.query.get(room_id) is None:
         raise LookupError("Room not found")
     playlist = Playlist.query.filter_by(room_id=room_id).all()
     return [video.to_json() for video in playlist]