Started styling the app and have got editing posts working.
This commit is contained in:
parent
7ef6725bdb
commit
bf5d6cbe52
20 changed files with 511 additions and 41 deletions
|
|
@ -11,6 +11,26 @@ import (
|
|||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const getPostWithID = `-- name: GetPostWithID :one
|
||||
SELECT id, site_id, title, body, state, props, post_date, created_at FROM post WHERE id = $1 LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) GetPostWithID(ctx context.Context, id int64) (Post, error) {
|
||||
row := q.db.QueryRow(ctx, getPostWithID, id)
|
||||
var i Post
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.SiteID,
|
||||
&i.Title,
|
||||
&i.Body,
|
||||
&i.State,
|
||||
&i.Props,
|
||||
&i.PostDate,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertPost = `-- name: InsertPost :one
|
||||
INSERT INTO post (
|
||||
site_id,
|
||||
|
|
@ -123,3 +143,38 @@ func (q *Queries) ListPublishablePosts(ctx context.Context, arg ListPublishableP
|
|||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updatePost = `-- name: UpdatePost :exec
|
||||
UPDATE post SET
|
||||
site_id = $2,
|
||||
title = $3,
|
||||
body = $4,
|
||||
state = $5,
|
||||
props = $6,
|
||||
post_date = $7
|
||||
-- updated_at = $7
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
type UpdatePostParams struct {
|
||||
ID int64
|
||||
SiteID int64
|
||||
Title pgtype.Text
|
||||
Body string
|
||||
State PostState
|
||||
Props []byte
|
||||
PostDate pgtype.Timestamptz
|
||||
}
|
||||
|
||||
func (q *Queries) UpdatePost(ctx context.Context, arg UpdatePostParams) error {
|
||||
_, err := q.db.Exec(ctx, updatePost,
|
||||
arg.ID,
|
||||
arg.SiteID,
|
||||
arg.Title,
|
||||
arg.Body,
|
||||
arg.State,
|
||||
arg.Props,
|
||||
arg.PostDate,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue