delete.go 922 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package maintainance
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "adm-vehicle-style/errors"
  7. "adm-vehicle-style/model"
  8. v1 "adm-vehicle-style/pb/v1"
  9. "git.getensh.com/common/gopkgsv2/database"
  10. "git.getensh.com/common/gopkgsv2/logger"
  11. "go.uber.org/zap"
  12. "google.golang.org/grpc/status"
  13. )
  14. func Delete(ctx context.Context, req *v1.DeleteMaintainaceRequest) (reply *v1.EmptyReply, err error) {
  15. reply = &v1.EmptyReply{}
  16. defer func() {
  17. if r := recover(); r != nil {
  18. err = fmt.Errorf("%+v", r)
  19. e := &status.Status{}
  20. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  21. logger.Error("err",
  22. zap.String("system_err", err.Error()),
  23. zap.Stack("stacktrace"))
  24. }
  25. }
  26. }()
  27. if req.Id == 0 {
  28. return reply, errors.ParamsError
  29. }
  30. if err := model.NewMaintainDetailModel().Delete(database.DB().Where("id = ?", req.Id)); err != nil {
  31. return reply, errors.SystemError
  32. }
  33. return reply, nil
  34. }