Onboarding: template backlink, bulk-create endpoint, climate-region scoring
Some checks failed
Some checks failed
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:
@@ -1664,27 +1664,10 @@ func TestTaskTemplateHandler_GetTemplatesByCategory(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestTaskTemplateHandler_GetTemplatesByRegion(t *testing.T) {
|
||||
handler, e, db := setupTaskTemplateHandler(t)
|
||||
testutil.SeedLookupData(t, db)
|
||||
|
||||
e.GET("/api/tasks/templates/by-region/", handler.GetTemplatesByRegion)
|
||||
|
||||
t.Run("missing both state and zip returns 400", func(t *testing.T) {
|
||||
w := testutil.MakeRequest(e, "GET", "/api/tasks/templates/by-region/", nil, "")
|
||||
testutil.AssertStatusCode(t, w, http.StatusBadRequest)
|
||||
})
|
||||
|
||||
t.Run("with state param returns 200", func(t *testing.T) {
|
||||
w := testutil.MakeRequest(e, "GET", "/api/tasks/templates/by-region/?state=TX", nil, "")
|
||||
testutil.AssertStatusCode(t, w, http.StatusOK)
|
||||
})
|
||||
|
||||
t.Run("with zip param returns 200", func(t *testing.T) {
|
||||
w := testutil.MakeRequest(e, "GET", "/api/tasks/templates/by-region/?zip=78701", nil, "")
|
||||
testutil.AssertStatusCode(t, w, http.StatusOK)
|
||||
})
|
||||
}
|
||||
// NOTE: TestTaskTemplateHandler_GetTemplatesByRegion was removed. The
|
||||
// /api/tasks/templates/by-region/ endpoint was deleted; climate-zone
|
||||
// affinity is now a JSON condition on each template and is scored by the
|
||||
// main /api/tasks/suggestions/ endpoint (see SuggestionService tests).
|
||||
|
||||
func TestTaskTemplateHandler_GetTemplate(t *testing.T) {
|
||||
handler, e, db := setupTaskTemplateHandler(t)
|
||||
|
||||
Reference in New Issue
Block a user