issues_bp route int issue_id vote methods POST login_required def voti

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
@issues_bp.route('/<int:issue_id>/vote/', methods=['POST'])
@login_required
def voting(issue_id):
issue = Issue()
vote = Vote(author=g.user, vote=True, target=issue)
vote.target_id = issue_id
db.session.add(vote)
db.session.commit()
return jsonify({}), 201
@issues_bp.route('/<int:issue_id>/unvote/', methods=['POST'])
@login_required
def unvoting(issue_id):
issue = Issue()
vote = Vote(author=g.user, vote=False, target=issue)
vote.target_id = issue_id
db.session.add(vote)
db.session.commit()
return jsonify({}), 201