wip
This commit is contained in:
parent
51775ae613
commit
801947ab30
|
@ -60,7 +60,7 @@ func Sync(client client.Client, syncRepo storage.Sync, localIDRepo storage.Local
|
|||
}
|
||||
for _, ri := range recItems {
|
||||
var eBody item.EventBody
|
||||
if err := json.Unmarshal([]byte(ri.Body), eBody); err != nil {
|
||||
if err := json.Unmarshal([]byte(ri.Body), &eBody); err != nil {
|
||||
return fmt.Errorf("could not unmarshal event body: %v", err)
|
||||
}
|
||||
e := item.Event{
|
||||
|
|
|
@ -24,18 +24,38 @@ func TestSync(t *testing.T) {
|
|||
it := item.Item{
|
||||
ID: "a",
|
||||
Kind: item.KindEvent,
|
||||
Body: `{}`,
|
||||
Body: `{
|
||||
"title":"title",
|
||||
"start":"2024-10-18T08:00:00Z",
|
||||
"duration":"1h"
|
||||
}`,
|
||||
}
|
||||
syncClient.Update([]item.Item{it})
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
ks []item.Kind
|
||||
ts time.Time
|
||||
expItems []item.Item
|
||||
}{
|
||||
{
|
||||
name: "single",
|
||||
ks: []item.Kind{item.KindEvent},
|
||||
expItems: []item.Item{it},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
|
||||
if err := command.Sync(syncClient, syncRepo, localIDRepo, eventRepo, false); err != nil {
|
||||
t.Errorf("exp nil, got %v", err)
|
||||
}
|
||||
actItems, actErr := syncClient.Updated([]item.Kind{item.KindEvent}, time.Time{})
|
||||
actItems, actErr := syncClient.Updated(tc.ks, tc.ts)
|
||||
if actErr != nil {
|
||||
t.Errorf("exp nil, got %v", actErr)
|
||||
}
|
||||
if diff := cmp.Diff([]item.Item{it}, actItems); diff != "" {
|
||||
if diff := cmp.Diff(tc.expItems, actItems); diff != "" {
|
||||
t.Errorf("(exp +, got -)\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
localIDRepo, eventRepo, err := sqlite.NewSqlites(conf.DBPath)
|
||||
localIDRepo, eventRepo, syncRepo, err := sqlite.NewSqlites(conf.DBPath)
|
||||
if err != nil {
|
||||
fmt.Printf("could not open db file: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
@ -40,7 +40,7 @@ func main() {
|
|||
command.NewListCmd(localIDRepo, eventRepo),
|
||||
command.NewUpdateCmd(localIDRepo, eventRepo),
|
||||
command.NewDeleteCmd(localIDRepo, eventRepo),
|
||||
command.NewSyncCmd(syncClient, localIDRepo, eventRepo),
|
||||
command.NewSyncCmd(syncClient, syncRepo, localIDRepo, eventRepo),
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,10 @@ FROM localids
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func (l *LocalID) FindOrNext(id string) (int, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (l *LocalID) Next() (int, error) {
|
||||
idMap, err := l.FindAll()
|
||||
if err != nil {
|
||||
|
|
|
@ -27,10 +27,10 @@ var (
|
|||
ErrSqliteFailure = errors.New("sqlite returned an error")
|
||||
)
|
||||
|
||||
func NewSqlites(dbPath string) (*LocalID, *SqliteEvent, error) {
|
||||
func NewSqlites(dbPath string) (*LocalID, *SqliteEvent, *SqliteSync, error) {
|
||||
db, err := sql.Open("sqlite", dbPath)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("%w: %v", ErrInvalidConfiguration, err)
|
||||
return nil, nil, nil, fmt.Errorf("%w: %v", ErrInvalidConfiguration, err)
|
||||
}
|
||||
|
||||
sl := &LocalID{
|
||||
|
@ -39,12 +39,13 @@ func NewSqlites(dbPath string) (*LocalID, *SqliteEvent, error) {
|
|||
se := &SqliteEvent{
|
||||
db: db,
|
||||
}
|
||||
ss := &SqliteSync{}
|
||||
|
||||
if err := migrate(db, migrations); err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
return sl, se, nil
|
||||
return sl, se, ss, nil
|
||||
}
|
||||
|
||||
func migrate(db *sql.DB, wanted []string) error {
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package sqlite
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go-mod.ewintr.nl/planner/item"
|
||||
)
|
||||
|
||||
type SqliteSync struct{}
|
||||
|
||||
func NewSqliteSync() *SqliteSync {
|
||||
return &SqliteSync{}
|
||||
}
|
||||
|
||||
func (s *SqliteSync) FindAll() ([]item.Item, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *SqliteSync) Store(i item.Item) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SqliteSync) DeleteAll() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SqliteSync) LastUpdate() (time.Time, error) {
|
||||
return time.Time{}, nil
|
||||
}
|
Loading…
Reference in New Issue