- Add go-i18n package for internationalization - Create i18n middleware to extract Accept-Language header - Add translation files for en, es, fr, de, pt languages - Localize all handler error messages and responses - Add language context to all API handlers Supported languages: English, Spanish, French, German, Portuguese 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
91 lines
2.8 KiB
Go
91 lines
2.8 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/treytartt/casera-api/internal/i18n"
|
|
"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": i18n.LocalizedMessage(c, "error.failed_to_fetch_residence_types")})
|
|
return
|
|
}
|
|
|
|
taskCategories, err := h.taskService.GetCategories()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": i18n.LocalizedMessage(c, "error.failed_to_fetch_task_categories")})
|
|
return
|
|
}
|
|
|
|
taskPriorities, err := h.taskService.GetPriorities()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": i18n.LocalizedMessage(c, "error.failed_to_fetch_task_priorities")})
|
|
return
|
|
}
|
|
|
|
taskFrequencies, err := h.taskService.GetFrequencies()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": i18n.LocalizedMessage(c, "error.failed_to_fetch_task_frequencies")})
|
|
return
|
|
}
|
|
|
|
taskStatuses, err := h.taskService.GetStatuses()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": i18n.LocalizedMessage(c, "error.failed_to_fetch_task_statuses")})
|
|
return
|
|
}
|
|
|
|
contractorSpecialties, err := h.contractorService.GetSpecialties()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": i18n.LocalizedMessage(c, "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": i18n.LocalizedMessage(c, "message.static_data_refreshed"),
|
|
"status": "success",
|
|
})
|
|
}
|