feat: food search sheet with FTS+trgm, dish/recent endpoints, multilingual aliases
Backend: - GET /dishes/search — hybrid FTS (english + simple) + trgm + ILIKE search - GET /diary/recent — recently used dishes and products for the current user - product search upgraded: FTS on canonical_name and product_aliases, ranked by GREATEST(ts_rank, similarity) - importoff: collect product_name_ru/de/fr/... as product_aliases for multilingual search (e.g. "сникерс" → "Snickers") - migrations: FTS + trgm indexes merged into 001_initial_schema.sql (002 removed) Flutter: - FoodSearchSheet: debounced search field, recently-used section, product/dish results, scan-photo and barcode chips - DishPortionSheet: quick ½/1/1½/2 buttons + custom input - + button in meal card now opens FoodSearchSheet instead of going directly to AI scan - 7 new l10n keys across all 12 languages Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/food-ai/backend/internal/infra/middleware"
|
||||
"github.com/go-chi/chi/v5"
|
||||
@@ -15,6 +16,7 @@ type DiaryRepository interface {
|
||||
ListByDate(ctx context.Context, userID, date string) ([]*Entry, error)
|
||||
Create(ctx context.Context, userID string, req CreateRequest) (*Entry, error)
|
||||
Delete(ctx context.Context, id, userID string) error
|
||||
GetRecent(ctx context.Context, userID string, limit int) ([]*RecentDiaryItem, error)
|
||||
}
|
||||
|
||||
// DishRepository is the subset of dish.Repository used by Handler to resolve dish IDs.
|
||||
@@ -119,6 +121,31 @@ func (h *Handler) Create(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusCreated, entry)
|
||||
}
|
||||
|
||||
// GetRecent handles GET /diary/recent?limit=<n>
|
||||
func (h *Handler) GetRecent(w http.ResponseWriter, r *http.Request) {
|
||||
userID := middleware.UserIDFromCtx(r.Context())
|
||||
if userID == "" {
|
||||
writeError(w, http.StatusUnauthorized, "unauthorized")
|
||||
return
|
||||
}
|
||||
limit := 10
|
||||
if limitStr := r.URL.Query().Get("limit"); limitStr != "" {
|
||||
if parsed, parseError := strconv.Atoi(limitStr); parseError == nil && parsed > 0 && parsed <= 20 {
|
||||
limit = parsed
|
||||
}
|
||||
}
|
||||
items, queryError := h.repo.GetRecent(r.Context(), userID, limit)
|
||||
if queryError != nil {
|
||||
slog.Error("get recent diary items", "err", queryError)
|
||||
writeError(w, http.StatusInternalServerError, "failed to get recent items")
|
||||
return
|
||||
}
|
||||
if items == nil {
|
||||
items = []*RecentDiaryItem{}
|
||||
}
|
||||
writeJSON(w, http.StatusOK, items)
|
||||
}
|
||||
|
||||
// Delete handles DELETE /diary/{id}
|
||||
func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
||||
userID := middleware.UserIDFromCtx(r.Context())
|
||||
|
||||
Reference in New Issue
Block a user