- Add is_hidden field to hide components from configurator - Add colored dot indicator showing component usage status: - Green: available in configurator - Cyan: used as source for meta-articles - Gray: hidden from configurator - Optimize price recalculation with caching and skip unchanged - Show current lot name during price recalculation - Add Dockerfile (Alpine-based multi-stage build) - Add docker-compose.yml and .dockerignore Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"git.mchus.pro/mchus/quoteforge/internal/repository"
|
|
"git.mchus.pro/mchus/quoteforge/internal/services"
|
|
)
|
|
|
|
type ComponentHandler struct {
|
|
componentService *services.ComponentService
|
|
}
|
|
|
|
func NewComponentHandler(componentService *services.ComponentService) *ComponentHandler {
|
|
return &ComponentHandler{componentService: componentService}
|
|
}
|
|
|
|
func (h *ComponentHandler) List(c *gin.Context) {
|
|
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
|
perPage, _ := strconv.Atoi(c.DefaultQuery("per_page", "20"))
|
|
|
|
filter := repository.ComponentFilter{
|
|
Category: c.Query("category"),
|
|
Search: c.Query("search"),
|
|
HasPrice: c.Query("has_price") == "true",
|
|
ExcludeHidden: c.Query("include_hidden") != "true", // По умолчанию скрытые не показываются
|
|
}
|
|
|
|
result, err := h.componentService.List(filter, page, perPage)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, result)
|
|
}
|
|
|
|
func (h *ComponentHandler) Get(c *gin.Context) {
|
|
lotName := c.Param("lot_name")
|
|
|
|
component, err := h.componentService.GetByLotName(lotName)
|
|
if err != nil {
|
|
c.JSON(http.StatusNotFound, gin.H{"error": "component not found"})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, component)
|
|
}
|
|
|
|
func (h *ComponentHandler) GetCategories(c *gin.Context) {
|
|
categories, err := h.componentService.GetCategories()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, categories)
|
|
}
|