Subtasks (#28)

This commit is contained in:
konrad 2018-12-01 02:00:57 +00:00 committed by Gitea
parent 007d8ec375
commit 6c5885747b
8 changed files with 59 additions and 11 deletions

View File

@ -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.

View File

@ -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)

View File

@ -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); %}

View File

@ -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
}
###

View File

@ -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"
},

View File

@ -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"
},

View File

@ -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:

View File

@ -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