Added ReadOne() for tasks
continuous-integration/drone/pr Build is failing
Details
continuous-integration/drone/pr Build is failing
Details
This commit is contained in:
parent
ed4c17892e
commit
4d9e3c60fe
|
@ -330,9 +330,18 @@ type LabelTaskBulk struct {
|
|||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /tasks/{taskID}/labels/bulk [post]
|
||||
func (ltb *LabelTaskBulk) Create(a web.Auth) (err error) {
|
||||
task, err := GetTaskByID(ltb.TaskID)
|
||||
task, err := GetTaskByIDSimple(ltb.TaskID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
labels, _, _, err := getLabelsByTaskIDs(&LabelByTaskIDsOptions{
|
||||
TaskIDs: []int64{ltb.TaskID},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, l := range labels {
|
||||
task.Labels = append(task.Labels, &l.Label)
|
||||
}
|
||||
return task.updateTaskLabels(a, ltb.Labels)
|
||||
}
|
||||
|
|
|
@ -284,9 +284,17 @@ type BulkAssignees struct {
|
|||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /tasks/{taskID}/assignees/bulk [post]
|
||||
func (ba *BulkAssignees) Create(a web.Auth) (err error) {
|
||||
task, err := GetTaskByID(ba.TaskID) // We need to use the full method here because we need all current assignees.
|
||||
task, err := GetTaskByIDSimple(ba.TaskID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
assignees, err := getRawTaskAssigneesForTasks([]int64{task.ID})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, a := range assignees {
|
||||
task.Assignees = append(task.Assignees, &a.User)
|
||||
}
|
||||
|
||||
return task.updateTaskAssignees(ba.Assignees)
|
||||
}
|
||||
|
|
|
@ -339,44 +339,6 @@ func GetTaskSimple(t *Task) (task Task, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// GetTaskByID returns all tasks a list has
|
||||
func GetTaskByID(listTaskID int64) (listTask Task, err error) {
|
||||
listTask, err = GetTaskByIDSimple(listTaskID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
u, err := GetUserByID(listTask.CreatedByID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
listTask.CreatedBy = u
|
||||
|
||||
// Get assignees
|
||||
taskAssignees, err := getRawTaskAssigneesForTasks([]int64{listTaskID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, u := range taskAssignees {
|
||||
if u != nil {
|
||||
listTask.Assignees = append(listTask.Assignees, &u.User)
|
||||
}
|
||||
}
|
||||
|
||||
// Get task labels
|
||||
taskLabels, _, _, err := getLabelsByTaskIDs(&LabelByTaskIDsOptions{
|
||||
TaskIDs: []int64{listTaskID},
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, label := range taskLabels {
|
||||
listTask.Labels = append(listTask.Labels, &label.Label)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetTasksByIDs returns all tasks for a list of ids
|
||||
func (bt *BulkTask) GetTasksByIDs() (err error) {
|
||||
for _, id := range bt.IDs {
|
||||
|
@ -636,7 +598,7 @@ func (t *Task) Create(a web.Auth) (err error) {
|
|||
// @Router /tasks/{id} [post]
|
||||
func (t *Task) Update() (err error) {
|
||||
// Check if the task exists
|
||||
ot, err := GetTaskByID(t.ID)
|
||||
ot, err := GetTaskByIDSimple(t.ID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -854,12 +816,6 @@ func (t *Task) updateReminders(reminders []int64) (err error) {
|
|||
// @Router /tasks/{id} [delete]
|
||||
func (t *Task) Delete() (err error) {
|
||||
|
||||
// Check if it exists
|
||||
_, err = GetTaskByID(t.ID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = x.ID(t.ID).Delete(Task{}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -874,3 +830,23 @@ func (t *Task) Delete() (err error) {
|
|||
err = updateListLastUpdated(&List{ID: t.ListID})
|
||||
return
|
||||
}
|
||||
|
||||
func (t *Task) ReadOne() (err error) {
|
||||
|
||||
taskMap := make(map[int64]*Task, 1)
|
||||
*taskMap[t.ID], err = GetTaskByIDSimple(t.ID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
tasks, err := addMoreInfoToTasks(taskMap)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if len(tasks) == 0 {
|
||||
return ErrTaskDoesNotExist{t.ID}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue