Skip to content

Commit abb1fd2

Browse files
committed
Added Implimentation for rating field
1 parent 4317f8d commit abb1fd2

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

backend/flaskr/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ def create_question():
135135
new_answer = body.get("answer", None)
136136
new_category = body.get("category", None)
137137
new_difficulty= body.get("difficulty",None)
138-
138+
new_rating= body.get("rating",None)
139+
139140
search= body.get("searchTerm",None)
140141
#print(f'search:{search}')
141142

@@ -154,7 +155,7 @@ def create_question():
154155
}
155156
return jsonify(response)
156157
else:
157-
add_question = Question(question=new_question, answer=new_answer, category=new_category,difficulty=new_difficulty)
158+
add_question = Question(question=new_question, answer=new_answer, category=new_category,difficulty=new_difficulty,rating=new_rating)
158159
print(f'question:{add_question}')
159160
add_question.insert()
160161

backend/models.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ class Question(db.Model):
2828
answer = Column(String, nullable=False)
2929
category = Column(String, nullable=False)
3030
difficulty = Column(Integer, nullable=False)
31+
rating = Column(Integer, nullable=False)
3132

32-
def __init__(self, question, answer, category, difficulty):
33+
def __init__(self, question, answer, category, difficulty,rating):
3334
self.question = question
3435
self.answer = answer
3536
self.category = category
3637
self.difficulty = difficulty
38+
self.rating =rating
3739

3840
def insert(self):
3941
db.session.add(self)
@@ -52,7 +54,8 @@ def format(self):
5254
'question': self.question,
5355
'answer': self.answer,
5456
'category': self.category,
55-
'difficulty': self.difficulty
57+
'difficulty': self.difficulty,
58+
'rating': self.rating
5659
}
5760

5861
"""

frontend/src/components/FormView.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class FormView extends Component {
1010
answer: '',
1111
difficulty: 1,
1212
category: 1,
13+
rating:1,
1314
categories: {},
1415
};
1516
}
@@ -41,6 +42,7 @@ class FormView extends Component {
4142
answer: this.state.answer,
4243
difficulty: this.state.difficulty,
4344
category: this.state.category,
45+
rating: this.state.rating,
4446
}),
4547
xhrFields: {
4648
withCredentials: true,
@@ -100,6 +102,16 @@ class FormView extends Component {
100102
})}
101103
</select>
102104
</label>
105+
<label>
106+
Rating
107+
<select name='rating' onChange={this.handleChange}>
108+
<option value='1'>1</option>
109+
<option value='2'>2</option>
110+
<option value='3'>3</option>
111+
<option value='4'>4</option>
112+
<option value='5'>5</option>
113+
</select>
114+
</label>
103115
<input type='submit' className='button' value='Submit' />
104116
</form>
105117
</div>

0 commit comments

Comments
 (0)