diff --git a/visions/server/src/routes.rs b/visions/server/src/routes.rs index f51d13b..37f4b08 100644 --- a/visions/server/src/routes.rs +++ b/visions/server/src/routes.rs @@ -7,7 +7,9 @@ use axum::{ routing::{get, post, put}, Json, Router, }; +use serde::{Deserialize, Serialize}; use tower_http::cors::{Any, CorsLayer}; +use typeshare::typeshare; use crate::{ core::Core, @@ -18,6 +20,50 @@ use crate::{ }, }; +#[derive(Clone, Debug, Deserialize, Serialize)] +#[serde(tag = "type", content = "content")] +#[typeshare] +pub enum AccountState { + Normal, + PasswordReset(String), + Locked, +} + +impl From for AccountState { + fn from(s: crate::types::AccountState) -> Self { + match s { + crate::types::AccountState::Normal => Self::Normal, + crate::types::AccountState::PasswordReset(r) => { + Self::PasswordReset(format!("{}", r.format("%Y-%m-%d %H:%M:%S"))) + } + crate::types::AccountState::Locked => Self::Locked, + } + } +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +#[typeshare] +pub struct User { + pub id: UserId, + pub name: String, + pub password: String, + pub admin: bool, + pub state: AccountState, +} + +impl From for User { + fn from(u: crate::types::User) -> Self { + Self { + id: u.id, + name: u.name, + password: u.password, + admin: u.admin, + state: AccountState::from(u.state), + } + } +} + pub fn routes(core: Core) -> Router { Router::new() .route( @@ -127,7 +173,7 @@ mod test { core::{AuthResponse, Core}, database::{Database, DbConn, GameId, SessionId, UserId}, handlers::CreateGameRequest, - types::{AccountState, UserOverview}, + types::UserOverview, }; async fn initialize_test_server() -> (Core, TestServer) { @@ -139,7 +185,7 @@ mod test { "admin", "aoeu", true, - AccountState::PasswordReset(password_exp), + crate::types::AccountState::PasswordReset(password_exp), ) .await .unwrap(); diff --git a/visions/server/src/types.rs b/visions/server/src/types.rs index cf7a342..c0a052d 100644 --- a/visions/server/src/types.rs +++ b/visions/server/src/types.rs @@ -75,9 +75,7 @@ pub struct Rgb { pub blue: u32, } -#[derive(Clone, Debug, Deserialize, Serialize)] -#[serde(tag = "type", content = "content")] -#[typeshare] +#[derive(Clone, Debug)] pub enum AccountState { Normal, PasswordReset(DateTime), @@ -119,9 +117,7 @@ impl ToSql for AccountState { } } -#[derive(Clone, Debug, Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] -#[typeshare] +#[derive(Clone, Debug)] pub struct User { pub id: UserId, pub name: String, diff --git a/visions/ui/package-lock.json b/visions/ui/package-lock.json index 807f246..7c4a385 100644 --- a/visions/ui/package-lock.json +++ b/visions/ui/package-lock.json @@ -33,7 +33,7 @@ "version": "0.0.1", "license": "ISC", "dependencies": { - "typescript": "^5.7.2" + "typescript": "^5.7.3" } }, "node_modules/@adobe/css-tools": {