2021-07-10 12:30:38 +02:00
|
|
|
package process
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"git.ewintr.nl/gte/internal/storage"
|
2021-07-29 07:01:24 +02:00
|
|
|
"git.ewintr.nl/gte/internal/task"
|
2021-07-10 12:30:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2021-07-29 07:01:24 +02:00
|
|
|
ErrUpdateTask = errors.New("could not update tsk")
|
2021-07-10 12:30:38 +02:00
|
|
|
)
|
|
|
|
|
2021-09-03 10:02:08 +02:00
|
|
|
// Update updates a local task
|
2021-07-10 12:30:38 +02:00
|
|
|
type Update struct {
|
2021-08-20 13:46:56 +02:00
|
|
|
local storage.LocalRepository
|
|
|
|
taskId string
|
2021-08-22 13:29:04 +02:00
|
|
|
update *task.LocalUpdate
|
2021-07-10 12:30:38 +02:00
|
|
|
}
|
|
|
|
|
2021-09-03 10:02:08 +02:00
|
|
|
func NewUpdate(local storage.LocalRepository, taskId string, update *task.LocalUpdate) *Update {
|
2021-07-10 12:30:38 +02:00
|
|
|
return &Update{
|
2021-08-20 13:46:56 +02:00
|
|
|
local: local,
|
|
|
|
taskId: taskId,
|
|
|
|
update: update,
|
2021-07-10 12:30:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *Update) Process() error {
|
2021-07-29 07:01:24 +02:00
|
|
|
tsk, err := u.local.FindById(u.taskId)
|
2021-07-10 12:30:38 +02:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("%w: %v", ErrUpdateTask, err)
|
|
|
|
}
|
2021-08-22 13:29:04 +02:00
|
|
|
tsk.AddUpdate(u.update)
|
2021-09-04 12:20:35 +02:00
|
|
|
if err := u.local.SetLocalUpdate(tsk.Id, tsk.LocalUpdate); err != nil {
|
2021-08-21 20:47:29 +02:00
|
|
|
return fmt.Errorf("%w: %v", ErrUpdateTask, err)
|
|
|
|
}
|
2021-07-10 12:30:38 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|