feat: Refactor template handling and brand management
- Removed schema_json from article templates and related queries. - Updated brand service to include website field in requests and responses. - Simplified template wizard view by eliminating unused schema fields and related logic. - Added tests for ark text format handling. - Created migrations for dropping schema_json and adding website to brands.
This commit is contained in:
@@ -31,7 +31,6 @@ type ArticleTemplate struct {
|
||||
ShareCodeID pgtype.Int8 `json:"share_code_id"`
|
||||
TemplateKey string `json:"template_key"`
|
||||
TemplateName string `json:"template_name"`
|
||||
SchemaJson []byte `json:"schema_json"`
|
||||
PromptTemplate pgtype.Text `json:"prompt_template"`
|
||||
PromptVisibility string `json:"prompt_visibility"`
|
||||
ProtectedPromptAssetKey pgtype.Text `json:"protected_prompt_asset_key"`
|
||||
|
||||
@@ -42,7 +42,6 @@ type Querier interface {
|
||||
GetRecentArticles(ctx context.Context, tenantID int64) ([]GetRecentArticlesRow, error)
|
||||
GetScheduleTaskByID(ctx context.Context, arg GetScheduleTaskByIDParams) (GetScheduleTaskByIDRow, error)
|
||||
GetTemplateByID(ctx context.Context, arg GetTemplateByIDParams) (GetTemplateByIDRow, error)
|
||||
GetTemplateSchema(ctx context.Context, id int64) (GetTemplateSchemaRow, error)
|
||||
GetTenantMembership(ctx context.Context, userID int64) (GetTenantMembershipRow, error)
|
||||
GetTenantMembershipByTenantAndUser(ctx context.Context, arg GetTenantMembershipByTenantAndUserParams) (GetTenantMembershipByTenantAndUserRow, error)
|
||||
GetUserByEmail(ctx context.Context, email string) (GetUserByEmailRow, error)
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
const getTemplateByID = `-- name: GetTemplateByID :one
|
||||
SELECT id, scope, tenant_id, origin_type, template_key, template_name,
|
||||
schema_json, prompt_template, prompt_visibility, protected_prompt_asset_key,
|
||||
prompt_template, prompt_visibility, protected_prompt_asset_key,
|
||||
card_config_json, status, version_no, created_at, updated_at
|
||||
FROM article_templates
|
||||
WHERE id = $1
|
||||
@@ -33,7 +33,6 @@ type GetTemplateByIDRow struct {
|
||||
OriginType string `json:"origin_type"`
|
||||
TemplateKey string `json:"template_key"`
|
||||
TemplateName string `json:"template_name"`
|
||||
SchemaJson []byte `json:"schema_json"`
|
||||
PromptTemplate pgtype.Text `json:"prompt_template"`
|
||||
PromptVisibility string `json:"prompt_visibility"`
|
||||
ProtectedPromptAssetKey pgtype.Text `json:"protected_prompt_asset_key"`
|
||||
@@ -54,7 +53,6 @@ func (q *Queries) GetTemplateByID(ctx context.Context, arg GetTemplateByIDParams
|
||||
&i.OriginType,
|
||||
&i.TemplateKey,
|
||||
&i.TemplateName,
|
||||
&i.SchemaJson,
|
||||
&i.PromptTemplate,
|
||||
&i.PromptVisibility,
|
||||
&i.ProtectedPromptAssetKey,
|
||||
@@ -67,28 +65,9 @@ func (q *Queries) GetTemplateByID(ctx context.Context, arg GetTemplateByIDParams
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getTemplateSchema = `-- name: GetTemplateSchema :one
|
||||
SELECT id, template_name, schema_json
|
||||
FROM article_templates
|
||||
WHERE id = $1 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
type GetTemplateSchemaRow struct {
|
||||
ID int64 `json:"id"`
|
||||
TemplateName string `json:"template_name"`
|
||||
SchemaJson []byte `json:"schema_json"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetTemplateSchema(ctx context.Context, id int64) (GetTemplateSchemaRow, error) {
|
||||
row := q.db.QueryRow(ctx, getTemplateSchema, id)
|
||||
var i GetTemplateSchemaRow
|
||||
err := row.Scan(&i.ID, &i.TemplateName, &i.SchemaJson)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listTemplates = `-- name: ListTemplates :many
|
||||
SELECT id, scope, tenant_id, origin_type, template_key, template_name,
|
||||
schema_json, prompt_template, prompt_visibility, card_config_json,
|
||||
prompt_template, prompt_visibility, card_config_json,
|
||||
status, version_no, created_at, updated_at
|
||||
FROM article_templates
|
||||
WHERE (scope = 'platform' OR tenant_id = $1::bigint)
|
||||
@@ -103,7 +82,6 @@ type ListTemplatesRow struct {
|
||||
OriginType string `json:"origin_type"`
|
||||
TemplateKey string `json:"template_key"`
|
||||
TemplateName string `json:"template_name"`
|
||||
SchemaJson []byte `json:"schema_json"`
|
||||
PromptTemplate pgtype.Text `json:"prompt_template"`
|
||||
PromptVisibility string `json:"prompt_visibility"`
|
||||
CardConfigJson []byte `json:"card_config_json"`
|
||||
@@ -129,7 +107,6 @@ func (q *Queries) ListTemplates(ctx context.Context, tenantID int64) ([]ListTemp
|
||||
&i.OriginType,
|
||||
&i.TemplateKey,
|
||||
&i.TemplateName,
|
||||
&i.SchemaJson,
|
||||
&i.PromptTemplate,
|
||||
&i.PromptVisibility,
|
||||
&i.CardConfigJson,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
-- name: ListTemplates :many
|
||||
SELECT id, scope, tenant_id, origin_type, template_key, template_name,
|
||||
schema_json, prompt_template, prompt_visibility, card_config_json,
|
||||
prompt_template, prompt_visibility, card_config_json,
|
||||
status, version_no, created_at, updated_at
|
||||
FROM article_templates
|
||||
WHERE (scope = 'platform' OR tenant_id = sqlc.arg(tenant_id)::bigint)
|
||||
@@ -9,14 +9,9 @@ ORDER BY created_at DESC;
|
||||
|
||||
-- name: GetTemplateByID :one
|
||||
SELECT id, scope, tenant_id, origin_type, template_key, template_name,
|
||||
schema_json, prompt_template, prompt_visibility, protected_prompt_asset_key,
|
||||
prompt_template, prompt_visibility, protected_prompt_asset_key,
|
||||
card_config_json, status, version_no, created_at, updated_at
|
||||
FROM article_templates
|
||||
WHERE id = sqlc.arg(id)
|
||||
AND (scope = 'platform' OR tenant_id = sqlc.arg(tenant_id)::bigint)
|
||||
AND deleted_at IS NULL;
|
||||
|
||||
-- name: GetTemplateSchema :one
|
||||
SELECT id, template_name, schema_json
|
||||
FROM article_templates
|
||||
WHERE id = sqlc.arg(id) AND deleted_at IS NULL;
|
||||
|
||||
@@ -61,7 +61,3 @@ func (r *cachedTemplateRepository) GetTemplateByID(ctx context.Context, id, tena
|
||||
}
|
||||
return record, nil
|
||||
}
|
||||
|
||||
func (r *cachedTemplateRepository) GetTemplateSchema(ctx context.Context, id int64) (*TemplateSchemaRecord, error) {
|
||||
return r.inner.GetTemplateSchema(ctx, id)
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ type TemplateRecord struct {
|
||||
OriginType string
|
||||
TemplateKey string
|
||||
TemplateName string
|
||||
SchemaJSON []byte
|
||||
PromptTemplate *string
|
||||
PromptVisibility string
|
||||
ProtectedPromptAssetKey *string
|
||||
@@ -25,16 +24,9 @@ type TemplateRecord struct {
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type TemplateSchemaRecord struct {
|
||||
ID int64
|
||||
TemplateName string
|
||||
SchemaJSON []byte
|
||||
}
|
||||
|
||||
type TemplateRepository interface {
|
||||
ListTemplates(ctx context.Context, tenantID int64) ([]TemplateRecord, error)
|
||||
GetTemplateByID(ctx context.Context, id, tenantID int64) (*TemplateRecord, error)
|
||||
GetTemplateSchema(ctx context.Context, id int64) (*TemplateSchemaRecord, error)
|
||||
}
|
||||
|
||||
type templateRepository struct {
|
||||
@@ -60,7 +52,6 @@ func (r *templateRepository) ListTemplates(ctx context.Context, tenantID int64)
|
||||
OriginType: row.OriginType,
|
||||
TemplateKey: row.TemplateKey,
|
||||
TemplateName: row.TemplateName,
|
||||
SchemaJSON: row.SchemaJson,
|
||||
PromptTemplate: nullableText(row.PromptTemplate),
|
||||
PromptVisibility: row.PromptVisibility,
|
||||
CardConfigJSON: row.CardConfigJson,
|
||||
@@ -90,7 +81,6 @@ func (r *templateRepository) GetTemplateByID(ctx context.Context, id, tenantID i
|
||||
OriginType: row.OriginType,
|
||||
TemplateKey: row.TemplateKey,
|
||||
TemplateName: row.TemplateName,
|
||||
SchemaJSON: row.SchemaJson,
|
||||
PromptTemplate: nullableText(row.PromptTemplate),
|
||||
PromptVisibility: row.PromptVisibility,
|
||||
ProtectedPromptAssetKey: nullableText(row.ProtectedPromptAssetKey),
|
||||
@@ -101,16 +91,3 @@ func (r *templateRepository) GetTemplateByID(ctx context.Context, id, tenantID i
|
||||
UpdatedAt: timeFromTimestamp(row.UpdatedAt),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *templateRepository) GetTemplateSchema(ctx context.Context, id int64) (*TemplateSchemaRecord, error) {
|
||||
row, err := r.q.GetTemplateSchema(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &TemplateSchemaRecord{
|
||||
ID: row.ID,
|
||||
TemplateName: row.TemplateName,
|
||||
SchemaJSON: row.SchemaJson,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user