Create client to establish connection with discord and add basic framework with sample command
This commit is contained in:
1
cipher_core/src/lib.rs
Normal file
1
cipher_core/src/lib.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod repository;
|
||||
35
cipher_core/src/repository/mod.rs
Normal file
35
cipher_core/src/repository/mod.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
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<'_>, RepositoryError<Self::BackendError>>;
|
||||
}
|
||||
|
||||
pub trait Repository
|
||||
where
|
||||
Self: UserRepository<BackendError = <Self as Repository>::BackendError>,
|
||||
{
|
||||
type BackendError: std::error::Error;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RepositoryError<E>(pub E);
|
||||
|
||||
impl<E> Display for RepositoryError<E>
|
||||
where
|
||||
E: Display,
|
||||
{
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
29
cipher_core/src/repository/user_repository.rs
Normal file
29
cipher_core/src/repository/user_repository.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use super::RepositoryError;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
pub trait UserRepository {
|
||||
type BackendError: std::error::Error;
|
||||
|
||||
async fn user(&mut self, id: i32) -> Result<Option<User>, RepositoryError<Self::BackendError>>;
|
||||
|
||||
async fn insert_user(&mut self, new_user: NewUser) -> Result<User, RepositoryError<Self::BackendError>>;
|
||||
|
||||
async fn update_user(&mut self, user: User) -> Result<Option<User>, RepositoryError<Self::BackendError>>;
|
||||
|
||||
async fn remove_user(&mut self, id: i32) -> Result<Option<User>, RepositoryError<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