feat(ECR-024): OpsCMS Banner 只读并 Closed

运营横幅目录(ops_banners + admin /cms),锁定 024–040 全队列。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
jackyu66git
2026-08-08 03:05:55 +08:00
co-authored by Cursor
parent ac1aec857d
commit 32ac559385
30 changed files with 808 additions and 3 deletions
+67
View File
@@ -0,0 +1,67 @@
package repository
import (
"context"
"errors"
"time"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
)
// BannerRow is OpsCMS Banner catalog row.
type BannerRow struct {
ID uuid.UUID `json:"id"`
Code string `json:"code"`
Title string `json:"title"`
Placement string `json:"placement"`
ImageURL *string `json:"image_url,omitempty"`
LinkPath *string `json:"link_path,omitempty"`
SortOrder int `json:"sort_order"`
Active bool `json:"active"`
System bool `json:"system"`
UpdatedAt time.Time `json:"updated_at"`
}
// ListBanners returns banner catalog.
func (r *AdminRepo) ListBanners(ctx context.Context) ([]BannerRow, error) {
rows, err := r.Pool.Query(ctx, `
SELECT id, code, title, placement, image_url, link_path, sort_order, active, system, updated_at
FROM ops_banners
ORDER BY active DESC, sort_order ASC, code ASC`)
if err != nil {
return nil, err
}
defer rows.Close()
var out []BannerRow
for rows.Next() {
var b BannerRow
if err := rows.Scan(
&b.ID, &b.Code, &b.Title, &b.Placement, &b.ImageURL, &b.LinkPath,
&b.SortOrder, &b.Active, &b.System, &b.UpdatedAt,
); err != nil {
return nil, err
}
out = append(out, b)
}
return out, rows.Err()
}
// GetBanner loads one banner by id.
func (r *AdminRepo) GetBanner(ctx context.Context, id uuid.UUID) (*BannerRow, error) {
var b BannerRow
err := r.Pool.QueryRow(ctx, `
SELECT id, code, title, placement, image_url, link_path, sort_order, active, system, updated_at
FROM ops_banners WHERE id=$1`, id,
).Scan(
&b.ID, &b.Code, &b.Title, &b.Placement, &b.ImageURL, &b.LinkPath,
&b.SortOrder, &b.Active, &b.System, &b.UpdatedAt,
)
if errors.Is(err, pgx.ErrNoRows) {
return nil, err
}
if err != nil {
return nil, err
}
return &b, nil
}