Styled the post list and added updating of posts
This commit is contained in:
parent
e77cac2fd5
commit
aef3bb6a1e
31 changed files with 1230 additions and 118 deletions
|
|
@ -19,6 +19,7 @@ type PublishTarget struct {
|
|||
ID int64
|
||||
SiteID int64
|
||||
TargetType string
|
||||
Enabled int64
|
||||
BaseUrl string
|
||||
TargetRef string
|
||||
TargetKey string
|
||||
|
|
|
|||
|
|
@ -47,6 +47,26 @@ func (q *Queries) InsertPost(ctx context.Context, arg InsertPostParams) (int64,
|
|||
return id, err
|
||||
}
|
||||
|
||||
const selectPost = `-- name: SelectPost :one
|
||||
SELECT id, site_id, guid, title, body, slug, created_at, published_at FROM posts WHERE id = ? LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) SelectPost(ctx context.Context, id int64) (Post, error) {
|
||||
row := q.db.QueryRowContext(ctx, selectPost, id)
|
||||
var i Post
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.SiteID,
|
||||
&i.Guid,
|
||||
&i.Title,
|
||||
&i.Body,
|
||||
&i.Slug,
|
||||
&i.CreatedAt,
|
||||
&i.PublishedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const selectPostByGUID = `-- name: SelectPostByGUID :one
|
||||
SELECT id, site_id, guid, title, body, slug, created_at, published_at FROM posts WHERE guid = ? LIMIT 1
|
||||
`
|
||||
|
|
|
|||
|
|
@ -13,16 +13,18 @@ const insertPublishTarget = `-- name: InsertPublishTarget :one
|
|||
INSERT INTO publish_targets (
|
||||
site_id,
|
||||
target_type,
|
||||
enabled,
|
||||
base_url,
|
||||
target_ref,
|
||||
target_key
|
||||
) VALUES (?, ?, ?, ?, ?)
|
||||
) VALUES (?, ?, ?, ?, ?, ?)
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
type InsertPublishTargetParams struct {
|
||||
SiteID int64
|
||||
TargetType string
|
||||
Enabled int64
|
||||
BaseUrl string
|
||||
TargetRef string
|
||||
TargetKey string
|
||||
|
|
@ -32,6 +34,7 @@ func (q *Queries) InsertPublishTarget(ctx context.Context, arg InsertPublishTarg
|
|||
row := q.db.QueryRowContext(ctx, insertPublishTarget,
|
||||
arg.SiteID,
|
||||
arg.TargetType,
|
||||
arg.Enabled,
|
||||
arg.BaseUrl,
|
||||
arg.TargetRef,
|
||||
arg.TargetKey,
|
||||
|
|
@ -42,7 +45,7 @@ func (q *Queries) InsertPublishTarget(ctx context.Context, arg InsertPublishTarg
|
|||
}
|
||||
|
||||
const selectPublishTargetsOfSite = `-- name: SelectPublishTargetsOfSite :many
|
||||
SELECT id, site_id, target_type, base_url, target_ref, target_key FROM publish_targets WHERE site_id = ?
|
||||
SELECT id, site_id, target_type, enabled, base_url, target_ref, target_key FROM publish_targets WHERE site_id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) SelectPublishTargetsOfSite(ctx context.Context, siteID int64) ([]PublishTarget, error) {
|
||||
|
|
@ -58,6 +61,7 @@ func (q *Queries) SelectPublishTargetsOfSite(ctx context.Context, siteID int64)
|
|||
&i.ID,
|
||||
&i.SiteID,
|
||||
&i.TargetType,
|
||||
&i.Enabled,
|
||||
&i.BaseUrl,
|
||||
&i.TargetRef,
|
||||
&i.TargetKey,
|
||||
|
|
|
|||
|
|
@ -21,6 +21,15 @@ func (db *Provider) SelectPostsOfSite(ctx context.Context, siteID int64) ([]*mod
|
|||
return posts, nil
|
||||
}
|
||||
|
||||
func (db *Provider) SelectPost(ctx context.Context, postID int64) (*models.Post, error) {
|
||||
row, err := db.queries.SelectPost(ctx, postID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return dbPostToPost(row), nil
|
||||
}
|
||||
|
||||
func (db *Provider) SelectPostByGUID(ctx context.Context, guid string) (*models.Post, error) {
|
||||
row, err := db.queries.SelectPostByGUID(ctx, guid)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ func (db *Provider) SelectPublishTargetsOfSite(ctx context.Context, siteID int64
|
|||
targets[i] = models.SitePublishTarget{
|
||||
ID: row.ID,
|
||||
SiteID: row.SiteID,
|
||||
Enabled: row.Enabled != 0,
|
||||
TargetType: row.TargetType,
|
||||
BaseURL: row.BaseUrl,
|
||||
TargetRef: row.TargetRef,
|
||||
|
|
@ -28,10 +29,16 @@ func (db *Provider) SelectPublishTargetsOfSite(ctx context.Context, siteID int64
|
|||
}
|
||||
|
||||
func (db *Provider) SavePublishTarget(ctx context.Context, target *models.SitePublishTarget) error {
|
||||
var enabled int64
|
||||
if target.Enabled {
|
||||
enabled = 1
|
||||
}
|
||||
|
||||
if target.ID == 0 {
|
||||
newID, err := db.queries.InsertPublishTarget(ctx, sqlgen.InsertPublishTargetParams{
|
||||
SiteID: target.SiteID,
|
||||
TargetType: target.TargetType,
|
||||
Enabled: enabled,
|
||||
BaseUrl: target.BaseURL,
|
||||
TargetRef: target.TargetRef,
|
||||
TargetKey: target.TargetKey,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue