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() { func (a *App) refreshTopics() {
latestTopics := a.getDeals(9, 1, 4) 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") log.Debug().Msg("Refreshing topics")
a.CurrentTopics = latestTopics a.CurrentTopics = latestTopics
a.LastRefresh = time.Now() 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 { func (a *App) getDeals(id int, firstPage int, lastPage int) []Topic {
var t []Topic var t []Topic

View File

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

View File

@@ -12,9 +12,8 @@
<thead class="thead thead-light text-muted"> <thead class="thead thead-light text-muted">
<tr> <tr>
<th scope="col">Deal</th> <th scope="col">Deal</th>
<th scope="col">Score</th>
<th scope="col">Views</th> <th scope="col">Views</th>
<!-- TODO:score -->
<!-- <th scope="col">Score</th> -->
<th scope="col">Last Post</th> <th scope="col">Last Post</th>
</tr> </tr>
</thead> </thead>
@@ -39,9 +38,8 @@
v-html="highlightMatches(topic.title)" v-html="highlightMatches(topic.title)"
></a> ></a>
</td> </td>
<td scope="col">{{ topic.score }}</td>
<td scope="col">{{ topic.total_views }}</td> <td scope="col">{{ topic.total_views }}</td>
<!-- <td scope="col">{{ topic.score }}</td> -->
<!-- <td scope="col">{{ topic.votes.up - topic.votes.down }}</td> -->
<td scope="col">{{ formatDate(topic.last_post_time) }}</td> <td scope="col">{{ formatDate(topic.last_post_time) }}</td>
</tr> </tr>
</tbody> </tbody>

View File

@@ -13,3 +13,4 @@ createApp(App)
config: { id: "G-YF11ZH9SYD" }, config: { id: "G-YF11ZH9SYD" },
}) })
.mount("#app"); .mount("#app");