Skip to content

fix: 属性検索でモンスターデータが返らないバグを修正#209

Merged
o-ga09 merged 1 commit intomainfrom
fix/191-usage-element-search
Apr 7, 2026
Merged

fix: 属性検索でモンスターデータが返らないバグを修正#209
o-ga09 merged 1 commit intomainfrom
fix/191-usage-element-search

Conversation

@o-ga09
Copy link
Copy Markdown
Owner

@o-ga09 o-ga09 commented Apr 7, 2026

close #191

変更内容

  • monsterQueryService.FetchListquery.Where() の戻り値を query に再代入していなかったため、WHERE 条件が無視されていた問題を修正
  • total カウントにも同じ WHERE 条件を適用し、フィルタ後の正確な件数を返すよう修正
  • テストの wantTotal をフィルタ後の正しい期待値に更新

変更の背景・目的

  • Issue 属性検索機能 #191: /v1/monsters?UsageElement=fire で検索すると {"total":333} しか返らない問題
  • GORM v2 では db.Where(...) はレシーバーを変更せず新しい *gorm.DB を返すため、query = query.Where(...) と再代入しなければ WHERE 条件が失われる

テスト結果

  • ユニットテスト実行済み(Test_monsterQueryService_FetchList 全12ケース PASS)
  • UsageElement/WeaknessElement 検索テストケース確認済み

Closes #191

- monsterQueryService.FetchList で query.Where() の戻り値を query に
  再代入していなかったため WHERE 条件が無視されていた問題を修正
- GORM v2 では db.Where() は新しい *gorm.DB を返すため query = query.Where(...) が必要
- total カウントにも同じ WHERE 条件を適用し、フィルタ後の件数を正しく返すよう修正
- テストの wantTotal をフィルタ後の正しい期待値に更新

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 7, 2026 14:23
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

Code Metrics Report

Coverage Code to Test Ratio Test Execution Time
30.2% 1:0.4 1m24s

Code coverage of files in pull request scope (92.2%)

Files Coverage
internal/database/mysql/monsterQueryService.go 92.2%

Reported by octocov

@o-ga09 o-ga09 merged commit 89f7135 into main Apr 7, 2026
5 checks passed
@o-ga09 o-ga09 deleted the fix/191-usage-element-search branch April 7, 2026 14:25
Copy link
Copy Markdown
Contributor

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

GORM v2 の Where() が新しい *gorm.DB を返す仕様により、属性検索などの WHERE 条件がクエリに適用されず /v1/monsters?UsageElement=fire 等でデータが返らない不具合を修正するPRです。

Changes:

  • FetchList の WHERE 条件適用時に query = query.Where(...) と再代入するよう修正
  • total 件数のカウントにも同一の WHERE 条件を適用するよう修正
  • テストの wantTotal をフィルタ後の件数に合わせて更新

Reviewed changes

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

File Description
internal/database/mysql/monsterQueryService.go WHERE条件の適用漏れ修正、および total カウントに同一条件を適用
internal/database/mysql/monsterQueryService_test.go フィルタ適用後の Total 期待値に合わせてテストを更新


if id != "" {
query.Where("monster_id = ? ", id)
query = query.Where("monster_id = ? ", id)
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

Where("monster_id = ? ", id) has an extra trailing space in the SQL fragment. It’s harmless for MySQL, but it’s inconsistent with the other queries in this function and makes it easier to miss subtle differences—please remove the trailing space for consistency.

Suggested change
query = query.Where("monster_id = ? ", id)
query = query.Where("monster_id = ?", id)

Copilot uses AI. Check for mistakes.
} else if where_clade != "" {
countQuery = countQuery.Where(where_clade, whereArgs...)
}
countQuery.Count(&total)
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

The result of countQuery.Count(&total) is not checked for errors. If the COUNT query fails (e.g., bad SQL, connection issues), the handler will still return a response with an incorrect total. Please capture the returned *gorm.DB, check Error, and return the error like the main Find query does.

Suggested change
countQuery.Count(&total)
countResult := countQuery.Count(&total)
if countResult.Error != nil {
return nil, countResult.Error
}

Copilot uses AI. Check for mistakes.
@github-actions github-actions bot mentioned this pull request Apr 8, 2026
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.

属性検索機能

2 participants