Create user repository

This commit is contained in:
2025-01-29 05:11:43 +00:00
parent 93aba69035
commit 9166818299
17 changed files with 2757 additions and 19 deletions

7
rotom_core/Cargo.toml Normal file
View File

@@ -0,0 +1,7 @@
[package]
name = "rotom_core"
version = "0.1.0"
edition = "2021"
[dependencies]
async-trait = "0.1.85"

1
rotom_core/src/lib.rs Normal file
View File

@@ -0,0 +1 @@
pub mod repository;

View File

@@ -0,0 +1,21 @@
use user_repository::UserRepository;
pub mod user_repository;
#[async_trait::async_trait]
pub trait RepositoryProvider {
type BackendError: std::error::Error;
type Repository<'a>: Repository<BackendError = <Self as RepositoryProvider>::BackendError> + Send + Sync
where
Self: 'a;
async fn get(&self) -> Result<Self::Repository<'_>, Self::BackendError>;
}
pub trait Repository
where
Self: UserRepository<BackendError = <Self as Repository>::BackendError>,
{
type BackendError: std::error::Error;
}

View File

@@ -0,0 +1,27 @@
#[async_trait::async_trait]
pub trait UserRepository {
type BackendError: std::error::Error;
async fn user(&mut self, id: i32) -> Result<Option<User>, Self::BackendError>;
async fn insert_user(&mut self, new_user: NewUser) -> Result<User, Self::BackendError>;
async fn update_user(&mut self, user: User) -> Result<Option<User>, Self::BackendError>;
async fn remove_user(&mut self, id: i32) -> Result<Option<User>, Self::BackendError>;
}
pub struct User {
pub id: i32,
pub discord_user_id: u64,
pub pokemon_go_code: Option<String>,
pub pokemon_pocket_code: Option<String>,
pub switch_code: Option<String>,
}
pub struct NewUser {
pub discord_user_id: u64,
pub pokemon_go_code: Option<String>,
pub pokemon_pocket_code: Option<String>,
pub switch_code: Option<String>,
}