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>
36 lines
1.9 KiB
Go
36 lines
1.9 KiB
Go
package models
|
|
|
|
import "encoding/json"
|
|
|
|
// TaskTemplate represents a predefined task template that users can select when creating tasks
|
|
type TaskTemplate struct {
|
|
BaseModel
|
|
Title string `gorm:"column:title;size:200;not null" json:"title"`
|
|
Description string `gorm:"column:description;type:text" json:"description"`
|
|
CategoryID *uint `gorm:"column:category_id;index" json:"category_id"`
|
|
Category *TaskCategory `gorm:"foreignKey:CategoryID" json:"category,omitempty"`
|
|
FrequencyID *uint `gorm:"column:frequency_id;index" json:"frequency_id"`
|
|
Frequency *TaskFrequency `gorm:"foreignKey:FrequencyID" json:"frequency,omitempty"`
|
|
IconIOS string `gorm:"column:icon_ios;size:100" json:"icon_ios"`
|
|
IconAndroid string `gorm:"column:icon_android;size:100" json:"icon_android"`
|
|
Tags string `gorm:"column:tags;type:text" json:"tags"` // Comma-separated tags for search
|
|
DisplayOrder int `gorm:"column:display_order;default:0" json:"display_order"`
|
|
IsActive bool `gorm:"column:is_active;default:true;index" json:"is_active"`
|
|
// Conditions is the JSON-encoded scoring condition set evaluated by
|
|
// SuggestionService. Supported keys: heating_type, cooling_type,
|
|
// water_heater_type, roof_type, exterior_type, flooring_primary,
|
|
// landscaping_type, has_pool, has_sprinkler_system, has_septic,
|
|
// has_fireplace, has_garage, has_basement, has_attic, property_type,
|
|
// climate_region_id.
|
|
//
|
|
// Climate regions used to be stored via a many-to-many with
|
|
// ClimateRegion; they are now driven entirely by the JSON condition
|
|
// above. See migration 000017 for the join-table drop.
|
|
Conditions json.RawMessage `gorm:"column:conditions;type:jsonb;default:'{}'" json:"conditions"`
|
|
}
|
|
|
|
// TableName returns the table name for GORM
|
|
func (TaskTemplate) TableName() string {
|
|
return "task_tasktemplate"
|
|
}
|