Files
app-api/internal/handler/brand.go
T

49 lines
1.0 KiB
Go
Raw Normal View History

2026-05-21 15:20:12 +08:00
package handler
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/luxsin/app-api/internal/repository"
"github.com/luxsin/app-api/internal/response"
"github.com/luxsin/app-api/pkg/encode"
"go.uber.org/zap"
)
type BrandHandler struct {
repo *repository.BrandRepository
log *zap.Logger
}
2026-05-27 18:07:55 +08:00
func NewBrandHandler(repo *repository.BrandRepository, log *zap.Logger) *BrandHandler {
2026-05-21 15:20:12 +08:00
return &BrandHandler{
2026-05-27 18:07:55 +08:00
repo: repo,
2026-05-21 15:20:12 +08:00
log: log,
}
}
func (h *BrandHandler) GetBrand(c *gin.Context) {
brandName := c.Query("brandName")
base64Resp := encode.ParseBase64Param(c)
list, err := h.repo.List(c.Request.Context(), brandName)
if err != nil {
h.log.Error("get brand list failed", zap.Error(err))
response.InternalError(c, "failed to get brand list")
return
}
if base64Resp {
encoded, err := encode.EncodeJSON(list)
if err != nil {
h.log.Error("encode response failed", zap.Error(err))
response.InternalError(c, "failed to encode response")
return
}
c.String(http.StatusOK, encoded)
return
}
c.JSON(http.StatusOK, list)
}