首次提交

This commit is contained in:
yangy
2026-05-21 15:20:12 +08:00
commit 3224041990
32 changed files with 1504 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
package handler
import (
"database/sql"
"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(db *sql.DB, log *zap.Logger) *BrandHandler {
return &BrandHandler{
repo: repository.NewBrandRepository(db),
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)
}