diff --git a/database.go b/database.go index 0756c30..9844ce9 100644 --- a/database.go +++ b/database.go @@ -117,6 +117,30 @@ func (d *DB) GetBooks(query bson.M, r ...int) (books []Book, num int, err error) return } +/* Get the most visited books + */ +func (d *DB) GetVisitedBooks(num int) (books []Book, err error) { + var q *mgo.Query + q = d.books.Find(bson.M{"active": true}).Sort("-VisitsCount").Limit(num) + err = q.All(&books) + for i, b := range books { + books[i].Id = bson.ObjectId(b.Id).Hex() + } + return +} + +/* Get the most downloaded books + */ +func (d *DB) GetDownloadedBooks(num int) (books []Book, err error) { + var q *mgo.Query + q = d.books.Find(bson.M{"active": true}).Sort("-DownloadCount").Limit(num) + err = q.All(&books) + for i, b := range books { + books[i].Id = bson.ObjectId(b.Id).Hex() + } + return +} + /* Returns: list of books, number found and err */ func (d *DB) GetNewBooks() (books []Book, num int, err error) { diff --git a/templates/index.html b/templates/index.html index e6dd51f..5ebf96c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -2,7 +2,7 @@
Last books added:
+{{.Count}} books
@@ -24,6 +24,46 @@ {{end}} +{{range .Tags}}{{.}} {{end}}