Initial commit.

This commit is contained in:
Florian THIERRY
2026-07-13 21:57:58 +02:00
commit b5a95b0fa3
49 changed files with 11243 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
pub mod port;
+14
View File
@@ -0,0 +1,14 @@
use std::io::Error;
pub trait ConfigurationPort: Send + Sync {
fn get_initialisation_code(&self) -> Result<Option<String>, Error>;
fn save(&self, initialisation_code: String) -> Result<(), Error>;
fn erase_initialisation_code(&self) -> Result<(), Error>;
fn clone_box(&self) -> Box<dyn ConfigurationPort>;
}
impl Clone for Box<dyn ConfigurationPort> {
fn clone(&self) -> Self {
self.clone_box()
}
}
+2
View File
@@ -0,0 +1,2 @@
pub mod configuration;
pub mod user;
+2
View File
@@ -0,0 +1,2 @@
pub mod model;
pub mod port;
+47
View File
@@ -0,0 +1,47 @@
use chrono::{DateTime, Duration, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Clone)]
pub struct User {
pub id: Uuid,
pub username: String,
pub encrypted_password: String,
}
impl User {
pub fn new(id: Uuid, username: String, encrypted_password: String) -> Self {
Self { id, username, encrypted_password }
}
}
pub struct LoginResponse {
pub token_type: String,
pub access_token: String,
pub refresh_token: RefreshToken,
}
pub struct RefreshToken {
pub user_id: Uuid,
pub value: String,
pub expiration_date: DateTime<Utc>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Claims {
pub sub: String,
pub exp: usize,
}
impl Claims {
pub fn new(user_id: String) -> Self {
let expiration = Utc::now()
.checked_add_signed(Duration::minutes(10))
.expect("Invalid timestamp")
.timestamp();
Self {
sub: user_id,
exp: expiration as usize
}
}
}
+21
View File
@@ -0,0 +1,21 @@
use std::io::Error;
use uuid::Uuid;
use crate::user::model::User;
pub trait UserPort: Send + Sync {
fn get_by_id(&self, id: &Uuid) -> Result<Option<User>, Error>;
fn get_by_username(&self, username: &String) -> Result<Option<User>, Error>;
fn get_all(&self) -> Result<Vec<User>, Error>;
fn count(&self) -> Result<u8, Error>;
fn exists_by_name(&self, username: &String) -> Result<bool, Error>;
fn insert(&self, user: &User) -> Result<(), Error>;
fn update(&self, user: &User) -> Result<(), Error>;
fn delete_by_id(&self, id: &Uuid) -> Result<(), Error>;
fn clone_box(&self) -> Box<dyn UserPort>;
}
impl Clone for Box<dyn UserPort> {
fn clone(&self) -> Self {
self.clone_box()
}
}