- 400 → 422 для всех ошибок валидации входных данных (handlers: export, quote, sync, vendor_spec, partnumber_books, pricelist) - SQL-запросы вынесены из handlers в localdb (partnumber_books, pricelist, support_bundle); ValidateMariaDBConnection перенесён в internal/db/validate.go - List-ответы унифицированы: ключ items, поля total_count/page/per_page/total_pages (component, pricelist, partnumber_books); шаблоны обновлены - Молчаливые ошибки заменены на slog.Warn/Error (support_bundle, vendor_spec, component, configuration, local_configuration, localdb) - N+1 запросы устранены: batch-запросы в export.go и vendor_workspace_import.go - fmt.Println → slog в cmd/ (qfs, migrate, migrate_ops_projects, migrate_project_updated_at) - Заголовки recovery/verify добавлены во все 28 SQL-миграций - Добавлены bible-local/runtime-flows.md и bible-local/decisions/ - Обновлён субмодуль bible до v0.2.0-13 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.mchus.pro/mchus/quoteforge/internal/services"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type QuoteHandler struct {
|
|
quoteService *services.QuoteService
|
|
}
|
|
|
|
func NewQuoteHandler(quoteService *services.QuoteService) *QuoteHandler {
|
|
return &QuoteHandler{quoteService: quoteService}
|
|
}
|
|
|
|
func (h *QuoteHandler) Validate(c *gin.Context) {
|
|
var req services.QuoteRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
RespondError(c, http.StatusUnprocessableEntity, "invalid request", err)
|
|
return
|
|
}
|
|
|
|
result, err := h.quoteService.ValidateAndCalculate(&req)
|
|
if err != nil {
|
|
RespondError(c, http.StatusUnprocessableEntity, "invalid request", err)
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, result)
|
|
}
|
|
|
|
func (h *QuoteHandler) Calculate(c *gin.Context) {
|
|
var req services.QuoteRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
RespondError(c, http.StatusUnprocessableEntity, "invalid request", err)
|
|
return
|
|
}
|
|
|
|
result, err := h.quoteService.ValidateAndCalculate(&req)
|
|
if err != nil {
|
|
RespondError(c, http.StatusUnprocessableEntity, "invalid request", err)
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"items": result.Items,
|
|
"total": result.Total,
|
|
})
|
|
}
|
|
|
|
func (h *QuoteHandler) PriceLevels(c *gin.Context) {
|
|
var req services.PriceLevelsRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
RespondError(c, http.StatusUnprocessableEntity, "invalid request", err)
|
|
return
|
|
}
|
|
|
|
result, err := h.quoteService.CalculatePriceLevels(&req)
|
|
if err != nil {
|
|
RespondError(c, http.StatusUnprocessableEntity, "invalid request", err)
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, result)
|
|
}
|