Esempio n. 1
0
    def put(self):
        body = request.json
        missed_param = check_for_params([Keys.ROOM_ID, Keys.START_TIME, Keys.END_TINE], body)

        if missed_param is not None:
            raise ApiException(pointer=missed_param, reason=Reasons.MISSED, code=400)

        user_id = g.user_id
        room_id = body[Keys.ROOM_ID]
        start_time = body[Keys.START_TIME]
        end_time = body[Keys.END_TINE]

        if end_time <= start_time:
            raise ApiException(pointer=Keys.END_TINE, reason=Reasons.INVALID, code=400)

        if if_reservation_created(self.cursor, room_id, user_id, start_time):
            raise ApiException(pointer=Keys.REQUEST, reason=Reasons.CREATED, code=409)

        user = User(user_id, None, None)
        room = Room(room_id, None, None, None, None, None)
        reservation = ReservationModel(None, room, user, start_time, end_time)
        result = put_reservation(self.cursor, reservation)

        if result:
            return get_response(reservation)
        else:
            raise ApiException(pointer=Keys.START_TIME, reason=Reasons.TAKEN, code=409)
Esempio n. 2
0
    def patch(self):
        body = request.json
        print(body)
        missed_param = check_for_params([
            Keys.R_ID, Keys.NAME, Keys.DESCRIPTION, Keys.WITH_PROJECTOR,
            Keys.WITH_BOARD, Keys.SEATS_COUNT
        ], body)

        if missed_param is not None:
            raise ApiException(pointer=missed_param,
                               reason=Reasons.MISSED,
                               code=400)

        r_id = body[Keys.R_ID]
        name = body[Keys.NAME]
        description = body[Keys.DESCRIPTION]
        with_projector = body[Keys.WITH_PROJECTOR]
        with_board = body[Keys.WITH_BOARD]
        places_count = body[Keys.SEATS_COUNT]

        room = RoomModel(r_id, name, description, with_projector, with_board,
                         places_count)
        edit_room(self.cursor, room)

        room = get_room(self.cursor, r_id)
        return get_response(room)
Esempio n. 3
0
    def patch(self):
        body = request.json
        missed_param = check_for_params([Keys.RESERVATION_ID, Keys.STATUS], body)

        if missed_param is not None:
            raise ApiException(pointer=missed_param, reason=Reasons.MISSED, code=400)

        reservation_id = body[Keys.RESERVATION_ID]
        status = body[Keys.STATUS]

        allowed_statuses = [ReservationStatuses.CONFIRMED, ReservationStatuses.DECLINED]

        if status not in allowed_statuses:
            raise ApiException(pointer=Keys.STATUS, reason=Reasons.INVALID, code=400)

        set_reservation_status(self.cursor, reservation_id, status)
        reservation = get_reservation(self.cursor, reservation_id)

        redis_queue = RedisQueue("notifications")
        redis_queue.put(str(reservation.to_json()))

        return get_response(reservation)
Esempio n. 4
0
    def post(self):
        body = request.json
        missed_param = check_for_params([Keys.EMAIL, Keys.PASSWORD], body)

        if missed_param is not None:
            raise ApiException(pointer=missed_param,
                               reason=Reasons.MISSED,
                               code=400)

        email = body[Keys.EMAIL]
        password = body[Keys.PASSWORD]

        user = get_user(self.cursor, email, password)

        if user is None:
            raise ApiException(pointer=Keys.DATA,
                               reason=Reasons.WRONG,
                               code=400)

        token = create_access_token(user)
        data = Auth(token, user)

        return get_response(data)
Esempio n. 5
0
    def put(self):
        body = request.json
        missed_param = check_for_params([Keys.NAME, Keys.EMAIL, Keys.PASSWORD],
                                        body)

        if missed_param is not None:
            raise ApiException(pointer=missed_param,
                               reason=Reasons.MISSED,
                               code=400)

        email = body[Keys.EMAIL]

        if if_user_exists(self.cursor, email):
            raise ApiException(pointer=Keys.EMAIL,
                               reason=Reasons.TAKEN,
                               code=409)

        name = body[Keys.NAME]
        password = body[Keys.PASSWORD]

        put_user(self.cursor, name, email, password)
        user = UserModel(None, name, email)

        return get_response(user)
Esempio n. 6
0
 def get(self):
     reservations = get_requested_reservations(self.cursor)
     return get_response(reservations)
Esempio n. 7
0
def handle_error(e: HTTPException):
    error = Error(pointer=Keys.API, reason=e.description)
    return get_response(error, True, e.code)