website-feeds

Make RSS feeds of your favorite "vote on posts" websites

git clone https://code.pdelong.com/website-feeds.git

 1package store
 2
 3import (
 4	"context"
 5	"time"
 6
 7	"website-feeds/model"
 8	"website-feeds/store/pg_store"
 9)
10
11// Store represents an abstract data storage subsystem to allow for testing.
12type Store interface {
13	// Close cleans up any resources the Store is holding on to and should be
14	// called when no longer needed.
15	Close()
16
17	// SiteByName fetches a site by its name
18	SiteByName(ctx context.Context, name string) (*model.Site, error)
19
20	// CreateSite creates a new site with the given name and display name
21	CreateSite(
22		ctx context.Context,
23		name, displayName string,
24	) (*model.Site, error)
25
26	// WriteSitePosts upsets posts into the database, updating their last
27	// fetched time. Also updates the site's last-fetched time and last-fetched
28	// number.
29	WriteSitePosts(
30		ctx context.Context,
31		siteID int,
32		posts []model.Post,
33		lastFetched model.SiteLastFetched,
34	) error
35
36	// TopPostsForSite returns the top numPosts posts for the given site over
37	// the range from 8 days ago to 1 day ago.
38	TopPostsForSite(
39		ctx context.Context,
40		siteID int,
41		now time.Time,
42		numPosts int,
43	) ([]model.Post, error)
44
45	// Settings returns the current global applicatio settings.
46	Settings(ctx context.Context) (*model.Settings, error)
47
48	// UpdateSettings updates the global application settings.
49	UpdateSettings(ctx context.Context, settings *model.Settings) error
50
51	// WriteRequest persists a client feed request.
52	WriteRequest(ctx context.Context, r *model.Request) error
53
54	// NumFetchPostsForSite determines the number of posts that should be
55	// fetched for the given site at this time.
56	//
57	// Might be higher than initially requested if we think other users are
58	// also reading the feed, but with a larger number of posts.
59	NumFetchPostsForSite(
60		ctx context.Context,
61		siteID int,
62		now time.Time,
63	) (int, error)
64}
65
66func NewPostgres(ctx context.Context, url string) (Store, error) {
67	return pg_store.New(ctx, url)
68}