mirror of
https://github.com/serty2005/rmser.git
synced 2026-02-04 19:02:33 -06:00
добавил ручки для фронта
This commit is contained in:
24
cmd/main.go
24
cmd/main.go
@@ -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)
|
||||
}
|
||||
|
||||
// Простой хелсчек
|
||||
|
||||
Reference in New Issue
Block a user