Migrate from Gin to Echo framework and add comprehensive integration tests
Major changes: - Migrate all handlers from Gin to Echo framework - Add new apperrors, echohelpers, and validator packages - Update middleware for Echo compatibility - Add ArchivedHandler to task categorization chain (archived tasks go to cancelled_tasks column) - Add 6 new integration tests: - RecurringTaskLifecycle: NextDueDate advancement for weekly/monthly tasks - MultiUserSharing: Complex sharing with user removal - TaskStateTransitions: All state transitions and kanban column changes - DateBoundaryEdgeCases: Threshold boundary testing - CascadeOperations: Residence deletion cascade effects - MultiUserOperations: Shared residence collaboration - Add single-purpose repository functions for kanban columns (GetOverdueTasks, GetDueSoonTasks, etc.) - Fix RemoveUser route param mismatch (userId -> user_id) - Fix determineExpectedColumn helper to correctly prioritize in_progress over overdue 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
@@ -51,20 +51,19 @@ func NewStaticDataHandler(
|
||||
|
||||
// GetStaticData handles GET /api/static_data/
|
||||
// Returns all lookup/reference data in a single response with ETag support
|
||||
func (h *StaticDataHandler) GetStaticData(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
func (h *StaticDataHandler) GetStaticData(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
|
||||
// Check If-None-Match header for conditional request
|
||||
// Strip W/ prefix if present (added by reverse proxy, but we store without it)
|
||||
clientETag := strings.TrimPrefix(c.GetHeader("If-None-Match"), "W/")
|
||||
clientETag := strings.TrimPrefix(c.Request().Header.Get("If-None-Match"), "W/")
|
||||
|
||||
// Try to get cached ETag first (fast path for 304 responses)
|
||||
if h.cache != nil && clientETag != "" {
|
||||
cachedETag, err := h.cache.GetSeededDataETag(ctx)
|
||||
if err == nil && cachedETag == clientETag {
|
||||
// Client has the latest data, return 304 Not Modified
|
||||
c.Status(http.StatusNotModified)
|
||||
return
|
||||
return c.NoContent(http.StatusNotModified)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,11 +75,10 @@ func (h *StaticDataHandler) GetStaticData(c *gin.Context) {
|
||||
// Cache hit - get the ETag and return data
|
||||
etag, etagErr := h.cache.GetSeededDataETag(ctx)
|
||||
if etagErr == nil {
|
||||
c.Header("ETag", etag)
|
||||
c.Header("Cache-Control", "private, max-age=3600")
|
||||
c.Response().Header().Set("ETag", etag)
|
||||
c.Response().Header().Set("Cache-Control", "private, max-age=3600")
|
||||
}
|
||||
c.JSON(http.StatusOK, cachedData)
|
||||
return
|
||||
return c.JSON(http.StatusOK, cachedData)
|
||||
} else if err != redis.Nil {
|
||||
// Log cache error but continue to fetch from DB
|
||||
log.Warn().Err(err).Msg("Failed to get cached seeded data")
|
||||
@@ -90,38 +88,32 @@ func (h *StaticDataHandler) GetStaticData(c *gin.Context) {
|
||||
// Cache miss - fetch all data from services
|
||||
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
|
||||
return err
|
||||
}
|
||||
|
||||
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
|
||||
return err
|
||||
}
|
||||
|
||||
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
|
||||
return err
|
||||
}
|
||||
|
||||
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
|
||||
return err
|
||||
}
|
||||
|
||||
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
|
||||
return err
|
||||
}
|
||||
|
||||
taskTemplates, err := h.taskTemplateService.GetGrouped()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": i18n.LocalizedMessage(c, "error.failed_to_fetch_task_templates")})
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
// Build response
|
||||
@@ -140,19 +132,19 @@ func (h *StaticDataHandler) GetStaticData(c *gin.Context) {
|
||||
if cacheErr != nil {
|
||||
log.Warn().Err(cacheErr).Msg("Failed to cache seeded data")
|
||||
} else {
|
||||
c.Header("ETag", etag)
|
||||
c.Header("Cache-Control", "private, max-age=3600")
|
||||
c.Response().Header().Set("ETag", etag)
|
||||
c.Response().Header().Set("Cache-Control", "private, max-age=3600")
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, seededData)
|
||||
return c.JSON(http.StatusOK, seededData)
|
||||
}
|
||||
|
||||
// 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{
|
||||
func (h *StaticDataHandler) RefreshStaticData(c echo.Context) error {
|
||||
return c.JSON(http.StatusOK, map[string]interface{}{
|
||||
"message": i18n.LocalizedMessage(c, "message.static_data_refreshed"),
|
||||
"status": "success",
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user