首次提交
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
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 ModelHandler struct {
|
||||
repo *repository.ModelRepository
|
||||
log *zap.Logger
|
||||
}
|
||||
|
||||
func NewModelHandler(db *sql.DB, log *zap.Logger) *ModelHandler {
|
||||
return &ModelHandler{
|
||||
repo: repository.NewModelRepository(db),
|
||||
log: log,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *ModelHandler) GetModel(c *gin.Context) {
|
||||
brandName := c.Query("brandName")
|
||||
modelName := c.Query("modelName")
|
||||
base64Resp := encode.ParseBase64Param(c)
|
||||
|
||||
list, err := h.repo.List(c.Request.Context(), brandName, modelName)
|
||||
if err != nil {
|
||||
h.log.Error("get model list failed", zap.Error(err))
|
||||
response.InternalError(c, "failed to get model 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)
|
||||
}
|
||||
Reference in New Issue
Block a user