Files
honeyDueAPI/internal/handlers/task_template_handler.go
Trey t 4976eafc6c Rebrand from Casera/MyCrib to honeyDue
Total rebrand across all Go API source files:
- Go module path: casera-api -> honeydue-api
- All imports updated (130+ files)
- Docker: containers, images, networks renamed
- Email templates: support email, noreply, icon URL
- Domains: casera.app/mycrib.treytartt.com -> honeyDue.treytartt.com
- Bundle IDs: com.tt.casera -> com.tt.honeyDue
- IAP product IDs updated
- Landing page, admin panel, config defaults
- Seeds, CI workflows, Makefile, docs
- Database table names preserved (no migration needed)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 06:33:38 -06:00

116 lines
3.0 KiB
Go

package handlers
import (
"net/http"
"strconv"
"github.com/labstack/echo/v4"
"github.com/treytartt/honeydue-api/internal/apperrors"
"github.com/treytartt/honeydue-api/internal/services"
)
// TaskTemplateHandler handles task template endpoints
type TaskTemplateHandler struct {
templateService *services.TaskTemplateService
}
// NewTaskTemplateHandler creates a new task template handler
func NewTaskTemplateHandler(templateService *services.TaskTemplateService) *TaskTemplateHandler {
return &TaskTemplateHandler{
templateService: templateService,
}
}
// GetTemplates handles GET /api/tasks/templates/
// Returns all active task templates as a flat list
func (h *TaskTemplateHandler) GetTemplates(c echo.Context) error {
templates, err := h.templateService.GetAll()
if err != nil {
return err
}
return c.JSON(http.StatusOK, templates)
}
// GetTemplatesGrouped handles GET /api/tasks/templates/grouped/
// Returns all templates grouped by category
func (h *TaskTemplateHandler) GetTemplatesGrouped(c echo.Context) error {
grouped, err := h.templateService.GetGrouped()
if err != nil {
return err
}
return c.JSON(http.StatusOK, grouped)
}
// SearchTemplates handles GET /api/tasks/templates/search/
// Searches templates by query string
func (h *TaskTemplateHandler) SearchTemplates(c echo.Context) error {
query := c.QueryParam("q")
if query == "" {
return apperrors.BadRequest("error.query_required")
}
if len(query) < 2 {
return apperrors.BadRequest("error.query_too_short")
}
templates, err := h.templateService.Search(query)
if err != nil {
return err
}
return c.JSON(http.StatusOK, templates)
}
// GetTemplatesByCategory handles GET /api/tasks/templates/by-category/:category_id/
// Returns templates for a specific category
func (h *TaskTemplateHandler) GetTemplatesByCategory(c echo.Context) error {
categoryID, err := strconv.ParseUint(c.Param("category_id"), 10, 32)
if err != nil {
return apperrors.BadRequest("error.invalid_id")
}
templates, err := h.templateService.GetByCategory(uint(categoryID))
if err != nil {
return err
}
return c.JSON(http.StatusOK, templates)
}
// GetTemplatesByRegion handles GET /api/tasks/templates/by-region/?state=XX or ?zip=12345
// Returns templates specific to the user's climate region based on state abbreviation or ZIP code
func (h *TaskTemplateHandler) GetTemplatesByRegion(c echo.Context) error {
state := c.QueryParam("state")
zip := c.QueryParam("zip")
if state == "" && zip == "" {
return apperrors.BadRequest("error.state_or_zip_required")
}
templates, err := h.templateService.GetByRegion(state, zip)
if err != nil {
return err
}
return c.JSON(http.StatusOK, templates)
}
// GetTemplate handles GET /api/tasks/templates/:id/
// Returns a single template by ID
func (h *TaskTemplateHandler) GetTemplate(c echo.Context) error {
id, err := strconv.ParseUint(c.Param("id"), 10, 32)
if err != nil {
return apperrors.BadRequest("error.invalid_id")
}
template, err := h.templateService.GetByID(uint(id))
if err != nil {
return err
}
return c.JSON(http.StatusOK, template)
}