data_api_add_api.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package data_api
  2. import (
  3. "context"
  4. "gd_management/apis"
  5. "gd_management/errors"
  6. "github.com/astaxie/beego/orm"
  7. "time"
  8. )
  9. func DataApiAddApi(ctx context.Context, req *apis.ManagementDataApiAddApiReq, reply *apis.ManagementDataApiAddApiReply) error {
  10. if req.DataApiName == "" || req.Version == "" {
  11. return errors.ArgsError
  12. }
  13. o := orm.NewOrm()
  14. var dataApiInfo apis.DataApi
  15. err := o.QueryTable("t_gd_data_api").Filter("data_api_name", req.DataApiName).Filter("version", req.Version).One(&dataApiInfo)
  16. if err != nil {
  17. if err != orm.ErrNoRows {
  18. return errors.DataBaseError
  19. }
  20. } else {
  21. return errors.DataApiExist
  22. }
  23. var timeLayout = "2006-01-02 15:04:05"
  24. timeNow := time.Now().Format(timeLayout)
  25. dataApiInfo.DataApiName = req.DataApiName
  26. dataApiInfo.DataApiDesc = req.DataApiDesc
  27. dataApiInfo.DataApiType = req.DataApiType
  28. dataApiInfo.Version = req.Version
  29. dataApiInfo.CreateTime = timeNow
  30. dataApiInfo.UpdateTime = timeNow
  31. dataApiInfo.ReleaseTime = "0000-00-00 00:00:00"
  32. id, err := o.Insert(&dataApiInfo)
  33. if err != nil {
  34. return errors.DataBaseError
  35. }
  36. reply.DataApiId = id
  37. return nil
  38. }