CreateSelection.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package handler
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/sirupsen/logrus"
  5. "youngee_b_api/consts"
  6. "youngee_b_api/middleware"
  7. "youngee_b_api/model/http_model"
  8. "youngee_b_api/service/selection_service"
  9. "youngee_b_api/util"
  10. )
  11. func WrapCreateSelectionHandler(ctx *gin.Context) {
  12. handler := newCreateSelectionHandler(ctx)
  13. baseRun(handler)
  14. }
  15. type CreateSelection struct {
  16. ctx *gin.Context
  17. req *http_model.CreateSelectionRequest
  18. resp *http_model.CommonResponse
  19. }
  20. func (c CreateSelection) getContext() *gin.Context {
  21. return c.ctx
  22. }
  23. func (c CreateSelection) getResponse() interface{} {
  24. return c.resp
  25. }
  26. func (c CreateSelection) getRequest() interface{} {
  27. return c.req
  28. }
  29. func (c CreateSelection) run() {
  30. data := http_model.CreateSelectionRequest{}
  31. data = *c.req
  32. auth := middleware.GetSessionAuth(c.ctx)
  33. enterpriseID := auth.EnterpriseID
  34. res, err := selection_service.Selection.Create(c.ctx, data, enterpriseID)
  35. if err != nil {
  36. logrus.Errorf("[CreateSelection] call CreateSelection err:%+v\n", err)
  37. util.HandlerPackErrorResp(c.resp, consts.ErrorInternal, "")
  38. logrus.Info("CreateSelection fail,req:%+v", c.req)
  39. return
  40. }
  41. c.resp.Message = "成功创建选品"
  42. c.resp.Data = res
  43. }
  44. func (c CreateSelection) checkParam() error {
  45. return nil
  46. }
  47. func newCreateSelectionHandler(ctx *gin.Context) *CreateSelection {
  48. return &CreateSelection{
  49. ctx: ctx,
  50. req: http_model.NewCreateSelectionRequest(),
  51. resp: http_model.NewCreateSelectionResponse(),
  52. }
  53. }