planner/plan/command/store.go

51 lines
992 B
Go
Raw Normal View History

2024-12-27 11:20:32 +01:00
package command
import (
"fmt"
"time"
"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 {
2024-12-27 11:27:59 +01:00
task item.Task
2024-12-27 11:20:32 +01:00
}
2024-12-27 11:27:59 +01:00
func NewStore(task item.Task) *Store {
2024-12-27 11:20:32 +01:00
return &Store{
2024-12-27 11:27:59 +01:00
task: task,
2024-12-27 11:20:32 +01:00
}
}
2024-12-27 11:27:59 +01:00
func (store *Store) Do(deps Dependencies) error {
if err := deps.TaskRepo.Store(store.task); err != nil {
2024-12-27 11:20:32 +01:00
return fmt.Errorf("could not store event: %v", err)
}
2024-12-27 11:27:59 +01:00
localID, err := deps.LocalIDRepo.Next()
2024-12-27 11:20:32 +01:00
if err != nil {
return fmt.Errorf("could not create next local id: %v", err)
}
2024-12-27 11:27:59 +01:00
if err := deps.LocalIDRepo.Store(store.task.ID, localID); err != nil {
2024-12-27 11:20:32 +01:00
return fmt.Errorf("could not store local id: %v", err)
}
2024-12-27 11:27:59 +01:00
it, err := store.task.Item()
2024-12-27 11:20:32 +01:00
if err != nil {
return fmt.Errorf("could not convert event to sync item: %v", err)
}
2024-12-27 11:27:59 +01:00
if err := deps.SyncRepo.Store(it); err != nil {
2024-12-27 11:20:32 +01:00
return fmt.Errorf("could not store sync item: %v", err)
}
return nil
}