V3 S4 : recherche FTS + facettes (serveur + mobile)
Backend : search_tsv french + GIN (000020), SearchDocumentsVisible (nom + TS + faits, rang nom > TS > fait sûr > fait douteux, jamais d'exclusion), facettes issuer/type/montant/période sur GET /files/search (400 si malformée). Tests repo + handlers + migrations. Mobile (Room v21) : FTS4 files_fts + triggers partagés (fresh-install/migration, entité déclarée pour KSP, SQL aligné 21.json), searchDocuments offline (même rang, accents préservés) + UI filtres (émetteur, types chips, montants, période ISO, compteur, effacer). Contrat docs/api-v1.md, V3.md (S4 livré, migrations renumérotées links->000021, token->000022).
This commit is contained in:
@@ -5,9 +5,11 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/kazier/backend/pkg/api"
|
||||
"github.com/kazier/backend/repository"
|
||||
"github.com/kazier/backend/service"
|
||||
)
|
||||
|
||||
@@ -408,10 +410,53 @@ func FilesSearch(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
files, total, err := Store.SearchFiles(userID, q, page, pageSize)
|
||||
facets, ok := parseSearchFacets(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
files, total, err := Store.SearchFiles(userID, q, page, pageSize, facets)
|
||||
if err != nil {
|
||||
writeError(c, err)
|
||||
return
|
||||
}
|
||||
api.OKList(c, files, page, pageSize, total)
|
||||
}
|
||||
|
||||
// parseSearchFacets lit les facettes V3 (`issuer`, `from`/`to` ISO,
|
||||
// `min_amount`/`max_amount` numériques, `doc_type`) — 400 si malformées.
|
||||
func parseSearchFacets(c *gin.Context) (repository.SearchFacets, bool) {
|
||||
var facets repository.SearchFacets
|
||||
facets.Issuer = strings.TrimSpace(c.Query("issuer"))
|
||||
facets.DocType = strings.TrimSpace(c.Query("doc_type"))
|
||||
if v := strings.TrimSpace(c.Query("from")); v != "" {
|
||||
if _, err := time.Parse("2006-01-02", v); err != nil {
|
||||
api.Error(c, http.StatusBadRequest, "INVALID_REQUEST", "query param `from` must be ISO YYYY-MM-DD")
|
||||
return facets, false
|
||||
}
|
||||
facets.From = v
|
||||
}
|
||||
if v := strings.TrimSpace(c.Query("to")); v != "" {
|
||||
if _, err := time.Parse("2006-01-02", v); err != nil {
|
||||
api.Error(c, http.StatusBadRequest, "INVALID_REQUEST", "query param `to` must be ISO YYYY-MM-DD")
|
||||
return facets, false
|
||||
}
|
||||
facets.To = v
|
||||
}
|
||||
if v := strings.TrimSpace(c.Query("min_amount")); v != "" {
|
||||
f, err := strconv.ParseFloat(strings.ReplaceAll(v, ",", "."), 64)
|
||||
if err != nil {
|
||||
api.Error(c, http.StatusBadRequest, "INVALID_REQUEST", "query param `min_amount` must be numeric")
|
||||
return facets, false
|
||||
}
|
||||
facets.MinAmount = &f
|
||||
}
|
||||
if v := strings.TrimSpace(c.Query("max_amount")); v != "" {
|
||||
f, err := strconv.ParseFloat(strings.ReplaceAll(v, ",", "."), 64)
|
||||
if err != nil {
|
||||
api.Error(c, http.StatusBadRequest, "INVALID_REQUEST", "query param `max_amount` must be numeric")
|
||||
return facets, false
|
||||
}
|
||||
facets.MaxAmount = &f
|
||||
}
|
||||
return facets, true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user