8958cb44c0
- 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.
72 lines
1.7 KiB
Go
72 lines
1.7 KiB
Go
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)
|
|
}
|