data_api_release.go 887 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package data_api
  2. import (
  3. "context"
  4. "gd_management/apis"
  5. "gd_management/errors"
  6. "time"
  7. "github.com/astaxie/beego/orm"
  8. )
  9. func DataApiReleaseApi(ctx context.Context, req *apis.ManagementDataApiReleaseApiReq, reply *apis.ManagementDataApiReleaseApiReply) error {
  10. if req.DataApiId == 0 {
  11. return errors.ArgsError
  12. }
  13. o := orm.NewOrm()
  14. var dataApiInfo apis.DataApi
  15. err := o.QueryTable("t_gd_data_api").Filter("id", req.DataApiId).One(&dataApiInfo)
  16. if err != nil {
  17. if err != orm.ErrNoRows {
  18. return errors.DataBaseError
  19. } else {
  20. return errors.DataApiNotExist
  21. }
  22. }
  23. var timeLayout = "2006-01-02 15:04:05"
  24. timeNow := time.Now().Format(timeLayout)
  25. dataApiInfo.ReleaseTime = timeNow
  26. dataApiInfo.IsRelease = true
  27. if req.Status == 0 {
  28. dataApiInfo.IsRelease = false
  29. }
  30. _, err = o.Update(&dataApiInfo)
  31. if err != nil {
  32. return errors.DataBaseError
  33. }
  34. return nil
  35. }