updated docs for pagination

This commit is contained in:
konrad 2018-11-09 17:28:59 +01:00
parent d232836423
commit ad74d24ee2
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B

View File

@ -14,7 +14,7 @@ The interface is defined as followed:
type CRUDable interface { type CRUDable interface {
Create(*User) error Create(*User) error
ReadOne() error ReadOne() error
ReadAll(*User) (interface{}, error) ReadAll(*User, int) (interface{}, error)
Update() error Update() error
Delete() error Delete() error
} }
@ -36,6 +36,19 @@ All functions should behave like this, if they create or update something, they
instance. The only exception is `ReadAll()` which returns an interface. Usually this is an array, because, well you cannot instance. The only exception is `ReadAll()` which returns an interface. Usually this is an array, because, well you cannot
make an array of a set type (If you know a way to do this, don't hesitate to drop me a message). make an array of a set type (If you know a way to do this, don't hesitate to drop me a message).
### Pagination
When using the `ReadAll`-method, the second parameter contains the requested page. Your function should return only the number of results
corresponding to that page. The number of items per page is definied in the config as `service.pagecount` (Get it with `viper.GetInt("service.pagecount")`).
These can be calculated in combination with a helper function, `getLimitFromPageIndex(pageIndex)` which returns
SQL-needed `limit` (max-length) and `offset` parameters. You can feed this function directly into xorm's `Limit`-Function like so:
```go
lists := []List{}
err := x.Limit(getLimitFromPageIndex(pageIndex)).Find(&lists)
```
## Rights ## Rights
This interface defines methods to check for rights on structs. They accept a `User` as parameter and usually return a `bool`. This interface defines methods to check for rights on structs. They accept a `User` as parameter and usually return a `bool`.