change to feed.Foo methods instead of passing in feed to package func
parent
ce02422b1d
commit
18fd8dfac5
|
|
@ -164,11 +164,14 @@ func oldGet(ctx context.Context, id string) (Feed, error) {
|
||||||
return Feed{}, fmt.Errorf("%+v, %+v, %+v", entry, version, execution)
|
return Feed{}, fmt.Errorf("%+v, %+v, %+v", entry, version, execution)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Executed(ctx context.Context, id string, version time.Time) error {
|
func (feed Feed) Executed(ctx context.Context) error {
|
||||||
if err := initDB(ctx); err != nil {
|
if err := initDB(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
id := feed.Entry.ID
|
||||||
|
version := feed.Version.Created
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
return db.Exec(ctx, `
|
return db.Exec(ctx, `
|
||||||
INSERT INTO "feed.executions" (
|
INSERT INTO "feed.executions" (
|
||||||
|
|
@ -208,11 +211,11 @@ func Insert(ctx context.Context, url, cron string) (string, error) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Update(ctx context.Context, id string, url, cron *string) error {
|
func (feed Feed) Update(ctx context.Context, url, cron *string) error {
|
||||||
return io.EOF
|
return io.EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
func Delete(ctx context.Context, id string) error {
|
func (feed Feed) Delete(ctx context.Context) error {
|
||||||
return io.EOF
|
return io.EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ func TestFeeds(t *testing.T) {
|
||||||
t.Error("execution.version")
|
t.Error("execution.version")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := feeds.Executed(ctx, got.Entry.ID, got.Version.Created); err != nil {
|
if err := got.Executed(ctx); err != nil {
|
||||||
t.Fatal("cannot executed:", err)
|
t.Fatal("cannot executed:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,7 +78,7 @@ func TestFeeds(t *testing.T) {
|
||||||
t.Errorf("changes after execution: was \n\t%+v but now \n\t%+v", got, got2)
|
t.Errorf("changes after execution: was \n\t%+v but now \n\t%+v", got, got2)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := feeds.Executed(ctx, got.Entry.ID, got.Version.Created); err != nil {
|
if err := got.Executed(ctx); err != nil {
|
||||||
t.Fatal("cannot executed again:", err)
|
t.Fatal("cannot executed again:", err)
|
||||||
}
|
}
|
||||||
got3, err := feeds.Get(ctx, id)
|
got3, err := feeds.Get(ctx, id)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package feeds
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (feed Feed) Fetch(ctx context.Context) (Items, error) {
|
||||||
|
return nil, io.EOF
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
package feeds_test
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package feeds
|
||||||
|
|
||||||
|
type Items []Item
|
||||||
|
|
||||||
|
type Item struct{}
|
||||||
Loading…
Reference in New Issue