added share list page
This commit is contained in:
@@ -3,6 +3,7 @@ package database
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"pool-stats/models"
|
||||
"time"
|
||||
|
||||
"github.com/ostafen/clover/v2"
|
||||
@@ -76,3 +77,25 @@ func PrintAllHashes(db *clover.DB) {
|
||||
fmt.Println(hash)
|
||||
}
|
||||
}
|
||||
|
||||
func ListShares(db *clover.DB, offset int, count int) []models.ShareLog {
|
||||
results, err := db.FindAll(
|
||||
c.NewQuery(CollectionName).
|
||||
Sort(c.SortOption{Field: "CreateDate", Direction: -1}).
|
||||
Skip(offset).
|
||||
Limit(count),
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("failed to list shares: %v", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
shareLogs := make([]models.ShareLog, len(results))
|
||||
for idx, doc := range results {
|
||||
var shareLog models.ShareLog
|
||||
doc.Unmarshal(&shareLog)
|
||||
shareLogs[idx] = shareLog
|
||||
}
|
||||
|
||||
return shareLogs
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user