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:
parent
7fe9e6d3f6
commit
1555081939
2 changed files with 26 additions and 6 deletions
|
@ -317,8 +317,9 @@ func (vcls *VikunjaCaldavListStorage) DeleteResource(rpath string) error {
|
|||
|
||||
// VikunjaListResourceAdapter holds the actual resource
|
||||
type VikunjaListResourceAdapter struct {
|
||||
list *models.List
|
||||
task *models.Task
|
||||
list *models.List
|
||||
listTasks []*models.Task
|
||||
task *models.Task
|
||||
|
||||
isPrincipal 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)
|
||||
func (vlra *VikunjaListResourceAdapter) GetContent() string {
|
||||
if vlra.list != nil && vlra.list.Tasks != nil {
|
||||
return getCaldavTodosForTasks(vlra.list)
|
||||
return getCaldavTodosForTasks(vlra.list, vlra.listTasks)
|
||||
}
|
||||
|
||||
if vlra.task != nil {
|
||||
list := models.List{Tasks: []*models.Task{vlra.task}}
|
||||
return getCaldavTodosForTasks(&list)
|
||||
return getCaldavTodosForTasks(&list, list.Tasks)
|
||||
}
|
||||
|
||||
return ""
|
||||
|
@ -397,8 +398,27 @@ func (vcls *VikunjaCaldavListStorage) getListRessource(isCollection bool) (rr Vi
|
|||
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{
|
||||
list: vcls.list,
|
||||
listTasks: listTasks,
|
||||
isCollection: isCollection,
|
||||
}
|
||||
|
||||
|
|
|
@ -26,11 +26,11 @@ import (
|
|||
"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
|
||||
var caldavtodos []*caldav.Todo
|
||||
for _, t := range list.Tasks {
|
||||
for _, t := range listTasks {
|
||||
|
||||
duration := t.EndDate.Sub(t.StartDate)
|
||||
|
||||
|
|
Loading…
Reference in a new issue