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,9 +4,9 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/labstack/echo/v4"
|
||||
|
||||
"github.com/treytartt/casera-api/internal/i18n"
|
||||
"github.com/treytartt/casera-api/internal/apperrors"
|
||||
"github.com/treytartt/casera-api/internal/services"
|
||||
)
|
||||
|
||||
@@ -24,83 +24,74 @@ func NewTaskTemplateHandler(templateService *services.TaskTemplateService) *Task
|
||||
|
||||
// GetTemplates handles GET /api/tasks/templates/
|
||||
// Returns all active task templates as a flat list
|
||||
func (h *TaskTemplateHandler) GetTemplates(c *gin.Context) {
|
||||
func (h *TaskTemplateHandler) GetTemplates(c echo.Context) error {
|
||||
templates, err := h.templateService.GetAll()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": i18n.LocalizedMessage(c, "error.failed_to_fetch_templates")})
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, templates)
|
||||
return c.JSON(http.StatusOK, templates)
|
||||
}
|
||||
|
||||
// GetTemplatesGrouped handles GET /api/tasks/templates/grouped/
|
||||
// Returns all templates grouped by category
|
||||
func (h *TaskTemplateHandler) GetTemplatesGrouped(c *gin.Context) {
|
||||
func (h *TaskTemplateHandler) GetTemplatesGrouped(c echo.Context) error {
|
||||
grouped, err := h.templateService.GetGrouped()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": i18n.LocalizedMessage(c, "error.failed_to_fetch_templates")})
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, grouped)
|
||||
return c.JSON(http.StatusOK, grouped)
|
||||
}
|
||||
|
||||
// SearchTemplates handles GET /api/tasks/templates/search/
|
||||
// Searches templates by query string
|
||||
func (h *TaskTemplateHandler) SearchTemplates(c *gin.Context) {
|
||||
query := c.Query("q")
|
||||
func (h *TaskTemplateHandler) SearchTemplates(c echo.Context) error {
|
||||
query := c.QueryParam("q")
|
||||
if query == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Query parameter 'q' is required"})
|
||||
return
|
||||
return apperrors.BadRequest("error.query_required")
|
||||
}
|
||||
|
||||
if len(query) < 2 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Query must be at least 2 characters"})
|
||||
return
|
||||
return apperrors.BadRequest("error.query_too_short")
|
||||
}
|
||||
|
||||
templates, err := h.templateService.Search(query)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": i18n.LocalizedMessage(c, "error.failed_to_search_templates")})
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, templates)
|
||||
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 *gin.Context) {
|
||||
func (h *TaskTemplateHandler) GetTemplatesByCategory(c echo.Context) error {
|
||||
categoryID, err := strconv.ParseUint(c.Param("category_id"), 10, 32)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid category ID"})
|
||||
return
|
||||
return apperrors.BadRequest("error.invalid_id")
|
||||
}
|
||||
|
||||
templates, err := h.templateService.GetByCategory(uint(categoryID))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": i18n.LocalizedMessage(c, "error.failed_to_fetch_templates")})
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, templates)
|
||||
return c.JSON(http.StatusOK, templates)
|
||||
}
|
||||
|
||||
// GetTemplate handles GET /api/tasks/templates/:id/
|
||||
// Returns a single template by ID
|
||||
func (h *TaskTemplateHandler) GetTemplate(c *gin.Context) {
|
||||
func (h *TaskTemplateHandler) GetTemplate(c echo.Context) error {
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 32)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid template ID"})
|
||||
return
|
||||
return apperrors.BadRequest("error.invalid_id")
|
||||
}
|
||||
|
||||
template, err := h.templateService.GetByID(uint(id))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": i18n.LocalizedMessage(c, "error.template_not_found")})
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, template)
|
||||
return c.JSON(http.StatusOK, template)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user