UpdateSelection.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 WrapUpdateSelectionHandler(ctx *gin.Context) {
  12. handler := newUpdateSelectionHandler(ctx)
  13. baseRun(handler)
  14. }
  15. type UpdateSelection struct {
  16. ctx *gin.Context
  17. req *http_model.UpdateSelectionRequest
  18. resp *http_model.CommonResponse
  19. }
  20. func (c UpdateSelection) getContext() *gin.Context {
  21. return c.ctx
  22. }
  23. func (c UpdateSelection) getResponse() interface{} {
  24. return c.resp
  25. }
  26. func (c UpdateSelection) getRequest() interface{} {
  27. return c.req
  28. }
  29. func (c UpdateSelection) run() {
  30. data := http_model.UpdateSelectionRequest{}
  31. data = *c.req
  32. auth := middleware.GetSessionAuth(c.ctx)
  33. enterpriseID := auth.EnterpriseID
  34. res, err := selection_service.Selection.Update(c.ctx, data, enterpriseID)
  35. if err != nil {
  36. logrus.Errorf("[UpdateSelection] call UpdateSelection err:%+v\n", err)
  37. util.HandlerPackErrorResp(c.resp, consts.ErrorInternal, "")
  38. logrus.Info("UpdateSelection fail,req:%+v", c.req)
  39. return
  40. }
  41. c.resp.Message = "ok"
  42. c.resp.Data = res
  43. c.resp.Status = 20000
  44. return
  45. }
  46. func (c UpdateSelection) checkParam() error {
  47. return nil
  48. }
  49. func newUpdateSelectionHandler(ctx *gin.Context) *UpdateSelection {
  50. return &UpdateSelection{
  51. ctx: ctx,
  52. req: http_model.NewUpdateSelectionRequest(),
  53. resp: http_model.NewUpdateSelectionResponse(),
  54. }
  55. }