This commit is contained in:
Erik Winter 2024-10-07 11:32:53 +02:00
parent 0f903a5645
commit 4c69f00abd
3 changed files with 23 additions and 5 deletions

View File

@ -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
}

View File

@ -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),
},
}
@ -48,6 +52,8 @@ func main() {
type Configuration struct {
DBPath string `yaml:"dbpath"`
SyncURL string `yaml:"sync_url"`
ApiKey string `yaml:"api_key"`
}
func LoadConfig(path string) (Configuration, error) {

View File

@ -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,