diff options
Diffstat (limited to 'src/api/users.rs')
-rw-r--r-- | src/api/users.rs | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/api/users.rs b/src/api/users.rs index d4e5d57..bfbc0d6 100644 --- a/src/api/users.rs +++ b/src/api/users.rs @@ -2,7 +2,8 @@ use std::str::FromStr; use axum::{ extract::{Path, State}, - response::IntoResponse, + http::header::LOCATION, + response::{IntoResponse, IntoResponseParts}, Json, }; use axum_extra::routing::Resource; @@ -32,6 +33,20 @@ pub struct User { pub updated_at: OffsetDateTime, } +impl IntoResponseParts for User { + type Error = Error; + + fn into_response_parts( + self, + mut res: axum::response::ResponseParts, + ) -> Result<axum::response::ResponseParts, Self::Error> { + res.headers_mut() + .append(LOCATION, format!("/users/{}", self.id).try_into()?); + + Ok(res) + } +} + #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Registration { pub name: String, @@ -59,16 +74,16 @@ pub async fn create( .await?; // TODO: Move this into a micro service, possibly behind a feature flag. - crate::auth::credentials::create( - State(pool.clone()), + let (status, (access, refresh)) = crate::auth::credentials::create( + State(pool), Json(Credential { id: user.id, password, }), ) - .await - .map(|(status, claims)| (status, claims, Json(user))) - .map_err(Into::into) + .await?; + + Ok((status, user, access, refresh)) } pub async fn show( |