Ejemplo n.º 1
0
 def put(self, review_id):
     review = ReviewModel.find_by_review_id(review_id)
     data = Review.parser.parse_args()
     if not review:
         new_review = ReviewModel(None, **data)
         new_review.save_to_db()
         return new_review.json(review_id)
     else:
         new_review = ReviewModel(review_id, **data)
         new_review.update_in_db()
         return new_review.json(review_id)
Ejemplo n.º 2
0
 def put(self, idd):
     data = self.__parse_request__()
     review = ReviewModel.find_by_id(idd)
     if not review:
         return {
             'message': "There is no review with ['id': {}]".format(idd)
         }, 404
     review.delete_from_db()
     user = AccountModel.find_by_id(data.get('user_id'))
     book = BookModel.find_by_id(data.get('book_id'))
     if not user or not book:
         if not user:
             return {
                 'message':
                 "There is no account with ['id': {}]".format(
                     data.get('user_id'))
             }, 404
         if not book:
             return {
                 'message':
                 "There is no book with ['id': {}]".format(
                     data.get('book_id'))
             }, 404
     new_review = ReviewModel(data.get('title'), data.get('user_id'),
                              data.get('book_id'), data.get('date'),
                              data.get('valuation'), data.get('comment'))
     new_review.save_to_db()
     user.reviews.append(new_review)
     book.reviews.append(new_review)
     return new_review.json(), 200
Ejemplo n.º 3
0
 def post(self, company_id: str):
     company_id = company_id.split("-")[-1]
     payload = ReviewResource.parser.parse_args()
     review = ReviewModel(company_id=company_id, **payload)
     try:
         review.save_to_db()
         review.company.update_review_count()  # Update number of reviews
     except Exception as e:
         return {"msg": f"Failed with error: {e}"}, 500
     return review.json(), 201
Ejemplo n.º 4
0
 def post(self, review_id):
     review = ReviewModel.find_by_review_id(review_id)
     if review:
         return {
             'message':
             'review with id of {} is already existing'.format(review_id)
         }
     data = Review.parser.parse_args()
     new_review = ReviewModel(None, **data)
     new_review.save_to_db()
     return new_review.json(review_id)