selection_delete.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package handler
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/sirupsen/logrus"
  5. "youngee_m_api/consts"
  6. "youngee_m_api/db"
  7. "youngee_m_api/model/http_model"
  8. "youngee_m_api/util"
  9. )
  10. func WrapDeleteSelectionHandler(ctx *gin.Context) {
  11. handler := NewDeleteSelection(ctx)
  12. BaseRun(handler)
  13. }
  14. type DeleteSelectionHandler struct {
  15. ctx *gin.Context
  16. req *http_model.DeleteSelectionRequest
  17. resp *http_model.CommonResponse
  18. }
  19. func (d DeleteSelectionHandler) getContext() *gin.Context {
  20. return d.ctx
  21. }
  22. func (d DeleteSelectionHandler) getResponse() interface{} {
  23. return d.resp
  24. }
  25. func (d DeleteSelectionHandler) getRequest() interface{} {
  26. return d.req
  27. }
  28. func (d DeleteSelectionHandler) run() {
  29. err := db.DeleteSelection(d.ctx, d.req.SelectionId)
  30. if err != nil {
  31. logrus.WithContext(d.ctx).Errorf("[DeleteSelectionHandler] error DeleteSelection, err:%+v", err)
  32. util.HandlerPackErrorResp(d.resp, consts.ErrorInternal, consts.DefaultToast)
  33. return
  34. }
  35. d.resp.Message = "选品删除成功"
  36. }
  37. func (d DeleteSelectionHandler) checkParam() error {
  38. return nil
  39. }
  40. func NewDeleteSelection(ctx *gin.Context) *DeleteSelectionHandler {
  41. return &DeleteSelectionHandler{
  42. ctx: ctx,
  43. req: http_model.NewDeleteSelectionRequest(),
  44. resp: http_model.NewDeleteSelectionResponse(),
  45. }
  46. }