feat: tenant content publish

This commit is contained in:
2025-12-25 14:29:16 +08:00
parent a66c0d9b90
commit 6542c71ec0
15 changed files with 1082 additions and 4 deletions

View File

@@ -27,6 +27,7 @@ field_type:
contents:
status: consts.ContentStatus
visibility: consts.ContentVisibility
tags: types.JSON
content_assets:
role: consts.ContentAssetRole
content_prices:

View File

@@ -0,0 +1,21 @@
-- +goose Up
-- +goose StatementBegin
-- contents补齐“简介/标签”字段,用于内容发布与列表展示
ALTER TABLE contents
ADD COLUMN IF NOT EXISTS summary varchar(256) NOT NULL DEFAULT '',
ADD COLUMN IF NOT EXISTS tags jsonb NOT NULL DEFAULT '[]'::jsonb;
COMMENT ON COLUMN contents.summary IS '简介:用于列表/卡片展示的短文本;建议 <= 256 字符(由业务校验)';
COMMENT ON COLUMN contents.tags IS '标签JSON 数组(字符串列表);用于分类/检索与聚合展示';
CREATE INDEX IF NOT EXISTS ix_contents_tenant_tags ON contents(tenant_id);
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP INDEX IF EXISTS ix_contents_tenant_tags;
ALTER TABLE contents
DROP COLUMN IF EXISTS tags,
DROP COLUMN IF EXISTS summary;
-- +goose StatementEnd

View File

@@ -11,6 +11,7 @@ import (
"quyun/v2/pkg/consts"
"go.ipao.vip/gen"
"go.ipao.vip/gen/types"
"gorm.io/gorm"
)
@@ -31,6 +32,8 @@ type Content struct {
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp with time zone;comment:软删除时间:非空表示已删除;对外接口需过滤" json:"deleted_at"` // 软删除时间:非空表示已删除;对外接口需过滤
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now();comment:创建时间:默认 now();用于审计与排序" json:"created_at"` // 创建时间:默认 now();用于审计与排序
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now();comment:更新时间:默认 now();编辑内容时写入" json:"updated_at"` // 更新时间:默认 now();编辑内容时写入
Summary string `gorm:"column:summary;type:character varying(256);not null;comment:简介:用于列表/卡片展示的短文本;建议 <= 256 字符(由业务校验)" json:"summary"` // 简介:用于列表/卡片展示的短文本;建议 <= 256 字符(由业务校验)
Tags types.JSON `gorm:"column:tags;type:jsonb;not null;default:[];comment:标签JSON 数组(字符串列表);用于分类/检索与聚合展示" json:"tags"` // 标签JSON 数组(字符串列表);用于分类/检索与聚合展示
}
// Quick operations without importing query package

View File

@@ -38,6 +38,8 @@ func newContent(db *gorm.DB, opts ...gen.DOOption) contentQuery {
_contentQuery.DeletedAt = field.NewField(tableName, "deleted_at")
_contentQuery.CreatedAt = field.NewTime(tableName, "created_at")
_contentQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
_contentQuery.Summary = field.NewString(tableName, "summary")
_contentQuery.Tags = field.NewJSONB(tableName, "tags")
_contentQuery.fillFieldMap()
@@ -61,6 +63,8 @@ type contentQuery struct {
DeletedAt field.Field // 软删除时间:非空表示已删除;对外接口需过滤
CreatedAt field.Time // 创建时间:默认 now();用于审计与排序
UpdatedAt field.Time // 更新时间:默认 now();编辑内容时写入
Summary field.String // 简介:用于列表/卡片展示的短文本;建议 <= 256 字符(由业务校验)
Tags field.JSONB // 标签JSON 数组(字符串列表);用于分类/检索与聚合展示
fieldMap map[string]field.Expr
}
@@ -90,6 +94,8 @@ func (c *contentQuery) updateTableName(table string) *contentQuery {
c.DeletedAt = field.NewField(table, "deleted_at")
c.CreatedAt = field.NewTime(table, "created_at")
c.UpdatedAt = field.NewTime(table, "updated_at")
c.Summary = field.NewString(table, "summary")
c.Tags = field.NewJSONB(table, "tags")
c.fillFieldMap()
@@ -122,7 +128,7 @@ func (c *contentQuery) GetFieldByName(fieldName string) (field.OrderExpr, bool)
}
func (c *contentQuery) fillFieldMap() {
c.fieldMap = make(map[string]field.Expr, 13)
c.fieldMap = make(map[string]field.Expr, 15)
c.fieldMap["id"] = c.ID
c.fieldMap["tenant_id"] = c.TenantID
c.fieldMap["user_id"] = c.UserID
@@ -136,6 +142,8 @@ func (c *contentQuery) fillFieldMap() {
c.fieldMap["deleted_at"] = c.DeletedAt
c.fieldMap["created_at"] = c.CreatedAt
c.fieldMap["updated_at"] = c.UpdatedAt
c.fieldMap["summary"] = c.Summary
c.fieldMap["tags"] = c.Tags
}
func (c contentQuery) clone(db *gorm.DB) contentQuery {