27 lines
511 B
Go
27 lines
511 B
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"mengyastore-backend/internal/storage"
|
|
)
|
|
|
|
type PublicHandler struct {
|
|
store *storage.JSONStore
|
|
}
|
|
|
|
func NewPublicHandler(store *storage.JSONStore) *PublicHandler {
|
|
return &PublicHandler{store: store}
|
|
}
|
|
|
|
func (h *PublicHandler) ListProducts(c *gin.Context) {
|
|
items, err := h.store.ListActive()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"data": items})
|
|
}
|