Skip to content

Notification エンドポイントの CRUD 実装#9

Open
kantacky wants to merge 16 commits intomainfrom
implment-notification
Open

Notification エンドポイントの CRUD 実装#9
kantacky wants to merge 16 commits intomainfrom
implment-notification

Conversation

@kantacky
Copy link
Copy Markdown
Member

概要

OpenAPI スキーマに定義された Notification エンドポイント(List / Create / Update / Delete)をクリーンアーキテクチャに沿って実装した。

変更内容

Domain 層

  • Notification 構造体と NotificationListFilter 構造体を追加

Database 層

  • Notification GORM モデル(ToDomain / FromDomain 変換付き)を追加
  • NotificationTargetUser 中間テーブルモデルを追加
  • AutoMigrate に両テーブルを登録

Repository 層

  • NotificationRepository に List / Create / Update / Delete をトランザクション付きで実装
  • Create 時に UUID を自動生成
  • Update / Delete 時に存在チェックを行い、未存在なら ErrNotFound を返却

Service 層

  • NotificationRepository インターフェースを定義し、NotificationService で委譲

Handler 層

  • not implemented スタブだった4ハンドラを実装
  • converter.go に API ⇔ Domain 変換関数を追加
  • NotifyAttime.RFC3339 形式で変換

Wiring

  • main.go に NotificationRepository → Service → Handler の DI 配線を追加

確認事項

  • go build ./... が通ること
  • 各エンドポイントの動作確認

kantacky and others added 6 commits April 10, 2026 06:56
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Notification と NotificationTargetUser の domain 構造体・
database 構造体・変換関数を定義し、AutoMigrate に登録した。
TargetUserIDs は中間テーブル notification_target_users で管理する。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
NotificationRepository に CRUD 操作(List/Create/Update/Delete)を
トランザクション付きで実装し、NotificationService でリポジトリ
インターフェースを定義して委譲する構成とした。
UUID 生成のため google/uuid を direct 依存に昇格。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
not implemented スタブだった4つの Notification ハンドラ
(List/Create/Update/Delete)を実装した。
converter.go に API⇔Domain 変換関数を追加し、
handler.go と main.go に NotificationService の配線を追加した。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@kantacky kantacky self-assigned this Apr 10, 2026
@kantacky kantacky marked this pull request as ready for review April 10, 2026 08:07
@kantacky kantacky requested review from a team, Copilot, hikaru-0602 and masaya-osuga April 10, 2026 08:07
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

OpenAPI スキーマに定義された Notification エンドポイント(List / Create / Update / Delete)を、クリーンアーキテクチャの層分割(Domain/DB/Repository/Service/Handler)に沿って追加実装する PR。

Changes:

  • Domain/DB モデル(Notification / NotificationTargetUser)と AutoMigrate への登録を追加
  • Repository/Service/Handler に Notification の CRUD + List を実装し、DI 配線を追加
  • API ⇔ Domain 変換(NotifyAt を RFC3339 で変換)を追加

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
internal/service/notification.go NotificationService と Repository interface を追加
internal/service/notification_create.go Create の service 委譲を追加
internal/service/notification_list.go List の service 委譲を追加
internal/service/notification_update.go Update の service 委譲を追加
internal/service/notification_delete.go Delete の service 委譲を追加
internal/repository/notification.go NotificationRepository 実装のベースを追加
internal/repository/notification_create.go Notification 作成とターゲット紐付けを追加
internal/repository/notification_list.go Notification 一覧取得+ターゲット取得を追加
internal/repository/notification_update.go Notification 更新+ターゲット再作成を追加
internal/repository/notification_delete.go Notification 削除+ターゲット削除を追加
internal/handler/notification_create.go Create ハンドラを実装
internal/handler/notification_list.go List ハンドラを実装
internal/handler/notification_update.go Update ハンドラを実装
internal/handler/notification_delete.go Delete ハンドラを実装
internal/handler/handler.go Handler に notificationService を追加し DI を更新
internal/handler/converter.go Notification の API ⇔ Domain 変換を追加
internal/domain/notification.go Notification ドメインモデルを追加
internal/domain/notification_list_filter.go NotificationListFilter を追加
internal/database/notification.go Notification の GORM モデル+変換を追加
internal/database/notification_target_user.go 中間テーブル GORM モデルを追加
internal/database/migrate.go AutoMigrate に Notification テーブル群を追加
go.mod uuid を direct dependency として追加
cmd/server/main.go Notification Repo/Service/Handler の DI 配線を追加

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

kantacky and others added 4 commits April 10, 2026 17:17
Begin() のエラー未チェックやコミット失敗時の rollback 漏れを防ぐため、
create/update/delete すべてで db.Transaction(...) に統一する。
また update 時に is_notified が既存値を無視してゼロ値にリセットされる
バグも合わせて修正する。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
通知ごとに TargetUserIDs を個別クエリしていた箇所を、
IN 句で一括取得しメモリ上でグルーピングする方式に変更する。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
NotificationRequest の notifyAt が string のままだったため、
不正な日時文字列が handler まで到達し 500 エラーになっていた。
OpenAPI スキーマに format: date-time を追加してコードを再生成し、
converter から手動の time.Parse を除去する。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 10, 2026 08:33
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

kantacky and others added 2 commits April 10, 2026 17:49
TargetUserIDs に重複が含まれた場合に notification_target_users の
複合PK制約違反で500エラーになる問題を修正。保存・更新前に
uniqueStrings で重複を排除するようにした。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 10, 2026 08:54
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 24 out of 24 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

masaya-osuga and others added 2 commits April 12, 2026 16:14
UpdateNotification で Save を実行すると全カラムが更新され、
並行処理で is_notified が変更された場合に元の値で上書きされる恐れがあった。
Omit("IsNotified") を使用することで is_notified を更新対象から外し、
通知済みフラグは別途専用の処理でのみ変更されるよう保護する。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
CreateNotification・UpdateNotification ともに、DB 保存時は uniqueStrings で
重複排除していたが、返却するドメインオブジェクトには元の(重複を含む可能性がある)
スライスをそのまま渡していた。
レスポンスでも uniqueStrings を適用し、保存内容と一致した値を返すよう修正する。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 24 out of 24 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

create/update で対象ユーザーを1件ずつ tx.Create していたため、
対象数に比例して INSERT が発行される N+1 状態になっていた。
スライスにまとめて単一の tx.Create(&targets) で投入するよう変更し、
DB 往復回数を削減した。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 24 out of 24 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants