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_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()
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_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()
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()