c_dataset_file.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. package controllers
  2. import (
  3. "github.com/gogf/gf/v2/net/ghttp"
  4. "yx-dataset-server/app/bll"
  5. "yx-dataset-server/app/errors"
  6. "yx-dataset-server/app/schema"
  7. "yx-dataset-server/library/gplus"
  8. )
  9. type DatasetFile struct {
  10. DatasetFileBll bll.IDatasetFile
  11. }
  12. func NewDatasetFile(bDatasetFile bll.IDatasetFile) *DatasetFile {
  13. return &DatasetFile{
  14. DatasetFileBll: bDatasetFile,
  15. }
  16. }
  17. // Query 查询数据
  18. func (a *DatasetFile) Query(r *ghttp.Request) {
  19. switch r.Get("q").String() {
  20. case "page":
  21. a.QueryPage(r)
  22. case "list":
  23. a.QueryList(r)
  24. default:
  25. gplus.ResError(r, errors.ErrUnknownQuery)
  26. }
  27. }
  28. // QueryPage 查询分页数据
  29. // @Tags
  30. // @Summary 查询分页数据
  31. // @Param Authorization header string false "Bearer 用户令牌"
  32. // @Param current query int true "分页索引" 1
  33. // @Param pageSize query int true "分页大小" 10
  34. // @Success 200 []schema.DatasetFile "查询结果:{list:列表数据,pagination:{current:页索引,pageSize:页大小,total:总数量}}"
  35. // @Failure 400 schema.HTTPError "{error:{code:0,message:未知的查询类型}}"
  36. // @Failure 401 schema.HTTPError "{error:{code:0,message:未授权}}"
  37. // @Failure 500 schema.HTTPError "{error:{code:0,message:服务器错误}}"
  38. // @Router GET /web/v1/dataset_files?q=page
  39. func (a *DatasetFile) QueryPage(r *ghttp.Request) {
  40. ctx := gplus.NewContext(r)
  41. var params schema.DatasetFileQueryParam
  42. params.DatasetId = r.Get("dataset_id").String()
  43. result, err := a.DatasetFileBll.Query(ctx, params, schema.DatasetFileQueryOptions{
  44. PageParam: &schema.PaginationParam{
  45. PageIndex: gplus.GetPageIndex(r),
  46. PageSize: gplus.GetPageSize(r),
  47. },
  48. })
  49. if err != nil {
  50. gplus.ResError(r, err)
  51. }
  52. ResPage(r, result.Data, result.PageResult)
  53. }
  54. // QueryList 查询列表数据
  55. // @Tags
  56. // @Summary 查询列表数据
  57. // @Param Authorization header string false "Bearer 用户令牌"
  58. // @Success 200 []schema.DatasetFile "查询结果:{list:列表数据}"
  59. // @Failure 400 schema.HTTPError "{error:{code:0,message:未知的查询类型}}"
  60. // @Failure 401 schema.HTTPError "{error:{code:0,message:未授权}}"
  61. // @Failure 500 schema.HTTPError "{error:{code:0,message:服务器错误}}"
  62. // @Router GET /web/v1/dataset_files?q=list
  63. func (a *DatasetFile) QueryList(r *ghttp.Request) {
  64. ctx := gplus.NewContext(r)
  65. var params schema.DatasetFileQueryParam
  66. params.DatasetId = r.Get("dataset_id").String()
  67. result, err := a.DatasetFileBll.Query(ctx, params)
  68. if err != nil {
  69. gplus.ResError(r, err)
  70. }
  71. ResSuccess(r, result.Data)
  72. }
  73. // Get 获取数据
  74. // @Summary 获取数据
  75. // @Param id path string true "记录ID"
  76. // @Success 200 schema.DatasetFile
  77. // @Failure 400 schema.HTTPError "{error:{code:0,message:无效的请求参数}}"
  78. // @Failure 401 schema.HTTPError "{error:{code:0,message:未授权}}"
  79. // @Failure 500 schema.HTTPError "{error:{code:0,message:服务器错误}}"
  80. // @Router /web/v1/dataset_file/{id}
  81. func (a *DatasetFile) Get(r *ghttp.Request) {
  82. ctx := gplus.NewContext(r)
  83. result, err := a.DatasetFileBll.Get(ctx, r.Get("id").String())
  84. if err != nil {
  85. gplus.ResError(r, err)
  86. }
  87. ResSuccess(r, result)
  88. }
  89. // Create 创建数据
  90. // @Tags API-DatasetFile
  91. // @Summary 创建数据
  92. // @Param body schema.DatasetFile true "提交的数据"
  93. // @Success 200 schema.DatasetFile
  94. // @Failure 400 schema.HTTPError "{error:{code:0,message:无效的请求参数}}"
  95. // @Failure 401 schema.HTTPError "{error:{code:0,message:未授权}}"
  96. // @Failure 500 schema.HTTPError "{error:{code:0,message:服务器错误}}"
  97. // @Router /web/v1/dataset_files/ [post]
  98. func (a *DatasetFile) Create(r *ghttp.Request) {
  99. var data schema.DatasetFile
  100. if err := gplus.ParseJson(r, &data); err != nil {
  101. gplus.ResError(r, err)
  102. }
  103. ctx := gplus.NewContext(r)
  104. err := a.DatasetFileBll.Create(ctx, data)
  105. if err != nil {
  106. gplus.ResError(r, err)
  107. }
  108. ResSuccess(r, nil)
  109. }
  110. func (a *DatasetFile) BatchCreate(r *ghttp.Request) {
  111. var data schema.DatasetFiles
  112. if err := gplus.ParseJson(r, &data); err != nil {
  113. gplus.ResError(r, err)
  114. }
  115. ctx := gplus.NewContext(r)
  116. err := a.DatasetFileBll.BatchCreate(ctx, data)
  117. if err != nil {
  118. gplus.ResError(r, err)
  119. }
  120. ResSuccess(r, nil)
  121. }
  122. // Update 更新数据
  123. // @Summary 更新数据
  124. // @Param body schema.DatasetFile true "更新数据"
  125. // @Success 200 schema.DatasetFile
  126. // @Failure 400 schema.HTTPError "{error:{code:0,message:无效的请求参数}}"
  127. // @Failure 401 schema.HTTPError "{error:{code:0,message:未授权}}"
  128. // @Failure 500 schema.HTTPError "{error:{code:0,message:服务器错误}}"
  129. // @Router /web/v1/dataset_files/{id}
  130. func (a *DatasetFile) Update(r *ghttp.Request) {
  131. var data schema.DatasetFile
  132. if err := gplus.ParseJson(r, &data); err != nil {
  133. gplus.ResError(r, err)
  134. }
  135. ctx := gplus.NewContext(r)
  136. err := a.DatasetFileBll.Update(ctx, r.Get("id").String(), data)
  137. if err != nil {
  138. gplus.ResError(r, err)
  139. }
  140. ResSuccess(r, nil)
  141. }
  142. // Delete 删除数据
  143. // @Summary 删除数据
  144. // @Param id path string true "记录ID"
  145. // @Success 200 schema.HTTPStatus "{status:OK}"
  146. // @Failure 400 schema.HTTPError "{error:{code:0,message:无效的请求参数}}"
  147. // @Failure 401 schema.HTTPError "{error:{code:0,message:未授权}}"
  148. // @Failure 500 schema.HTTPError "{error:{code:0,message:服务器错误}}"
  149. // @Router /web/v1/dataset_file/{id}
  150. func (a *DatasetFile) Delete(r *ghttp.Request) {
  151. ctx := gplus.NewContext(r)
  152. err := a.DatasetFileBll.Delete(ctx, r.Get("id").String())
  153. if err != nil {
  154. gplus.ResError(r, err)
  155. }
  156. ResSuccess(r, nil)
  157. }
  158. func (a *DatasetFile) BatchDelete(r *ghttp.Request) {
  159. var Ids schema.DeleteIds
  160. if err := gplus.ParseJson(r, &Ids); err != nil {
  161. gplus.ResError(r, err)
  162. }
  163. ctx := gplus.NewContext(r)
  164. err := a.DatasetFileBll.BatchDelete(ctx, Ids.Ids)
  165. if err != nil {
  166. gplus.ResError(r, err)
  167. }
  168. ResSuccess(r, nil)
  169. }
  170. func (a *DatasetFile) Enabled(r *ghttp.Request) {
  171. ctx := gplus.NewContext(r)
  172. err := a.DatasetFileBll.UpdateEnabled(ctx, r.Get("id").String(), true)
  173. if err != nil {
  174. gplus.ResError(r, err)
  175. }
  176. ResSuccess(r, nil)
  177. }
  178. func (a *DatasetFile) Disabled(r *ghttp.Request) {
  179. ctx := gplus.NewContext(r)
  180. err := a.DatasetFileBll.UpdateEnabled(ctx, r.Get("id").String(), false)
  181. if err != nil {
  182. gplus.ResError(r, err)
  183. }
  184. ResSuccess(r, nil)
  185. }