- Update Go module from mycrib-api to casera-api - Update all import statements across 69 Go files - Update admin panel branding (title, sidebar, login form) - Update email templates (subjects, bodies, signatures) - Update PDF report generation branding - Update Docker container names and network - Update config defaults (database name, email sender, APNS topic) - Update README and documentation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
90 lines
2.6 KiB
Go
90 lines
2.6 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/treytartt/casera-api/internal/services"
|
|
)
|
|
|
|
// StaticDataHandler handles static/lookup data endpoints
|
|
type StaticDataHandler struct {
|
|
residenceService *services.ResidenceService
|
|
taskService *services.TaskService
|
|
contractorService *services.ContractorService
|
|
}
|
|
|
|
// NewStaticDataHandler creates a new static data handler
|
|
func NewStaticDataHandler(
|
|
residenceService *services.ResidenceService,
|
|
taskService *services.TaskService,
|
|
contractorService *services.ContractorService,
|
|
) *StaticDataHandler {
|
|
return &StaticDataHandler{
|
|
residenceService: residenceService,
|
|
taskService: taskService,
|
|
contractorService: contractorService,
|
|
}
|
|
}
|
|
|
|
// GetStaticData handles GET /api/static_data/
|
|
// Returns all lookup/reference data in a single response
|
|
func (h *StaticDataHandler) GetStaticData(c *gin.Context) {
|
|
// Get all lookup data
|
|
residenceTypes, err := h.residenceService.GetResidenceTypes()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to fetch residence types"})
|
|
return
|
|
}
|
|
|
|
taskCategories, err := h.taskService.GetCategories()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to fetch task categories"})
|
|
return
|
|
}
|
|
|
|
taskPriorities, err := h.taskService.GetPriorities()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to fetch task priorities"})
|
|
return
|
|
}
|
|
|
|
taskFrequencies, err := h.taskService.GetFrequencies()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to fetch task frequencies"})
|
|
return
|
|
}
|
|
|
|
taskStatuses, err := h.taskService.GetStatuses()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to fetch task statuses"})
|
|
return
|
|
}
|
|
|
|
contractorSpecialties, err := h.contractorService.GetSpecialties()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to fetch contractor specialties"})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"residence_types": residenceTypes,
|
|
"task_categories": taskCategories,
|
|
"task_priorities": taskPriorities,
|
|
"task_frequencies": taskFrequencies,
|
|
"task_statuses": taskStatuses,
|
|
"contractor_specialties": contractorSpecialties,
|
|
})
|
|
}
|
|
|
|
// RefreshStaticData handles POST /api/static_data/refresh/
|
|
// This is a no-op since data is fetched fresh each time
|
|
// Kept for API compatibility with mobile clients
|
|
func (h *StaticDataHandler) RefreshStaticData(c *gin.Context) {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"message": "Static data refreshed",
|
|
"status": "success",
|
|
})
|
|
}
|