feat: added new commands
- added follow command - added unfollow command - following command - introduced logged in user middleware
This commit is contained in:
@@ -12,3 +12,7 @@ RETURNING *;
|
||||
|
||||
-- name: GetAllFeeds :many
|
||||
SELECT id, created_at, updated_at, name, url, user_id FROM feeds;
|
||||
|
||||
-- name: GetFeedByUrl :one
|
||||
SELECT id, created_at, updated_at, name, url, user_id FROM feeds
|
||||
WHERE url = $1;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
-- name: CreateFollow :one
|
||||
WITH inserted_follow as (
|
||||
INSERT INTO follows (id, created_at, updated_at, feed_id, user_id)
|
||||
VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5
|
||||
)
|
||||
RETURNING *
|
||||
)
|
||||
SELECT inserted_follow.*,
|
||||
feeds.name as feed_name,
|
||||
users.name as user_name
|
||||
FROM inserted_follow
|
||||
INNER JOIN users
|
||||
ON inserted_follow.user_id = users.id
|
||||
INNER JOIN feeds
|
||||
ON inserted_follow.feed_id = feeds.id;
|
||||
|
||||
-- name: GetFollowsForUser :many
|
||||
SELECT follows.*, feeds.name as feed_name FROM follows
|
||||
INNER JOIN feeds
|
||||
ON follows.feed_id = feeds.id
|
||||
WHERE follows.user_id = $1;
|
||||
|
||||
-- name: DeleteFollowForUser :exec
|
||||
DELETE FROM follows
|
||||
WHERE feed_id = $1 AND user_id = $2;
|
||||
@@ -0,0 +1,14 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE follows (
|
||||
id UUID PRIMARY KEY,
|
||||
created_at TIMESTAMP NOT NULL,
|
||||
updated_at TIMESTAMP NOT NULL,
|
||||
user_id UUID NOT NULL,
|
||||
feed_id UUID NOT NULL,
|
||||
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY(feed_id) REFERENCES feeds(id) ON DELETE CASCADE,
|
||||
CONSTRAINT unique_user_feed UNIQUE(user_id, feed_id)
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE follows;
|
||||
Reference in New Issue
Block a user