Merge branch 'feature-inventory' of https://github.com/ForFarmTeam/ForFarm into feature-inventory

This commit is contained in:
THIS ONE IS A LITTLE BIT TRICKY KRUB 2025-04-04 20:04:00 +07:00
commit ac994f3d39

View File

@ -20,6 +20,7 @@ import (
"github.com/forfarm/backend/internal/domain"
m "github.com/forfarm/backend/internal/middlewares"
"github.com/forfarm/backend/internal/repository"
"github.com/forfarm/backend/internal/services"
"github.com/forfarm/backend/internal/services/weather"
"github.com/forfarm/backend/internal/utilities"
)
@ -39,12 +40,12 @@ type api struct {
knowledgeHubRepo domain.KnowledgeHubRepository
weatherFetcher domain.WeatherFetcher
chatService *services.ChatService
}
var weatherFetcherInstance domain.WeatherFetcher
func GetWeatherFetcher() domain.WeatherFetcher {
return weatherFetcherInstance
func (a *api) GetWeatherFetcher() domain.WeatherFetcher {
return a.weatherFetcher
}
func NewAPI(
@ -76,7 +77,12 @@ func NewAPI(
cleanupInterval = 5 * time.Minute
}
cachedWeatherFetcher := weather.NewCachedWeatherFetcher(owmFetcher, cacheTTL, cleanupInterval, logger)
weatherFetcherInstance = cachedWeatherFetcher
chatService, chatErr := services.NewChatService(logger, analyticsRepo, farmRepo, croplandRepo, inventoryRepo, plantRepository)
if chatErr != nil {
logger.Error("Failed to initialize ChatService", "error", chatErr)
chatService = nil
}
return &api{
logger: logger,
@ -92,6 +98,8 @@ func NewAPI(
analyticsRepo: analyticsRepo,
knowledgeHubRepo: knowledgeHubRepository,
weatherFetcher: cachedWeatherFetcher,
chatService: chatService,
}
}
@ -134,6 +142,7 @@ func (a *api) Routes() *chi.Mux {
a.registerPlantRoutes(r, api)
a.registerKnowledgeHubRoutes(r, api)
a.registerOauthRoutes(r, api)
a.registerChatRoutes(r, api)
a.registerInventoryRoutes(r, api)
})
@ -142,7 +151,6 @@ func (a *api) Routes() *chi.Mux {
a.registerHelloRoutes(r, api)
a.registerFarmRoutes(r, api)
a.registerUserRoutes(r, api)
a.registerInventoryRoutes(r, api)
a.registerAnalyticsRoutes(r, api)
})