From 2096fc52740a12200b62f743099e3729486ef013 Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 14 Mar 2024 09:47:42 +0100 Subject: [PATCH] feat(views): return tasks in a view --- pkg/models/task_collection.go | 15 +++++++++++++-- pkg/routes/routes.go | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/models/task_collection.go b/pkg/models/task_collection.go index 745369d24..78709f535 100644 --- a/pkg/models/task_collection.go +++ b/pkg/models/task_collection.go @@ -24,7 +24,8 @@ import ( // TaskCollection is a struct used to hold filter details and not clutter the Task struct with information not related to actual tasks. type TaskCollection struct { - ProjectID int64 `param:"project" json:"-"` + ProjectID int64 `param:"project" json:"-"` + ProjectViewID int64 `param:"view" json:"-"` // The query parameter to sort by. This is for ex. done, priority, etc. SortBy []string `query:"sort_by" json:"sort_by"` @@ -120,6 +121,7 @@ func getTaskFilterOptsFromCollection(tf *TaskCollection) (opts *taskSearchOption // @Accept json // @Produce json // @Param id path int true "The project ID." +// @Param view path int true "The project view ID." // @Param page query int false "The page number. Used for pagination. If not provided, the first page of results is returned." // @Param per_page query int false "The maximum number of items per page. Note this parameter is limited by the configured maximum of items per page." // @Param s query string false "Search tasks by task text." @@ -131,7 +133,7 @@ func getTaskFilterOptsFromCollection(tf *TaskCollection) (opts *taskSearchOption // @Security JWTKeyAuth // @Success 200 {array} models.Task "The tasks" // @Failure 500 {object} models.Message "Internal error" -// @Router /projects/{id}/tasks [get] +// @Router /projects/{id}/views/{view}/tasks [get] func (tf *TaskCollection) ReadAll(s *xorm.Session, a web.Auth, search string, page int, perPage int) (result interface{}, resultCount int, totalItems int64, err error) { // If the project id is < -1 this means we're dealing with a saved filter - in that case we get and populate the filter @@ -169,6 +171,15 @@ func (tf *TaskCollection) ReadAll(s *xorm.Session, a web.Auth, search string, pa return sf.getTaskCollection().ReadAll(s, a, search, page, perPage) } + if tf.ProjectViewID != 0 { + view, err := GetProjectViewByID(s, tf.ProjectViewID) + if err != nil { + return nil, 0, 0, err + } + + tf.Filter = view.Filter + } + taskopts, err := getTaskFilterOptsFromCollection(tf) if err != nil { return nil, 0, 0, err diff --git a/pkg/routes/routes.go b/pkg/routes/routes.go index 1936eaf5e..18e05ae2a 100644 --- a/pkg/routes/routes.go +++ b/pkg/routes/routes.go @@ -355,6 +355,7 @@ func registerAPIRoutes(a *echo.Group) { return &models.TaskCollection{} }, } + a.GET("/projects/:project/views/:view/tasks", taskCollectionHandler.ReadAllWeb) a.GET("/projects/:project/tasks", taskCollectionHandler.ReadAllWeb) kanbanBucketHandler := &handler.WebHandler{