device_genre.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package admin
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "server/dao"
  5. "server/model/common/response"
  6. "server/utils/logger"
  7. "strconv"
  8. )
  9. type DeviceGenreApi struct{}
  10. func (dga *DeviceGenreApi) QueryAllDeviceGenres(c *gin.Context) {
  11. deviceGenres, err := deviceGenreService.QueryAllDeviceGenres()
  12. if err != nil {
  13. logger.Get().Error("QueryAllDeviceGenres ---- " + err.Error())
  14. response.FailWithMessage("获取设备类型失败", c)
  15. return
  16. }
  17. response.OkWithData(deviceGenres, c)
  18. }
  19. func (dga *DeviceGenreApi) CreateDeviceGenre(c *gin.Context) {
  20. var deviceGenre dao.DeviceGenre
  21. err := c.ShouldBindJSON(&deviceGenre)
  22. if err != nil {
  23. logger.Get().Error("CreateDeviceGenre ---- " + err.Error())
  24. response.FailWithMessage("参数解析失败", c)
  25. return
  26. }
  27. err = deviceGenreService.CreateDeviceGenre(deviceGenre)
  28. if err != nil {
  29. logger.Get().Error("CreateDeviceGenre ---- " + err.Error())
  30. response.FailWithMessage("创建设备类型失败", c)
  31. return
  32. }
  33. response.OkWithMessage("创建成功", c)
  34. }
  35. func (dga *DeviceGenreApi) UpdateDeviceGenre(c *gin.Context) {
  36. var deviceGenre dao.DeviceGenre
  37. err := c.ShouldBindJSON(&deviceGenre)
  38. if err != nil {
  39. logger.Get().Error("UpdateDeviceGenre ---- " + err.Error())
  40. response.FailWithMessage("参数解析失败", c)
  41. return
  42. }
  43. err = deviceGenreService.UpdateDeviceGenre(deviceGenre)
  44. if err != nil {
  45. logger.Get().Error("UpdateDeviceGenre ---- " + err.Error())
  46. response.FailWithMessage("更新设备类型失败", c)
  47. return
  48. }
  49. response.OkWithMessage("更新成功", c)
  50. }
  51. func (dga *DeviceGenreApi) DeleteDeviceGenre(c *gin.Context) {
  52. id, err := strconv.Atoi(c.Query("id"))
  53. if err != nil {
  54. logger.Get().Error("DeleteDeviceGenre ---- " + err.Error())
  55. response.FailWithMessage("参数错误", c)
  56. return
  57. }
  58. err = deviceGenreService.DeleteDeviceGenre(id)
  59. if err != nil {
  60. logger.Get().Error("DeleteDeviceGenre ---- " + err.Error())
  61. response.FailWithMessage("删除设备类型失败", c)
  62. return
  63. }
  64. response.OkWithMessage("删除成功", c)
  65. }