Conversation
There was a problem hiding this comment.
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: []stringinstead of a singleanswer. - Persist
answersas a JSON-serialized slice onmodels.Roundand 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.
| 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) |
There was a problem hiding this comment.
geminiData.Answers が空/未設定のまま CreateRound に渡ると、DB側で answers が NULL になってINSERT失敗するか(not null制約)、後段の GetAnswer で Answers[0] がpanicになります。json.Unmarshal 後に len(geminiData.Answers) > 0 を必須チェックし、空ならエラーにするか、最低1要素に正規化してから保存してください(必要なら旧フォーマット answer のフォールバックも)。
| @@ -101,15 +101,19 @@ func (s *HintService) GetAnswer(id uint) (string, error) { | |||
| if err != nil { | |||
| return "", err | |||
| } | |||
There was a problem hiding this comment.
round.Answers[0] は Answers が空の場合に index out of range でpanicします。過去データ(旧 answer カラムのみ)や生成結果の不正で Answers が空になり得るので、len(round.Answers)==0 の場合はエラーを返す/代表値を決めて補完する等のハンドリングを入れてください。
| } | |
| } | |
| if len(round.Answers) == 0 { | |
| return "", errors.New("no answers available for this round") | |
| } |
概要
内部で正解を複数保持
解答の表記ゆれに対応
動作確認
変更内容・エビデンス
解答は「大阪」



解答のリクエスト

その他
略称一覧