feat(api): list tasks for template

This commit is contained in:
Denis Gukov 2020-11-02 15:57:46 +05:00
parent 8b88446054
commit ff82c40d23
2 changed files with 12 additions and 4 deletions

View File

@ -174,6 +174,8 @@ func Route() *mux.Router {
projectTmplManagement.HandleFunc("/{template_id}", projects.UpdateTemplate).Methods("PUT")
projectTmplManagement.HandleFunc("/{template_id}", projects.RemoveTemplate).Methods("DELETE")
projectTmplManagement.HandleFunc("/{template_id}", projects.GetTemplate).Methods("GET")
projectTmplManagement.HandleFunc("/{template_id}/tasks", tasks.GetAllTasks).Methods("GET")
projectTmplManagement.HandleFunc("/{template_id}/tasks/last", tasks.GetLastTasks).Methods("GET")
projectTaskManagement := projectUserAPI.PathPrefix("/tasks").Subrouter()
projectTaskManagement.Use(tasks.GetTaskMiddleware)

View File

@ -57,11 +57,17 @@ func GetTasksList(w http.ResponseWriter, r *http.Request, limit uint64) {
project := context.Get(r, "project").(db.Project)
q := squirrel.Select("task.*, tpl.playbook as tpl_playbook, user.name as user_name, tpl.alias as tpl_alias").
From(taskTypeID).
From("task").
Join("project__template as tpl on task.template_id=tpl.id").
LeftJoin("user on task.user_id=user.id").
Where("tpl.project_id=?", project.ID).
OrderBy("task.created desc")
LeftJoin("user on task.user_id=user.id");
if tpl := context.Get(r, "template"); tpl != nil {
q = q.Where("tpl.project_id=? AND task.template_id=?", project.ID, tpl.(db.Template).ID)
} else {
q = q.Where("tpl.project_id=?", project.ID)
}
q = q.OrderBy("task.created desc, id desc")
if limit > 0 {
q = q.Limit(limit)