Add getting tasks from a saved filter
This commit is contained in:
parent
ca857b1f5a
commit
5988bc508f
|
@ -51,6 +51,17 @@ func (s *SavedFilter) TableName() string {
|
||||||
return "saved_filters"
|
return "saved_filters"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SavedFilter) getTaskCollection() *TaskCollection {
|
||||||
|
// We're resetting the listID to return tasks from all lists
|
||||||
|
s.Filters.ListID = 0
|
||||||
|
return s.Filters
|
||||||
|
}
|
||||||
|
|
||||||
|
func getSavedFilterIDFromListID(listID int64) int64 {
|
||||||
|
// We get the id of the saved filter by multiplying the ListID with -1 and subtracting one
|
||||||
|
return listID*-1 - 1
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SavedFilter) Create(auth web.Auth) error {
|
func (s *SavedFilter) Create(auth web.Auth) error {
|
||||||
s.OwnerID = auth.GetID()
|
s.OwnerID = auth.GetID()
|
||||||
_, err := x.Insert(s)
|
_, err := x.Insert(s)
|
||||||
|
@ -69,7 +80,10 @@ func (s *SavedFilter) ReadOne() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadAll returns all tasks of a saved filter.
|
||||||
|
// Since saved filters are shown in a pseudo-namespace, we can use this function to get all tasks
|
||||||
func (s *SavedFilter) ReadAll(auth web.Auth, search string, page int, perPage int) (result interface{}, resultCount int, numberOfTotalItems int64, err error) {
|
func (s *SavedFilter) ReadAll(auth web.Auth, search string, page int, perPage int) (result interface{}, resultCount int, numberOfTotalItems int64, err error) {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SavedFilter) Update() error {
|
func (s *SavedFilter) Update() error {
|
||||||
|
|
|
@ -102,6 +102,17 @@ func validateTaskField(fieldName string) error {
|
||||||
// @Router /lists/{listID}/tasks [get]
|
// @Router /lists/{listID}/tasks [get]
|
||||||
func (tf *TaskCollection) ReadAll(a web.Auth, search string, page int, perPage int) (result interface{}, resultCount int, totalItems int64, err error) {
|
func (tf *TaskCollection) ReadAll(a web.Auth, search string, page int, perPage int) (result interface{}, resultCount int, totalItems int64, err error) {
|
||||||
|
|
||||||
|
// If the list id is < -1 this means we're dealing with a saved filter - in that case we get and populate the filter
|
||||||
|
// -1 is the favorites list which works as intended
|
||||||
|
if tf.ListID < -1 {
|
||||||
|
s, err := getSavedFilterSimpleByID(getSavedFilterIDFromListID(tf.ListID))
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.getTaskCollection().ReadAll(a, search, page, perPage)
|
||||||
|
}
|
||||||
|
|
||||||
if len(tf.SortByArr) > 0 {
|
if len(tf.SortByArr) > 0 {
|
||||||
tf.SortBy = append(tf.SortBy, tf.SortByArr...)
|
tf.SortBy = append(tf.SortBy, tf.SortByArr...)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue