package command import ( "fmt" "time" "github.com/google/uuid" "go-mod.ewintr.nl/planner/item" ) type StoreParams struct { Title string Date item.Date Time item.Time Duration time.Duration Recurrer item.Recurrer } type Store struct { deps Dependencies params StoreParams } func NewStore(deps Dependencies, params StoreParams) *Store { return &Store{ deps: deps, params: params, } } func (store *Store) Do() error { tsk := item.Task{ ID: uuid.New().String(), Date: store.params.Date, Recurrer: store.params.Recurrer, TaskBody: item.TaskBody{ Title: store.params.Title, Time: store.params.Time, Duration: store.params.Duration, }, } if tsk.Recurrer != nil { tsk.RecurNext = tsk.Recurrer.First() } // TODO check valid if err := store.deps.TaskRepo.Store(tsk); err != nil { return fmt.Errorf("could not store event: %v", err) } localID, err := store.deps.LocalIDRepo.Next() if err != nil { return fmt.Errorf("could not create next local id: %v", err) } if err := store.deps.LocalIDRepo.Store(tsk.ID, localID); err != nil { return fmt.Errorf("could not store local id: %v", err) } it, err := tsk.Item() if err != nil { return fmt.Errorf("could not convert event to sync item: %v", err) } if err := store.deps.SyncRepo.Store(it); err != nil { return fmt.Errorf("could not store sync item: %v", err) } return nil }