setting.go 991 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package api
  2. import (
  3. "box-cost/db/model"
  4. "time"
  5. "github.com/gin-gonic/gin"
  6. )
  7. func Setting(router *GinRouter) {
  8. CreateCRUD(router, "/units", &CRUDOption{
  9. Collection: "units",
  10. NewModel: func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
  11. entity := &model.Unit{}
  12. c.ShouldBindJSON(entity)
  13. entity.CreateTime = time.Now()
  14. return entity, nil
  15. },
  16. EmtyModel: func(c *gin.Context, apictx *ApiSession) interface{} {
  17. return &model.Unit{}
  18. },
  19. JWT: true,
  20. SearchProject: []string{"name", "createTime"},
  21. })
  22. CreateCRUD(router, "/cates", &CRUDOption{
  23. Collection: "cates",
  24. NewModel: func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
  25. entity := &model.Category{}
  26. c.ShouldBindJSON(entity)
  27. entity.CreateTime = time.Now()
  28. return entity, nil
  29. },
  30. EmtyModel: func(c *gin.Context, apictx *ApiSession) interface{} {
  31. return &model.Category{}
  32. },
  33. JWT: true,
  34. SearchProject: []string{"name", "createTime"},
  35. })
  36. }