fetch tasks for caldav lists (#641)

Fix shadowed error

Panic if a TaskCollection.ReadAll does not return []*models.Task

Fetch tasks for caldav lists

Co-authored-by: kolaente <k@knt.li>
Co-authored-by: konrad <konrad@kola-entertainments.de>
Co-authored-by: Martin Giger <martin@humanoids.be>
Reviewed-on: https://kolaente.dev/vikunja/api/pulls/641
Co-Authored-By: freaktechnik <martin@humanoids.be>
Co-Committed-By: freaktechnik <martin@humanoids.be>
This commit is contained in:
freaktechnik 2020-10-18 10:40:50 +00:00 committed by konrad
parent 7fe9e6d3f6
commit 1555081939
2 changed files with 26 additions and 6 deletions

View file

@ -317,8 +317,9 @@ func (vcls *VikunjaCaldavListStorage) DeleteResource(rpath string) error {
// VikunjaListResourceAdapter holds the actual resource // VikunjaListResourceAdapter holds the actual resource
type VikunjaListResourceAdapter struct { type VikunjaListResourceAdapter struct {
list *models.List list *models.List
task *models.Task listTasks []*models.Task
task *models.Task
isPrincipal bool isPrincipal bool
isCollection bool isCollection bool
@ -354,12 +355,12 @@ func (vlra *VikunjaListResourceAdapter) CalculateEtag() string {
// GetContent returns the content string of a resource (a task in our case) // GetContent returns the content string of a resource (a task in our case)
func (vlra *VikunjaListResourceAdapter) GetContent() string { func (vlra *VikunjaListResourceAdapter) GetContent() string {
if vlra.list != nil && vlra.list.Tasks != nil { if vlra.list != nil && vlra.list.Tasks != nil {
return getCaldavTodosForTasks(vlra.list) return getCaldavTodosForTasks(vlra.list, vlra.listTasks)
} }
if vlra.task != nil { if vlra.task != nil {
list := models.List{Tasks: []*models.Task{vlra.task}} list := models.List{Tasks: []*models.Task{vlra.task}}
return getCaldavTodosForTasks(&list) return getCaldavTodosForTasks(&list, list.Tasks)
} }
return "" return ""
@ -397,8 +398,27 @@ func (vcls *VikunjaCaldavListStorage) getListRessource(isCollection bool) (rr Vi
return return
} }
listTasks := vcls.list.Tasks
if listTasks == nil {
tk := models.TaskCollection{
ListID: vcls.list.ID,
}
iface, _, _, err := tk.ReadAll(vcls.user, "", 1, 1000)
if err != nil {
return rr, err
}
tasks, ok := iface.([]*models.Task)
if !ok {
panic("Tasks returned from TaskCollection.ReadAll are not []*models.Task!")
}
listTasks = tasks
vcls.list.Tasks = tasks
}
rr = VikunjaListResourceAdapter{ rr = VikunjaListResourceAdapter{
list: vcls.list, list: vcls.list,
listTasks: listTasks,
isCollection: isCollection, isCollection: isCollection,
} }

View file

@ -26,11 +26,11 @@ import (
"github.com/laurent22/ical-go" "github.com/laurent22/ical-go"
) )
func getCaldavTodosForTasks(list *models.List) string { func getCaldavTodosForTasks(list *models.List, listTasks []*models.Task) string {
// Make caldav todos from Vikunja todos // Make caldav todos from Vikunja todos
var caldavtodos []*caldav.Todo var caldavtodos []*caldav.Todo
for _, t := range list.Tasks { for _, t := range listTasks {
duration := t.EndDate.Sub(t.StartDate) duration := t.EndDate.Sub(t.StartDate)