You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.3 KiB

  1. package service
  2. import (
  3. "gin-vue-admin/global"
  4. "gin-vue-admin/model"
  5. "gin-vue-admin/model/request"
  6. )
  7. // @title Create{{.StructName}}
  8. // @description create a {{.StructName}}
  9. // @param {{.Abbreviation}} model.{{.StructName}}
  10. // @auth (2020/04/05 20:22)
  11. // @return err error
  12. func Create{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) {
  13. err = global.GVA_DB.Create(&{{.Abbreviation}}).Error
  14. return err
  15. }
  16. // @title Delete{{.StructName}}
  17. // @description delete a {{.StructName}}
  18. // @auth (2020/04/05 20:22)
  19. // @param {{.Abbreviation}} model.{{.StructName}}
  20. // @return error
  21. func Delete{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) {
  22. err = global.GVA_DB.Delete({{.Abbreviation}}).Error
  23. return err
  24. }
  25. // @title Update{{.StructName}}
  26. // @description update a {{.StructName}}
  27. // @param {{.Abbreviation}} *model.{{.StructName}}
  28. // @auth (2020/04/05 20:22)
  29. // @return error
  30. func Update{{.StructName}}({{.Abbreviation}} *model.{{.StructName}}) (err error) {
  31. err = global.GVA_DB.Save({{.Abbreviation}}).Error
  32. return err
  33. }
  34. // @title Get{{.StructName}}
  35. // @description get the info of a {{.StructName}}
  36. // @auth (2020/04/05 20:22)
  37. // @param id uint
  38. // @return error
  39. // @return {{.StructName}} {{.StructName}}
  40. func Get{{.StructName}}(id uint) (err error, {{.Abbreviation}} model.{{.StructName}}) {
  41. err = global.GVA_DB.Where("id = ?", id).First(&{{.Abbreviation}}).Error
  42. return
  43. }
  44. // @title Get{{.StructName}}InfoList
  45. // @description get {{.StructName}} list by pagination, 分页获取用户列表
  46. // @auth (2020/04/05 20:22)
  47. // @param info PageInfo
  48. // @return error
  49. func Get{{.StructName}}InfoList(info request.PageInfo) (err error, list interface{}, total int) {
  50. limit := info.PageSize
  51. offset := info.PageSize * (info.Page - 1)
  52. db := global.GVA_DB
  53. var {{.Abbreviation}}s []model.{{.StructName}}
  54. err = db.Find(&{{.Abbreviation}}s).Count(&total).Error
  55. err = db.Limit(limit).Offset(offset).Find(&{{.Abbreviation}}s).Error
  56. return err, {{.Abbreviation}}s, total
  57. }