category.go 1006 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package sites
  2. import (
  3. "github.com/0xJacky/Nginx-UI/model"
  4. "github.com/gin-gonic/gin"
  5. "github.com/uozi-tech/cosy"
  6. "gorm.io/gorm"
  7. )
  8. func GetCategory(c *gin.Context) {
  9. cosy.Core[model.SiteCategory](c).Get()
  10. }
  11. func GetCategoryList(c *gin.Context) {
  12. cosy.Core[model.SiteCategory](c).GormScope(func(tx *gorm.DB) *gorm.DB {
  13. return tx.Order("order_id ASC")
  14. }).PagingList()
  15. }
  16. func AddCategory(c *gin.Context) {
  17. cosy.Core[model.SiteCategory](c).
  18. SetValidRules(gin.H{
  19. "name": "required",
  20. "sync_node_ids": "omitempty",
  21. }).
  22. Create()
  23. }
  24. func ModifyCategory(c *gin.Context) {
  25. cosy.Core[model.SiteCategory](c).
  26. SetValidRules(gin.H{
  27. "name": "required",
  28. "sync_node_ids": "omitempty",
  29. }).
  30. Modify()
  31. }
  32. func DeleteCategory(c *gin.Context) {
  33. cosy.Core[model.SiteCategory](c).Destroy()
  34. }
  35. func RecoverCategory(c *gin.Context) {
  36. cosy.Core[model.SiteCategory](c).Recover()
  37. }
  38. func UpdateCategoriesOrder(c *gin.Context) {
  39. cosy.Core[model.SiteCategory](c).UpdateOrder()
  40. }