handle empty mentions list

This commit is contained in:
Erik Winter 2024-01-06 14:58:29 +01:00
parent 255afcc373
commit bb91927bae
1 changed files with 16 additions and 5 deletions

View File

@ -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 { if err := row.Scan(&r.ID, &r.MovieID, &r.Source, &r.URL, &r.Review, &r.Quality, &mentions); err != nil {
return Review{}, err return Review{}, err
} }
r.Mentions = make([]string, 0)
if mentions != "" {
r.Mentions = strings.Split(mentions, MentionsSeparator) r.Mentions = strings.Split(mentions, MentionsSeparator)
}
return r, nil 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 { if err := rows.Scan(&r.ID, &r.MovieID, &r.Source, &r.URL, &r.Review, &r.Quality, &mentions); err != nil {
return nil, err return nil, err
} }
r.Mentions = make([]string, 0)
if mentions != "" {
r.Mentions = strings.Split(mentions, MentionsSeparator) r.Mentions = strings.Split(mentions, MentionsSeparator)
}
reviews = append(reviews, r) reviews = append(reviews, r)
} }
rows.Close() 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 { if err := row.Scan(&r.ID, &r.MovieID, &r.Source, &r.URL, &r.Review, &r.Quality, &mentions); err != nil {
return Review{}, err return Review{}, err
} }
r.Mentions = make([]string, 0)
if mentions != "" {
r.Mentions = strings.Split(mentions, MentionsSeparator) r.Mentions = strings.Split(mentions, MentionsSeparator)
}
return r, nil 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 { if err := rows.Scan(&r.ID, &r.MovieID, &r.Source, &r.URL, &r.Review, &r.Quality, &mentions); err != nil {
return nil, err return nil, err
} }
r.Mentions = make([]string, 0)
if mentions != "" {
r.Mentions = strings.Split(mentions, MentionsSeparator) r.Mentions = strings.Split(mentions, MentionsSeparator)
}
reviews = append(reviews, r) reviews = append(reviews, r)
} }
rows.Close() rows.Close()