From bb91927bae706ad1a02b514871947e4b2a02183a Mon Sep 17 00:00:00 2001 From: Erik Winter Date: Sat, 6 Jan 2024 14:58:29 +0100 Subject: [PATCH] handle empty mentions list --- cmd/api-service/moviestore/review.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/cmd/api-service/moviestore/review.go b/cmd/api-service/moviestore/review.go index 5bac644..8405883 100644 --- a/cmd/api-service/moviestore/review.go +++ b/cmd/api-service/moviestore/review.go @@ -50,8 +50,10 @@ func (rr *ReviewRepository) FindOne(id string) (Review, error) { if err := row.Scan(&r.ID, &r.MovieID, &r.Source, &r.URL, &r.Review, &r.Quality, &mentions); err != nil { return Review{}, err } - r.Mentions = strings.Split(mentions, MentionsSeparator) - + r.Mentions = make([]string, 0) + if mentions != "" { + r.Mentions = strings.Split(mentions, MentionsSeparator) + } return r, nil } @@ -68,7 +70,10 @@ func (rr *ReviewRepository) FindByMovieID(movieID string) ([]Review, error) { if err := rows.Scan(&r.ID, &r.MovieID, &r.Source, &r.URL, &r.Review, &r.Quality, &mentions); err != nil { return nil, err } - r.Mentions = strings.Split(mentions, MentionsSeparator) + r.Mentions = make([]string, 0) + if mentions != "" { + r.Mentions = strings.Split(mentions, MentionsSeparator) + } reviews = append(reviews, r) } rows.Close() @@ -87,7 +92,10 @@ func (rr *ReviewRepository) FindNextUnrated() (Review, error) { if err := row.Scan(&r.ID, &r.MovieID, &r.Source, &r.URL, &r.Review, &r.Quality, &mentions); err != nil { return Review{}, err } - r.Mentions = strings.Split(mentions, MentionsSeparator) + r.Mentions = make([]string, 0) + if mentions != "" { + r.Mentions = strings.Split(mentions, MentionsSeparator) + } return r, nil } @@ -105,7 +113,10 @@ func (rr *ReviewRepository) FindUnrated() ([]Review, error) { if err := rows.Scan(&r.ID, &r.MovieID, &r.Source, &r.URL, &r.Review, &r.Quality, &mentions); err != nil { return nil, err } - r.Mentions = strings.Split(mentions, MentionsSeparator) + r.Mentions = make([]string, 0) + if mentions != "" { + r.Mentions = strings.Split(mentions, MentionsSeparator) + } reviews = append(reviews, r) } rows.Close()