full backend rewrite.
calling this v0.4.0
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
use rocket::serde::{Deserialize, Serialize};
|
||||
use chrono::{DateTime, Utc};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct SignupCredentials {
|
||||
pub email: String,
|
||||
pub username: String,
|
||||
pub password: String,
|
||||
pub access_token: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct LoginCredentials {
|
||||
pub username: String,
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct AuthResponse {
|
||||
pub token: String,
|
||||
pub totp_required: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AccessTokenForm {
|
||||
pub name: String,
|
||||
pub max_uses: i32,
|
||||
pub expiry_date: DateTime<Utc>,
|
||||
pub start_date: DateTime<Utc>,
|
||||
}
|
||||
|
||||
pub struct AccessToken {
|
||||
pub id: i64,
|
||||
pub code: String,
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod auth;
|
||||
pub mod user;
|
||||
pub mod space;
|
||||
@@ -0,0 +1,35 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::FromRow;
|
||||
use chrono::{DateTime, Utc};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
|
||||
pub struct Space {
|
||||
pub id: i64,
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
pub owner_id: i64,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
|
||||
pub struct Channel {
|
||||
pub id: i64,
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
pub space_id: i64,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SpaceDto {
|
||||
pub channels: Vec<Channel>,
|
||||
pub id: i64,
|
||||
pub owner_id: i64,
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
use crate::api::auth::Session;
|
||||
use crate::error::ApiResult;
|
||||
use crate::svc::user_svc::UserService;
|
||||
use chrono::{DateTime, Utc};
|
||||
use rocket::State;
|
||||
use sqlx::FromRow;
|
||||
use crate::api::totp::TotpStatus;
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(FromRow)]
|
||||
pub struct User {
|
||||
pub id: i64,
|
||||
pub email: Option<String>,
|
||||
pub username: String,
|
||||
pub nickname: Option<String>,
|
||||
pub passhash: String,
|
||||
pub totp_status: TotpStatus,
|
||||
pub totp_secret: Option<String>,
|
||||
pub created_at: Option<DateTime<Utc>>,
|
||||
pub updated_at: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
// pub struct UserCache {}
|
||||
//
|
||||
// impl UserCache {
|
||||
// pub async fn username(
|
||||
// id: usize,
|
||||
// redis_conn: &mut Connection<Redis>,
|
||||
// pgsql_conn: &mut Connection<Postgres>,
|
||||
// ) -> String {
|
||||
// if let Ok(val) = redis_conn.get(format!("users:{id}")).await {
|
||||
// return val;
|
||||
// }
|
||||
//
|
||||
// if let Ok(v) = sqlx::query!("SELECT username FROM users WHERE id = $1", id as i32)
|
||||
// .fetch_one(&mut ***pgsql_conn)
|
||||
// .await
|
||||
// {
|
||||
// let username = v.username;
|
||||
// Self::insert(id, &username, redis_conn).await;
|
||||
// username
|
||||
// } else {
|
||||
// unimplemented!()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// pub async fn insert(id: usize, username: &str, conn: &mut Connection<Redis>) {
|
||||
// conn.set_ex::<_, _, ()>(format!("users:{id}"), username.to_string(), 1800)
|
||||
// .await
|
||||
// .expect("failed to insert key");
|
||||
// }
|
||||
// }
|
||||
Reference in New Issue
Block a user