Get user profile #7
No files matched your search
@@ -43,7 +43,6 @@ pub mod request {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod response {
|
pub mod response {
|
||||||
@@ -414,7 +413,10 @@ pub mod endpoint {
|
|||||||
pub async fn get_user_profile(
|
pub async fn get_user_profile(
|
||||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||||
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
|
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
|
||||||
) -> (axum::http::StatusCode, axum::Json<super::response::get_user_profile::GetUserProfileResponse>) {
|
) -> (
|
||||||
|
axum::http::StatusCode,
|
||||||
|
axum::Json<super::response::get_user_profile::GetUserProfileResponse>,
|
||||||
|
) {
|
||||||
let mut response = super::response::get_user_profile::GetUserProfileResponse::default();
|
let mut response = super::response::get_user_profile::GetUserProfileResponse::default();
|
||||||
if id.is_nil() {
|
if id.is_nil() {
|
||||||
response.message = "Invalid request".to_string();
|
response.message = "Invalid request".to_string();
|
||||||
@@ -426,7 +428,7 @@ pub mod endpoint {
|
|||||||
firstname: user.firstname,
|
firstname: user.firstname,
|
||||||
lastname: user.lastname,
|
lastname: user.lastname,
|
||||||
username: user.username,
|
username: user.username,
|
||||||
email: user.email
|
email: user.email,
|
||||||
};
|
};
|
||||||
|
|
||||||
response.message = "SUCCESSFUL".to_string();
|
response.message = "SUCCESSFUL".to_string();
|
||||||
@@ -435,7 +437,10 @@ pub mod endpoint {
|
|||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
response.message = err.to_string();
|
response.message = err.to_string();
|
||||||
(axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response))
|
(
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -128,8 +128,10 @@ mod init {
|
|||||||
callers::endpoints::REFRESH_TOKEN,
|
callers::endpoints::REFRESH_TOKEN,
|
||||||
post(callers::login::endpoint::refresh_token),
|
post(callers::login::endpoint::refresh_token),
|
||||||
)
|
)
|
||||||
.route(callers::endpoints::GET_USER_PROFILE,
|
.route(
|
||||||
get(callers::login::endpoint::get_user_profile))
|
callers::endpoints::GET_USER_PROFILE,
|
||||||
|
get(callers::login::endpoint::get_user_profile),
|
||||||
|
)
|
||||||
.layer(cors::configure_cors().await)
|
.layer(cors::configure_cors().await)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+51
-32
@@ -31,7 +31,6 @@ pub mod user {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub async fn get_with_id(
|
pub async fn get_with_id(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
id: &uuid::Uuid,
|
id: &uuid::Uuid,
|
||||||
@@ -47,43 +46,63 @@ pub mod user {
|
|||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => match r {
|
Ok(r) => match r {
|
||||||
Some(roww) => {
|
Some(roww) => parse_row(&roww).await,
|
||||||
parse_row(&roww).await
|
None => Err(sqlx::Error::RowNotFound),
|
||||||
}
|
},
|
||||||
None => {
|
|
||||||
Err(sqlx::Error::RowNotFound)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn parse_row(row: &sqlx::postgres::PgRow) -> Result<simodels::user::User, sqlx::Error> {
|
async fn parse_row(row: &sqlx::postgres::PgRow) -> Result<simodels::user::User, sqlx::Error> {
|
||||||
Ok(simodels::user::User {
|
Ok(simodels::user::User {
|
||||||
id: row.try_get("id")
|
id: row
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound).unwrap(),
|
.try_get("id")
|
||||||
username: row.try_get("id")
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound).unwrap(),
|
.unwrap(),
|
||||||
password: row.try_get("id")
|
username: row
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound).unwrap(),
|
.try_get("id")
|
||||||
email: row.try_get("id")
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound).unwrap(),
|
.unwrap(),
|
||||||
phone: row.try_get("id")
|
password: row
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound).unwrap(),
|
.try_get("id")
|
||||||
firstname: row.try_get("id")
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound).unwrap(),
|
.unwrap(),
|
||||||
lastname: row.try_get("id")
|
email: row
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound).unwrap(),
|
.try_get("id")
|
||||||
email_verified: row.try_get("id")
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound).unwrap(),
|
.unwrap(),
|
||||||
date_created: row.try_get("id")
|
phone: row
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound).unwrap(),
|
.try_get("id")
|
||||||
status: row.try_get("id")
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound).unwrap(),
|
.unwrap(),
|
||||||
last_login: row.try_get("id")
|
firstname: row
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound).unwrap(),
|
.try_get("id")
|
||||||
salt_id: row.try_get("id")
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound).unwrap(),
|
.unwrap(),
|
||||||
|
lastname: row
|
||||||
|
.try_get("id")
|
||||||
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
|
.unwrap(),
|
||||||
|
email_verified: row
|
||||||
|
.try_get("id")
|
||||||
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
|
.unwrap(),
|
||||||
|
date_created: row
|
||||||
|
.try_get("id")
|
||||||
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
|
.unwrap(),
|
||||||
|
status: row
|
||||||
|
.try_get("id")
|
||||||
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
|
.unwrap(),
|
||||||
|
last_login: row
|
||||||
|
.try_get("id")
|
||||||
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
|
.unwrap(),
|
||||||
|
salt_id: row
|
||||||
|
.try_get("id")
|
||||||
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
|
.unwrap(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user