From a2860a1294b250402114fa016c4639881abc2172 Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Tue, 16 Apr 2024 20:28:46 -0500 Subject: refactor: improve account extractors --- src/api/users.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/api/users.rs') diff --git a/src/api/users.rs b/src/api/users.rs index c8a390d..6ac0bb8 100644 --- a/src/api/users.rs +++ b/src/api/users.rs @@ -11,7 +11,10 @@ use sqlx::FromRow; use time::OffsetDateTime; use uuid::Uuid; -use crate::{auth::AccessClaims, state::AppState}; +use crate::{ + auth::{credentials::Credential, AccessClaims}, + state::AppState, +}; use super::error::Error; @@ -30,7 +33,7 @@ pub struct User { } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct RegisterSchema { +pub struct Registration { pub name: String, pub email: String, pub password: String, @@ -38,11 +41,11 @@ pub struct RegisterSchema { pub async fn create( State(state): State, - Json(RegisterSchema { + Json(Registration { name, email, password, - }): Json, + }): Json, ) -> impl IntoResponse { email_address::EmailAddress::from_str(&email)?; @@ -58,11 +61,9 @@ pub async fn create( } // TODO: Move this into a micro service, possibly behind a feature flag. - let (status, (access, refresh)) = crate::auth::credentials::create( - State(state.clone()), - Json(crate::auth::credentials::Credential { password }), - ) - .await?; + let (status, (access, refresh)) = + crate::auth::credentials::create(State(state.clone()), Json(Credential { password })) + .await?; let user = sqlx::query_as!( User, -- cgit v1.2.3-70-g09d2