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.
This commit is contained in:
@@ -19,10 +19,14 @@ func NewTemplateHandler(a *bootstrap.App) *TemplateHandler {
|
||||
return &TemplateHandler{
|
||||
svc: app.NewTemplateService(
|
||||
a.DB,
|
||||
repository.NewTemplateRepository(a.DB),
|
||||
repository.NewCachedTemplateRepository(
|
||||
repository.NewTemplateRepository(a.DB),
|
||||
a.Cache,
|
||||
),
|
||||
a.LLM,
|
||||
a.GenerationStreams,
|
||||
a.Config.Generation,
|
||||
a.Config.LLM.MaxOutputTokens,
|
||||
),
|
||||
}
|
||||
}
|
||||
@@ -82,3 +86,148 @@ func (h *TemplateHandler) Generate(c *gin.Context) {
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *TemplateHandler) SaveDraft(c *gin.Context) {
|
||||
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40001, "invalid_id", "template id must be a number"))
|
||||
return
|
||||
}
|
||||
var req app.SaveDraftRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40001, "invalid_params", err.Error()))
|
||||
return
|
||||
}
|
||||
data, err := h.svc.SaveDraft(c.Request.Context(), id, req)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *TemplateHandler) CreateAnalyzeTask(c *gin.Context) {
|
||||
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40001, "invalid_id", "template id must be a number"))
|
||||
return
|
||||
}
|
||||
|
||||
var req app.AnalyzeTaskRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40001, "invalid_params", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
data, err := h.svc.CreateAnalyzeTask(c.Request.Context(), id, req)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *TemplateHandler) GetAnalyzeTaskResult(c *gin.Context) {
|
||||
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40001, "invalid_id", "template id must be a number"))
|
||||
return
|
||||
}
|
||||
|
||||
taskID := c.Query("task_id")
|
||||
if taskID == "" {
|
||||
response.Error(c, response.ErrBadRequest(40001, "invalid_task_id", "task id must not be empty"))
|
||||
return
|
||||
}
|
||||
|
||||
data, err := h.svc.GetAnalyzeTask(c.Request.Context(), id, taskID)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *TemplateHandler) CreateTitleTask(c *gin.Context) {
|
||||
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40001, "invalid_id", "template id must be a number"))
|
||||
return
|
||||
}
|
||||
|
||||
var req app.TitleTaskRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40001, "invalid_params", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
data, err := h.svc.CreateTitleTask(c.Request.Context(), id, req)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *TemplateHandler) GetTitleTaskResult(c *gin.Context) {
|
||||
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40001, "invalid_id", "template id must be a number"))
|
||||
return
|
||||
}
|
||||
|
||||
taskID := c.Query("task_id")
|
||||
if taskID == "" {
|
||||
response.Error(c, response.ErrBadRequest(40001, "invalid_task_id", "task id must not be empty"))
|
||||
return
|
||||
}
|
||||
|
||||
data, err := h.svc.GetTitleTask(c.Request.Context(), id, taskID)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *TemplateHandler) CreateOutlineTask(c *gin.Context) {
|
||||
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40001, "invalid_id", "template id must be a number"))
|
||||
return
|
||||
}
|
||||
|
||||
var req app.OutlineTaskRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40001, "invalid_params", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
data, err := h.svc.CreateOutlineTask(c.Request.Context(), id, req)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
func (h *TemplateHandler) GetOutlineTaskResult(c *gin.Context) {
|
||||
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40001, "invalid_id", "template id must be a number"))
|
||||
return
|
||||
}
|
||||
|
||||
taskID := c.Query("task_id")
|
||||
if taskID == "" {
|
||||
response.Error(c, response.ErrBadRequest(40001, "invalid_task_id", "task id must not be empty"))
|
||||
return
|
||||
}
|
||||
|
||||
data, err := h.svc.GetOutlineTask(c.Request.Context(), id, taskID)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user