-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ログイン状態でAPIにアクセスした場合に、UUIDと名前をDBに保存するように
- Loading branch information
Showing
13 changed files
with
123 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
pub mod form_repository; | ||
pub mod user_repository; | ||
|
||
pub trait Repositories: Send + Sync { | ||
type ConcreteFormRepository: form_repository::FormRepository; | ||
type ConcreteUserRepository: user_repository::UserRepository; | ||
|
||
fn form_repository(&self) -> &Self::ConcreteFormRepository; | ||
fn user_repository(&self) -> &Self::ConcreteUserRepository; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
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>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ pub mod components; | |
pub mod config; | ||
pub mod connection; | ||
pub mod form; | ||
pub mod user; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
server/infra/resource/src/repository/user_repository_impl.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod form; | ||
pub mod user; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
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 | ||
} | ||
} |