diff --git a/db/queries.sql.go b/db/queries.sql.go index 650854f..66653b6 100644 --- a/db/queries.sql.go +++ b/db/queries.sql.go @@ -226,11 +226,17 @@ func (q *Queries) GetEntries(ctx context.Context, userID int64) ([]Entry, error) const getEntry = `-- name: GetEntry :one SELECT entry_id, user_id, created_at, updated_at, title, body FROM entries -WHERE entry_id = $1 LIMIT 1 +WHERE entry_id = $1 and user_id = $2 +LIMIT 1 ` -func (q *Queries) GetEntry(ctx context.Context, entryID uuid.UUID) (Entry, error) { - row := q.queryRow(ctx, q.getEntryStmt, getEntry, entryID) +type GetEntryParams struct { + EntryID uuid.UUID `json:"entry_id"` + UserID int64 `json:"user_id"` +} + +func (q *Queries) GetEntry(ctx context.Context, arg GetEntryParams) (Entry, error) { + row := q.queryRow(ctx, q.getEntryStmt, getEntry, arg.EntryID, arg.UserID) var i Entry err := row.Scan( &i.EntryID, diff --git a/sql/queries/queries.sql b/sql/queries/queries.sql index 7feb10f..a2de6e2 100644 --- a/sql/queries/queries.sql +++ b/sql/queries/queries.sql @@ -14,7 +14,8 @@ WHERE entry_id = $1; -- name: GetEntry :one SELECT * FROM entries -WHERE entry_id = $1 LIMIT 1; +WHERE entry_id = $1 and user_id = $2 +LIMIT 1; -- name: GetEntries :many SELECT * FROM entries