package tasks import ( dbtypes "git.andr3h3nriqu3s.com/andr3/fyp/logic/db_types" . "git.andr3h3nriqu3s.com/andr3/fyp/logic/models/utils" . "git.andr3h3nriqu3s.com/andr3/fyp/logic/tasks/utils" . "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils" ) func handleList(handler *Handle) { handler.PostAuth("/tasks/list", 1, func(c *Context) *Error { var err error = nil var requestData struct { ModelId string `json:"model_id"` Page int `json:"page"` } if _err := c.ToJSON(&requestData); _err != nil { return _err } if requestData.ModelId == "" && c.User.UserType < int(dbtypes.User_Admin) { return c.SendJSONStatus(400, "Please provide a model_id") } if requestData.ModelId != "" { _, err := GetBaseModel(c.Db, requestData.ModelId) if err == ModelNotFoundError { return c.SendJSONStatus(404, "Model not found!") } else if err != nil { return c.Error500(err) } } var rows []*Task = nil if requestData.ModelId != "" { rows, err = GetDbMultitple[Task](c, "tasks where model_id=$1 order by created_on desc limit 11 offset $2", requestData.ModelId, requestData.Page * 10) if err != nil { return c.Error500(err) } } else { rows, err = GetDbMultitple[Task](c, "tasks order by created_on desc limit 11 offset $1", requestData.Page * 10) if err != nil { return c.Error500(err) } } max_len := min(11, len(rows)) c.ShowMessage = false return c.SendJSON(struct { TaskList []*Task `json:"task_list"` ShowNext bool `json:"show_next"` } { rows[0:max_len], len(rows) > 10, }) }) }