1
0

Implemented search for everything (#17)

This commit is contained in:
konrad
2018-11-09 17:33:06 +00:00
committed by Gitea
parent ad74d24ee2
commit d3de658882
18 changed files with 49 additions and 32 deletions

View File

@ -14,7 +14,7 @@ The interface is defined as followed:
type CRUDable interface {
Create(*User) error
ReadOne() error
ReadAll(*User, int) (interface{}, error)
ReadAll(string, *User, int) (interface{}, error)
Update() error
Delete() error
}
@ -38,7 +38,7 @@ make an array of a set type (If you know a way to do this, don't hesitate to dro
### Pagination
When using the `ReadAll`-method, the second parameter contains the requested page. Your function should return only the number of results
When using the `ReadAll`-method, the third 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
@ -49,6 +49,14 @@ lists := []List{}
err := x.Limit(getLimitFromPageIndex(pageIndex)).Find(&lists)
```
### Search
When using the `ReadAll`-method, the first parameter is a search term which should be used to search items of your struct. You define the critera.
Users can then pass the `?s=something` parameter to the url to search.
As the logic for "give me everything" and "give me everything where the name contains 'something'" is mostly the same, we made the decision to design the function like this, in order to keep the places with mostly the same logic as few as possible. Also just adding `?s=query` to the url one already knows and uses is a lot more convenient.
## Rights
This interface defines methods to check for rights on structs. They accept a `User` as parameter and usually return a `bool`.