Add regional task templates API with climate zone lookup
Adds a new endpoint GET /api/tasks/templates/by-region/?zip= that resolves ZIP codes to IECC climate regions and returns relevant home maintenance task templates. Includes climate region model, region lookup service with tests, seed data for all 8 climate zones with 50+ templates, and OpenAPI spec. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
28
internal/models/climate_region.go
Normal file
28
internal/models/climate_region.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package models
|
||||
|
||||
// ClimateRegion represents an IECC climate zone for regional task templates
|
||||
type ClimateRegion struct {
|
||||
BaseModel
|
||||
Name string `gorm:"column:name;size:100;not null;uniqueIndex" json:"name"`
|
||||
ZoneNumber int `gorm:"column:zone_number;not null;index" json:"zone_number"`
|
||||
Description string `gorm:"column:description;type:text" json:"description"`
|
||||
IsActive bool `gorm:"column:is_active;default:true;index" json:"is_active"`
|
||||
}
|
||||
|
||||
// TableName returns the table name for GORM
|
||||
func (ClimateRegion) TableName() string {
|
||||
return "task_climateregion"
|
||||
}
|
||||
|
||||
// ZipClimateRegion maps ZIP codes to climate regions (static lookup)
|
||||
type ZipClimateRegion struct {
|
||||
BaseModel
|
||||
ZipCode string `gorm:"column:zip_code;size:10;uniqueIndex;not null" json:"zip_code"`
|
||||
ClimateRegionID uint `gorm:"column:climate_region_id;index;not null" json:"climate_region_id"`
|
||||
ClimateRegion ClimateRegion `gorm:"foreignKey:ClimateRegionID" json:"climate_region,omitempty"`
|
||||
}
|
||||
|
||||
// TableName returns the table name for GORM
|
||||
func (ZipClimateRegion) TableName() string {
|
||||
return "task_zipclimateregion"
|
||||
}
|
||||
@@ -13,7 +13,8 @@ type TaskTemplate struct {
|
||||
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"`
|
||||
IsActive bool `gorm:"column:is_active;default:true;index" json:"is_active"`
|
||||
Regions []ClimateRegion `gorm:"many2many:task_tasktemplate_regions;" json:"regions,omitempty"`
|
||||
}
|
||||
|
||||
// TableName returns the table name for GORM
|
||||
|
||||
Reference in New Issue
Block a user