Skip to content

[BE-28] 内部で正解を複数保持#41

Merged
yone-al merged 1 commit intodevelopfrom
BE-28
Feb 19, 2026
Merged

[BE-28] 内部で正解を複数保持#41
yone-al merged 1 commit intodevelopfrom
BE-28

Conversation

@yone-al
Copy link
Contributor

@yone-al yone-al commented Feb 18, 2026

概要

内部で正解を複数保持
解答の表記ゆれに対応

動作確認

  • 違う表記でも正解判定(大阪/おおさか など)
  • 解答をリクエストした場合は代表的な1つを返す

変更内容・エビデンス

解答は「大阪」
image
image
image

解答のリクエスト
image

その他

略称一覧

  • LGTM : Looks Good To Me(レビューアーがPRの内容を確認し、問題がないと判断した際に使用する)
  • ask : 質問・確認事項(修正は任意、回答や説明を求める)
  • imo : In My Opinion(個人的な意見、修正は任意)
  • nits : 些細な指摘(修正は任意、気になった点の共有)
  • must : 必須の修正事項(マージ前に必ず対応が必要)
  • memo : メモ(参考情報として共有)

@yone-al yone-al marked this pull request as ready for review February 18, 2026 14:33
@yone-al yone-al requested a review from Copilot February 18, 2026 14:33
@github-actions github-actions bot added the back label Feb 18, 2026
Copy link

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

This PR updates the solo hint game backend to store multiple acceptable correct answers internally, enabling answer-variant matching (e.g., 大阪 / おおさか / Osaka) while still returning a single representative answer on request.

Changes:

  • Update Gemini prompt/JSON parsing to accept answers: []string instead of a single answer.
  • Persist answers as a JSON-serialized slice on models.Round and update repository/service APIs accordingly.
  • Update answer checking to match against any stored answer variant.

Reviewed changes

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

File Description
backend/services/hint_service.go Parse/store multiple answers; return representative answer; check user answer against all variants
backend/repositories/hint_repository.go Change CreateRound to accept/store answers []string
backend/models/hint.go Replace Answer string column with Answers []string (JSON-serialized)

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

Comment on lines 71 to +75
if err := json.Unmarshal([]byte(rawText), &geminiData); err != nil {
return nil, fmt.Errorf("JSONパースに失敗しました: %w (raw: %s)", err, rawText)
}

result, err := s.repository.CreateRound(geminiData.Answer, geminiData.Hints)
result, err := s.repository.CreateRound(geminiData.Answers, geminiData.Hints)
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

geminiData.Answers が空/未設定のまま CreateRound に渡ると、DB側で answers が NULL になってINSERT失敗するか(not null制約)、後段の GetAnswerAnswers[0] がpanicになります。json.Unmarshal 後に len(geminiData.Answers) > 0 を必須チェックし、空ならエラーにするか、最低1要素に正規化してから保存してください(必要なら旧フォーマット answer のフォールバックも)。

Copilot uses AI. Check for mistakes.
@@ -101,15 +101,19 @@ func (s *HintService) GetAnswer(id uint) (string, error) {
if err != nil {
return "", err
}
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

round.Answers[0]Answers が空の場合に index out of range でpanicします。過去データ(旧 answer カラムのみ)や生成結果の不正で Answers が空になり得るので、len(round.Answers)==0 の場合はエラーを返す/代表値を決めて補完する等のハンドリングを入れてください。

Suggested change
}
}
if len(round.Answers) == 0 {
return "", errors.New("no answers available for this round")
}

Copilot uses AI. Check for mistakes.
@yone-al yone-al merged commit c53e8e0 into develop Feb 19, 2026
8 checks passed
@yone-al yone-al deleted the BE-28 branch February 19, 2026 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments