refactor: migrate DI to Wire, replace startup registries with on-demand DB queries

- Add google/wire; generate wire_gen.go from wire.go injector
- Move all constructor wiring out of main.go into providers.go / wire.go
- Export recognition.IngredientRepository (was unexported, blocked Wire binding)
- Delete units/cuisine/tag registry.go files (global state + unused NameFor helpers)
- Replace List handlers with NewListHandler(pool) using COALESCE SQL queries
- Remove units/cuisine/tag LoadFromDB from server startup; locale.LoadFromDB kept
  (locale.Supported is used by language middleware on every request)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
dbastrikin
2026-03-15 18:45:21 +02:00
parent 61feb91bba
commit 0ce111fa08
14 changed files with 552 additions and 423 deletions

View File

@@ -0,0 +1,73 @@
// Code generated by Wire. DO NOT EDIT.
//go:generate go run -mod=mod github.com/google/wire/cmd/wire
//go:build !wireinject
// +build !wireinject
package main
import (
"github.com/food-ai/backend/internal/auth"
"github.com/food-ai/backend/internal/config"
"github.com/food-ai/backend/internal/diary"
"github.com/food-ai/backend/internal/dish"
"github.com/food-ai/backend/internal/home"
"github.com/food-ai/backend/internal/ingredient"
"github.com/food-ai/backend/internal/menu"
"github.com/food-ai/backend/internal/product"
"github.com/food-ai/backend/internal/recipe"
"github.com/food-ai/backend/internal/recognition"
"github.com/food-ai/backend/internal/recommendation"
"github.com/food-ai/backend/internal/savedrecipe"
"github.com/food-ai/backend/internal/user"
"github.com/jackc/pgx/v5/pgxpool"
"net/http"
)
// Injectors from wire.go:
func initRouter(appConfig *config.Config, pool *pgxpool.Pool) (http.Handler, error) {
string2 := newFirebaseCredentialsFile(appConfig)
tokenVerifier, err := auth.NewFirebaseAuthOrNoop(string2)
if err != nil {
return nil, err
}
repository := user.NewRepository(pool)
mainJwtSecret := newJWTSecret(appConfig)
mainJwtAccessDuration := newJWTAccessDuration(appConfig)
mainJwtRefreshDuration := newJWTRefreshDuration(appConfig)
jwtManager := newJWTManager(mainJwtSecret, mainJwtAccessDuration, mainJwtRefreshDuration)
service := auth.NewService(tokenVerifier, repository, jwtManager)
handler := auth.NewHandler(service)
userService := user.NewService(repository)
userHandler := user.NewHandler(userService)
mainGeminiAPIKey := newGeminiAPIKey(appConfig)
client := newGeminiClient(mainGeminiAPIKey)
mainPexelsAPIKey := newPexelsAPIKey(appConfig)
pexelsClient := newPexelsClient(mainPexelsAPIKey)
productRepository := product.NewRepository(pool)
recommendationHandler := recommendation.NewHandler(client, pexelsClient, repository, productRepository)
dishRepository := dish.NewRepository(pool)
savedrecipeRepository := savedrecipe.NewRepository(pool, dishRepository)
savedrecipeHandler := savedrecipe.NewHandler(savedrecipeRepository)
ingredientRepository := ingredient.NewRepository(pool)
ingredientHandler := ingredient.NewHandler(ingredientRepository)
productHandler := product.NewHandler(productRepository)
recognitionHandler := recognition.NewHandler(client, ingredientRepository)
menuRepository := menu.NewRepository(pool)
menuHandler := menu.NewHandler(menuRepository, client, pexelsClient, repository, productRepository, dishRepository)
diaryRepository := diary.NewRepository(pool)
diaryHandler := diary.NewHandler(diaryRepository)
homeHandler := home.NewHandler(pool)
dishHandler := dish.NewHandler(dishRepository)
recipeRepository := recipe.NewRepository(pool)
recipeHandler := recipe.NewHandler(recipeRepository)
mainJwtAdapter := newJWTAdapter(jwtManager)
v := newAuthMiddleware(mainJwtAdapter)
mainAllowedOrigins := newAllowedOrigins(appConfig)
mainUnitsListHandler := newUnitsListHandler(pool)
mainCuisineListHandler := newCuisineListHandler(pool)
mainTagListHandler := newTagListHandler(pool)
httpHandler := newRouter(pool, handler, userHandler, recommendationHandler, savedrecipeHandler, ingredientHandler, productHandler, recognitionHandler, menuHandler, diaryHandler, homeHandler, dishHandler, recipeHandler, v, mainAllowedOrigins, mainUnitsListHandler, mainCuisineListHandler, mainTagListHandler)
return httpHandler, nil
}