provider_delete_api.go 785 B

1234567891011121314151617181920212223242526272829
  1. package provider
  2. import (
  3. "context"
  4. "gd_management/apis"
  5. "gd_management/errors"
  6. "gd_management/impl/pubsub"
  7. "github.com/astaxie/beego/orm"
  8. )
  9. func ManagementDelProviderApi(ctx context.Context, req *apis.ManagementDelProviderApiReq, reply *apis.ManagementDelProviderApiReply) error {
  10. if req.ProviderApiId == 0 {
  11. return errors.ArgsError
  12. }
  13. if err := pubsub.PublishNameNotify("provider_api_id", req.ProviderApiId, 0); err != nil {
  14. return err
  15. }
  16. exist := orm.NewOrm().QueryTable("t_gd_api_provider_relation").Filter("provider_api_id", req.ProviderApiId).Exist()
  17. if exist {
  18. return errors.ProviderApiInApi
  19. }
  20. _, err := orm.NewOrm().Raw("delete from t_gd_provider_api where id = ?", req.ProviderApiId).Exec()
  21. if err != nil {
  22. return errors.DataBaseError
  23. }
  24. return nil
  25. }