diff --git a/Featurecreep.md b/Featurecreep.md index 2f8137679..32c342570 100644 --- a/Featurecreep.md +++ b/Featurecreep.md @@ -99,8 +99,8 @@ Sorry for some of them being in German, I'll tranlate them at some point. * [x] Timeline/Calendar view -> Dazu tasks die in einem Bestimmten Bereich due sind, macht dann das Frontend * [x] Tasks innerhalb eines definierbarem Bereich, sollte aber trotzdem der server machen, so à la "Gib mir alles für diesen Monat" * [x] Bulk-edit -> Transactions +* [x] Assignees * [ ] Labels -* [ ] Assignees * [ ] Attachments * [ ] Task-Templates innerhalb namespaces und Listen (-> Mehrere, die auswählbar sind) * [ ] Ein Task muss von mehreren Assignees abgehakt werden bis er als done markiert wird diff --git a/REST-Tests/auth.http b/REST-Tests/auth.http index 5c7e34281..33c7c7a67 100644 --- a/REST-Tests/auth.http +++ b/REST-Tests/auth.http @@ -15,7 +15,7 @@ POST http://localhost:8080/api/v1/register Content-Type: application/json { - "username": "user5", + "username": "user", "password": "1234", "email": "5@knt.li" } diff --git a/REST-Tests/lists.http b/REST-Tests/lists.http index 7c05e80e7..c5c7a0fdb 100644 --- a/REST-Tests/lists.http +++ b/REST-Tests/lists.http @@ -5,13 +5,13 @@ Authorization: Bearer {{auth_token}} ### # Get one list -GET http://localhost:8080/api/v1/lists/1163 +GET http://localhost:8080/api/v1/lists/1172 Authorization: Bearer {{auth_token}} ### # Add a new list -PUT http://localhost:8080/api/v1/namespaces/6/lists +PUT http://localhost:8080/api/v1/namespaces/35/lists Authorization: Bearer {{auth_token}} Content-Type: application/json @@ -22,14 +22,13 @@ Content-Type: application/json ### # Add a new item -PUT http://localhost:8080/api/v1/lists/15 +PUT http://localhost:8080/api/v1/lists/1172 Authorization: Bearer {{auth_token}} Content-Type: application/json { - "text": "this is a subtask 2", - "description": "Schinken", - "parentTaskID": 34 + "text": "Task", + "description": "Schinken" } ### diff --git a/pkg/models/list_tasks.go b/pkg/models/list_tasks.go index 37c1a2544..c0d172b76 100644 --- a/pkg/models/list_tasks.go +++ b/pkg/models/list_tasks.go @@ -36,6 +36,7 @@ type ListTask struct { Priority int64 `xorm:"int(11)" json:"priority"` StartDateUnix int64 `xorm:"int(11) INDEX" json:"startDate"` EndDateUnix int64 `xorm:"int(11) INDEX" json:"endDate"` + Assignees []*User `xorm:"-" json:"assignees"` Sorting string `xorm:"-" json:"-" param:"sort"` // Parameter to sort by StartDateSortUnix int64 `xorm:"-" json:"-" param:"startdatefilter"` @@ -57,6 +58,17 @@ func (ListTask) TableName() string { return "tasks" } +// ListTaskAssginee represents an assignment of a user to a task +type ListTaskAssginee struct { + ID int64 `xorm:"int(11) autoincr not null unique pk"` + TaskID int64 `xorm:"int(11) not null"` + UserID int64 `xorm:"int(11) not null"` +} + +func (ListTaskAssginee) TableName() string { + return "task_assignees" +} + // GetTasksByListID gets all todotasks for a list func GetTasksByListID(listID int64) (tasks []*ListTask, err error) { err = x.Where("list_id = ?", listID).Find(&tasks) @@ -72,9 +84,11 @@ func GetTasksByListID(listID int64) (tasks []*ListTask, err error) { // make a map so we can put in subtasks more easily taskMap := make(map[int64]*ListTask, len(tasks)) - // Get all users and put them into the array + // Get all users & task ids and put them into the array var userIDs []int64 + var taskIDs []int64 for _, i := range tasks { + taskIDs = append(taskIDs, i.ID) found := false for _, u := range userIDs { if i.CreatedByID == u { @@ -90,6 +104,24 @@ func GetTasksByListID(listID int64) (tasks []*ListTask, err error) { taskMap[i.ID] = i } + // Get all assignee users + type ListTaskAssigneeWithUser struct { + TaskID int64 + User `xorm:"extends"` + } + taskAssignees := []*ListTaskAssigneeWithUser{nil} + err = x.Table("task_assignees"). + In("task_id", taskIDs). + Join("INNER", "users", "task_assignees.user_id = users.id"). + Find(&taskAssignees) + // Make a map with tasks as key + taskAssigneesMap := make(map[int64][]*User) + for _, a := range taskAssignees { + if a != nil { + taskAssigneesMap[a.TaskID] = append(taskAssigneesMap[a.TaskID], &a.User) + } + } + var users []User err = x.In("id", userIDs).Find(&users) if err != nil { @@ -107,6 +139,9 @@ func GetTasksByListID(listID int64) (tasks []*ListTask, err error) { } } + // Put the assignees in + taskMap[task.ID].Assignees = taskAssigneesMap[task.ID] + // Reorder all subtasks if task.ParentTaskID != 0 { taskMap[task.ParentTaskID].Subtasks = append(taskMap[task.ParentTaskID].Subtasks, task) diff --git a/pkg/models/models.go b/pkg/models/models.go index 433e119df..5b95173c4 100644 --- a/pkg/models/models.go +++ b/pkg/models/models.go @@ -68,6 +68,7 @@ func init() { new(Namespace), new(ListUser), new(NamespaceUser), + new(ListTaskAssginee), ) tablesWithPointer = append(tables, @@ -81,6 +82,7 @@ func init() { &Namespace{}, &ListUser{}, &NamespaceUser{}, + &ListTaskAssginee{}, ) }