From abb1fd25da2cfd14cdd28e0e0f66834d5bf77813 Mon Sep 17 00:00:00 2001 From: Manollo-36 Date: Fri, 8 Nov 2024 10:11:14 +0200 Subject: [PATCH] Added Implimentation for rating field --- backend/flaskr/__init__.py | 5 +++-- backend/models.py | 7 +++++-- frontend/src/components/FormView.js | 12 ++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/backend/flaskr/__init__.py b/backend/flaskr/__init__.py index abac00ddc..346870f95 100644 --- a/backend/flaskr/__init__.py +++ b/backend/flaskr/__init__.py @@ -135,7 +135,8 @@ def create_question(): new_answer = body.get("answer", None) new_category = body.get("category", None) new_difficulty= body.get("difficulty",None) - + new_rating= body.get("rating",None) + search= body.get("searchTerm",None) #print(f'search:{search}') @@ -154,7 +155,7 @@ def create_question(): } return jsonify(response) else: - add_question = Question(question=new_question, answer=new_answer, category=new_category,difficulty=new_difficulty) + add_question = Question(question=new_question, answer=new_answer, category=new_category,difficulty=new_difficulty,rating=new_rating) print(f'question:{add_question}') add_question.insert() diff --git a/backend/models.py b/backend/models.py index 9adcfe9c2..89eb4ad03 100644 --- a/backend/models.py +++ b/backend/models.py @@ -28,12 +28,14 @@ class Question(db.Model): answer = Column(String, nullable=False) category = Column(String, nullable=False) difficulty = Column(Integer, nullable=False) + rating = Column(Integer, nullable=False) - def __init__(self, question, answer, category, difficulty): + def __init__(self, question, answer, category, difficulty,rating): self.question = question self.answer = answer self.category = category self.difficulty = difficulty + self.rating =rating def insert(self): db.session.add(self) @@ -52,7 +54,8 @@ def format(self): 'question': self.question, 'answer': self.answer, 'category': self.category, - 'difficulty': self.difficulty + 'difficulty': self.difficulty, + 'rating': self.rating } """ diff --git a/frontend/src/components/FormView.js b/frontend/src/components/FormView.js index fce7b4e4a..a2020b395 100755 --- a/frontend/src/components/FormView.js +++ b/frontend/src/components/FormView.js @@ -10,6 +10,7 @@ class FormView extends Component { answer: '', difficulty: 1, category: 1, + rating:1, categories: {}, }; } @@ -41,6 +42,7 @@ class FormView extends Component { answer: this.state.answer, difficulty: this.state.difficulty, category: this.state.category, + rating: this.state.rating, }), xhrFields: { withCredentials: true, @@ -100,6 +102,16 @@ class FormView extends Component { })} +