Add top DMs route and handlers

Этот коммит содержится в:
Shivashis Padhi
2022-06-22 16:11:40 +05:30
родитель 56cf4b4ee7
Коммит 0ab2189941
11 изменённых файлов: 226 добавлений и 0 удалений

Просмотреть файл

@@ -97,6 +97,18 @@ type DurationPostCount struct {
PostCount int `db:"postcount"`
}
// Top DMs
type TopDM struct {
MessageCount int64 `json:"post_count"`
Participants string `json:"-"`
SecondParticipant string `json:"second_participant"`
}
type TopDMList struct {
InsightsListData
Items []*TopDM `json:"items"`
}
func TimeRangeToNumberDays(timeRange string) int {
var n int
switch timeRange {
@@ -243,3 +255,17 @@ func GetTopThreadListWithPagination(threads []*TopThread, limit int) *TopThreadL
return &TopThreadList{InsightsListData: InsightsListData{HasNext: hasNext}, Items: threads}
}
// GetTopDMListWithPagination adds a rank to each item in the given list of TopDM and checks if there is
// another page that can be fetched based on the given limit and offset. The given list of TopDM is assumed to be
// sorted by MessageCount(score). Returns a TopDMList.
func GetTopDMListWithPagination(dms []*TopDM, limit int) *TopDMList {
// Add pagination support
var hasNext bool
if (limit != 0) && (len(dms) == limit+1) {
hasNext = true
dms = dms[:len(dms)-1]
}
return &TopDMList{InsightsListData: InsightsListData{HasNext: hasNext}, Items: dms}
}