Пример #1
0
    def delete_comment(cls, db, room_id, comment_id):
        if not RoomDAO.room_is_present(db, room_id):
            raise NotFoundError("room")

        comment = db.query(RoomComment).get(comment_id)

        if comment is None:
            raise NotFoundError("room comment")

        if not comment.is_from(room_id):
            raise NoRelationError("room", "room comment")

        db.delete(comment)

        if not comment.is_answer():
            answers = db.query(RoomComment)\
                .filter(RoomComment.main_comment_id == comment_id)\
                .all()

            for answer in answers:
                db.delete(answer)

        db.commit()

        return comment.serialize()
    def get_room_review(cls, db, room_id, review_id):
        if not RoomDAO.room_is_present(db, room_id):
            raise NotFoundError("room")

        room_review = db.query(RoomReview).get(review_id)

        if room_review is None:
            raise NotFoundError("room review")

        if not room_review.is_from(room_id):
            raise NoRelationError("room", "room review")

        return room_review.serialize()
Пример #3
0
    def get_comment(cls, db, room_id, comment_id):
        if not RoomDAO.room_is_present(db, room_id):
            raise NotFoundError("room")

        comment = db.query(RoomComment).get(comment_id)

        if comment is None:
            raise NotFoundError("room comment")

        if not comment.is_from(room_id):
            raise NoRelationError("room", "room comment")

        return comment.serialize()
    def get_room_rating(cls, db, room_id, rating_id):
        if not RoomDAO.room_is_present(db, room_id):
            raise NotFoundError("room")

        room_rating = db.query(RoomRating).get(rating_id)

        if room_rating is None:
            raise NotFoundError("room rating")

        if not room_rating.is_from(room_id):
            raise NoRelationError("room", "room rating")

        return room_rating.serialize()
Пример #5
0
    def _remove_image(self, filename):
        bucket = storage.bucket(app=self.app)
        blob = bucket.get_blob(filename)
        if blob is None:
            raise NotFoundError("Photo")

        blob.delete()
Пример #6
0
    def get_room(cls, db, room_id):
        room = db.query(Room).get(room_id)

        if room is None:
            raise NotFoundError("room")

        return room.serialize()
Пример #7
0
    def get_user(cls, db, uuid):
        registerd_user = (db.query(RegisteredUser).filter(
            RegisteredUser.uuid == uuid).first())

        if registerd_user is None:
            raise NotFoundError("User")

        return registerd_user.serialize()
    def delete_room_booking(cls, db, room_id, booking_id):
        if not RoomDAO.room_is_present(db, room_id):
            raise NotFoundError("room")

        room_booking = db.query(RoomBooking)\
                         .get(booking_id)

        if room_booking is None:
            raise NotFoundError("room booking")

        if not room_booking.is_from(room_id):
            raise NoRelationError("room", "room booking")

        db.delete(room_booking)
        db.commit()

        return room_booking.serialize()
Пример #9
0
    def get_by_email(cls, db, email):
        registerd_user = (db.query(RegisteredUser).filter(
            RegisteredUser.email == email).first())

        if registerd_user is None:
            raise NotFoundError("User")

        return registerd_user.serialize()
Пример #10
0
    def get_room_photo(cls, db, room_id, firebase_id):
        room_photo = (db.query(RoomPhoto).filter(
            RoomPhoto.room_id == room_id).filter(
                RoomPhoto.firebase_id == firebase_id).first())

        if room_photo is None:
            raise NotFoundError("room_photo")

        return room_photo.serialize()
Пример #11
0
    def delete_by_uuid(cls, db, uuid):
        registerd_user = db.query(RegisteredUser).get(uuid)

        if registerd_user is None:
            raise NotFoundError("User")

        db.delete(registerd_user)
        db.commit()

        return registerd_user.serialize()
Пример #12
0
    def delete_room(cls, db, room_id):
        room = db.query(Room).get(room_id)

        # TODO -> borrar todos los comentarios y reviews/ratings

        if room is None:
            raise NotFoundError("room")

        db.delete(room)
        db.commit()

        return room.serialize()
    def get_all_ratings(cls, db, room_id):
        if not RoomDAO.room_is_present(db, room_id):
            raise NotFoundError("room")

        rating_list = db.query(RoomRating)\
                        .filter(room_id == RoomRating.room_id)\
                        .all()

        serialized_list = []
        for rating in rating_list:
            serialized_list.append(rating.serialize())

        return serialized_list
Пример #14
0
    def add_new_comment(cls, db, room_id, comment_args):
        if not RoomDAO.room_is_present(db, room_id):
            raise NotFoundError("room")

        if comment_args.main_comment_id is not None:
            if not cls.comment_is_present(db, comment_args.main_comment_id):
                raise NotFoundError("room comment")

            main_comment = db.query(RoomComment).get(
                comment_args.main_comment_id)
            if main_comment.is_answer():
                raise MainCommentIsAnswerError()

        new_comment = RoomComment(comment=comment_args.comment,
                                  room_id=room_id,
                                  commentator=comment_args.commentator,
                                  commentator_id=comment_args.commentator_id,
                                  main_comment_id=comment_args.main_comment_id)

        db.add(new_comment)
        db.commit()

        return new_comment.serialize()
    def add_new_room_rating(cls, db, room_id, room_rating_args):
        if not RoomDAO.room_is_present(db, room_id):
            raise NotFoundError("room")

        new_room_rating = RoomRating(
            rating=room_rating_args.rating,
            room_id=room_id,
            reviewer=room_rating_args.reviewer,
            reviewer_id=room_rating_args.reviewer_id,
        )

        db.add(new_room_rating)
        db.commit()

        return new_room_rating.serialize()
Пример #16
0
    def get_comment_with_answers(cls, db, room_id, comment_id):
        if not RoomDAO.room_is_present(db, room_id):
            raise NotFoundError("room")

        comment = db.query(RoomComment).get(comment_id)

        answers = db.query(RoomComment) \
            .filter(comment.id == RoomComment.main_comment_id) \
            .all()

        serialized_answers = []
        for answer in answers:
            serialized_answers.append(answer.serialize())

        return {"comment": comment.serialize(), "answers": serialized_answers}
    def add_new_room_review(cls, db, room_id, room_review_args):
        if not RoomDAO.room_is_present(db, room_id):
            raise NotFoundError("room")

        new_room_review = RoomReview(
            review=room_review_args.review,
            room_id=room_id,
            reviewer=room_review_args.reviewer,
            reviewer_id=room_review_args.reviewer_id,
        )

        db.add(new_room_review)
        db.commit()

        return new_room_review.serialize()
Пример #18
0
    def get_all_comments(cls, db, room_id):
        if not RoomDAO.room_is_present(db, room_id):
            raise NotFoundError("room")

        main_comments = db.query(RoomComment) \
            .filter(room_id == RoomComment.room_id and
                    RoomComment.main_comment_id is None) \
            .all()

        all_comments = []
        for comment in main_comments:
            comment_with_answers = cls.get_comment_with_answers(
                db, room_id, comment.id)
            all_comments.append(comment_with_answers)

        return all_comments
Пример #19
0
    def get_uuid_from_token(cls, token):
        # if not cls.url:
        #    cls._mock_get_info(int(token))
        #    return int(token)

        response, code = Requester.auth_srv_fetch(
            method="GET",
            path="/user/id",
            expected_statuses={HTTP_200_OK},
            payload={},
            extra_headers=cls.tkn_hdr(token),
        )
        logger.debug("Auth server get uuid response: %s, status_code: %s",
                     response, code)

        if code != 200:
            raise NotFoundError("User")

        logger.info("Obtained user uuid: %d", response["uuid"])
        return response["uuid"]
Пример #20
0
    def update_room(cls, db, room_id, update_args):
        room = db.query(Room).get(room_id)

        if room is None:
            raise NotFoundError("room")

        # we should see if is necessary to update
        # owner and owner id. May be this should
        # be a restricted method)

        if update_args.title is not None:
            room.title = update_args.title

        if update_args.description is not None:
            room.description = update_args.description

        if update_args.type is not None:
            room.type = update_args.type

        if update_args.price_per_day is not None:
            room.price_per_day = update_args.price_per_day

        if validate_location_args(update_args):
            room.coordinates = WKTElement(
                f'POINT({update_args.longitude} {update_args.latitude})',
                srid=4326)
            room.location = update_args.location

        if update_args.capacity is not None:
            room.capacity = update_args.capacity

        if update_args.blocked is not None:
            room.blocked = update_args.blocked

        db.commit()

        return room.serialize()
    def add_new_room_booking(cls, db, room_id, room_booking_args):
        if not RoomDAO.room_is_present(db, room_id):
            raise NotFoundError("room")

        booking_to = room_booking_args.date_to
        booking_from = room_booking_args.date_from

        bookings_on_same_date = cls.bookings_on_same_date(
            db, room_id, booking_from, booking_to)

        if bookings_on_same_date > 0:
            raise RoomAlreadyBookedError()

        new_room_booking = RoomBooking(
            id=room_booking_args.id,
            room_id=room_id,
            date_to=booking_to,
            date_from=booking_from,
        )

        db.add(new_room_booking)
        db.commit()

        return new_room_booking.serialize()