добавил ручки для фронта

This commit is contained in:
2025-11-30 02:02:11 +03:00
parent da62ea5b98
commit 714844058f
9 changed files with 99 additions and 9 deletions

View File

@@ -5,6 +5,7 @@ import (
"log"
"time"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/shopspring/decimal"
@@ -71,7 +72,11 @@ func main() {
recService := recServicePkg.NewService(recRepo)
ocrService := ocrServicePkg.NewService(ocrRepo, catalogRepo, pyClient)
invoiceService := invServicePkg.NewService(rmsClient)
// --- Инициализация Handler'ов ---
invoiceHandler := handlers.NewInvoiceHandler(invoiceService)
ocrHandler := handlers.NewOCRHandler(ocrService)
recommendHandler := handlers.NewRecommendationsHandler(recService)
// --- БЛОК ПРОВЕРКИ СИНХРОНИЗАЦИИ (Run-once on start) ---
go func() {
@@ -129,16 +134,33 @@ func main() {
} else {
logger.Log.Warn("Telegram token не задан, бот не запущен")
}
// 5. Запуск HTTP сервера (Gin)
if cfg.App.Mode == "release" {
gin.SetMode(gin.ReleaseMode)
}
r := gin.Default()
// --- Настройка CORS ---
// Разрешаем запросы с любых источников для разработки Frontend
corsConfig := cors.DefaultConfig()
corsConfig.AllowAllOrigins = true // В продакшене заменить на AllowOrigins: []string{"http://domain.com"}
corsConfig.AllowMethods = []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"}
corsConfig.AllowHeaders = []string{"Origin", "Content-Length", "Content-Type", "Authorization"}
r.Use(cors.New(corsConfig))
api := r.Group("/api")
{
// ... другие роуты ...
// Invoices
api.POST("/invoices/send", invoiceHandler.SendInvoice)
// Recommendations
api.GET("/recommendations", recommendHandler.GetRecommendations)
// OCR
api.GET("/ocr/catalog", ocrHandler.GetCatalog)
api.GET("/ocr/matches", ocrHandler.GetMatches)
api.POST("/ocr/match", ocrHandler.SaveMatch)
}
// Простой хелсчек