Fix backend API parity: document filters, task days param, i18n locales, contract tests
- Add document list filter support (residence, type, category, contractor, is_active, expiring_soon, search) to handler/service/repo - Add `days` query param parsing to ListTasks handler (matches ListTasksByResidence) - Add `error.invalid_token` i18n key to all 9 non-English locale files - Update contract test to include VerificationResponse mapping Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/treytartt/casera-api/internal/dto/requests"
|
||||
"github.com/treytartt/casera-api/internal/middleware"
|
||||
"github.com/treytartt/casera-api/internal/models"
|
||||
"github.com/treytartt/casera-api/internal/repositories"
|
||||
"github.com/treytartt/casera-api/internal/services"
|
||||
)
|
||||
|
||||
@@ -34,9 +35,45 @@ func NewDocumentHandler(documentService *services.DocumentService, storageServic
|
||||
// ListDocuments handles GET /api/documents/
|
||||
func (h *DocumentHandler) ListDocuments(c echo.Context) error {
|
||||
user := c.Get(middleware.AuthUserKey).(*models.User)
|
||||
response, err := h.documentService.ListDocuments(user.ID)
|
||||
|
||||
// Build filter from query params (matching KMP DocumentApi parameters)
|
||||
var filter *repositories.DocumentFilter
|
||||
if c.QueryParam("residence") != "" || c.QueryParam("document_type") != "" ||
|
||||
c.QueryParam("category") != "" || c.QueryParam("contractor") != "" ||
|
||||
c.QueryParam("is_active") != "" || c.QueryParam("expiring_soon") != "" ||
|
||||
c.QueryParam("tags") != "" || c.QueryParam("search") != "" {
|
||||
filter = &repositories.DocumentFilter{
|
||||
DocumentType: c.QueryParam("document_type"),
|
||||
Category: c.QueryParam("category"),
|
||||
Tags: c.QueryParam("tags"),
|
||||
Search: c.QueryParam("search"),
|
||||
}
|
||||
if rid := c.QueryParam("residence"); rid != "" {
|
||||
if parsed, err := strconv.ParseUint(rid, 10, 32); err == nil {
|
||||
residenceID := uint(parsed)
|
||||
filter.ResidenceID = &residenceID
|
||||
}
|
||||
}
|
||||
if cid := c.QueryParam("contractor"); cid != "" {
|
||||
if parsed, err := strconv.ParseUint(cid, 10, 32); err == nil {
|
||||
contractorID := uint(parsed)
|
||||
filter.ContractorID = &contractorID
|
||||
}
|
||||
}
|
||||
if ia := c.QueryParam("is_active"); ia != "" {
|
||||
isActive := ia == "true" || ia == "1"
|
||||
filter.IsActive = &isActive
|
||||
}
|
||||
if es := c.QueryParam("expiring_soon"); es != "" {
|
||||
if parsed, err := strconv.Atoi(es); err == nil {
|
||||
filter.ExpiringSoon = &parsed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
response, err := h.documentService.ListDocuments(user.ID, filter)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, map[string]interface{}{"error": err.Error()})
|
||||
return err
|
||||
}
|
||||
return c.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user