1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package handler
- import (
- "youngee_b_api/consts"
- "youngee_b_api/middleware"
- "youngee_b_api/model/http_model"
- "youngee_b_api/service"
- "youngee_b_api/util"
- "github.com/gin-gonic/gin"
- "github.com/sirupsen/logrus"
- )
- func WrapFindAllProductHandler(ctx *gin.Context) {
- handler := newFindAllProductHandler(ctx)
- baseRun(handler)
- }
- func newFindAllProductHandler(ctx *gin.Context) *FindAllProductHandler {
- return &FindAllProductHandler{
- req: http_model.NewFindAllProductRequest(),
- resp: http_model.NewFindAllProductResponse(),
- ctx: ctx,
- }
- }
- type FindAllProductHandler struct {
- req *http_model.FindAllProductRequest
- resp *http_model.CommonResponse
- ctx *gin.Context
- }
- func (h *FindAllProductHandler) getRequest() interface{} {
- return h.req
- }
- func (h *FindAllProductHandler) getContext() *gin.Context {
- return h.ctx
- }
- func (h *FindAllProductHandler) getResponse() interface{} {
- return h.resp
- }
- func (h *FindAllProductHandler) run() {
- auth := middleware.GetSessionAuth(h.ctx)
- enterpriseID := auth.EnterpriseID
- res, err := service.Product.FindAll(h.ctx, enterpriseID)
- if err != nil {
- // 数据库查询失败,返回5001
- logrus.Errorf("[FindAllProductHandler] call FindAll err:%+v\n", err)
- util.HandlerPackErrorResp(h.resp, consts.ErrorInternal)
- return
- }
- h.resp.Data = res
- }
- func (h *FindAllProductHandler) checkParam() error {
- return nil
- }
|