Skip to content

Commit

Permalink
style: apply pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
rito528 committed Oct 13, 2023
1 parent ac157a1 commit 4c1dc48
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 68 deletions.
21 changes: 11 additions & 10 deletions server/domain/src/repository/user_repository.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::user::models::User;
use async_trait::async_trait;
use errors::Error;
use mockall::automock;

#[automock]
#[async_trait]
pub trait UserRepository: Send + Sync + 'static {
async fn upsert_user(&self, user: &User) -> Result<(), Error>;
}
use async_trait::async_trait;
use errors::Error;
use mockall::automock;

use crate::user::models::User;

#[automock]
#[async_trait]
pub trait UserRepository: Send + Sync + 'static {
async fn upsert_user(&self, user: &User) -> Result<(), Error>;
}
46 changes: 23 additions & 23 deletions server/infra/resource/src/database/user.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
use crate::database::components::UserDatabase;
use crate::database::connection::ConnectionPool;
use async_trait::async_trait;
use domain::user::models::User;
use errors::infra::InfraError;
use sea_orm::{ConnectionTrait, DatabaseBackend, Statement};

#[async_trait]
impl UserDatabase for ConnectionPool {
async fn upsert_user(&self, user: &User) -> Result<(), InfraError> {
self.pool
.execute(Statement::from_sql_and_values(
DatabaseBackend::MySql,
"INSERT INTO users (uuid, name) VALUES (UUID_TO_BIN(?), ?)
ON DUPLICATE KEY UPDATE
name = VALUES(name)",
[user.id.to_string().into(), user.name.to_owned().into()],
))
.await?;

Ok(())
}
}
use async_trait::async_trait;
use domain::user::models::User;
use errors::infra::InfraError;
use sea_orm::{ConnectionTrait, DatabaseBackend, Statement};

use crate::database::{components::UserDatabase, connection::ConnectionPool};

#[async_trait]
impl UserDatabase for ConnectionPool {
async fn upsert_user(&self, user: &User) -> Result<(), InfraError> {
self.pool
.execute(Statement::from_sql_and_values(
DatabaseBackend::MySql,
"INSERT INTO users (uuid, name) VALUES (UUID_TO_BIN(?), ?)
ON DUPLICATE KEY UPDATE
name = VALUES(name)",
[user.id.to_string().into(), user.name.to_owned().into()],
))
.await?;

Ok(())
}
}
36 changes: 19 additions & 17 deletions server/infra/resource/src/repository/user_repository_impl.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use crate::database::components::UserDatabase;
use crate::{database::components::DatabaseComponents, repository::Repository};
use async_trait::async_trait;
use domain::repository::user_repository::UserRepository;
use domain::user::models::User;
use errors::Error;

#[async_trait]
impl<Client: DatabaseComponents + 'static> UserRepository for Repository<Client> {
async fn upsert_user(&self, user: &User) -> Result<(), Error> {
self.client
.user()
.upsert_user(user)
.await
.map_err(Into::into)
}
}
use async_trait::async_trait;
use domain::{repository::user_repository::UserRepository, user::models::User};
use errors::Error;

use crate::{
database::components::{DatabaseComponents, UserDatabase},
repository::Repository,
};

#[async_trait]
impl<Client: DatabaseComponents + 'static> UserRepository for Repository<Client> {
async fn upsert_user(&self, user: &User) -> Result<(), Error> {
self.client
.user()
.upsert_user(user)
.await
.map_err(Into::into)
}
}
10 changes: 5 additions & 5 deletions server/presentation/src/auth.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use axum::extract::State;
use axum::{
extract::TypedHeader,
extract::{State, TypedHeader},
headers::authorization::{Authorization, Bearer},
http::{HeaderValue, Request, StatusCode},
middleware::Next,
response::Response,
};
use common::config::ENV;
use domain::repository::user_repository::UserRepository;
use domain::repository::Repositories;
use domain::user::models::User;
use domain::{
repository::{user_repository::UserRepository, Repositories},
user::models::User,
};
use reqwest::header::{ACCEPT, CONTENT_TYPE};
use resource::repository::RealInfrastructureRepository;
use usecase::user::UserUseCase;
Expand Down
25 changes: 12 additions & 13 deletions server/usecase/src/user.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use domain::repository::user_repository::UserRepository;
use domain::user::models::User;
use errors::Error;

pub struct UserUseCase<'a, UserRepo: UserRepository> {
pub repository: &'a UserRepo,
}

impl<R: UserRepository> UserUseCase<'_, R> {
pub async fn upsert_user(&self, user: &User) -> Result<(), Error> {
self.repository.upsert_user(user).await
}
}
use domain::{repository::user_repository::UserRepository, user::models::User};
use errors::Error;

pub struct UserUseCase<'a, UserRepo: UserRepository> {
pub repository: &'a UserRepo,
}

impl<R: UserRepository> UserUseCase<'_, R> {
pub async fn upsert_user(&self, user: &User) -> Result<(), Error> {
self.repository.upsert_user(user).await
}
}

0 comments on commit 4c1dc48

Please sign in to comment.