Get user profile (#7)
soaricarus_auth Build / Check (push) Successful in 58s
soaricarus_auth Build / Rustfmt (push) Successful in 1m1s
Release Tagging / release (push) Successful in 1m2s
soaricarus_auth Build / Clippy (push) Successful in 1m7s
soaricarus_auth Build / build (push) Successful in 1m9s
soaricarus_auth Build / Test Suite (push) Successful in 1m20s
soaricarus_auth Build / Check (pull_request) Successful in 36s
soaricarus_auth Build / Test Suite (pull_request) Successful in 49s
soaricarus_auth Build / Rustfmt (pull_request) Successful in 41s
soaricarus_auth Build / Clippy (pull_request) Successful in 47s
soaricarus_auth Build / build (pull_request) Successful in 37s

Reviewed-on: http://git.kundeng.us/phoenix/soaricarus_auth/pulls/7
This commit was merged in pull request #7.
This commit is contained in:
phoenix committed 2026-10-08 17:17:36 -04:00
1 parent 5ff75f66b8
commit 0c0e1bdde3
10 files changed
+290 -257

No files matched your search

+57
View File
@@ -79,6 +79,16 @@ pub mod response {
pub data: Vec<uuid::Uuid>,
}
}
pub mod get_user_profile {
use serde::{Deserialize, Serialize};
#[derive(Default, Deserialize, Serialize, utoipa::ToSchema)]
pub struct GetUserProfileResponse {
pub message: String,
pub data: Vec<simodels::user::UserProfile>,
}
}
}
/// Module for login endpoints
@@ -388,4 +398,51 @@ pub mod endpoint {
}
}
}
/// Endpoint to get user profile
#[utoipa::path(
get,
path = super::super::endpoints::GET_USER_PROFILE,
params(("id" = uuid::Uuid, Path, description = "Get user profile")),
responses(
(status = 200, description = "User profile found", body = super::response::get_user_profile::GetUserProfileResponse),
(status = 404, description = "Song not found", body = super::response::get_user_profile::GetUserProfileResponse),
(status = 400, description = "Error downloading song", body = super::response::get_user_profile::GetUserProfileResponse),
)
)]
pub async fn get_user_profile(
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
) -> (
axum::http::StatusCode,
axum::Json<super::response::get_user_profile::GetUserProfileResponse>,
) {
let mut response = super::response::get_user_profile::GetUserProfileResponse::default();
if id.is_nil() {
response.message = "Invalid request".to_string();
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
} else {
match repo::user::get_with_id(&pool, &id).await {
Ok(user) => {
let user_profile = simodels::user::UserProfile {
firstname: user.firstname,
lastname: user.lastname,
username: user.username,
email: user.email,
};
response.message = "SUCCESSFUL".to_string();
response.data.push(user_profile);
(axum::http::StatusCode::OK, axum::Json(response))
}
Err(err) => {
response.message = err.to_string();
(
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response),
)
}
}
}
}
}