diff --git a/backend/app.go b/backend/app.go index e93bdcd..10d8b56 100644 --- a/backend/app.go +++ b/backend/app.go @@ -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 diff --git a/backend/model.go b/backend/model.go index 6ef9343..c35b5aa 100644 --- a/backend/model.go +++ b/backend/model.go @@ -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 { diff --git a/src/App.vue b/src/App.vue index c18267b..7e61bad 100644 --- a/src/App.vue +++ b/src/App.vue @@ -12,9 +12,8 @@ Deal + Score Views - - Last Post @@ -39,9 +38,8 @@ v-html="highlightMatches(topic.title)" > + {{ topic.score }} {{ topic.total_views }} - - {{ formatDate(topic.last_post_time) }} diff --git a/src/main.js b/src/main.js index 2376a82..1eba8bc 100644 --- a/src/main.js +++ b/src/main.js @@ -13,3 +13,4 @@ createApp(App) config: { id: "G-YF11ZH9SYD" }, }) .mount("#app"); +