package handler import ( "net/http" "github.com/gin-gonic/gin" "gorm.io/gorm" "github.com/wangjia/jiu/backend/internal/model" ) type PublicHandler struct { db *gorm.DB } func NewPublicHandler(db *gorm.DB) *PublicHandler { return &PublicHandler{db: db} } // GetProduct GET /api/v1/public/products/:public_id (no auth) func (h *PublicHandler) GetProduct(c *gin.Context) { publicID := c.Param("public_id") var product model.Product if err := h.db.Where("public_id = ? AND deleted_at IS NULL", publicID). Preload("Images"). First(&product).Error; err != nil { c.JSON(http.StatusNotFound, gin.H{"error": "not found"}) return } // Return only public-safe fields (no price/stock info) c.JSON(http.StatusOK, gin.H{ "data": gin.H{ "id": product.ID, "name": product.Name, "series": product.Series, "spec": product.Spec, "brand": product.Brand, "unit": product.Unit, "description": product.Description, "images": product.Images, }, }) }