From cebc4f1569b3dba939d2b5be607ca486aff51139 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Tue, 4 Dec 2018 13:26:49 +0100 Subject: [PATCH] Update paging to use pages instead of offset, make page 1-based --- crm/repository/content.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crm/repository/content.go b/crm/repository/content.go index c6f7f121f..38547703c 100644 --- a/crm/repository/content.go +++ b/crm/repository/content.go @@ -67,8 +67,8 @@ func (r *content) FindByID(id uint64) (*types.Content, error) { } func (r *content) Find(moduleID uint64, query string, page int, perPage int) (*FindResponse, error) { - if page < 0 { - page = 0 + if page < 1 { + page = 1 } if perPage <= 0 { perPage = 50 @@ -95,7 +95,7 @@ func (r *content) Find(moduleID uint64, query string, page int, perPage int) (*F sqlWhere := "WHERE module_id=? and deleted_at IS NULL" sqlOrder := "ORDER BY id DESC" - sqlLimit := fmt.Sprintf("LIMIT %d, %d", page, perPage) + sqlLimit := fmt.Sprintf("LIMIT %d, %d", (page-1)*perPage, perPage) switch true { case query != "":