1package store23import (4 "context"5 "time"67 "website-feeds/model"8 "website-feeds/store/pg_store"9)1011// 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 be14 // called when no longer needed.15 Close()1617 // SiteByName fetches a site by its name18 SiteByName(ctx context.Context, name string) (*model.Site, error)1920 // CreateSite creates a new site with the given name and display name21 CreateSite(22 ctx context.Context,23 name, displayName string,24 ) (*model.Site, error)2526 // WriteSitePosts upsets posts into the database, updating their last27 // fetched time. Also updates the site's last-fetched time and last-fetched28 // number.29 WriteSitePosts(30 ctx context.Context,31 siteID int,32 posts []model.Post,33 lastFetched model.SiteLastFetched,34 ) error3536 // TopPostsForSite returns the top numPosts posts for the given site over37 // 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)4445 // Settings returns the current global applicatio settings.46 Settings(ctx context.Context) (*model.Settings, error)4748 // UpdateSettings updates the global application settings.49 UpdateSettings(ctx context.Context, settings *model.Settings) error5051 // WriteRequest persists a client feed request.52 WriteRequest(ctx context.Context, r *model.Request) error5354 // NumFetchPostsForSite determines the number of posts that should be55 // fetched for the given site at this time.56 //57 // Might be higher than initially requested if we think other users are58 // 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}6566func NewPostgres(ctx context.Context, url string) (Store, error) {67 return pg_store.New(ctx, url)68}