Files
geo/server/internal/tenant/repository/audit_repo.go
T
root b31d8d0096 feat(migrations): Harden task audit tracking and optimize article templates
- Added migration to harden task audit tracking by modifying audit_logs and related tables.
- Introduced operator_id to several tables for better tracking of actions.
- Updated article_templates with new prompt templates for various article types, enhancing content generation.
- Created prompt_rules and schedule_tasks tables to manage content generation rules and scheduling.
- Added foreign key constraints to articles for better data integrity.
2026-04-02 00:31:28 +08:00

94 lines
2.6 KiB
Go

package repository
import (
"context"
"time"
"github.com/geo-platform/tenant-api/internal/tenant/repository/generated"
)
type AuditLogInput struct {
OperatorID int64
TenantID *int64
Module string
Action string
ResourceType *string
ResourceID *int64
RequestID *string
BeforeJSON []byte
AfterJSON []byte
Result *string
ErrorMessage *string
}
type GenerationTaskInput struct {
OperatorID int64
TenantID int64
ArticleID *int64
QuotaReservationID *int64
TaskType string
InputParamsJSON []byte
}
type GenerationTaskStatusInput struct {
ID int64
TenantID int64
Status string
ErrorMessage *string
StartedAt *time.Time
CompletedAt *time.Time
}
type AuditRepository interface {
CreateAuditLog(ctx context.Context, input AuditLogInput) error
CreateGenerationTask(ctx context.Context, input GenerationTaskInput) (int64, error)
UpdateGenerationTaskStatus(ctx context.Context, input GenerationTaskStatusInput) error
}
type auditRepository struct {
q generated.Querier
}
func NewAuditRepository(db generated.DBTX) AuditRepository {
return &auditRepository{q: newQuerier(db)}
}
func (r *auditRepository) CreateAuditLog(ctx context.Context, input AuditLogInput) error {
return r.q.CreateAuditLog(ctx, generated.CreateAuditLogParams{
OperatorID: input.OperatorID,
TenantID: pgInt8(input.TenantID),
Module: input.Module,
Action: input.Action,
ResourceType: pgText(input.ResourceType),
ResourceID: pgInt8(input.ResourceID),
RequestID: pgText(input.RequestID),
BeforeJson: input.BeforeJSON,
AfterJson: input.AfterJSON,
Result: pgText(input.Result),
ErrorMessage: pgText(input.ErrorMessage),
})
}
func (r *auditRepository) CreateGenerationTask(ctx context.Context, input GenerationTaskInput) (int64, error) {
operatorID := input.OperatorID
return r.q.CreateGenerationTask(ctx, generated.CreateGenerationTaskParams{
OperatorID: pgInt8(&operatorID),
TenantID: input.TenantID,
ArticleID: pgInt8(input.ArticleID),
QuotaReservationID: pgInt8(input.QuotaReservationID),
TaskType: input.TaskType,
InputParamsJson: input.InputParamsJSON,
})
}
func (r *auditRepository) UpdateGenerationTaskStatus(ctx context.Context, input GenerationTaskStatusInput) error {
return r.q.UpdateGenerationTaskStatus(ctx, generated.UpdateGenerationTaskStatusParams{
Status: input.Status,
ErrorMessage: pgText(input.ErrorMessage),
StartedAt: pgTimestamp(input.StartedAt),
CompletedAt: pgTimestamp(input.CompletedAt),
ID: input.ID,
TenantID: input.TenantID,
})
}