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:
@@ -104,6 +104,20 @@ func (r *TaskTemplateRepository) Count() (int64, error) {
|
||||
return count, err
|
||||
}
|
||||
|
||||
// GetByRegion returns active templates associated with a specific climate region
|
||||
func (r *TaskTemplateRepository) GetByRegion(regionID uint) ([]models.TaskTemplate, error) {
|
||||
var templates []models.TaskTemplate
|
||||
err := r.db.
|
||||
Preload("Category").
|
||||
Preload("Frequency").
|
||||
Preload("Regions").
|
||||
Joins("JOIN task_tasktemplate_regions ON task_tasktemplate_regions.task_template_id = task_tasktemplate.id").
|
||||
Where("task_tasktemplate_regions.climate_region_id = ? AND task_tasktemplate.is_active = ?", regionID, true).
|
||||
Order("task_tasktemplate.display_order ASC, task_tasktemplate.title ASC").
|
||||
Find(&templates).Error
|
||||
return templates, err
|
||||
}
|
||||
|
||||
// GetGroupedByCategory returns templates grouped by category name
|
||||
func (r *TaskTemplateRepository) GetGroupedByCategory() (map[string][]models.TaskTemplate, error) {
|
||||
templates, err := r.GetAll()
|
||||
|
||||
Reference in New Issue
Block a user