1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#[derive(Debug, Deserialize)]
pub struct TokenQuery {
pub token: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct UserRegisterInfo {
pub name: String,
pub age: i32,
pub phone: String,
pub verification_code: String,
}
pub async fn update(query: Query<TokenQuery>, info: web::Json<UserRegisterInfo>) -> impl Responder {
match get_user_by_token(&get_pool(), &query.token).await {
Ok(Some(mut user)) => {
match update_user(&get_pool(), &info, &user.userid).await {
Ok(()) => api_response::ok_handler(Some(user), Some("更新成功".to_string())).await,
Err(sqlx::Error::RowNotFound) => api_response::notfound_handler::<String>("未找到该用户,请检查更新的账号是否正确?").await,
Err(_) => api_response::error_handler::<String>("未知错误".to_string().as_str()).await,
}
},
Ok(None) => api_response::notfound_handler::<String>("未找到该用户,请检查更新的账号是否正确?").await,
Err(e) => api_response::error_handler::<String>(e.to_string().as_str()).await,
}
}
|