From 4c69f00abd5038dfb78fd987dfd07f7331080939 Mon Sep 17 00:00:00 2001 From: Erik Winter Date: Mon, 7 Oct 2024 11:32:53 +0200 Subject: [PATCH] wip --- plan/command/sync.go | 18 +++++++++++++++--- plan/main.go | 8 +++++++- sync/client/client.go | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/plan/command/sync.go b/plan/command/sync.go index 5a1b80b..886f054 100644 --- a/plan/command/sync.go +++ b/plan/command/sync.go @@ -3,6 +3,7 @@ package command import ( "github.com/urfave/cli/v2" "go-mod.ewintr.nl/planner/plan/storage" + "go-mod.ewintr.nl/planner/sync/client" ) var SyncCmd = &cli.Command{ @@ -17,14 +18,25 @@ var SyncCmd = &cli.Command{ }, } -func NewSyncCmd(localRepo storage.LocalID, eventRepo storage.Event) *cli.Command { +func NewSyncCmd(client *client.Client, localRepo storage.LocalID, eventRepo storage.Event) *cli.Command { SyncCmd.Action = func(cCtx *cli.Context) error { - return Sync(localRepo, eventRepo, cCtx.Bool("full")) + return Sync(client, localRepo, eventRepo, cCtx.Bool("full")) } return SyncCmd } -func Sync(localRepo storage.LocalID, eventRepo storage.Event, full bool) error { +func Sync(client *client.Client, localRepo storage.LocalID, eventRepo storage.Event, full bool) error { + // get new/updated items + + // delete deleted + + // update existing + + // localid and add new + + // find local new and updated + + // send new and updated return nil } diff --git a/plan/main.go b/plan/main.go index ac217af..a1933c1 100644 --- a/plan/main.go +++ b/plan/main.go @@ -8,6 +8,7 @@ import ( "github.com/urfave/cli/v2" "go-mod.ewintr.nl/planner/plan/command" "go-mod.ewintr.nl/planner/plan/storage/sqlite" + "go-mod.ewintr.nl/planner/sync/client" "gopkg.in/yaml.v3" ) @@ -29,6 +30,8 @@ func main() { os.Exit(1) } + syncClient := client.New(conf.SyncURL, conf.ApiKey) + app := &cli.App{ Name: "plan", Usage: "Plan your day with events", @@ -37,6 +40,7 @@ func main() { command.NewListCmd(localIDRepo, eventRepo), command.NewUpdateCmd(localIDRepo, eventRepo), command.NewDeleteCmd(localIDRepo, eventRepo), + command.NewSyncCmd(syncClient, localIDRepo, eventRepo), }, } @@ -47,7 +51,9 @@ func main() { } type Configuration struct { - DBPath string `yaml:"dbpath"` + DBPath string `yaml:"dbpath"` + SyncURL string `yaml:"sync_url"` + ApiKey string `yaml:"api_key"` } func LoadConfig(path string) (Configuration, error) { diff --git a/sync/client/client.go b/sync/client/client.go index 9b3a4bc..cd4cc25 100644 --- a/sync/client/client.go +++ b/sync/client/client.go @@ -19,7 +19,7 @@ type Client struct { c *http.Client } -func NewClient(url, apiKey string) *Client { +func New(url, apiKey string) *Client { return &Client{ baseURL: url, apiKey: apiKey,