mirror of
https://github.com/serty2005/rmser.git
synced 2026-02-04 19:02:33 -06:00
start rmser
This commit is contained in:
50
internal/transport/http/handlers/invoices.go
Normal file
50
internal/transport/http/handlers/invoices.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
|
||||
invService "rmser/internal/services/invoices"
|
||||
"rmser/pkg/logger"
|
||||
)
|
||||
|
||||
type InvoiceHandler struct {
|
||||
service *invService.Service
|
||||
}
|
||||
|
||||
func NewInvoiceHandler(service *invService.Service) *InvoiceHandler {
|
||||
return &InvoiceHandler{service: service}
|
||||
}
|
||||
|
||||
// SendInvoice godoc
|
||||
// @Summary Создать приходную накладную в iikoRMS
|
||||
// @Description Принимает JSON с данными накладной и отправляет их в iiko
|
||||
// @Tags invoices
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param input body invService.CreateRequestDTO true "Invoice Data"
|
||||
// @Success 200 {object} map[string]string "created_number"
|
||||
// @Failure 400 {object} map[string]string
|
||||
// @Failure 500 {object} map[string]string
|
||||
func (h *InvoiceHandler) SendInvoice(c *gin.Context) {
|
||||
var req invService.CreateRequestDTO
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Неверный формат JSON: " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
docNum, err := h.service.SendInvoiceToRMS(req)
|
||||
if err != nil {
|
||||
logger.Log.Error("Ошибка отправки накладной", zap.Error(err))
|
||||
// Возвращаем 502 Bad Gateway, т.к. ошибка скорее всего на стороне RMS
|
||||
c.JSON(http.StatusBadGateway, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": "ok",
|
||||
"created_number": docNum,
|
||||
})
|
||||
}
|
||||
59
internal/transport/http/handlers/ocr.go
Normal file
59
internal/transport/http/handlers/ocr.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"go.uber.org/zap"
|
||||
|
||||
ocrService "rmser/internal/services/ocr"
|
||||
"rmser/pkg/logger"
|
||||
)
|
||||
|
||||
type OCRHandler struct {
|
||||
service *ocrService.Service
|
||||
}
|
||||
|
||||
func NewOCRHandler(service *ocrService.Service) *OCRHandler {
|
||||
return &OCRHandler{service: service}
|
||||
}
|
||||
|
||||
// GetCatalog возвращает список товаров для OCR сервиса
|
||||
func (h *OCRHandler) GetCatalog(c *gin.Context) {
|
||||
items, err := h.service.GetCatalogForIndexing()
|
||||
if err != nil {
|
||||
logger.Log.Error("Ошибка получения каталога для OCR", zap.Error(err))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, items)
|
||||
}
|
||||
|
||||
type MatchRequest struct {
|
||||
RawName string `json:"raw_name" binding:"required"`
|
||||
ProductID string `json:"product_id" binding:"required"`
|
||||
}
|
||||
|
||||
// SaveMatch сохраняет привязку (обучение)
|
||||
func (h *OCRHandler) SaveMatch(c *gin.Context) {
|
||||
var req MatchRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
pID, err := uuid.Parse(req.ProductID)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid product_id format"})
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.service.SaveMapping(req.RawName, pID); err != nil {
|
||||
logger.Log.Error("Ошибка сохранения матчинга", zap.Error(err))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"status": "saved"})
|
||||
}
|
||||
Reference in New Issue
Block a user