Adding base for adsb

This commit is contained in:
2025-04-21 19:15:11 -04:00
parent 06f9a96498
commit 95e4b8abf3
15 changed files with 1185 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use sqlx::{Postgres, QueryBuilder};
use uuid::Uuid;
use crate::{account::hash, error::ApiResult};
use crate::db;
@@ -8,7 +9,7 @@ pub const ADMIN_ROLE: &str = "ADMIN";
pub const USER_ROLE: &str = "USER";
const TABLE_NAME: &str = "users";
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize)]
pub struct RegisterRequest {
pub email: String,
pub password: String,
@@ -20,49 +21,59 @@ impl RegisterRequest {
pub fn to_user(self) -> ApiResult<User> {
let password_hash = hash(&self.password)?;
Ok(User {
id: Uuid::new_v4(),
email: self.email.to_lowercase(),
emailVerified: false,
password_hash,
role: USER_ROLE.to_string(),
first_name: self.first_name,
last_name: self.last_name,
avatar: None,
updated_at: Utc::now(),
created_at: Utc::now(),
})
}
}
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize)]
pub struct LoginRequest {
pub email: String,
pub password: String,
}
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize)]
pub struct UserResponse {
pub email: String,
pub id: Uuid,
pub email_verified: bool,
pub role: String,
pub first_name: String,
pub last_name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub avatar: Option<String>,
}
impl From<User> for UserResponse {
fn from(user: User) -> Self {
UserResponse {
email: user.email,
id: user.id,
email_verified: user.emailVerified,
role: user.role,
first_name: user.first_name,
last_name: user.last_name,
avatar: user.avatar,
}
}
}
#[derive(Debug, Serialize, Deserialize, sqlx::FromRow)]
#[derive(Debug, Deserialize, sqlx::FromRow)]
pub struct UpdateUser {
pub id: Uuid,
pub email: Option<String>,
pub password: Option<String>,
pub role: Option<String>,
pub first_name: Option<String>,
pub last_name: Option<String>,
pub avatar: Option<String>,
}
impl UpdateUser {
@@ -123,13 +134,16 @@ impl UpdateUser {
}
}
#[derive(Serialize, Deserialize, sqlx::FromRow, Debug)]
#[derive(Debug, Serialize, Deserialize, sqlx::FromRow)]
pub struct User {
pub id: Uuid,
pub email: String,
pub emailVerified: bool,
pub password_hash: String,
pub role: String,
pub first_name: String,
pub last_name: String,
pub avatar: Option<String>,
pub updated_at: DateTime<Utc>,
pub created_at: DateTime<Utc>,
}