Task Attachments #104

Merged
konrad merged 63 commits from feature/attachments into master 2019-10-16 20:52:31 +00:00
1 changed files with 33 additions and 0 deletions
Showing only changes of commit dcaece9aef - Show all commits

View File

@ -17,6 +17,7 @@
package models
import (
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/metrics"
"code.vikunja.io/api/pkg/utils"
"code.vikunja.io/web"
@ -71,6 +72,9 @@ type Task struct {
// All related tasks, grouped by their relation kind
RelatedTasks RelatedTaskMap `xorm:"-" json:"related_tasks"`
// All attachments this task has
Attachments []*TaskAttachment `xorm:"-" json:"attachments"`
// A unix timestamp when this task was created. You cannot change this value.
Created int64 `xorm:"created not null" json:"created"`
// A unix timestamp when this task was last updated. You cannot change this value.
@ -409,6 +413,28 @@ func addMoreInfoToTasks(taskMap map[int64]*Task) (tasks []*Task, err error) {
}
}
// Get task attachments
attachments := []*TaskAttachment{}
err = x.
In("task_id", taskIDs).
Find(&attachments)
if err != nil {
return nil, err
}
fileIDs := []int64{}
for _, a := range attachments {
userIDs = append(userIDs, a.CreatedByID)
fileIDs = append(fileIDs, a.FileID)
}
// Get all files
fs := make(map[int64]*files.File)
err = x.In("id", fileIDs).Find(&fs)
if err != nil {
return
}
// Get all users of a task
// aka the ones who created a task
users := make(map[int64]*User)
@ -422,6 +448,13 @@ func addMoreInfoToTasks(taskMap map[int64]*Task) (tasks []*Task, err error) {
u.Email = ""
}
// Put the users and files in task attachments
for _, a := range attachments {
a.CreatedBy = users[a.CreatedByID]
a.File = fs[a.FileID]
taskMap[a.TaskID].Attachments = append(taskMap[a.TaskID].Attachments, a)
}
// Get all reminders and put them in a map to have it easier later
reminders := []*TaskReminder{}
err = x.Table("task_reminders").In("task_id", taskIDs).Find(&reminders)