Onboarding: template backlink, bulk-create endpoint, climate-region scoring
Some checks failed
Backend CI / Test (push) Has been cancelled
Backend CI / Contract Tests (push) Has been cancelled
Backend CI / Build (push) Has been cancelled
Backend CI / Lint (push) Has been cancelled
Backend CI / Secret Scanning (push) Has been cancelled

Clients that send users through a multi-task onboarding step no longer
loop N POST /api/tasks/ calls and no longer create "orphan" tasks with
no reference to the TaskTemplate they came from.

Task model
- New task_template_id column + GORM FK (migration 000016)
- CreateTaskRequest.template_id, TaskResponse.template_id
- task_service.CreateTask persists the backlink

Bulk endpoint
- POST /api/tasks/bulk/ — 1-50 tasks in a single transaction,
  returns every created row + TotalSummary. Single residence access
  check, per-entry residence_id is overridden with batch value
- task_handler.BulkCreateTasks + task_service.BulkCreateTasks using
  db.Transaction; task_repo.CreateTx + FindByIDTx helpers

Climate-region scoring
- templateConditions gains ClimateRegionID; suggestion_service scores
  residence.PostalCode -> ZipToState -> GetClimateRegionIDByState against
  the template's conditions JSON (no penalty on mismatch / unknown ZIP)
- regionMatchBonus 0.35, totalProfileFields 14 -> 15
- Standalone GET /api/tasks/templates/by-region/ removed; legacy
  task_tasktemplate_regions many-to-many dropped (migration 000017).
  Region affinity now lives entirely in the template's conditions JSON

Tests
- +11 cases across task_service_test, task_handler_test, suggestion_
  service_test: template_id persistence, bulk rollback + cap + auth,
  region match / mismatch / no-ZIP / unknown-ZIP / stacks-with-others

Docs
- docs/openapi.yaml: /tasks/bulk/ + BulkCreateTasks schemas, template_id
  on TaskResponse + CreateTaskRequest, /templates/by-region/ removed

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-04-14 15:23:57 -05:00
parent 33eee812b6
commit 237c6b84ee
24 changed files with 678 additions and 169 deletions

View File

@@ -523,39 +523,6 @@ paths:
items:
$ref: '#/components/schemas/TaskTemplateResponse'
/tasks/templates/by-region/:
get:
tags: [Static Data]
operationId: getTaskTemplatesByRegion
summary: Get task templates for a climate region by state or ZIP code
description: Returns templates matching the climate zone for a given US state abbreviation or ZIP code. At least one parameter is required. If both are provided, state takes priority.
parameters:
- name: state
in: query
required: false
schema:
type: string
example: MA
description: US state abbreviation (e.g., MA, FL, TX)
- name: zip
in: query
required: false
schema:
type: string
example: "02101"
description: US ZIP code (resolved to state on the server)
responses:
'200':
description: Regional templates for the climate zone
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/TaskTemplateResponse'
'400':
$ref: '#/components/responses/BadRequest'
/tasks/templates/{id}/:
get:
tags: [Static Data]
@@ -972,6 +939,34 @@ paths:
'403':
$ref: '#/components/responses/Forbidden'
/tasks/bulk/:
post:
tags: [Tasks]
operationId: bulkCreateTasks
summary: Create multiple tasks atomically
description: Inserts 1-50 tasks in a single database transaction. If any entry fails, the entire batch is rolled back. Used primarily by onboarding to create the user's initial task list in one request.
security:
- tokenAuth: []
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/BulkCreateTasksRequest'
responses:
'201':
description: All tasks created
content:
application/json:
schema:
$ref: '#/components/schemas/BulkCreateTasksResponse'
'400':
$ref: '#/components/responses/ValidationError'
'401':
$ref: '#/components/responses/Unauthorized'
'403':
$ref: '#/components/responses/Forbidden'
/tasks/by-residence/{residence_id}/:
get:
tags: [Tasks]
@@ -3690,6 +3685,38 @@ components:
type: integer
format: uint
nullable: true
template_id:
type: integer
format: uint
nullable: true
description: TaskTemplate ID this task was spawned from (onboarding suggestion, browse-catalog pick). Omit for custom tasks.
BulkCreateTasksRequest:
type: object
required: [residence_id, tasks]
properties:
residence_id:
type: integer
format: uint
description: Residence that owns every task in the batch; overrides the per-entry residence_id.
tasks:
type: array
minItems: 1
maxItems: 50
items:
$ref: '#/components/schemas/CreateTaskRequest'
BulkCreateTasksResponse:
type: object
properties:
tasks:
type: array
items:
$ref: '#/components/schemas/TaskResponse'
summary:
$ref: '#/components/schemas/TotalSummary'
created_count:
type: integer
UpdateTaskRequest:
type: object
@@ -3827,6 +3854,11 @@ components:
type: integer
format: uint
nullable: true
template_id:
type: integer
format: uint
nullable: true
description: TaskTemplate this task was spawned from; nil for custom user tasks.
completion_count:
type: integer
kanban_column: