feat: scope articles by brand
This commit is contained in:
@@ -59,6 +59,10 @@ type InstantTaskListResponse struct {
|
||||
|
||||
func (s *InstantTaskService) List(ctx context.Context, params InstantTaskListParams) (*InstantTaskListResponse, error) {
|
||||
actor := auth.MustActor(ctx)
|
||||
brandID, err := requireCurrentBrandID(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if params.Page < 1 {
|
||||
params.Page = 1
|
||||
}
|
||||
@@ -90,12 +94,13 @@ func (s *InstantTaskService) List(ctx context.Context, params InstantTaskListPar
|
||||
LEFT JOIN article_versions av ON av.id = a.current_version_id
|
||||
LEFT JOIN prompt_rules pr ON pr.id = COALESCE(a.prompt_rule_id, NULLIF(gt.input_params_json ->> 'prompt_rule_id', '')::bigint)
|
||||
WHERE gt.tenant_id = $1
|
||||
AND COALESCE(a.brand_id, NULLIF(gt.input_params_json ->> 'brand_id', '')::bigint) = $2
|
||||
AND gt.task_type = 'custom_generation'
|
||||
AND COALESCE(NULLIF(gt.input_params_json ->> 'generation_mode', ''), 'instant') = 'instant'
|
||||
AND ($2::bigint IS NULL OR pr.id = $2)
|
||||
AND ($4::text IS NULL OR COALESCE(NULLIF(gt.input_params_json ->> 'task_name', ''), pr.name, '') ILIKE '%' || $4 || '%')
|
||||
AND ($5::timestamptz IS NULL OR gt.created_at >= $5)
|
||||
AND ($6::timestamptz IS NULL OR gt.created_at <= $6)
|
||||
AND ($3::bigint IS NULL OR pr.id = $3)
|
||||
AND ($5::text IS NULL OR COALESCE(NULLIF(gt.input_params_json ->> 'task_name', ''), pr.name, '') ILIKE '%' || $5 || '%')
|
||||
AND ($6::timestamptz IS NULL OR gt.created_at >= $6)
|
||||
AND ($7::timestamptz IS NULL OR gt.created_at <= $7)
|
||||
),
|
||||
keyed AS (
|
||||
SELECT *,
|
||||
@@ -150,11 +155,11 @@ func (s *InstantTaskService) List(ctx context.Context, params InstantTaskListPar
|
||||
)`
|
||||
|
||||
var total int64
|
||||
err := s.pool.QueryRow(ctx, instantTaskBatchCTE+`
|
||||
err = s.pool.QueryRow(ctx, instantTaskBatchCTE+`
|
||||
SELECT COUNT(*)
|
||||
FROM aggregated
|
||||
WHERE ($3::text IS NULL OR status = $3)
|
||||
`, actor.TenantID, params.PromptRuleID, params.Status, params.Keyword, params.CreatedFrom, params.CreatedTo).Scan(&total)
|
||||
WHERE ($4::text IS NULL OR status = $4)
|
||||
`, actor.TenantID, brandID, params.PromptRuleID, params.Status, params.Keyword, params.CreatedFrom, params.CreatedTo).Scan(&total)
|
||||
if err != nil {
|
||||
return nil, response.ErrInternal(50010, "count_failed", "failed to count instant tasks")
|
||||
}
|
||||
@@ -163,10 +168,10 @@ func (s *InstantTaskService) List(ctx context.Context, params InstantTaskListPar
|
||||
SELECT id, article_id, task_batch_id, prompt_rule_id, prompt_rule_name, task_name,
|
||||
status, execution_time, input_params_json, generate_count, articles, created_at
|
||||
FROM aggregated
|
||||
WHERE ($3::text IS NULL OR status = $3)
|
||||
WHERE ($4::text IS NULL OR status = $4)
|
||||
ORDER BY created_at DESC, id DESC
|
||||
LIMIT $7 OFFSET $8
|
||||
`, actor.TenantID, params.PromptRuleID, params.Status, params.Keyword, params.CreatedFrom, params.CreatedTo, params.PageSize, offset)
|
||||
LIMIT $8 OFFSET $9
|
||||
`, actor.TenantID, brandID, params.PromptRuleID, params.Status, params.Keyword, params.CreatedFrom, params.CreatedTo, params.PageSize, offset)
|
||||
if err != nil {
|
||||
return nil, response.ErrInternal(50010, "query_failed", "failed to list instant tasks")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user