wip
This commit is contained in:
parent
5bafda072b
commit
f7cc1082b9
|
@ -44,14 +44,14 @@ var AddCmd = &cli.Command{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAddCmd(localRepo storage.LocalID, eventRepo storage.Event) *cli.Command {
|
func NewAddCmd(localRepo storage.LocalID, eventRepo storage.Event, syncRepo storage.Sync) *cli.Command {
|
||||||
AddCmd.Action = func(cCtx *cli.Context) error {
|
AddCmd.Action = func(cCtx *cli.Context) error {
|
||||||
return Add(localRepo, eventRepo, cCtx.String("name"), cCtx.String("on"), cCtx.String("at"), cCtx.String("for"))
|
return Add(localRepo, eventRepo, syncRepo, cCtx.String("name"), cCtx.String("on"), cCtx.String("at"), cCtx.String("for"))
|
||||||
}
|
}
|
||||||
return AddCmd
|
return AddCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func Add(localIDRepo storage.LocalID, eventRepo storage.Event, nameStr, onStr, atStr, frStr string) error {
|
func Add(localIDRepo storage.LocalID, eventRepo storage.Event, syncRepo storage.Sync, nameStr, onStr, atStr, frStr string) error {
|
||||||
if nameStr == "" {
|
if nameStr == "" {
|
||||||
return fmt.Errorf("%w: name is required", ErrInvalidArg)
|
return fmt.Errorf("%w: name is required", ErrInvalidArg)
|
||||||
}
|
}
|
||||||
|
@ -103,5 +103,13 @@ func Add(localIDRepo storage.LocalID, eventRepo storage.Event, nameStr, onStr, a
|
||||||
return fmt.Errorf("could not store local id: %v", err)
|
return fmt.Errorf("could not store local id: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
it, err := e.Item()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not convert event to sync item: %v", err)
|
||||||
|
}
|
||||||
|
if err := syncRepo.Store(it); err != nil {
|
||||||
|
return fmt.Errorf("could not store sync item: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,14 +20,14 @@ var DeleteCmd = &cli.Command{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDeleteCmd(localRepo storage.LocalID, eventRepo storage.Event) *cli.Command {
|
func NewDeleteCmd(localRepo storage.LocalID, eventRepo storage.Event, syncRepo storage.Sync) *cli.Command {
|
||||||
DeleteCmd.Action = func(cCtx *cli.Context) error {
|
DeleteCmd.Action = func(cCtx *cli.Context) error {
|
||||||
return Delete(localRepo, eventRepo, cCtx.Int("localID"))
|
return Delete(localRepo, eventRepo, syncRepo, cCtx.Int("localID"))
|
||||||
}
|
}
|
||||||
return DeleteCmd
|
return DeleteCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func Delete(localRepo storage.LocalID, eventRepo storage.Event, localID int) error {
|
func Delete(localRepo storage.LocalID, eventRepo storage.Event, syncRepo storage.Sync, localID int) error {
|
||||||
var id string
|
var id string
|
||||||
idMap, err := localRepo.FindAll()
|
idMap, err := localRepo.FindAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -46,5 +46,17 @@ func Delete(localRepo storage.LocalID, eventRepo storage.Event, localID int) err
|
||||||
return fmt.Errorf("could not delete event: %v", err)
|
return fmt.Errorf("could not delete event: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
e, err := eventRepo.Find(id)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not get event: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
it, err := e.Item()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not convert event to sync item: %v", err)
|
||||||
|
}
|
||||||
|
if err := syncRepo.Store(it); err != nil {
|
||||||
|
return fmt.Errorf("could not store sync item: %v", err)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,14 +41,14 @@ var UpdateCmd = &cli.Command{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUpdateCmd(localRepo storage.LocalID, eventRepo storage.Event) *cli.Command {
|
func NewUpdateCmd(localRepo storage.LocalID, eventRepo storage.Event, syncRepo storage.Sync) *cli.Command {
|
||||||
UpdateCmd.Action = func(cCtx *cli.Context) error {
|
UpdateCmd.Action = func(cCtx *cli.Context) error {
|
||||||
return Update(localRepo, eventRepo, cCtx.Int("localID"), cCtx.String("name"), cCtx.String("on"), cCtx.String("at"), cCtx.String("for"))
|
return Update(localRepo, eventRepo, syncRepo, cCtx.Int("localID"), cCtx.String("name"), cCtx.String("on"), cCtx.String("at"), cCtx.String("for"))
|
||||||
}
|
}
|
||||||
return UpdateCmd
|
return UpdateCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func Update(localRepo storage.LocalID, eventRepo storage.Event, localID int, nameStr, onStr, atStr, frStr string) error {
|
func Update(localRepo storage.LocalID, eventRepo storage.Event, syncRepo storage.Sync, localID int, nameStr, onStr, atStr, frStr string) error {
|
||||||
var id string
|
var id string
|
||||||
idMap, err := localRepo.FindAll()
|
idMap, err := localRepo.FindAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -99,5 +99,13 @@ func Update(localRepo storage.LocalID, eventRepo storage.Event, localID int, nam
|
||||||
return fmt.Errorf("could not store event: %v", err)
|
return fmt.Errorf("could not store event: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
it, err := e.Item()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not convert event to sync item: %v", err)
|
||||||
|
}
|
||||||
|
if err := syncRepo.Store(it); err != nil {
|
||||||
|
return fmt.Errorf("could not store sync item: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,10 +37,10 @@ func main() {
|
||||||
Name: "plan",
|
Name: "plan",
|
||||||
Usage: "Plan your day with events",
|
Usage: "Plan your day with events",
|
||||||
Commands: []*cli.Command{
|
Commands: []*cli.Command{
|
||||||
command.NewAddCmd(localIDRepo, eventRepo),
|
command.NewAddCmd(localIDRepo, eventRepo, syncRepo),
|
||||||
command.NewListCmd(localIDRepo, eventRepo),
|
command.NewListCmd(localIDRepo, eventRepo),
|
||||||
command.NewUpdateCmd(localIDRepo, eventRepo),
|
command.NewUpdateCmd(localIDRepo, eventRepo, syncRepo),
|
||||||
command.NewDeleteCmd(localIDRepo, eventRepo),
|
command.NewDeleteCmd(localIDRepo, eventRepo, syncRepo),
|
||||||
command.NewSyncCmd(syncClient, syncRepo, localIDRepo, eventRepo),
|
command.NewSyncCmd(syncClient, syncRepo, localIDRepo, eventRepo),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue