categorycontroller.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "strconv"
  5. "trading-go/model"
  6. "trading-go/response"
  7. )
  8. // GetAllCategories
  9. // @Tags 分类模块
  10. // @Summary 获取所有分类
  11. // @Accept application/json
  12. // @Produce application/json
  13. // @Success 200 {object} response.Response
  14. // @Router /category [get]
  15. func GetAllCategories(c *gin.Context) {
  16. var categories []model.Category
  17. categories = append(categories, model.Category{})
  18. categories = append(categories, model.Category{})
  19. response.Success(c.Writer, "success", categories)
  20. }
  21. // CreateCategory
  22. // @Tags 分类模块
  23. // @Summary 创建分类
  24. // @Accept application/json
  25. // @Produce application/json
  26. // @Param json body model.CategoryJson true "分类数据"
  27. // @Success 200 {object} response.Response
  28. // @Router /category/create [post]
  29. func CreateCategory(c *gin.Context) {
  30. var categoryJson model.CategoryJson
  31. err := c.ShouldBindJSON(&categoryJson)
  32. if err != nil {
  33. msg := err.Error()
  34. response.Fail(c.Writer, msg, 500)
  35. return
  36. }
  37. response.Success(c.Writer, "success", nil)
  38. }
  39. // DCategory
  40. // @Tags 分类模块
  41. // @Summary 根据分类id删除某个分类
  42. // @Produce application/json
  43. // @Param id path int64 true "分类id"
  44. // @Success 200 {object} response.Response
  45. // @Router /category/delete/{id} [delete]
  46. func DCategory(c *gin.Context) {
  47. var category model.Category
  48. ids := c.Param("id")
  49. id, err := strconv.Atoi(ids)
  50. if err != nil {
  51. response.Fail(c.Writer, err.Error(), 500)
  52. return
  53. }
  54. category.Id = int64(id)
  55. response.Success(c.Writer, "success", nil)
  56. }