添加用户记录功能,在问题检查中记录用户答案,优化答题反馈机制
This commit is contained in:
		
							parent
							
								
									c0f8e4c4e6
								
							
						
					
					
						commit
						fb4d7df519
					
				| @ -1,4 +1,5 @@ | |||||||
| #include "db/problems.h" | #include "db/problems.h" | ||||||
|  | #include "db/records.h" | ||||||
| #include "jwt/jwt.h" | #include "jwt/jwt.h" | ||||||
| #include "server/response.h" | #include "server/response.h" | ||||||
| #include "server/study.h" | #include "server/study.h" | ||||||
| @ -176,7 +177,7 @@ static void impl_modify(mg_connection* conn, problem_form_t* form) | |||||||
|     res_200(conn, "success to modify the problem"); |     res_200(conn, "success to modify the problem"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void impl_check(mg_connection* conn, problem_form_t* form) | static void impl_check(mg_connection* conn, problem_form_t* form, const char* user_id) | ||||||
| { | { | ||||||
|     if (!form->has_id) { |     if (!form->has_id) { | ||||||
|         res_need_xxx(conn, "problem id"); |         res_need_xxx(conn, "problem id"); | ||||||
| @ -198,9 +199,15 @@ static void impl_check(mg_connection* conn, problem_form_t* form) | |||||||
| 
 | 
 | ||||||
|     int flag = check_answer(form->id, form->answer, &result); |     int flag = check_answer(form->id, form->answer, &result); | ||||||
|     if (!flag) { |     if (!flag) { | ||||||
|  |         add_record_uke(user_id, form->id, form->answer); | ||||||
|         res_500(conn, "fail to check the answer"); |         res_500(conn, "fail to check the answer"); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |     if (result) { | ||||||
|  |         add_record_ac(user_id, form->id, form->answer); | ||||||
|  |     } else { | ||||||
|  |         add_record_wa(user_id, form->id, form->answer); | ||||||
|  |     } | ||||||
|     res_check_answer(conn, result); |     res_check_answer(conn, result); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -276,17 +283,14 @@ int problems_handler(mg_connection* conn, void* cbdata) | |||||||
|                     impl_modify(conn, &form); |                     impl_modify(conn, &form); | ||||||
|                 } |                 } | ||||||
|             } else if (!strcmp(form.action, "check")) { |             } else if (!strcmp(form.action, "check")) { | ||||||
|                 impl_check(conn, &form); |                 impl_check(conn, &form, user_id); | ||||||
|             } else if (!strcmp(form.action, "all")) { |             } else if (!strcmp(form.action, "all")) { | ||||||
|                 if (result == 2) { |  | ||||||
|                     res_permission_denied(conn); |  | ||||||
|                 } else { |  | ||||||
|                 impl_all(conn, &form); |                 impl_all(conn, &form); | ||||||
|                 } |  | ||||||
|             } else { |             } else { | ||||||
|                 res_bad_action(conn); |                 res_bad_action(conn); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |         free(user_id); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     problem_form_dtor(&form); |     problem_form_dtor(&form); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user