diff --git a/Featurecreep.md b/Featurecreep.md index 75e1380d0d4..6ea6189c4e0 100644 --- a/Featurecreep.md +++ b/Featurecreep.md @@ -163,7 +163,7 @@ Teams sind global, d.h. Ein Team kann mehrere Namespaces verwalten. * [ ] Labels * [ ] Priorities * [ ] Assignees -* [ ] Subtasks +* [x] Subtasks * [ ] Attachments * [x] Repeating tasks * [x] Tagesübersicht ("Was ist heute/diese Woche due?") -> Machen letztenendes die Clients, wir brauchen nur nen endpoint, der alle tasks auskotzt, der Client macht dann die Sortierung. diff --git a/README.md b/README.md index 9ca99933bf0..e59f42f3c48 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Try it under [try.vikunja.io](https://try.vikunja.io)! * [ ] Labels for todo lists and tasks * [ ] Prioritize tasks * [ ] Assign users to tasks -* [ ] Subtasks +* [x] Subtasks * [x] Repeating tasks * [ ] Attachments on tasks * [ ] Get all tasks for you per interval (day/month/period) diff --git a/REST-Tests/auth.http b/REST-Tests/auth.http index 55e36ac0618..2744c0dee87 100644 --- a/REST-Tests/auth.http +++ b/REST-Tests/auth.http @@ -3,8 +3,8 @@ POST http://localhost:8080/api/v1/login Content-Type: application/json { - "username": "user5", - "password": "1234" + "username": "user", + "password": "12345" } > {% client.global.set("auth_token", response.body.token); %} diff --git a/REST-Tests/lists.http b/REST-Tests/lists.http index dcfdc62db76..8dae649a659 100644 --- a/REST-Tests/lists.http +++ b/REST-Tests/lists.http @@ -22,11 +22,15 @@ Content-Type: application/json ### # Add a new item -PUT http://localhost:8080/api/v1/lists/14 +PUT http://localhost:8080/api/v1/lists/15 Authorization: Bearer {{auth_token}} Content-Type: application/json -{"text": "test2", "description": "Schinken"} +{ + "text": "this is a subtask 2", + "description": "Schinken", + "parentTaskID": 34 +} ### diff --git a/docs/docs.go b/docs/docs.go index 716b1bdbdc9..57fb7e8b845 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1,6 +1,6 @@ // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT // This file was generated by swaggo/swag at -// 2018-12-01 02:54:44.444779863 +0100 CET m=+0.257728460 +// 2018-12-01 03:00:26.732522708 +0100 CET m=+0.097387323 package docs @@ -2877,6 +2877,9 @@ var doc = `{ "listID": { "type": "integer" }, + "parentTaskID": { + "type": "integer" + }, "reminderDates": { "type": "array", "items": { @@ -2886,6 +2889,12 @@ var doc = `{ "repeatAfter": { "type": "integer" }, + "subtasks": { + "type": "array", + "items": { + "$ref": "#/definitions/models.ListTask" + } + }, "text": { "type": "string" }, diff --git a/docs/swagger/swagger.json b/docs/swagger/swagger.json index d062d637c64..e416f5b710a 100644 --- a/docs/swagger/swagger.json +++ b/docs/swagger/swagger.json @@ -2864,6 +2864,9 @@ "listID": { "type": "integer" }, + "parentTaskID": { + "type": "integer" + }, "reminderDates": { "type": "array", "items": { @@ -2873,6 +2876,12 @@ "repeatAfter": { "type": "integer" }, + "subtasks": { + "type": "array", + "items": { + "$ref": "#/definitions/models.ListTask" + } + }, "text": { "type": "string" }, diff --git a/docs/swagger/swagger.yaml b/docs/swagger/swagger.yaml index 8615735305e..99ad22ca65d 100644 --- a/docs/swagger/swagger.yaml +++ b/docs/swagger/swagger.yaml @@ -53,12 +53,18 @@ definitions: type: integer listID: type: integer + parentTaskID: + type: integer reminderDates: items: type: integer type: array repeatAfter: type: integer + subtasks: + items: + $ref: '#/definitions/models.ListTask' + type: array text: type: string updated: diff --git a/pkg/models/list_tasks.go b/pkg/models/list_tasks.go index 031d13e5f47..a2cc26d6fce 100644 --- a/pkg/models/list_tasks.go +++ b/pkg/models/list_tasks.go @@ -29,6 +29,9 @@ type ListTask struct { CreatedByID int64 `xorm:"int(11)" json:"-"` // ID of the user who put that task on the list ListID int64 `xorm:"int(11) INDEX" json:"listID" param:"list"` RepeatAfter int64 `xorm:"int(11) INDEX" json:"repeatAfter"` + ParentTaskID int64 `xorm:"int(11) INDEX" json:"parentTaskID"` + + Subtasks []*ListTask `xorm:"-" json:"subtasks"` Created int64 `xorm:"created" json:"created"` Updated int64 `xorm:"updated" json:"updated"` @@ -56,6 +59,9 @@ func GetTasksByListID(listID int64) (tasks []*ListTask, err error) { return } + // make a map so we can put in subtasks more easily + taskMap := make(map[int64]*ListTask) + // Get all users and put them into the array var userIDs []int64 for _, i := range tasks { @@ -70,6 +76,8 @@ func GetTasksByListID(listID int64) (tasks []*ListTask, err error) { if !found { userIDs = append(userIDs, i.CreatedByID) } + + taskMap[i.ID] = i } var users []User @@ -78,16 +86,28 @@ func GetTasksByListID(listID int64) (tasks []*ListTask, err error) { return } - for in, task := range tasks { + // Add all user objects to the appropriate tasks + for _, task := range taskMap { + + // Make created by user objects for _, u := range users { if task.CreatedByID == u.ID { - tasks[in].CreatedBy = u + taskMap[task.ID].CreatedBy = u break } } - // obsfucate the user password - tasks[in].CreatedBy.Password = "" + // Reorder all subtasks + if task.ParentTaskID != 0 { + taskMap[task.ParentTaskID].Subtasks = append(taskMap[task.ParentTaskID].Subtasks, task) + delete(taskMap, task.ID) + } + } + + // make a complete slice from the map + tasks = []*ListTask{} + for _, t := range taskMap { + tasks = append(tasks, t) } return