59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
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
|
|
}
|
|
|
|
func NewBrandHandler(repo *repository.BrandRepository, log *zap.Logger) *BrandHandler {
|
|
return &BrandHandler{
|
|
repo: repo,
|
|
log: log,
|
|
}
|
|
}
|
|
|
|
// GetBrand 获取品牌列表
|
|
//
|
|
// @Summary 获取品牌列表
|
|
// @Tags Brand
|
|
// @Produce json
|
|
// @Param brandName query string false "品牌名称(模糊匹配)"
|
|
// @Param base64Resp query string false "是否返回 base64 编码响应"
|
|
// @Success 200 {array} object
|
|
// @Failure 500 {object} object
|
|
// @Router /audio/getBrand [get]
|
|
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)
|
|
}
|