c_demo.go 993 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package controllers
  2. import (
  3. "github.com/gogf/gf/v2/net/ghttp"
  4. "gxt-api-frame/app/bll"
  5. "gxt-api-frame/app/schema"
  6. "gxt-api-frame/library/gplus"
  7. )
  8. type Demo struct {
  9. cBll bll.IDemo
  10. }
  11. func NewDemo(cb bll.IDemo) *Demo {
  12. return &Demo{
  13. cBll: cb,
  14. }
  15. }
  16. // Create 创建数据
  17. // @Tags API-Demo
  18. // @Summary 创建数据
  19. // @Param body body schema.Demo true "提交的数据"
  20. // @Success 200 {object} schema.Demo
  21. // @Failure 400 {object} schema.HTTPError "{error:{code:0,message:无效的请求参数}}"
  22. // @Failure 401 {object} schema.HTTPError "{error:{code:0,message:未授权}}"
  23. // @Failure 500 {object} schema.HTTPError "{error:{code:0,message:服务器错误}}"
  24. // @Router /api/v1/demos/ [post]
  25. func (a *Demo) Create(r *ghttp.Request) {
  26. var data schema.Demo
  27. if err := gplus.ParseJson(r, &data); err != nil {
  28. gplus.ResError(r, err)
  29. }
  30. ctx := gplus.NewContext(r)
  31. result, err := a.cBll.Create(ctx, data)
  32. if err != nil {
  33. gplus.ResError(r, err)
  34. }
  35. gplus.ResSuccess(r, result)
  36. }