Fixed ordering of published posts
This commit is contained in:
parent
9b20665d11
commit
deca23b599
8 changed files with 81 additions and 10 deletions
|
|
@ -227,7 +227,7 @@ func (q *Queries) SelectCategoryBySlugAndSite(ctx context.Context, arg SelectCat
|
|||
return i, err
|
||||
}
|
||||
|
||||
const selectPostsOfCategory = `-- name: SelectPostsOfCategory :many
|
||||
const selectPublishedPostsOfCategory = `-- name: SelectPublishedPostsOfCategory :many
|
||||
SELECT p.id, p.site_id, p.state, p.guid, p.title, p.body, p.slug, p.created_at, p.updated_at, p.published_at, p.deleted_at FROM posts p
|
||||
INNER JOIN post_categories pc ON pc.post_id = p.id
|
||||
WHERE pc.category_id = ? AND p.state = 0 AND p.deleted_at = 0
|
||||
|
|
@ -235,14 +235,14 @@ ORDER BY p.published_at DESC
|
|||
LIMIT ? OFFSET ?
|
||||
`
|
||||
|
||||
type SelectPostsOfCategoryParams struct {
|
||||
type SelectPublishedPostsOfCategoryParams struct {
|
||||
CategoryID int64
|
||||
Limit int64
|
||||
Offset int64
|
||||
}
|
||||
|
||||
func (q *Queries) SelectPostsOfCategory(ctx context.Context, arg SelectPostsOfCategoryParams) ([]Post, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectPostsOfCategory, arg.CategoryID, arg.Limit, arg.Offset)
|
||||
func (q *Queries) SelectPublishedPostsOfCategory(ctx context.Context, arg SelectPublishedPostsOfCategoryParams) ([]Post, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectPublishedPostsOfCategory, arg.CategoryID, arg.Limit, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -200,6 +200,54 @@ func (q *Queries) SelectPostsOfSite(ctx context.Context, arg SelectPostsOfSitePa
|
|||
return items, nil
|
||||
}
|
||||
|
||||
const selectPublishedPostsOfSite = `-- name: SelectPublishedPostsOfSite :many
|
||||
SELECT id, site_id, state, guid, title, body, slug, created_at, updated_at, published_at, deleted_at
|
||||
FROM posts
|
||||
WHERE site_id = ?1 AND state = 0 AND deleted_at = 0
|
||||
ORDER BY published_at DESC LIMIT ?3 OFFSET ?2
|
||||
`
|
||||
|
||||
type SelectPublishedPostsOfSiteParams struct {
|
||||
SiteID int64
|
||||
Offset int64
|
||||
Limit int64
|
||||
}
|
||||
|
||||
func (q *Queries) SelectPublishedPostsOfSite(ctx context.Context, arg SelectPublishedPostsOfSiteParams) ([]Post, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectPublishedPostsOfSite, arg.SiteID, arg.Offset, arg.Limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Post
|
||||
for rows.Next() {
|
||||
var i Post
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.SiteID,
|
||||
&i.State,
|
||||
&i.Guid,
|
||||
&i.Title,
|
||||
&i.Body,
|
||||
&i.Slug,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.PublishedAt,
|
||||
&i.DeletedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const softDeletePost = `-- name: SoftDeletePost :exec
|
||||
UPDATE posts SET deleted_at = ? WHERE id = ?
|
||||
`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue