Skip to content

Commit

Permalink
Added Implimentation for rating field
Browse files Browse the repository at this point in the history
  • Loading branch information
Manollo-36 committed Nov 8, 2024
1 parent 4317f8d commit abb1fd2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
5 changes: 3 additions & 2 deletions backend/flaskr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')

Expand All @@ -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()

Expand Down
7 changes: 5 additions & 2 deletions backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

"""
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/components/FormView.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class FormView extends Component {
answer: '',
difficulty: 1,
category: 1,
rating:1,
categories: {},
};
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -100,6 +102,16 @@ class FormView extends Component {
})}
</select>
</label>
<label>
Rating
<select name='rating' onChange={this.handleChange}>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
</select>
</label>
<input type='submit' className='button' value='Submit' />
</form>
</div>
Expand Down

0 comments on commit abb1fd2

Please sign in to comment.