Exemple #1
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
Exemple #2
0
    def post(self, product_id):
        data = Review.parser.parse_args()

        if not OrderModel.is_ordered_by(data["user_id"], product_id):
            return {"message": "You didn't rent this product yet"}, 400

        if ReviewModel.is_reviewed_by(data["user_id"], product_id):
            return {"message": "You have reviewed this product"}, 400

        ReviewModel.add_to_database(ReviewModel(**data))
        return {"message": "Product is successfully reviewed"}, 201
Exemple #3
0
def form():
    myform = FeatureForm()

    if myform.is_submitted():
        line = myform.review_text.data
        review_model = ReviewModel()
        sentiment, hightwords = review_model.predict(line, highlight=True)

        return render_template('result.html',
                               line=line,
                               highlight_words=hightwords,
                               sentiment=sentiment)

    return render_template('form.html', form=myform)
Exemple #4
0
 def delete(self, review_id):
     review = ReviewModel.find_by_review_id(review_id)
     if not review:
         return {
             'message':
             'review with id of {} is not existing'.format(review_id)
         }
     review.delete_from_db()
     return {'message': 'review with id of {} is deleted'.format(review_id)}
Exemple #5
0
 def get(self, company_id: str):
     company_id = company_id.split("-")[-1]  # endpoint input structure is companyid-<id>
     try:
         reviews = ReviewModel.find_by_company(company_id)
     except Exception as e:
         return {"msg": f"Failed with error: {e}"}, 500
     if reviews:
         return {"reviews": [review.json() for review in reviews]}, 200
     return {"msg": "No reviews found"}, 404
Exemple #6
0
 def get(self, user_id):
     user = AccountModel.find_by_id(user_id)
     if not user:
         return {
             'message': "User with ['id': {}] not found".format(user_id)
         }, 404
     return {
         'reviews':
         [i.json()['review'] for i in ReviewModel.find_by_user(user_id)]
     }, 200
Exemple #7
0
 def get(self, book_id):
     book = BookModel.find_by_id(book_id)
     if not book:
         return {
             'message': "Book with ['id': {}] not found".format(book_id)
         }, 404
     return {
         'reviews':
         [i.json()['review'] for i in ReviewModel.find_by_book(book_id)]
     }, 200
Exemple #8
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
Exemple #9
0
 def delete(self, idd):
     exists = ReviewModel.find_by_id(idd)
     if not exists:
         return {
             'message':
             "There is no review with ['id': {}], therefore it cannot be deleted"
             .format(idd)
         }, 404
     user = AccountModel.find_by_id(exists.user_id)
     book = BookModel.find_by_id(exists.book_id)
     exists.delete_from_db()
     return {
         'message':
         "Review with ['id': {}] has successfully been deleted".format(idd)
     }, 200
Exemple #10
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)
Exemple #11
0
 def test_put_review(self):
     response = self.app.post(
         'api/review',
         data={
             "user_id": 1,
             "book_id": 1,
             "title": "asd",
             "date": "25/11/2090 11:25",
             "valuation": 5,
             "comment": "lel"
         },
         headers={
             'Authorization':
             'Basic ' + base64.b64encode(
                 bytes(
                     str(self.acc.id) + ":" +
                     json.loads(self.resp_account_admin.data)['token'],
                     'ascii')).decode('ascii')
         },
         follow_redirects=True)
     response = self.app.put(
         'api/review/1',
         data={
             "user_id": 1,
             "book_id": 1,
             "title": "asd",
             "date": "25/11/2090 11:25",
             "valuation": 4,
             "comment": "lel"
         },
         headers={
             'Authorization':
             'Basic ' + base64.b64encode(
                 bytes(
                     str(self.acc.id) + ":" +
                     json.loads(self.resp_account_admin.data)['token'],
                     'ascii')).decode('ascii')
         },
         follow_redirects=True)
     rev = ReviewModel.find_by_id(1)
     self.assertEqual(200, response.status_code)
     self.assertEqual(4, rev.valuation)
Exemple #12
0
 def get(self, product_id):
     return {
         "reviews": review.json()
         for review in ReviewModel.search_from_database_by_product_id(
             product_id)
     }, 200
Exemple #13
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)
Exemple #14
0
 def get(self, review_id):
     review = ReviewModel.find_by_review_id(review_id)
     return review.json(review_id) if review else None
Exemple #15
0
 def get(self, idd):
     review = ReviewModel.find_by_id(idd)
     if review:
         return review.json(), 200
     return {'message': "Review with ['id': {}] not found".format(idd)}, 404
Exemple #16
0
from . import app
from .forms import FeatureForm

from flask import render_template

from models.review import ReviewModel, ReviewModel_LR, ReviewModel_NB

review_model = ReviewModel()
review_model_lr = ReviewModel_LR()
review_model_nb = ReviewModel_NB()


@app.route('/')
def index():
    return render_template('welcome.html')


@app.route('/form/', methods=('GET', 'POST'))
def form():
    myform = FeatureForm()

    if myform.is_submitted():
        line = myform.review_text.data
        # review_model = ReviewModel()
        sentiment, hightwords = review_model.predict(line, highlight=True)
        sentiment_lr, hightwords_lr = review_model_lr.predict(line,
                                                              highlight=True)
        sentiment_nb, hightwords_nb = review_model_nb.predict(line,
                                                              highlight=True)

        return render_template('result.html',
Exemple #17
0
        # products=[product_1],
        customer=daniel,
        current_order=False)

    order_2 = OrderModel(
        total_amount=200,
        order_status='In Progress',
        # products=[product_1],
        customer=daniel,
        current_order=True)

    order_1.save()

    review1 = ReviewModel(
        content='This product is crazyyyyy',
        customer=daniel,
        # product=product_1
    )
    review1.save()

    review2 = ReviewModel(
        content='This product is brazyyyyy',
        customer=mitty,
        # product=product_1
    )
    review2.save()

    review3 = ReviewModel(
        content='This product is crazyyyyy 2',
        customer=daniel,
        # product=product_1