def test_reset_all_checked_count(client): assert checklist_1.checked_count != 0 assert checklist_1.last_review_id != 0 with get_session() as s: Checklist.reset_all_checked_count(s, checklist_1.scene_id) with get_session() as s: checklist_1_after = Checklist.get_by_id(s, checklist_1.id) assert checklist_1_after.checked_count == 0 assert checklist_1_after.last_review_id == 0
def add_review(): json_dict = g.json_dict s = g.mysql_session user = g.user checklist = Checklist.get_by_id(s, json_dict["checklist_id"]) is_new, review = ChecklistReview.add_or_update(s, user.id, checklist.id, json_dict.get("mood", "打卡")) s.commit() if is_new: # 下面的更新存在并发问题 checklist.checked_count += 1 checklist.last_review_id = review.id return succeed(data=dict( checklist=dict( id=checklist.id, checked_count=checklist.checked_count, ), is_new=(1 if is_new else 0), review_id=review.id, mood=review.detail, ))