Refactor brand service and related components
- Removed ListQuestionVersions method and associated types from BrandService and Queries. - Updated PromptRuleGenerationService to change task naming and handling. - Enhanced ScheduleTaskService to support filtering by created date range and keyword. - Introduced InstantTaskService for managing instant tasks with appropriate filtering and response structures. - Added InstantTaskHandler for handling API requests related to instant tasks. - Created InstantTaskTab component for the admin web interface to display and manage instant tasks. - Updated database migrations to rename source types for articles and generation tasks. - Adjusted models and repository queries to reflect the removal of question version handling.
This commit is contained in:
@@ -50,6 +50,9 @@ func (h *ArticleHandler) List(c *gin.Context) {
|
||||
if v := c.Query("source_type"); v != "" {
|
||||
params.SourceType = &v
|
||||
}
|
||||
if v := c.Query("generation_mode"); v != "" {
|
||||
params.GenerationMode = &v
|
||||
}
|
||||
if v := c.Query("template_id"); v != "" {
|
||||
if id, err := strconv.ParseInt(v, 10, 64); err == nil {
|
||||
params.TemplateID = &id
|
||||
|
||||
@@ -202,16 +202,6 @@ func (h *BrandHandler) DeleteQuestion(c *gin.Context) {
|
||||
response.Success(c, nil)
|
||||
}
|
||||
|
||||
func (h *BrandHandler) ListQuestionVersions(c *gin.Context) {
|
||||
brandID, _ := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
data, err := h.svc.ListQuestionVersions(c.Request.Context(), brandID)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
// Competitors
|
||||
func (h *BrandHandler) ListCompetitors(c *gin.Context) {
|
||||
brandID, _ := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package transport
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/geo-platform/tenant-api/internal/bootstrap"
|
||||
"github.com/geo-platform/tenant-api/internal/shared/response"
|
||||
"github.com/geo-platform/tenant-api/internal/tenant/app"
|
||||
)
|
||||
|
||||
type InstantTaskHandler struct {
|
||||
svc *app.InstantTaskService
|
||||
}
|
||||
|
||||
func NewInstantTaskHandler(a *bootstrap.App) *InstantTaskHandler {
|
||||
return &InstantTaskHandler{svc: app.NewInstantTaskService(a.DB)}
|
||||
}
|
||||
|
||||
func (h *InstantTaskHandler) List(c *gin.Context) {
|
||||
params := app.InstantTaskListParams{
|
||||
Page: 1,
|
||||
PageSize: 20,
|
||||
}
|
||||
if v := c.Query("page"); v != "" {
|
||||
if p, err := strconv.Atoi(v); err == nil {
|
||||
params.Page = p
|
||||
}
|
||||
}
|
||||
if v := c.Query("page_size"); v != "" {
|
||||
if ps, err := strconv.Atoi(v); err == nil {
|
||||
params.PageSize = ps
|
||||
}
|
||||
}
|
||||
if v := c.Query("prompt_rule_id"); v != "" {
|
||||
if rid, err := strconv.ParseInt(v, 10, 64); err == nil {
|
||||
params.PromptRuleID = &rid
|
||||
}
|
||||
}
|
||||
if v := c.Query("status"); v != "" {
|
||||
params.Status = &v
|
||||
}
|
||||
if v := c.Query("keyword"); v != "" {
|
||||
params.Keyword = &v
|
||||
}
|
||||
if v := c.Query("created_from"); v != "" {
|
||||
parsed, err := time.Parse(time.RFC3339, v)
|
||||
if err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40014, "invalid_created_from", "created_from must be RFC3339"))
|
||||
return
|
||||
}
|
||||
params.CreatedFrom = &parsed
|
||||
}
|
||||
if v := c.Query("created_to"); v != "" {
|
||||
parsed, err := time.Parse(time.RFC3339, v)
|
||||
if err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40015, "invalid_created_to", "created_to must be RFC3339"))
|
||||
return
|
||||
}
|
||||
params.CreatedTo = &parsed
|
||||
}
|
||||
|
||||
data, err := h.svc.List(c.Request.Context(), params)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
@@ -64,7 +64,6 @@ func RegisterRoutes(app *bootstrap.App) {
|
||||
brands.POST("/:id/questions", brandHandler.CreateQuestion)
|
||||
brands.PUT("/:id/questions/:qid", brandHandler.UpdateQuestion)
|
||||
brands.DELETE("/:id/questions/:qid", brandHandler.DeleteQuestion)
|
||||
brands.GET("/:id/question-versions", brandHandler.ListQuestionVersions)
|
||||
brands.GET("/:id/competitors", brandHandler.ListCompetitors)
|
||||
brands.POST("/:id/competitors", brandHandler.CreateCompetitor)
|
||||
brands.PUT("/:id/competitors/:cid", brandHandler.UpdateCompetitor)
|
||||
@@ -95,4 +94,8 @@ func RegisterRoutes(app *bootstrap.App) {
|
||||
schedules.PUT("/:id", schHandler.Update)
|
||||
schedules.DELETE("/:id", schHandler.Delete)
|
||||
schedules.PUT("/:id/status", schHandler.ToggleStatus)
|
||||
|
||||
instantTasks := protected.Group("/tenant/instant-tasks")
|
||||
instHandler := NewInstantTaskHandler(app)
|
||||
instantTasks.GET("", instHandler.List)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package transport
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
@@ -41,6 +42,25 @@ func (h *ScheduleTaskHandler) List(c *gin.Context) {
|
||||
if v := c.Query("status"); v != "" {
|
||||
params.Status = &v
|
||||
}
|
||||
if v := c.Query("keyword"); v != "" {
|
||||
params.Keyword = &v
|
||||
}
|
||||
if v := c.Query("created_from"); v != "" {
|
||||
parsed, err := time.Parse(time.RFC3339, v)
|
||||
if err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40014, "invalid_created_from", "created_from must be RFC3339"))
|
||||
return
|
||||
}
|
||||
params.CreatedFrom = &parsed
|
||||
}
|
||||
if v := c.Query("created_to"); v != "" {
|
||||
parsed, err := time.Parse(time.RFC3339, v)
|
||||
if err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40015, "invalid_created_to", "created_to must be RFC3339"))
|
||||
return
|
||||
}
|
||||
params.CreatedTo = &parsed
|
||||
}
|
||||
|
||||
data, err := h.svc.List(c.Request.Context(), params)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user