拆分大文件
This commit is contained in:
@@ -6,11 +6,8 @@ use axum::{
|
||||
use shared_contracts::auth::PublicUserSearchResponse;
|
||||
|
||||
use crate::{
|
||||
api_response::json_success_body,
|
||||
auth_payload::map_public_user_summary_payload,
|
||||
http_error::AppError,
|
||||
request_context::RequestContext,
|
||||
state::AppState,
|
||||
api_response::json_success_body, auth_payload::map_public_user_summary_payload,
|
||||
http_error::AppError, request_context::RequestContext, state::AppState,
|
||||
};
|
||||
|
||||
pub async fn get_public_user_by_code(
|
||||
@@ -34,6 +31,32 @@ pub async fn get_public_user_by_code(
|
||||
))
|
||||
}
|
||||
|
||||
pub async fn get_public_user_by_id(
|
||||
State(state): State<AppState>,
|
||||
Extension(request_context): Extension<RequestContext>,
|
||||
Path(user_id): Path<String>,
|
||||
) -> Result<Json<serde_json::Value>, AppError> {
|
||||
let user_id = user_id.trim();
|
||||
if user_id.is_empty() {
|
||||
return Err(AppError::from_status(StatusCode::BAD_REQUEST).with_message("用户 ID 不能为空"));
|
||||
}
|
||||
|
||||
let user = state
|
||||
.auth_user_service()
|
||||
.get_user_by_id(user_id)
|
||||
.map_err(map_public_user_id_search_error)?
|
||||
.ok_or_else(|| {
|
||||
AppError::from_status(StatusCode::NOT_FOUND).with_message("未找到对应用户")
|
||||
})?;
|
||||
|
||||
Ok(json_success_body(
|
||||
Some(&request_context),
|
||||
PublicUserSearchResponse {
|
||||
user: map_public_user_summary_payload(user),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
fn map_public_user_search_error(error: module_auth::PasswordEntryError) -> AppError {
|
||||
match error {
|
||||
module_auth::PasswordEntryError::InvalidPublicUserCode => {
|
||||
@@ -48,3 +71,14 @@ fn map_public_user_search_error(error: module_auth::PasswordEntryError) -> AppEr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn map_public_user_id_search_error(error: module_auth::LogoutError) -> AppError {
|
||||
match error {
|
||||
module_auth::LogoutError::UserNotFound => {
|
||||
AppError::from_status(StatusCode::NOT_FOUND).with_message("未找到对应用户")
|
||||
}
|
||||
module_auth::LogoutError::Store(_) => {
|
||||
AppError::from_status(StatusCode::INTERNAL_SERVER_ERROR).with_message(error.to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user