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:
@@ -63,6 +63,26 @@ func (s *TaskTemplateService) GetByID(id uint) (*responses.TaskTemplateResponse,
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
// GetByRegion returns templates for a specific climate region.
|
||||
// Accepts either a state abbreviation or ZIP code (state takes priority).
|
||||
// ZIP codes are resolved to a state via the ZipToState lookup.
|
||||
func (s *TaskTemplateService) GetByRegion(state, zip string) ([]responses.TaskTemplateResponse, error) {
|
||||
// Resolve ZIP to state if no state provided
|
||||
if state == "" && zip != "" {
|
||||
state = ZipToState(zip)
|
||||
}
|
||||
|
||||
regionID := GetClimateRegionIDByState(state)
|
||||
if regionID == 0 {
|
||||
return []responses.TaskTemplateResponse{}, nil
|
||||
}
|
||||
templates, err := s.templateRepo.GetByRegion(regionID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return responses.NewTaskTemplateListResponse(templates), nil
|
||||
}
|
||||
|
||||
// Count returns the total count of active templates
|
||||
func (s *TaskTemplateService) Count() (int64, error) {
|
||||
return s.templateRepo.Count()
|
||||
|
||||
Reference in New Issue
Block a user