updated docs for pagination

This commit is contained in:
konrad 2018-11-09 17:28:59 +01:00
parent d232836423
commit ad74d24ee2
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B

View file

@ -14,7 +14,7 @@ The interface is defined as followed:
type CRUDable interface {
Create(*User) error
ReadOne() error
ReadAll(*User) (interface{}, error)
ReadAll(*User, int) (interface{}, error)
Update() 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
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
This interface defines methods to check for rights on structs. They accept a `User` as parameter and usually return a `bool`.