change to feed.Foo methods instead of passing in feed to package func

main
Bel LaPointe 2025-04-27 11:55:00 -06:00
parent ce02422b1d
commit 18fd8dfac5
5 changed files with 24 additions and 5 deletions

View File

@ -164,11 +164,14 @@ func oldGet(ctx context.Context, id string) (Feed, error) {
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 {
return err
}
id := feed.Entry.ID
version := feed.Version.Created
now := time.Now()
return db.Exec(ctx, `
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
}
func Delete(ctx context.Context, id string) error {
func (feed Feed) Delete(ctx context.Context) error {
return io.EOF
}

View File

@ -56,7 +56,7 @@ func TestFeeds(t *testing.T) {
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)
}
@ -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)
}
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)
}
got3, err := feeds.Get(ctx, id)

10
src/feeds/http.go Normal file
View File

@ -0,0 +1,10 @@
package feeds
import (
"context"
"io"
)
func (feed Feed) Fetch(ctx context.Context) (Items, error) {
return nil, io.EOF
}

1
src/feeds/http_test.go Normal file
View File

@ -0,0 +1 @@
package feeds_test

5
src/feeds/item.go Normal file
View File

@ -0,0 +1,5 @@
package feeds
type Items []Item
type Item struct{}