@@ -18,10 +18,11 @@ import (
1818const MinRoundAnswerRevealDuration = 90 * time .Second
1919
2020var (
21- ErrRoundNotFound = errors .New ("round not found" )
22- ErrRoundNotFinished = errors .New ("round is not finished yet" )
23- ErrRoundTooEarly = errors .New ("game has not been played long enough" )
24- ErrBookmarkNotFound = errors .New ("bookmark not found" )
21+ ErrRoundNotFound = errors .New ("round not found" )
22+ ErrRoundNotFinished = errors .New ("round is not finished yet" )
23+ ErrRoundTooEarly = errors .New ("game has not been played long enough" )
24+ ErrBookmarkNotFound = errors .New ("bookmark not found" )
25+ ErrNoAnswersAvailable = errors .New ("no answers available" )
2526)
2627
2728type IHintService interface {
@@ -186,8 +187,6 @@ func (s *HintService) StartGame() (*dto.StartGameResult, error) {
186187
187188 text := res .Text ()
188189
189- fmt .Println (text )
190-
191190 if err := json .Unmarshal ([]byte (text ), & geminiData ); err != nil {
192191 return nil , fmt .Errorf ("JSONパースに失敗しました: %w (raw: %s)" , err , text )
193192 }
@@ -221,6 +220,9 @@ func (s *HintService) GetAnswer(id uint) (string, error) {
221220 if err != nil {
222221 return "" , err
223222 }
223+ if len (round .Answers ) == 0 {
224+ return "" , fmt .Errorf ("%w: id=%d" , ErrNoAnswersAvailable , id )
225+ }
224226 if ! round .IsFinished {
225227 if time .Since (round .CreatedAt ) < MinRoundAnswerRevealDuration {
226228 return "" , fmt .Errorf ("%w" , ErrRoundTooEarly )
@@ -257,6 +259,9 @@ func (s *HintService) GetFinishedRoundByID(id uint) (*dto.RoundResponse, error)
257259 if ! round .IsFinished {
258260 return nil , fmt .Errorf ("%w: id=%d" , ErrRoundNotFinished , id )
259261 }
262+ if len (round .Answers ) == 0 {
263+ return nil , fmt .Errorf ("%w: id=%d" , ErrNoAnswersAvailable , id )
264+ }
260265 result := & dto.RoundResponse {
261266 ID : round .ID ,
262267 Answer : round .Answers [0 ],
@@ -274,6 +279,9 @@ func (s *HintService) BookmarkRound(id uint) (*dto.RoundResponse, error) {
274279 if ! round .IsFinished {
275280 return nil , fmt .Errorf ("%w: id=%d" , ErrRoundNotFinished , id )
276281 }
282+ if len (round .Answers ) == 0 {
283+ return nil , fmt .Errorf ("%w: id=%d" , ErrNoAnswersAvailable , id )
284+ }
277285 if err := s .repository .BookmarkRound (id ); err != nil {
278286 return nil , fmt .Errorf ("failed to bookmark round: %w" , err )
279287 }
@@ -295,6 +303,9 @@ func (s *HintService) GetRandomBookmark() (*dto.RoundResponse, error) {
295303 return nil , ErrBookmarkNotFound
296304 }
297305
306+ if len (round .Answers ) == 0 {
307+ return nil , ErrNoAnswersAvailable
308+ }
298309 return & dto.RoundResponse {
299310 ID : round .ID ,
300311 Answer : round .Answers [0 ],
@@ -312,6 +323,9 @@ func (s *HintService) GetBookmarkedList() ([]dto.RoundResponse, error) {
312323 response := []dto.RoundResponse {}
313324
314325 for _ , r := range rounds {
326+ if len (r .Answers ) == 0 {
327+ continue
328+ }
315329 limit := 4
316330 if len (r .Hints ) < limit {
317331 limit = len (r .Hints )
0 commit comments