refactor: single refusal shape with openapi contract test
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::extractors::{Params, PathId};
|
||||
use crate::{extractors::AuthenticatedUser, state::AppState};
|
||||
use api_types::mappers::goal_with_progress_to_dto;
|
||||
use api_types::{
|
||||
@@ -8,12 +9,7 @@ use application::users::{
|
||||
get_federated_profile, get_federated_profile_stats, get_local_profile,
|
||||
queries::GetUserProfileQuery,
|
||||
};
|
||||
use axum::{
|
||||
Json,
|
||||
extract::{Path, Query, State},
|
||||
http::StatusCode,
|
||||
response::IntoResponse,
|
||||
};
|
||||
use axum::{Json, extract::State, http::StatusCode, response::IntoResponse};
|
||||
use domain::errors::DomainError;
|
||||
use std::str::FromStr;
|
||||
use uuid::Uuid;
|
||||
@@ -26,19 +22,25 @@ use uuid::Uuid;
|
||||
),
|
||||
responses(
|
||||
(status = 200, body = UserProfileResponse),
|
||||
(status = 404, description = "User not found"),
|
||||
(status = 404, description = "User not found", body = api_types::ErrorResponse),
|
||||
)
|
||||
)]
|
||||
pub async fn get_user_profile(
|
||||
State(state): State<AppState>,
|
||||
AuthenticatedUser(viewer_id): AuthenticatedUser,
|
||||
Path(user_id): Path<Uuid>,
|
||||
Query(params): Query<UserProfileQueryParams>,
|
||||
PathId(user_id): PathId<Uuid>,
|
||||
Params(params): Params<UserProfileQueryParams>,
|
||||
) -> impl IntoResponse {
|
||||
let view_str = params.view.as_deref().unwrap_or("recent");
|
||||
let profile_view = match application::users::queries::ProfileView::from_str(view_str) {
|
||||
Ok(v) => v,
|
||||
Err(_) => return StatusCode::BAD_REQUEST.into_response(),
|
||||
Err(_) => {
|
||||
return crate::errors::refuse(
|
||||
StatusCode::BAD_REQUEST,
|
||||
crate::errors::INVALID_INPUT,
|
||||
"invalid profile view",
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
let profile = match get_local_profile::execute(
|
||||
@@ -73,9 +75,13 @@ pub async fn get_user_profile(
|
||||
)
|
||||
.await;
|
||||
}
|
||||
return StatusCode::NOT_FOUND.into_response();
|
||||
return crate::errors::refuse(
|
||||
StatusCode::NOT_FOUND,
|
||||
crate::errors::NOT_FOUND,
|
||||
"not found",
|
||||
);
|
||||
}
|
||||
Err(e) => return crate::errors::domain_error_response(e),
|
||||
Err(e) => return crate::errors::ApiError(e).into_response(),
|
||||
};
|
||||
|
||||
let view_data = if let Some(p) = profile.entries {
|
||||
@@ -174,7 +180,7 @@ async fn build_federated_profile_response(
|
||||
.await
|
||||
{
|
||||
Ok(p) => p,
|
||||
Err(e) => return crate::errors::domain_error_response(e),
|
||||
Err(e) => return crate::errors::ApiError(e).into_response(),
|
||||
};
|
||||
|
||||
let view_data = if let Some(p) = profile.entries {
|
||||
|
||||
Reference in New Issue
Block a user