shortlist.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package vehicle
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "server/dao"
  5. "server/model/common/request"
  6. "server/model/common/response"
  7. "strconv"
  8. )
  9. type ShortlistApi struct{}
  10. func (sa *ShortlistApi) QueryAllShortlists(c *gin.Context) {
  11. shortlists, err := shortlistService.QueryAllShortlists()
  12. if err != nil {
  13. response.FailWithMessage("查询失败", c)
  14. return
  15. }
  16. response.OkWithData(shortlists, c)
  17. }
  18. func (sa *ShortlistApi) QueryShortlistList(c *gin.Context) {
  19. var info request.PageInfo
  20. err := c.ShouldBindJSON(&info)
  21. if err != nil {
  22. response.FailWithMessage("参数错误", c)
  23. return
  24. }
  25. list, total, err := shortlistService.QueryShortlistList(info)
  26. if err != nil {
  27. response.FailWithMessage("查询失败", c)
  28. return
  29. }
  30. response.OkWithDetailed(response.PageResult{
  31. List: list,
  32. Total: total,
  33. Page: info.Page,
  34. PageSize: info.PageSize,
  35. }, "获取成功", c)
  36. }
  37. func (sa *ShortlistApi) CreateShortlist(c *gin.Context) {
  38. var shortlist dao.Shortlist
  39. err := c.ShouldBindJSON(&shortlist)
  40. if err != nil {
  41. response.FailWithMessage("参数错误", c)
  42. return
  43. }
  44. err = shortlistService.CreateShortlist(shortlist)
  45. if err != nil {
  46. response.FailWithMessage("新增失败", c)
  47. return
  48. }
  49. response.OkWithMessage("新增成功", c)
  50. }
  51. func (sa *ShortlistApi) UpdateShortlist(c *gin.Context) {
  52. var shortlist dao.Shortlist
  53. err := c.ShouldBindJSON(&shortlist)
  54. if err != nil {
  55. response.FailWithMessage("参数错误", c)
  56. return
  57. }
  58. err = shortlistService.UpdateShortlist(shortlist)
  59. if err != nil {
  60. response.FailWithMessage("修改失败", c)
  61. return
  62. }
  63. response.OkWithMessage("修改成功", c)
  64. }
  65. func (sa *ShortlistApi) DeleteShortlist(c *gin.Context) {
  66. id, err := strconv.Atoi(c.Param("id"))
  67. if err != nil {
  68. response.FailWithMessage("参数错误", c)
  69. return
  70. }
  71. err = shortlistService.DeleteShortlist(id)
  72. if err != nil {
  73. response.FailWithMessage("删除失败", c)
  74. return
  75. }
  76. response.OkWithMessage("删除成功", c)
  77. }