Create user repository
This commit is contained in:
7
rotom_core/Cargo.toml
Normal file
7
rotom_core/Cargo.toml
Normal 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
1
rotom_core/src/lib.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod repository;
|
||||
21
rotom_core/src/repository/mod.rs
Normal file
21
rotom_core/src/repository/mod.rs
Normal 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;
|
||||
}
|
||||
27
rotom_core/src/repository/user_repository.rs
Normal file
27
rotom_core/src/repository/user_repository.rs
Normal 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>,
|
||||
}
|
||||
Reference in New Issue
Block a user