mirror of
https://github.com/davegallant/rfd-fyi.git
synced 2025-08-06 07:13:39 +00:00
Add scores
This commit is contained in:
@@ -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
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user