summaryrefslogtreecommitdiffstats
path: root/src/model.rs
diff options
context:
space:
mode:
authorToby Vincent <tobyv@tobyvin.dev>2024-03-21 21:39:15 -0500
committerToby Vincent <tobyv@tobyvin.dev>2024-03-21 21:39:15 -0500
commitfd1447999d9665866d65002b2c2317b8b150225f (patch)
treedce0c5282a60fc27f65a066200fcd8aa86b4370e /src/model.rs
parentf977dce01be9de61a64b94aab883fb43949234b3 (diff)
feat: impl user api endpoint
Diffstat (limited to 'src/model.rs')
-rw-r--r--src/model.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/model.rs b/src/model.rs
new file mode 100644
index 0000000..9c1bfe6
--- /dev/null
+++ b/src/model.rs
@@ -0,0 +1,46 @@
+use chrono::prelude::*;
+use serde::{Deserialize, Serialize};
+
+#[allow(non_snake_case)]
+#[derive(Debug, Deserialize, sqlx::FromRow, Serialize, Clone)]
+pub struct User {
+ pub id: uuid::Uuid,
+ pub name: String,
+ pub email: String,
+ pub password: String,
+ #[serde(rename = "createdAt")]
+ pub created_at: Option<DateTime<Utc>>,
+ #[serde(rename = "updatedAt")]
+ pub updated_at: Option<DateTime<Utc>>,
+}
+
+impl User {
+ pub fn into_query_response(self) -> axum::Json<serde_json::Value> {
+ axum::Json(serde_json::json!({
+ "status": "success",
+ "data": serde_json::json!({
+ "user": self
+ })
+ }))
+ }
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct TokenClaims {
+ pub sub: String,
+ pub iat: usize,
+ pub exp: usize,
+}
+
+#[derive(Debug, Deserialize)]
+pub struct RegisterUserSchema {
+ pub name: String,
+ pub email: String,
+ pub password: String,
+}
+
+#[derive(Debug, Deserialize)]
+pub struct LoginUserSchema {
+ pub email: String,
+ pub password: String,
+}