Issue1524 CreateGameCreatorCustomJobsの実装#1542
Conversation
|
Migrate lint ✅ Lint output |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughCreateGameCreatorCustomJobs をスタブから実装へ差し替え。空スライスは no-op、ドメイン構造体をスキーマレコードへ変換して DB に一括作成し、DB取得および作成エラーをラップして返す。対応する統合テストを追加。 Changes
Sequence Diagram(s)sequenceDiagram
participant Test as テスト
participant Repo as GameCreator リポジトリ
participant DB as データベース
participant Schema as スキーマ変換
Test->>Repo: CreateGameCreatorCustomJobs(ctx, jobs)
Repo->>DB: gc.db.getDB(ctx)
DB-->>Repo: db handle / error
alt db handle
Repo->>Schema: domain jobs を schema レコードに変換
Schema-->>Repo: schema レコードリスト
Repo->>DB: db.Create(&customJobs)
DB-->>Repo: success / error
Repo-->>Test: return nil / error
else error
Repo-->>Test: return fmt.Errorf("get db: %w", err)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 分 Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1542 +/- ##
==========================================
+ Coverage 52.03% 52.10% +0.07%
==========================================
Files 143 143
Lines 10689 10705 +16
==========================================
+ Hits 5562 5578 +16
+ Misses 4800 4799 -1
- Partials 327 328 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/repository/gorm2/game_creator_test.go`:
- Around line 561-565: The test case "空配列を渡してもエラーにならない" currently returns early
on len(jobIDs)==0 and only asserts no error; update that test in
game_creator_test.go to capture the DB row count for the relevant table (e.g.,
via the repository or gorm DB used in tests) before calling the method under
test, call the function as before, then re-query the row count after and assert
the counts are equal (no new rows inserted); apply the same pattern to the other
similar cases mentioned (around the other tests referencing empty job slices and
jobIDs).
In `@src/repository/gorm2/game_creator.go`:
- Around line 127-131: In CreateGameCreatorCustomJobs, move the early-return
check for empty input before calling gc.db.getDB(ctx): if len(jobs) == 0 {
return nil }, so noop calls do not attempt to open the DB via gc.db.getDB(ctx);
apply the same change to the other similar function in this file that takes jobs
(the second Create... method around the later block) so both short-circuit on
empty jobs before any DB access.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 48e2d532-d847-4a04-a931-a85a3ad5fe4c
📒 Files selected for processing (2)
src/repository/gorm2/game_creator.gosrc/repository/gorm2/game_creator_test.go
| func (gc *GameCreator) CreateGameCreatorCustomJobs(ctx context.Context, jobs []*domain.GameCreatorCustomJob) error { | ||
| db, err := gc.db.getDB(ctx) | ||
| if err != nil { | ||
| return fmt.Errorf("get db: %w", err) | ||
| } |
There was a problem hiding this comment.
空入力の早期 return を DB 取得より前に移動してください。
jobs が空でも先に gc.db.getDB(ctx) を呼んでいるため、no-op で終わるべき呼び出しが DB 状態に依存して失敗し得ます。len(jobs) == 0 を先に判定して戻す方が安全です。
💡 修正案
func (gc *GameCreator) CreateGameCreatorCustomJobs(ctx context.Context, jobs []*domain.GameCreatorCustomJob) error {
+ if len(jobs) == 0 {
+ return nil
+ }
+
db, err := gc.db.getDB(ctx)
if err != nil {
return fmt.Errorf("get db: %w", err)
}
customJobs := make([]schema.GameCreatorCustomJobTable, 0, len(jobs))
for _, job := range jobs {
customJobs = append(customJobs, schema.GameCreatorCustomJobTable{
ID: uuid.UUID(job.GetID()),
GameID: uuid.UUID(job.GetGameID()),
DisplayName: string(job.GetDisplayName()),
CreatedAt: job.GetCreatedAt(),
})
}
- if len(customJobs) == 0 {
- return nil
- }
-
err = db.Create(&customJobs).Error
if err != nil {
return fmt.Errorf("create custom jobs: %w", err)
}
return nil
}Also applies to: 143-145
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/repository/gorm2/game_creator.go` around lines 127 - 131, In
CreateGameCreatorCustomJobs, move the early-return check for empty input before
calling gc.db.getDB(ctx): if len(jobs) == 0 { return nil }, so noop calls do not
attempt to open the DB via gc.db.getDB(ctx); apply the same change to the other
similar function in this file that takes jobs (the second Create... method
around the later block) so both short-circuit on empty jobs before any DB
access.
mathsuky
left a comment
There was a problem hiding this comment.
ありがとうございます!いくつかコメントしたのでご確認お願いいたします:bow-nya:
| if err != nil { | ||
| return fmt.Errorf("create custom jobs: %w", err) | ||
| } |
There was a problem hiding this comment.
repositoryパッケージにErrForeignKeyViolatedを定義してそれを使うようにするのが良いと思います。
| if len(jobIDs) == 0 { | ||
| err = db.Model(&schema.GameCreatorCustomJobTable{}).Where("id IN ?", jobIDs).Count(&beforeCount).Error | ||
| require.NoError(t, err) | ||
| require.Equal(t, int64(0), beforeCount, "テスト開始前に同じIDのカスタムジョブが存在しています") | ||
| } |
There was a problem hiding this comment.
jobIDsの長さが0のケースでやっているので,beforeCountは常に0になるはずです。このブロックは不要なのでまるまる削除して良いと思います。
それに伴って,afterCountの方も削除して良いともいます。jobが空配列の時にエラーを返さないことはassert.NoError(t, err)で十分チェックできていると思います。
| if !testCase.verifyByID || len(jobIDs) == 0 { | ||
| if len(jobIDs) == 0 && !testCase.expectErr { | ||
| var afterCount int64 | ||
| err = db.Model(&schema.GameCreatorCustomJobTable{}). | ||
| Where("game_id IN ?", []uuid.UUID{uuid.UUID(gameID1), uuid.UUID(gameID2)}). | ||
| Count(&afterCount).Error | ||
| require.NoError(t, err) | ||
| assert.Equal(t, beforeCount, afterCount) | ||
| } | ||
| return | ||
| } |
There was a problem hiding this comment.
用意しているテストケースにおいて!testCase.verifyByID || len(jobIDs) == 0は常にtrueなので,この条件分岐は不要に思います。
Summary by CodeRabbit
リリースノート
バグ修正
テスト