diff --git a/database.go b/database.go index a98b46b..2fff90b 100644 --- a/database.go +++ b/database.go @@ -41,7 +41,7 @@ func GetBook(coll *mgo.Collection, query bson.M, r ...int) (books []Book, num in start = r[1] } } - q := coll.Find(query) + q := coll.Find(query).Sort("-_id") num, err = q.Count() if err != nil { return diff --git a/search.go b/search.go index af5d606..b245e98 100644 --- a/search.go +++ b/search.go @@ -50,7 +50,7 @@ func searchHandler(coll *mgo.Collection) func(http.ResponseWriter, *http.Request page = 0 } } - res, num, _ := GetBook(coll, buildQuery(req), SEARCH_ITEMS_PAGE, page) + res, num, _ := GetBook(coll, buildQuery(req), SEARCH_ITEMS_PAGE, page*SEARCH_ITEMS_PAGE) var data searchData data.S = GetStatus(w, r) diff --git a/trantor.go b/trantor.go index 5b2434c..1f4db10 100644 --- a/trantor.go +++ b/trantor.go @@ -103,11 +103,7 @@ func indexHandler(coll *mgo.Collection) func(http.ResponseWriter, *http.Request) data.S = GetStatus(w, r) data.S.Home = true - data.Count, _ = coll.Count() - coll.Find(bson.M{}).Sort("-_id").Limit(6).All(&data.Books) - for i, b := range data.Books { - data.Books[i].Id = bson.ObjectId(b.Id).Hex() - } + data.Books, data.Count, _ = GetBook(coll, bson.M{}, 6) loadTemplate(w, "index", data) } }