From 453732d5f51df05aced186f04b10912bde49769c Mon Sep 17 00:00:00 2001 From: Arata Date: Mon, 15 Apr 2024 15:44:27 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E3=83=AD=E3=82=B0=E3=82=92?= =?UTF-8?q?=E5=87=BA=E5=8A=9B=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/firebase/firebase_user.rs | 24 ++++++++++--- .../sos24-infrastructure/src/mongodb/form.rs | 24 +++++++++++-- .../src/mongodb/form_answer.rs | 36 ++++++++++++++++--- crates/sos24-infrastructure/src/postgresql.rs | 18 ++++++++++ .../src/postgresql/file_data.rs | 23 +++++++++--- .../src/postgresql/invitation.rs | 30 ++++++++++++++-- .../src/postgresql/news.rs | 24 +++++++++++-- .../src/postgresql/project.rs | 36 ++++++++++++++++--- .../src/postgresql/user.rs | 23 ++++++++++-- .../src/s3/file_object.rs | 13 ++++++- 10 files changed, 225 insertions(+), 26 deletions(-) diff --git a/crates/sos24-infrastructure/src/firebase/firebase_user.rs b/crates/sos24-infrastructure/src/firebase/firebase_user.rs index 208a8c1c..f20bd550 100644 --- a/crates/sos24-infrastructure/src/firebase/firebase_user.rs +++ b/crates/sos24-infrastructure/src/firebase/firebase_user.rs @@ -27,6 +27,8 @@ impl FirebaseUserRepository for FirebaseUserRepositoryImpl { &self, new_firebase_user: NewFirebaseUser, ) -> Result { + tracing::info!("Firebaseのユーザーを作成します"); + let new_firebase_user = new_firebase_user.destruct(); let created_user = self .auth @@ -36,6 +38,7 @@ impl FirebaseUserRepository for FirebaseUserRepositoryImpl { )) .await; + tracing::info!("Firebaseのユーザー作成が完了しました"); match created_user { Ok(created_user) => Ok(FirebaseUserId::new(created_user.uid)), Err(err) => match err.current_context() { @@ -52,18 +55,31 @@ impl FirebaseUserRepository for FirebaseUserRepositoryImpl { id: FirebaseUserId, email: FirebaseUserEmail, ) -> Result<(), FirebaseUserRepositoryError> { - let update = UserUpdate::builder(id.value()).email(email.value()).build(); + tracing::info!("Firebaseのユーザーのメールアドレスを更新します: {id:?}"); + + let update = UserUpdate::builder(id.clone().value()) + .email(email.value()) + .build(); self.auth .update_user(update) .await .map(|_| ()) - .map_err(|err| anyhow::anyhow!("Failed to update firebase user: {err}").into()) + .map_err(|err| anyhow::anyhow!("Failed to update firebase user: {err}").into())?; + + tracing::info!("Firebaseのユーザーのメールアドレスの更新が完了しました: {id:?}"); + Ok(()) } async fn delete_by_id(&self, id: FirebaseUserId) -> Result<(), FirebaseUserRepositoryError> { + tracing::info!("Firebaseのユーザーを削除します: {id:?}"); + self.auth - .delete_user(id.value()) + .delete_user(id.clone().value()) .await - .map_err(|err| anyhow::anyhow!("Failed to delete firebase user: {err}").into()) + .map_err(|err| anyhow::anyhow!("Failed to delete firebase user: {err}").into())?; + + tracing::info!("Firebaseのユーザーの削除が完了しました: {id:?}"); + + Ok(()) } } diff --git a/crates/sos24-infrastructure/src/mongodb/form.rs b/crates/sos24-infrastructure/src/mongodb/form.rs index 771d807b..e8fe831a 100644 --- a/crates/sos24-infrastructure/src/mongodb/form.rs +++ b/crates/sos24-infrastructure/src/mongodb/form.rs @@ -247,6 +247,8 @@ impl MongoFormRepository { impl FormRepository for MongoFormRepository { async fn list(&self) -> Result>, FormRepositoryError> { + tracing::info!("申請一覧を取得します"); + let form_list = self .collection .aggregate( @@ -262,31 +264,43 @@ impl FormRepository for MongoFormRepository { .map(|doc| WithDate::try_from(bson::from_document::(doc?)?)) .try_collect() .await?; + + tracing::info!("申請一覧を取得しました"); Ok(forms) } async fn create(&self, form: Form) -> Result<(), FormRepositoryError> { + tracing::info!("申請を作成します"); + let form_doc = FormDoc::from(form); self.collection .insert_one(form_doc, None) .await .context("Failed to create form")?; + + tracing::info!("申請を作成しました"); Ok(()) } async fn find_by_id(&self, id: FormId) -> Result>, FormRepositoryError> { + tracing::info!("申請を取得します: {id:?}"); + let form_doc = self .collection .find_one( - doc! { "_id": id.value(), "deleted_at": None:: }, + doc! { "_id": id.clone().value(), "deleted_at": None:: }, None, ) .await .context("Failed to find form")?; + + tracing::info!("申請を取得しました: {id:?}"); Ok(form_doc.map(WithDate::try_from).transpose()?) } async fn update(&self, form: Form) -> Result<(), FormRepositoryError> { + tracing::info!("申請を更新します"); + let form_doc = FormDoc::from(form); self.collection .update_one( @@ -307,18 +321,24 @@ impl FormRepository for MongoFormRepository { ) .await .context("Failed to update form")?; + + tracing::info!("申請を更新しました"); Ok(()) } async fn delete_by_id(&self, id: FormId) -> Result<(), FormRepositoryError> { + tracing::info!("申請を削除します: {id:?}"); + self.collection .update_one( - doc! { "_id": id.value(), "deleted_at": None:: }, + doc! { "_id": id.clone().value(), "deleted_at": None:: }, doc! { "$set": { "deleted_at": chrono::Utc::now() } }, None, ) .await .context("Failed to delete form")?; + + tracing::info!("申請を削除しました: {id:?}"); Ok(()) } } diff --git a/crates/sos24-infrastructure/src/mongodb/form_answer.rs b/crates/sos24-infrastructure/src/mongodb/form_answer.rs index 5d3e838f..5d543b39 100644 --- a/crates/sos24-infrastructure/src/mongodb/form_answer.rs +++ b/crates/sos24-infrastructure/src/mongodb/form_answer.rs @@ -174,6 +174,8 @@ impl MongoFormAnswerRepository { impl FormAnswerRepository for MongoFormAnswerRepository { async fn list(&self) -> Result>, FormAnswerRepositoryError> { + tracing::info!("申請回答一覧を取得します"); + let form_answer_list = self .collection .aggregate( @@ -189,15 +191,21 @@ impl FormAnswerRepository for MongoFormAnswerRepository { .map(|doc| WithDate::try_from(bson::from_document::(doc?)?)) .try_collect() .await?; + + tracing::info!("申請回答一覧を取得しました"); Ok(form_answers) } async fn create(&self, form_answer: FormAnswer) -> Result<(), FormAnswerRepositoryError> { + tracing::info!("申請回答を作成します"); + let form_answer_doc = FormAnswerDoc::from(form_answer); self.collection .insert_one(form_answer_doc, None) .await .context("Failed to insert form answer")?; + + tracing::info!("申請回答を作成しました"); Ok(()) } @@ -205,11 +213,15 @@ impl FormAnswerRepository for MongoFormAnswerRepository { &self, id: FormAnswerId, ) -> Result>, FormAnswerRepositoryError> { + tracing::info!("申請回答を取得します: {id:?}"); + let form_answer_doc = self .collection - .find_one(doc! { "_id": id.value() }, None) + .find_one(doc! { "_id": id.clone().value() }, None) .await .context("Failed to find form answer")?; + + tracing::info!("申請回答を取得しました: {id:?}"); Ok(form_answer_doc.map(WithDate::try_from).transpose()?) } @@ -217,10 +229,12 @@ impl FormAnswerRepository for MongoFormAnswerRepository { &self, project_id: ProjectId, ) -> Result>, FormAnswerRepositoryError> { + tracing::info!("企画の申請回答を取得します: {project_id:?}"); + let form_answer_list = self .collection .aggregate(vec![ - doc! { "$match": { "project_id": project_id.value(), "deleted_at": None:: } }, + doc! { "$match": { "project_id": project_id.clone().value(), "deleted_at": None:: } }, doc! { "$sort": { "created_at": 1 } }, ], None) .await @@ -229,6 +243,8 @@ impl FormAnswerRepository for MongoFormAnswerRepository { .map(|doc| WithDate::try_from(bson::from_document::(doc?)?)) .try_collect() .await?; + + tracing::info!("企画の申請回答を取得しました: {project_id:?}"); Ok(form_answers) } @@ -236,11 +252,13 @@ impl FormAnswerRepository for MongoFormAnswerRepository { &self, form_id: FormId, ) -> Result>, FormAnswerRepositoryError> { + tracing::info!("申請の回答を取得します: {form_id:?}"); + let form_answer_list = self .collection .aggregate( vec![ - doc! { "$match": { "form_id": form_id.value(), "deleted_at": None:: } }, + doc! { "$match": { "form_id": form_id.clone().value(), "deleted_at": None:: } }, doc! { "$sort": { "created_at": 1 } }, ], None, @@ -251,6 +269,8 @@ impl FormAnswerRepository for MongoFormAnswerRepository { .map(|doc| WithDate::try_from(bson::from_document::(doc?)?)) .try_collect() .await?; + + tracing::info!("申請の回答を取得しました: {form_id:?}"); Ok(form_answers) } @@ -259,18 +279,24 @@ impl FormAnswerRepository for MongoFormAnswerRepository { project_id: ProjectId, form_id: FormId, ) -> Result>, FormAnswerRepositoryError> { + tracing::info!("企画の申請の回答を取得します: {project_id:?}, {form_id:?}"); + let form_answer_doc = self .collection .find_one( - doc! { "project_id": project_id.value(), "form_id": form_id.value() }, + doc! { "project_id": project_id.clone().value(), "form_id": form_id.clone().value() }, None, ) .await .context("Failed to find form answer")?; + + tracing::info!("企画の申請の回答を取得しました: {project_id:?}, {form_id:?}"); Ok(form_answer_doc.map(WithDate::try_from).transpose()?) } async fn update(&self, form_answer: FormAnswer) -> Result<(), FormAnswerRepositoryError> { + tracing::info!("申請回答を更新します"); + let form_answer_doc = FormAnswerDoc::from(form_answer); self.collection .update_one( @@ -287,6 +313,8 @@ impl FormAnswerRepository for MongoFormAnswerRepository { ) .await .context("Failed to update form")?; + + tracing::info!("申請回答を更新しました"); Ok(()) } } diff --git a/crates/sos24-infrastructure/src/postgresql.rs b/crates/sos24-infrastructure/src/postgresql.rs index fbcdd719..e059b259 100644 --- a/crates/sos24-infrastructure/src/postgresql.rs +++ b/crates/sos24-infrastructure/src/postgresql.rs @@ -18,6 +18,24 @@ impl Postgresql { let pool = PgPoolOptions::new() .max_connections(8) + .after_connect(|_, _| { + Box::pin(async move { + tracing::info!("after connect"); + Ok(()) + }) + }) + .before_acquire(|_, _| { + Box::pin(async move { + tracing::info!("before acquire"); + Ok(true) + }) + }) + .after_release(|_, _| { + Box::pin(async move { + tracing::info!("after release"); + Ok(true) + }) + }) .connect(db_url) .await?; diff --git a/crates/sos24-infrastructure/src/postgresql/file_data.rs b/crates/sos24-infrastructure/src/postgresql/file_data.rs index 1dcb3884..180fb199 100644 --- a/crates/sos24-infrastructure/src/postgresql/file_data.rs +++ b/crates/sos24-infrastructure/src/postgresql/file_data.rs @@ -55,6 +55,8 @@ impl PgFileDataRepository { impl FileDataRepository for PgFileDataRepository { async fn list(&self) -> Result>, FileDataRepositoryError> { + tracing::info!("ファイルデータ一覧を取得しています"); + let file_data_list = sqlx::query_as!( FileDataRow, r#"SELECT * FROM files WHERE deleted_at IS NULL"# @@ -65,12 +67,14 @@ impl FileDataRepository for PgFileDataRepository { .await .context("Failed to fetch file data list")?; + tracing::info!("ファイルデータ一覧の取得が完了しました"); Ok(file_data_list) } async fn create(&self, file_data: FileData) -> Result<(), FileDataRepositoryError> { - let file_data = file_data.destruct(); + tracing::info!("ファイルデータを作成しています"); + let file_data = file_data.destruct(); sqlx::query!( r#"INSERT INTO files (id, name, url, owner_project) VALUES ($1, $2, $3, $4)"#, file_data.id.value(), @@ -82,6 +86,7 @@ impl FileDataRepository for PgFileDataRepository { .await .context("Failed to create file data")?; + tracing::info!("ファイルデータの作成が完了しました"); Ok(()) } @@ -89,15 +94,18 @@ impl FileDataRepository for PgFileDataRepository { &self, id: FileId, ) -> Result>, FileDataRepositoryError> { + tracing::info!("ファイルデータを取得しています: {id:?}"); + let file_data_row = sqlx::query_as!( FileDataRow, r#"SELECT * FROM files WHERE id = $1 AND deleted_at IS NULL"#, - id.value() + id.clone().value() ) .fetch_optional(&*self.db) .await .context("Failed to fetch file data")?; + tracing::info!("ファイルデータの取得が完了しました: {id:?}"); Ok(file_data_row.map(WithDate::try_from).transpose()?) } @@ -105,10 +113,12 @@ impl FileDataRepository for PgFileDataRepository { &self, owner_project: ProjectId, ) -> Result>, FileDataRepositoryError> { + tracing::info!("プロジェクトに紐づくファイルデータを取得しています: {owner_project:?}"); + let file_data_list = sqlx::query_as!( FileDataRow, r#"SELECT * FROM files WHERE owner_project = $1 AND deleted_at IS NULL"#, - owner_project.value() + owner_project.clone().value() ) .fetch(&*self.db) .map(|row| WithDate::try_from(row?)) @@ -116,17 +126,22 @@ impl FileDataRepository for PgFileDataRepository { .await .context("Failed to fetch file data list by owner")?; + tracing::info!("プロジェクトに紐づくファイルデータの取得が完了しました: {owner_project:?}"); Ok(file_data_list) } async fn delete_by_id(&self, id: FileId) -> Result<(), FileDataRepositoryError> { + tracing::info!("ファイルデータを削除しています: {id:?}"); + sqlx::query!( r#"UPDATE files SET deleted_at = NOW() WHERE id = $1 AND deleted_at IS NULL"#, - id.value() + id.clone().value() ) .execute(&*self.db) .await .context("Failed to delete file data")?; + + tracing::info!("ファイルデータの削除が完了しました: {id:?}"); Ok(()) } } diff --git a/crates/sos24-infrastructure/src/postgresql/invitation.rs b/crates/sos24-infrastructure/src/postgresql/invitation.rs index 55bb8070..17e9a35d 100644 --- a/crates/sos24-infrastructure/src/postgresql/invitation.rs +++ b/crates/sos24-infrastructure/src/postgresql/invitation.rs @@ -80,6 +80,8 @@ impl PgInvitationRepository { impl InvitationRepository for PgInvitationRepository { async fn list(&self) -> Result>, InvitationRepositoryError> { + tracing::info!("招待一覧を取得します"); + let invitations_list = sqlx::query_as!( InvitationRow, r#"SELECT id, inviter, project_id, position AS "position: InvitationPositionRow", used_by, created_at, updated_at, deleted_at FROM invitations WHERE deleted_at IS NULL"# @@ -89,10 +91,14 @@ impl InvitationRepository for PgInvitationRepository { .try_collect() .await .context("Failed to fetch invitations list")?; + + tracing::info!("招待一覧を取得しました"); Ok(invitations_list) } async fn create(&self, invitation: Invitation) -> Result<(), InvitationRepositoryError> { + tracing::info!("招待を作成します"); + let invitation = invitation.destruct(); sqlx::query!( r#"INSERT INTO invitations (id, inviter, project_id, position) VALUES ($1, $2, $3, $4)"#, @@ -104,6 +110,8 @@ impl InvitationRepository for PgInvitationRepository { .execute(&*self.db) .await .context("Failed to create invitation")?; + + tracing::info!("招待を作成しました"); Ok(()) } @@ -111,14 +119,18 @@ impl InvitationRepository for PgInvitationRepository { &self, id: InvitationId, ) -> Result>, InvitationRepositoryError> { + tracing::info!("招待を取得します: {id:?}"); + let invitation_row = sqlx::query_as!( InvitationRow, r#"SELECT id, inviter, project_id, position AS "position: InvitationPositionRow", used_by, created_at, updated_at, deleted_at FROM invitations WHERE id = $1 AND deleted_at IS NULL"#, - id.value() + id.clone().value() ) .fetch_optional(&*self.db) .await .context("Failed to fetch invitation")?; + + tracing::info!("招待を取得しました: {id:?}"); Ok(invitation_row.map(WithDate::from)) } @@ -126,20 +138,26 @@ impl InvitationRepository for PgInvitationRepository { &self, inviter: UserId, ) -> Result>, InvitationRepositoryError> { + tracing::info!("招待を取得します: {inviter:?}"); + let invitation_list = sqlx::query_as!( InvitationRow, r#"SELECT id, inviter, project_id, position AS "position: InvitationPositionRow", used_by, created_at, updated_at, deleted_at FROM invitations WHERE inviter = $1 AND deleted_at IS NULL"#, - inviter.value(), + inviter.clone().value(), ) .fetch(&*self.db) .map(|row| Ok::<_, anyhow::Error>(WithDate::from(row?))) .try_collect() .await .context("Failed to fetch invitation")?; + + tracing::info!("招待を取得しました: {inviter:?}"); Ok(invitation_list) } async fn update(&self, invitation: Invitation) -> Result<(), InvitationRepositoryError> { + tracing::info!("招待を更新します"); + let invitation = invitation.destruct(); sqlx::query!( r#"UPDATE invitations SET inviter = $2, project_id = $3, position = $4, used_by = $5 WHERE id = $1 AND deleted_at IS NULL"#, @@ -152,17 +170,23 @@ impl InvitationRepository for PgInvitationRepository { .execute(&*self.db) .await .context("Failed to update invitation")?; + + tracing::info!("招待を更新しました"); Ok(()) } async fn delete_by_id(&self, id: InvitationId) -> Result<(), InvitationRepositoryError> { + tracing::info!("招待を削除します: {id:?}"); + sqlx::query!( r#"UPDATE invitations SET deleted_at = now() WHERE id = $1 AND deleted_at IS NULL"#, - id.value() + id.clone().value() ) .execute(&*self.db) .await .context("Failed to delete invitation")?; + + tracing::info!("招待を削除しました: {id:?}"); Ok(()) } } diff --git a/crates/sos24-infrastructure/src/postgresql/news.rs b/crates/sos24-infrastructure/src/postgresql/news.rs index 7acc389d..20b3788b 100644 --- a/crates/sos24-infrastructure/src/postgresql/news.rs +++ b/crates/sos24-infrastructure/src/postgresql/news.rs @@ -56,6 +56,8 @@ impl PgNewsRepository { impl NewsRepository for PgNewsRepository { async fn list(&self) -> Result>, NewsRepositoryError> { + tracing::info!("お知らせ一覧を取得します"); + let news_list = sqlx::query_as!( NewsRow, r#"SELECT * FROM news WHERE deleted_at IS NULL ORDER BY created_at DESC"# @@ -65,10 +67,14 @@ impl NewsRepository for PgNewsRepository { .try_collect() .await .context("Failed to fetch news list")?; + + tracing::info!("お知らせ一覧を取得しました"); Ok(news_list) } async fn create(&self, news: News) -> Result<(), NewsRepositoryError> { + tracing::info!("お知らせを作成します"); + let news = news.destruct(); sqlx::query!( r#"INSERT INTO news (id, title, body, attachments, categories, attributes) VALUES ($1, $2, $3, $4, $5, $6)"#, @@ -82,22 +88,30 @@ impl NewsRepository for PgNewsRepository { .execute(&*self.db) .await .context("Failed to create news")?; + + tracing::info!("お知らせを作成しました"); Ok(()) } async fn find_by_id(&self, id: NewsId) -> Result>, NewsRepositoryError> { + tracing::info!("お知らせを取得します: {id:?}"); + let news_row = sqlx::query_as!( NewsRow, r#"SELECT * FROM news WHERE id = $1 AND deleted_at IS NULL"#, - id.value() + id.clone().value() ) .fetch_optional(&*self.db) .await .context("Failed to fetch news")?; + + tracing::info!("お知らせを取得しました: {id:?}"); Ok(news_row.map(WithDate::try_from).transpose()?) } async fn update(&self, news: News) -> Result<(), NewsRepositoryError> { + tracing::info!("お知らせを更新します"); + let news = news.destruct(); sqlx::query!( r#"UPDATE news SET title = $2, body = $3, attachments = $4, categories = $5, attributes = $6 WHERE id = $1 and deleted_at IS NULL"#, @@ -111,17 +125,23 @@ impl NewsRepository for PgNewsRepository { .execute(&*self.db) .await .context("Failed to update news")?; + + tracing::info!("お知らせを更新しました"); Ok(()) } async fn delete_by_id(&self, id: NewsId) -> Result<(), NewsRepositoryError> { + tracing::info!("お知らせを削除します: {id:?}"); + sqlx::query!( r#"UPDATE news SET deleted_at = NOW() WHERE id = $1 AND deleted_at IS NULL"#, - id.value() + id.clone().value() ) .execute(&*self.db) .await .context("Failed to delete news")?; + + tracing::info!("お知らせを削除しました: {id:?}"); Ok(()) } } diff --git a/crates/sos24-infrastructure/src/postgresql/project.rs b/crates/sos24-infrastructure/src/postgresql/project.rs index 93f20338..b5fd10a5 100644 --- a/crates/sos24-infrastructure/src/postgresql/project.rs +++ b/crates/sos24-infrastructure/src/postgresql/project.rs @@ -114,6 +114,8 @@ impl PgProjectRepository { impl ProjectRepository for PgProjectRepository { async fn list(&self) -> Result>, ProjectRepositoryError> { + tracing::info!("企画一覧を取得します"); + let project_list = sqlx::query_as!( ProjectRow, r#"SELECT id, index, title, kana_title, group_name, kana_group_name, category AS "category: ProjectCategoryRow", attributes, owner_id, sub_owner_id, remarks, created_at, updated_at, deleted_at @@ -125,10 +127,14 @@ impl ProjectRepository for PgProjectRepository { .try_collect() .await .context("Failed to fetch project list")?; + + tracing::info!("企画一覧を取得しました"); Ok(project_list) } async fn create(&self, project: Project) -> Result<(), ProjectRepositoryError> { + tracing::info!("企画を作成します"); + let project = project.destruct(); sqlx::query!( r#"INSERT INTO projects (id, title, kana_title, group_name, kana_group_name, category, attributes, owner_id, remarks) @@ -146,6 +152,8 @@ impl ProjectRepository for PgProjectRepository { .execute(&*self.db) .await .context("Failed to create project")?; + + tracing::info!("企画を作成しました"); Ok(()) } @@ -153,16 +161,20 @@ impl ProjectRepository for PgProjectRepository { &self, id: ProjectId, ) -> Result>, ProjectRepositoryError> { + tracing::info!("企画を取得します: {id:?}"); + let project_row = sqlx::query_as!( ProjectRow, r#"SELECT id, index, title, kana_title, group_name, kana_group_name, category AS "category: ProjectCategoryRow", attributes, owner_id, sub_owner_id, remarks, created_at, updated_at, deleted_at FROM projects WHERE id = $1 AND deleted_at IS NULL"#, - id.value() + id.clone().value() ) .fetch_optional(&*self.db) .await .context("Failed to fetch project")?; + + tracing::info!("企画を取得しました: {id:?}"); Ok(project_row.map(WithDate::try_from).transpose()?) } @@ -170,16 +182,20 @@ impl ProjectRepository for PgProjectRepository { &self, owner_id: UserId, ) -> Result>, ProjectRepositoryError> { + tracing::info!("企画責任者に紐づく企画を取得します: {owner_id:?}"); + let project_row = sqlx::query_as!( ProjectRow, r#"SELECT id, index, title, kana_title, group_name, kana_group_name, category AS "category: ProjectCategoryRow", attributes, owner_id, sub_owner_id, remarks, created_at, updated_at, deleted_at FROM projects WHERE owner_id = $1 AND deleted_at IS NULL"#, - owner_id.value() + owner_id.clone().value() ) .fetch_optional(&*self.db) .await .context("Failed to fetch project")?; + + tracing::info!("企画責任者に紐づく企画を取得しました: {owner_id:?}"); Ok(project_row.map(WithDate::try_from).transpose()?) } @@ -187,19 +203,25 @@ impl ProjectRepository for PgProjectRepository { &self, sub_owner_id: UserId, ) -> Result>, ProjectRepositoryError> { + tracing::info!("副企画責任者に紐づく企画を取得します: {sub_owner_id:?}"); + let project_row = sqlx::query_as!( ProjectRow, r#"SELECT id, index, title, kana_title, group_name, kana_group_name, category AS "category: ProjectCategoryRow", attributes, owner_id, sub_owner_id, remarks, created_at, updated_at, deleted_at FROM projects WHERE sub_owner_id = $1 AND deleted_at IS NULL"#, - sub_owner_id.value() + sub_owner_id.clone().value() ).fetch_optional(&*self.db) .await .context("Failed to fetch project")?; + + tracing::info!("副企画責任者に紐づく企画を取得しました: {sub_owner_id:?}"); Ok(project_row.map(WithDate::try_from).transpose()?) } async fn update(&self, project: Project) -> Result<(), ProjectRepositoryError> { + tracing::info!("企画を更新します"); + let project = project.destruct(); sqlx::query!( r#"UPDATE projects @@ -219,19 +241,25 @@ impl ProjectRepository for PgProjectRepository { .execute(&*self.db) .await .context("Failed to update project")?; + + tracing::info!("企画を更新しました"); Ok(()) } async fn delete_by_id(&self, id: ProjectId) -> Result<(), ProjectRepositoryError> { + tracing::info!("企画を削除します: {id:?}"); + sqlx::query!( r#"UPDATE projects SET deleted_at = NOW() WHERE id = $1 AND deleted_at IS NULL"#, - id.value() + id.clone().value() ) .execute(&*self.db) .await .context("Failed to delete project")?; + + tracing::info!("企画を削除しました: {id:?}"); Ok(()) } } diff --git a/crates/sos24-infrastructure/src/postgresql/user.rs b/crates/sos24-infrastructure/src/postgresql/user.rs index e9f427df..58bc332c 100644 --- a/crates/sos24-infrastructure/src/postgresql/user.rs +++ b/crates/sos24-infrastructure/src/postgresql/user.rs @@ -91,6 +91,8 @@ impl PgUserRepository { impl UserRepository for PgUserRepository { async fn list(&self) -> Result>, UserRepositoryError> { + tracing::info!("ユーザー一覧を取得します"); + let user_list = sqlx::query_as!(UserRow, r#" SELECT id, name, kana_name, email, phone_number, role AS "role: UserRoleRow", created_at, updated_at, deleted_at FROM users @@ -100,10 +102,14 @@ impl UserRepository for PgUserRepository { .map(|row| WithDate::try_from(row.context("Failed to fetch user list")?)) .try_collect() .await?; + + tracing::info!("ユーザー一覧を取得しました"); Ok(user_list) } async fn create(&self, user: User) -> Result<(), UserRepositoryError> { + tracing::info!("ユーザーを作成します"); + let user = user.destruct(); let res = sqlx::query!( r#" @@ -118,6 +124,7 @@ impl UserRepository for PgUserRepository { .execute(&*self.db) .await; + tracing::info!("ユーザーを作成しました"); match res { Ok(_) => Ok(()), Err(e) => match e.as_database_error() { @@ -133,20 +140,26 @@ impl UserRepository for PgUserRepository { } async fn find_by_id(&self, id: UserId) -> Result>, UserRepositoryError> { + tracing::info!("ユーザーを取得します: {id:?}"); + let user_row = sqlx::query_as!( UserRow, r#"SELECT id, name, kana_name, email, phone_number, role AS "role: UserRoleRow", created_at, updated_at, deleted_at FROM users WHERE id = $1 AND deleted_at IS NULL"#, - id.value(), + id.clone().value(), ) .fetch_optional(&*self.db) .await .context("Failed to fetch user by id")?; + + tracing::info!("ユーザーを取得しました: {id:?}"); Ok(user_row.map(WithDate::try_from).transpose()?) } async fn update(&self, user: User) -> Result<(), UserRepositoryError> { + tracing::info!("ユーザーを更新します"); + let user = user.destruct(); sqlx::query!( r#"UPDATE users @@ -162,19 +175,25 @@ impl UserRepository for PgUserRepository { .execute(&*self.db) .await .context("Failed to update user")?; + + tracing::info!("ユーザーを更新しました"); Ok(()) } async fn delete_by_id(&self, id: UserId) -> Result<(), UserRepositoryError> { + tracing::info!("ユーザーを削除します: {id:?}"); + sqlx::query!( r#"UPDATE users SET deleted_at = NOW() WHERE id = $1 AND deleted_at IS NULL"#, - id.value(), + id.clone().value(), ) .execute(&*self.db) .await .context("Failed to delete user")?; + + tracing::info!("ユーザーを削除しました: {id:?}"); Ok(()) } } diff --git a/crates/sos24-infrastructure/src/s3/file_object.rs b/crates/sos24-infrastructure/src/s3/file_object.rs index 6fc9565c..3fad546a 100644 --- a/crates/sos24-infrastructure/src/s3/file_object.rs +++ b/crates/sos24-infrastructure/src/s3/file_object.rs @@ -32,6 +32,8 @@ impl FileObjectRepository for S3FileObjectRepository { bucket: String, object: FileObject, ) -> Result<(), FileObjectRepositoryError> { + tracing::info!("ファイルをS3にアップロードします"); + let raw_file_object = object.destruct(); self.s3 .put_object() @@ -41,6 +43,8 @@ impl FileObjectRepository for S3FileObjectRepository { .send() .await .context("failed to create object")?; + + tracing::info!("ファイルのアップロードが完了しました"); Ok(()) } @@ -50,6 +54,8 @@ impl FileObjectRepository for S3FileObjectRepository { key: FileObjectKey, content_disposition: Option, ) -> Result { + tracing::info!("ファイルの署名付きURLを生成します: {key:?}"); + let presign_config = PresigningConfig::builder() .expires_in(Duration::new(3000, 0)) .build() @@ -58,11 +64,13 @@ impl FileObjectRepository for S3FileObjectRepository { .s3 .get_object() .bucket(bucket) - .key(key.value()) + .key(key.clone().value()) .set_response_content_disposition(content_disposition.map(|value| value.value())) .presigned(presign_config) .await .context("Failed to generate presign url")?; + + tracing::info!("ファイルの署名付きURLを生成しました: {key:?}"); Ok(FileSignedUrl::try_from(request.uri()).context("Failed to parse")?) } @@ -71,6 +79,8 @@ impl FileObjectRepository for S3FileObjectRepository { bucket: String, files: Vec>, ) -> Result { + tracing::info!("ファイルのアーカイブを作成します"); + let (writer, reader) = tokio::io::duplex(65535); let mut zip_writer = ZipFileWriter::with_tokio(writer); @@ -108,6 +118,7 @@ impl FileObjectRepository for S3FileObjectRepository { zip_writer.close().await.context("Failed to close")?; + tracing::info!("ファイルのアーカイブを作成しました"); Ok(reader) } } From 5857aa9cf06634dae052c05b27d3c4d0a8a8085b Mon Sep 17 00:00:00 2001 From: Arata Date: Mon, 15 Apr 2024 15:49:47 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E3=82=A8=E3=83=A9=E3=83=BC=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/firebase/firebase_user.rs | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/crates/sos24-infrastructure/src/firebase/firebase_user.rs b/crates/sos24-infrastructure/src/firebase/firebase_user.rs index f20bd550..9cce5dc8 100644 --- a/crates/sos24-infrastructure/src/firebase/firebase_user.rs +++ b/crates/sos24-infrastructure/src/firebase/firebase_user.rs @@ -60,26 +60,29 @@ impl FirebaseUserRepository for FirebaseUserRepositoryImpl { let update = UserUpdate::builder(id.clone().value()) .email(email.value()) .build(); - self.auth - .update_user(update) - .await - .map(|_| ()) - .map_err(|err| anyhow::anyhow!("Failed to update firebase user: {err}").into())?; - tracing::info!("Firebaseのユーザーのメールアドレスの更新が完了しました: {id:?}"); - Ok(()) + let res = self.auth.update_user(update).await; + + match res { + Ok(_) => { + tracing::info!("Firebaseのユーザーのメールアドレスの更新が完了しました: {id:?}"); + Ok(()) + } + Err(err) => Err(anyhow::anyhow!("Failed to update firebase user: {err}").into()), + } } async fn delete_by_id(&self, id: FirebaseUserId) -> Result<(), FirebaseUserRepositoryError> { tracing::info!("Firebaseのユーザーを削除します: {id:?}"); - self.auth - .delete_user(id.clone().value()) - .await - .map_err(|err| anyhow::anyhow!("Failed to delete firebase user: {err}").into())?; + let res = self.auth.delete_user(id.clone().value()).await; - tracing::info!("Firebaseのユーザーの削除が完了しました: {id:?}"); - - Ok(()) + match res { + Ok(_) => { + tracing::info!("Firebaseのユーザーの削除が完了しました: {id:?}"); + Ok(()) + } + Err(err) => Err(anyhow::anyhow!("Failed to delete firebase user: {err}").into()), + } } }