chore: refactor task resource creation
All checks were successful
continuous-integration/drone/pr Build is passing

This commit is contained in:
JD
2024-09-27 21:25:29 -04:00
parent 4b05986186
commit 36102f7b57

View File

@ -92,12 +92,11 @@ func (vcls *VikunjaCaldavProjectStorage) GetResources(rpath string, withChildren
}
r := data.NewResource(rpath, &rr)
r.Name = vcls.project.Title
// If the request is withChildren (Depth: 1), we need to return all tasks of the project
if withChildren {
var resources []data.Resource
resources = append(resources, r)
resources := []data.Resource{r}
// Check if there are tasks to iterate over
if vcls.project.Tasks != nil {
for i := range vcls.project.Tasks {
@ -106,9 +105,7 @@ func (vcls *VikunjaCaldavProjectStorage) GetResources(rpath string, withChildren
task: &vcls.project.Tasks[i].Task,
isCollection: false,
}
taskResourceInstance := data.NewResource(getTaskURL(&vcls.project.Tasks[i].Task), &taskResource)
taskResourceInstance.Name = vcls.project.Tasks[i].Title
resources = append(resources, taskResourceInstance)
addTaskResource(&vcls.project.Tasks[i].Task, &taskResource, &resources)
}
}
return resources, nil
@ -184,9 +181,7 @@ func (vcls *VikunjaCaldavProjectStorage) GetResourcesByList(rpaths []string) (re
rr := VikunjaProjectResourceAdapter{
task: t,
}
r := data.NewResource(getTaskURL(t), &rr)
r.Name = t.Title
resources = append(resources, r)
addTaskResource(t, &rr, &resources)
}
return
@ -692,3 +687,9 @@ func (vcls *VikunjaCaldavProjectStorage) getProjectRessource(isCollection bool)
return
}
func addTaskResource(task *models.Task, rr *VikunjaProjectResourceAdapter, resources *[]data.Resource) {
taskResourceInstance := data.NewResource(getTaskURL(task), rr)
taskResourceInstance.Name = task.Title
*resources = append(*resources, taskResourceInstance)
}