diff options
Diffstat (limited to 'backend/db')
| -rw-r--r-- | backend/db/articles.sql.go | 12 | ||||
| -rw-r--r-- | backend/db/feeds.sql.go | 17 | ||||
| -rw-r--r-- | backend/db/queries/articles.sql | 4 | ||||
| -rw-r--r-- | backend/db/queries/feeds.sql | 4 |
4 files changed, 21 insertions, 16 deletions
diff --git a/backend/db/articles.sql.go b/backend/db/articles.sql.go index 7492598..bf6ea1d 100644 --- a/backend/db/articles.sql.go +++ b/backend/db/articles.sql.go @@ -184,7 +184,7 @@ SELECT f.id as feed_id_2, f.url as feed_url, f.title as feed_title, f.is_subscribed as feed_is_subscribed FROM articles AS a INNER JOIN feeds AS f ON a.feed_id = f.id -WHERE a.is_read = 1 AND f.is_subscribed = 1 +WHERE a.is_read = 1 AND f.is_subscribed = 1 AND f.user_id = ? ORDER BY a.id DESC LIMIT 100 ` @@ -202,8 +202,8 @@ type GetReadArticlesRow struct { FeedIsSubscribed int64 } -func (q *Queries) GetReadArticles(ctx context.Context) ([]GetReadArticlesRow, error) { - rows, err := q.db.QueryContext(ctx, getReadArticles) +func (q *Queries) GetReadArticles(ctx context.Context, userID int64) ([]GetReadArticlesRow, error) { + rows, err := q.db.QueryContext(ctx, getReadArticles, userID) if err != nil { return nil, err } @@ -242,7 +242,7 @@ SELECT f.id as feed_id_2, f.url as feed_url, f.title as feed_title, f.is_subscribed as feed_is_subscribed FROM articles AS a INNER JOIN feeds AS f ON a.feed_id = f.id -WHERE a.is_read = 0 AND f.is_subscribed = 1 +WHERE a.is_read = 0 AND f.is_subscribed = 1 AND f.user_id = ? ORDER BY a.id DESC LIMIT 100 ` @@ -260,8 +260,8 @@ type GetUnreadArticlesRow struct { FeedIsSubscribed int64 } -func (q *Queries) GetUnreadArticles(ctx context.Context) ([]GetUnreadArticlesRow, error) { - rows, err := q.db.QueryContext(ctx, getUnreadArticles) +func (q *Queries) GetUnreadArticles(ctx context.Context, userID int64) ([]GetUnreadArticlesRow, error) { + rows, err := q.db.QueryContext(ctx, getUnreadArticles, userID) if err != nil { return nil, err } diff --git a/backend/db/feeds.sql.go b/backend/db/feeds.sql.go index 140fa3a..cec228a 100644 --- a/backend/db/feeds.sql.go +++ b/backend/db/feeds.sql.go @@ -74,11 +74,16 @@ func (q *Queries) GetFeed(ctx context.Context, id int64) (Feed, error) { const getFeedByURL = `-- name: GetFeedByURL :one SELECT id, url, title, fetched_at, is_subscribed, user_id FROM feeds -WHERE url = ? +WHERE url = ? AND user_id = ? ` -func (q *Queries) GetFeedByURL(ctx context.Context, url string) (Feed, error) { - row := q.db.QueryRowContext(ctx, getFeedByURL, url) +type GetFeedByURLParams struct { + Url string + UserID int64 +} + +func (q *Queries) GetFeedByURL(ctx context.Context, arg GetFeedByURLParams) (Feed, error) { + row := q.db.QueryRowContext(ctx, getFeedByURL, arg.Url, arg.UserID) var i Feed err := row.Scan( &i.ID, @@ -94,12 +99,12 @@ func (q *Queries) GetFeedByURL(ctx context.Context, url string) (Feed, error) { const getFeeds = `-- name: GetFeeds :many SELECT id, url, title, fetched_at, is_subscribed, user_id FROM feeds -WHERE is_subscribed = 1 +WHERE is_subscribed = 1 AND user_id = ? ORDER BY id ` -func (q *Queries) GetFeeds(ctx context.Context) ([]Feed, error) { - rows, err := q.db.QueryContext(ctx, getFeeds) +func (q *Queries) GetFeeds(ctx context.Context, userID int64) ([]Feed, error) { + rows, err := q.db.QueryContext(ctx, getFeeds, userID) if err != nil { return nil, err } diff --git a/backend/db/queries/articles.sql b/backend/db/queries/articles.sql index c1feaae..5acdada 100644 --- a/backend/db/queries/articles.sql +++ b/backend/db/queries/articles.sql @@ -12,7 +12,7 @@ SELECT f.id as feed_id_2, f.url as feed_url, f.title as feed_title, f.is_subscribed as feed_is_subscribed FROM articles AS a INNER JOIN feeds AS f ON a.feed_id = f.id -WHERE a.is_read = 0 AND f.is_subscribed = 1 +WHERE a.is_read = 0 AND f.is_subscribed = 1 AND f.user_id = ? ORDER BY a.id DESC LIMIT 100; @@ -22,7 +22,7 @@ SELECT f.id as feed_id_2, f.url as feed_url, f.title as feed_title, f.is_subscribed as feed_is_subscribed FROM articles AS a INNER JOIN feeds AS f ON a.feed_id = f.id -WHERE a.is_read = 1 AND f.is_subscribed = 1 +WHERE a.is_read = 1 AND f.is_subscribed = 1 AND f.user_id = ? ORDER BY a.id DESC LIMIT 100; diff --git a/backend/db/queries/feeds.sql b/backend/db/queries/feeds.sql index 9725252..acf36d2 100644 --- a/backend/db/queries/feeds.sql +++ b/backend/db/queries/feeds.sql @@ -6,7 +6,7 @@ WHERE id = ?; -- name: GetFeeds :many SELECT id, url, title, fetched_at, is_subscribed, user_id FROM feeds -WHERE is_subscribed = 1 +WHERE is_subscribed = 1 AND user_id = ? ORDER BY id; -- name: CreateFeed :one @@ -26,7 +26,7 @@ WHERE id = ?; -- name: GetFeedByURL :one SELECT id, url, title, fetched_at, is_subscribed, user_id FROM feeds -WHERE url = ?; +WHERE url = ? AND user_id = ?; -- name: GetFeedsToFetch :many SELECT id, url, fetched_at, user_id |
