Skip to content

Commit

Permalink
Fix programme query logic to return 7 days of data and anything with …
Browse files Browse the repository at this point in the history
…a start or end time of >= now
  • Loading branch information
robbiet480 committed Sep 16, 2018
1 parent 25a4493 commit d56d292
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/models/guide_source_programme.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (db *GuideSourceProgrammeDB) UpdateGuideSourceProgramme(programmeID string,
// GetProgrammesForActiveChannels returns a slice of GuideSourceProgrammes for actively assigned channels.
func (db *GuideSourceProgrammeDB) GetProgrammesForActiveChannels() ([]GuideSourceProgramme, error) {
programmes := make([]GuideSourceProgramme, 0)
sql, args, sqlGenErr := squirrel.Select("*").From("guide_source_programme").Where("channel IN (SELECT xmltv_id FROM guide_source_channel WHERE id IN (SELECT guide_channel_id FROM lineup_channel)) AND start >= datetime('now') AND start <= datetime('now', '+12 hours')").OrderBy("start ASC").ToSql()
sql, args, sqlGenErr := squirrel.Select("*").From("guide_source_programme").Where("channel IN (SELECT xmltv_id FROM guide_source_channel WHERE id IN (SELECT guide_channel_id FROM lineup_channel)) AND (start >= datetime('now') OR end >= datetime('now')) AND start <= datetime('now', '+7 days')").OrderBy("start ASC").ToSql()
if sqlGenErr != nil {
return nil, sqlGenErr
}
Expand All @@ -162,7 +162,7 @@ func (db *GuideSourceProgrammeDB) GetProgrammesForActiveChannels() ([]GuideSourc
// GetProgrammesForChannel returns a slice of GuideSourceProgrammes for the given XMLTV channel ID.
func (db *GuideSourceProgrammeDB) GetProgrammesForChannel(channelID string) ([]GuideSourceProgramme, error) {
programmes := make([]GuideSourceProgramme, 0)
sql, args, sqlGenErr := squirrel.Select("*").From("guide_source_programme").Where(fmt.Sprintf("channel = '%s' AND start >= datetime('now') AND start <= datetime('now', '+6 hours')", channelID)).ToSql()
sql, args, sqlGenErr := squirrel.Select("*").From("guide_source_programme").Where(fmt.Sprintf("channel = '%s' AND (start >= datetime('now') OR end >= datetime('now')) AND start <= datetime('now', '+7 days')", channelID)).ToSql()
if sqlGenErr != nil {
return nil, sqlGenErr
}
Expand Down

0 comments on commit d56d292

Please sign in to comment.