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) }