Conversation
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>
There was a problem hiding this comment.
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.
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>
There was a problem hiding this comment.
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.
TargetUserIDs に重複が含まれた場合に notification_target_users の 複合PK制約違反で500エラーになる問題を修正。保存・更新前に uniqueStrings で重複を排除するようにした。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
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.
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>
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
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.
概要
OpenAPI スキーマに定義された Notification エンドポイント(List / Create / Update / Delete)をクリーンアーキテクチャに沿って実装した。
変更内容
Domain 層
Notification構造体とNotificationListFilter構造体を追加Database 層
NotificationGORM モデル(ToDomain / FromDomain 変換付き)を追加NotificationTargetUser中間テーブルモデルを追加AutoMigrateに両テーブルを登録Repository 層
NotificationRepositoryに List / Create / Update / Delete をトランザクション付きで実装ErrNotFoundを返却Service 層
NotificationRepositoryインターフェースを定義し、NotificationServiceで委譲Handler 層
not implementedスタブだった4ハンドラを実装converter.goに API ⇔ Domain 変換関数を追加NotifyAtはtime.RFC3339形式で変換Wiring
main.goに NotificationRepository → Service → Handler の DI 配線を追加確認事項
go build ./...が通ること