Add scores

This commit is contained in:
Dave Gallant
2022-12-23 21:11:19 -05:00
parent fca2f4a5b0
commit e69d0f632e
4 changed files with 13 additions and 6 deletions

View File

@@ -91,12 +91,20 @@ func (a *App) listTopics(w http.ResponseWriter, r *http.Request) {
func (a *App) refreshTopics() {
latestTopics := a.getDeals(9, 1, 4)
// TODO: only drop deals if a timer has been met
latestTopics = a.updateScores(latestTopics)
log.Debug().Msg("Refreshing topics")
a.CurrentTopics = latestTopics
a.LastRefresh = time.Now()
}
func (a *App) updateScores(t []Topic) []Topic {
for i := range t {
t[i].Score = t[i].Votes.Up - t[i].Votes.Down
log.Debug().Msgf("Added score: %d", t[i].Score)
}
return t
}
func (a *App) getDeals(id int, firstPage int, lastPage int) []Topic {
var t []Topic

View File

@@ -14,7 +14,7 @@ type Topic struct {
PostTime string `json:"post_time"`
LastPostTime string `json:"last_post_time"`
Votes Votes
Score string `json:",omitempty"`
Score int `json:"score"`
} // @name Topic
type Votes struct {