Skip to content

repositoryのGetGameCreatorsByGameID#1578

Open
ikura-hamu wants to merge 4 commits intomainfrom
feat/repository_get_game_creators_by_game_id
Open

repositoryのGetGameCreatorsByGameID#1578
ikura-hamu wants to merge 4 commits intomainfrom
feat/repository_get_game_creators_by_game_id

Conversation

@ikura-hamu
Copy link
Copy Markdown
Member

@ikura-hamu ikura-hamu commented May 1, 2026

fix #1528

  • ✨ repositoryのGetGameCreatorsByUserIDs実装
  • ✅ GetGameCreatorsByUserIDsのテスト

Summary by CodeRabbit

  • New Features

    • Game creators can now be efficiently retrieved and filtered by user IDs, enabling improved query performance.
  • Tests

    • Added comprehensive test coverage for game creator retrieval, validating behavior across single users, multiple users, and cross-game scenarios.

@ikura-hamu ikura-hamu requested a review from a team as a code owner May 1, 2026 13:04
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 1, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR implements the GetGameCreatorsByUserIDs repository method in GORM2, replacing a stub with a full database query implementation that filters game creators by game ID and user IDs, orders results by creation time, and maps rows into domain objects. A comprehensive test suite validates the method across multiple scenarios with field-level assertions.

Changes

GameCreator User Lookup

Layer / File(s) Summary
Repository Implementation
src/repository/gorm2/game_creator.go
GetGameCreatorsByUserIDs method retrieves schema rows by game_id and user_id IN (...), orders by created_at ASC, converts user IDs to UUIDs, and maps each row to a domain.GameCreator with ID, GameID, UserID, UserName, and CreatedAt fields.
Unit Tests
src/repository/gorm2/game_creator_test.go
TestGetGameCreatorsByUserIDs verifies correct row filtering and mapping across scenarios: single user, multiple users, no matches, and same user across different games, with per-scenario DB cleanup and CreatedAt timestamp tolerance of 1 second.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested labels

Review effort 3/5

Suggested reviewers

  • mathsuky

Poem

🐰 A fetch query hops through the database,
GameCreators by user, none more gracious!
UUIDs convert, rows align in order,
Tests verify each hop, both near and farther.
From stub to glory, the implementation's fine! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title 'repositoryのGetGameCreatorsByGameID' mentions GetGameCreatorsByGameID, but the actual implementation is for GetGameCreatorsByUserIDs, creating a mismatch with the changeset. Update the PR title to accurately reflect the implemented method, e.g., 'repositoryのGetGameCreatorsByUserIDs実装' or similar to match the actual changes.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR successfully implements GetGameCreatorsByUserIDs method to retrieve game creator information by specified game ID and user IDs, and includes comprehensive test coverage with multiple test cases.
Out of Scope Changes check ✅ Passed All changes in the PR are directly related to implementing GetGameCreatorsByUserIDs method and its test cases as specified in the linked issue #1528, with no out-of-scope modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/repository_get_game_creators_by_game_id

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ikura-hamu ikura-hamu force-pushed the feat/repository_get_game_creators_by_game_id branch from 3bcbc51 to 40240ff Compare May 1, 2026 13:06
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

Migrate lint ✅

Lint output

@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.81%. Comparing base (2bdb273) to head (81f85cc).
⚠️ Report is 25 commits behind head on main.

Files with missing lines Patch % Lines
src/repository/gorm2/game_creator.go 83.33% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1578      +/-   ##
==========================================
- Coverage   52.13%   51.81%   -0.32%     
==========================================
  Files         143      145       +2     
  Lines       10713    10836     +123     
==========================================
+ Hits         5585     5615      +30     
- Misses       4800     4891      +91     
- Partials      328      330       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@mathsuky mathsuky left a comment

Choose a reason for hiding this comment

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

ありがとうございます!
2点コメントしたのでご確認お願い致します:bow-nya:

Comment thread src/repository/gorm2/game_creator.go Outdated
Comment thread src/repository/gorm2/game_creator_test.go
@ikura-hamu ikura-hamu changed the title repositoryのGeGameCreatorsByGameID repositoryのGetGameCreatorsByGameID May 8, 2026
@ikura-hamu ikura-hamu requested a review from mathsuky May 8, 2026 13:02
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/repository/gorm2/game_creator.go (1)

184-193: 💤 Low value

Consider an early return when userIDs is empty.

When userIDs is empty userUUIDs becomes []uuid.UUID{}. GORM v2 converts WHERE user_id IN ? with an empty slice into IN (NULL), which returns zero rows safely — no crash. But it still pays the cost of a DB round-trip that can never produce results.

♻️ Proposed optimization
 	userUUIDs := make([]uuid.UUID, 0, len(userIDs))
 	for _, userID := range userIDs {
 		userUUIDs = append(userUUIDs, uuid.UUID(userID))
 	}
+
+	if len(userUUIDs) == 0 {
+		return []*domain.GameCreator{}, nil
+	}
+
 	var gameCreators []schema.GameCreatorTable
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/repository/gorm2/game_creator.go` around lines 184 - 193, When userIDs is
empty, avoid the unnecessary DB query: add an early return before the conversion
loop and GORM call (check len(userIDs) == 0) and return an empty
[]schema.GameCreatorTable (or the same zero-value result and nil error expected
by the surrounding function) instead of executing the
db.Where(...).Where("user_id IN ?", userUUIDs).Find(&gameCreators).Error. This
prevents building userUUIDs and issuing the GORM IN query with an empty slice
while preserving the existing return types/behavior of the function that
contains userIDs, userUUIDs, and the gameCreators query.
src/repository/gorm2/game_creator_test.go (1)

755-763: ⚡ Quick win

Associated GameTable2 records are not cleaned up.

When db.Create(testCase.creators) runs, GORM implicitly creates the associated GameTable2 records (for creatorSchema1.Game, creatorSchema2.Game, and creatorSchema3.Game). The cleanup only deletes the GameCreatorTable rows:

err = db.Session(&gorm.Session{AllowGlobalUpdate: true}).Delete(testCase.creators).Error

The GameTable2 records remain in the database. Compare with TestGetGameCreatorsByGameID (lines 39–44) which adds an explicit global cleanup for &schema.GameTable2{}. Without similar cleanup here, game records leak across subtests, and if this test function runs in isolation or last in the suite, those records persist indefinitely.

Add a t.Cleanup outside the subtest loop (or inside with clause.Associations) to remove the game records:

♻️ Proposed fix
 	for name, testCase := range testCases {
 		t.Run(name, func(t *testing.T) {
 			ctx := t.Context()
 			db, err := testDB.getDB(ctx)
 			require.NoError(t, err)

 			if len(testCase.creators) > 0 {
 				err = db.Create(testCase.creators).Error
 				require.NoError(t, err)
 				t.Cleanup(func() {
 					db, err := testDB.getDB(context.Background())
 					require.NoError(t, err)
-					err = db.Session(&gorm.Session{AllowGlobalUpdate: true}).Delete(testCase.creators).Error
+					err = db.Select(clause.Associations).Delete(testCase.creators).Error
 					require.NoError(t, err)
 				})
 			}

Alternatively, add a top-level t.Cleanup (after all subtests) to globally wipe GameTable2, matching the pattern used by TestGetGameCreatorsByGameID.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/repository/gorm2/game_creator_test.go` around lines 755 - 763, The
cleanup currently removes only testCase.creators after
db.Create(testCase.creators) but not the implicitly created GameTable2 rows;
update the test to also remove those game records by adding a t.Cleanup that
calls db.Session(&gorm.Session{AllowGlobalUpdate:
true}).Delete(&schema.GameTable2{}) (or, if deleting per-subtest, call
Delete(testCase.creators, clause.Associations) to cascade associations) so that
the GameTable2 rows created by db.Create(testCase.creators) are removed and do
not leak between subtests; reference testCase.creators, db.Create, and
schema.GameTable2 when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/repository/gorm2/game_creator_test.go`:
- Around line 755-763: The cleanup currently removes only testCase.creators
after db.Create(testCase.creators) but not the implicitly created GameTable2
rows; update the test to also remove those game records by adding a t.Cleanup
that calls db.Session(&gorm.Session{AllowGlobalUpdate:
true}).Delete(&schema.GameTable2{}) (or, if deleting per-subtest, call
Delete(testCase.creators, clause.Associations) to cascade associations) so that
the GameTable2 rows created by db.Create(testCase.creators) are removed and do
not leak between subtests; reference testCase.creators, db.Create, and
schema.GameTable2 when making the change.

In `@src/repository/gorm2/game_creator.go`:
- Around line 184-193: When userIDs is empty, avoid the unnecessary DB query:
add an early return before the conversion loop and GORM call (check len(userIDs)
== 0) and return an empty []schema.GameCreatorTable (or the same zero-value
result and nil error expected by the surrounding function) instead of executing
the db.Where(...).Where("user_id IN ?", userUUIDs).Find(&gameCreators).Error.
This prevents building userUUIDs and issuing the GORM IN query with an empty
slice while preserving the existing return types/behavior of the function that
contains userIDs, userUUIDs, and the gameCreators query.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 504c2f6f-2391-4a4e-9161-ab7d40097413

📥 Commits

Reviewing files that changed from the base of the PR and between 2bdb273 and 81f85cc.

📒 Files selected for processing (2)
  • src/repository/gorm2/game_creator.go
  • src/repository/gorm2/game_creator_test.go

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.

repositoryのGetGameCreatorsByUserIDsの実装

2 participants