Files
geo/server/internal/tenant/repository/template_repo.go
T
root 111498a65f 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.
2026-04-02 11:38:08 +08:00

94 lines
2.8 KiB
Go

package repository
import (
"context"
"time"
"github.com/geo-platform/tenant-api/internal/tenant/repository/generated"
)
type TemplateRecord struct {
ID int64
Scope string
TenantID *int64
OriginType string
TemplateKey string
TemplateName string
PromptTemplate *string
PromptVisibility string
ProtectedPromptAssetKey *string
CardConfigJSON []byte
Status string
VersionNo int
CreatedAt time.Time
UpdatedAt time.Time
}
type TemplateRepository interface {
ListTemplates(ctx context.Context, tenantID int64) ([]TemplateRecord, error)
GetTemplateByID(ctx context.Context, id, tenantID int64) (*TemplateRecord, error)
}
type templateRepository struct {
q generated.Querier
}
func NewTemplateRepository(db generated.DBTX) TemplateRepository {
return &templateRepository{q: newQuerier(db)}
}
func (r *templateRepository) ListTemplates(ctx context.Context, tenantID int64) ([]TemplateRecord, error) {
rows, err := r.q.ListTemplates(ctx, tenantID)
if err != nil {
return nil, err
}
templates := make([]TemplateRecord, 0, len(rows))
for _, row := range rows {
templates = append(templates, TemplateRecord{
ID: row.ID,
Scope: row.Scope,
TenantID: nullableInt64(row.TenantID),
OriginType: row.OriginType,
TemplateKey: row.TemplateKey,
TemplateName: row.TemplateName,
PromptTemplate: nullableText(row.PromptTemplate),
PromptVisibility: row.PromptVisibility,
CardConfigJSON: row.CardConfigJson,
Status: row.Status,
VersionNo: int(row.VersionNo),
CreatedAt: timeFromTimestamp(row.CreatedAt),
UpdatedAt: timeFromTimestamp(row.UpdatedAt),
})
}
return templates, nil
}
func (r *templateRepository) GetTemplateByID(ctx context.Context, id, tenantID int64) (*TemplateRecord, error) {
row, err := r.q.GetTemplateByID(ctx, generated.GetTemplateByIDParams{
ID: id,
TenantID: tenantID,
})
if err != nil {
return nil, err
}
return &TemplateRecord{
ID: row.ID,
Scope: row.Scope,
TenantID: nullableInt64(row.TenantID),
OriginType: row.OriginType,
TemplateKey: row.TemplateKey,
TemplateName: row.TemplateName,
PromptTemplate: nullableText(row.PromptTemplate),
PromptVisibility: row.PromptVisibility,
ProtectedPromptAssetKey: nullableText(row.ProtectedPromptAssetKey),
CardConfigJSON: row.CardConfigJson,
Status: row.Status,
VersionNo: int(row.VersionNo),
CreatedAt: timeFromTimestamp(row.CreatedAt),
UpdatedAt: timeFromTimestamp(row.UpdatedAt),
}, nil
}