category.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package models
  2. import (
  3. "context"
  4. "fmt"
  5. "strconv"
  6. "strings"
  7. "github.com/lib/pq"
  8. "github.com/qor/oss"
  9. "github.com/qor5/admin/publish"
  10. "gorm.io/gorm"
  11. )
  12. type Category struct {
  13. gorm.Model
  14. Name string
  15. Products pq.StringArray `gorm:"type:text[]"`
  16. publish.Status
  17. publish.Schedule
  18. publish.Version
  19. }
  20. func (c *Category) PrimarySlug() string {
  21. return fmt.Sprintf("%v_%v", c.ID, c.Version.Version)
  22. }
  23. func (c *Category) PrimaryColumnValuesBySlug(slug string) map[string]string {
  24. segs := strings.Split(slug, "_")
  25. if len(segs) != 2 {
  26. panic("wrong slug")
  27. }
  28. return map[string]string{
  29. "id": segs[0],
  30. "version": segs[1],
  31. }
  32. }
  33. func (c *Category) GetPublishActions(db *gorm.DB, ctx context.Context, storage oss.StorageInterface) (objs []*publish.PublishAction, err error) {
  34. return
  35. }
  36. func (c *Category) GetUnPublishActions(db *gorm.DB, ctx context.Context, storage oss.StorageInterface) (objs []*publish.PublishAction, err error) {
  37. return
  38. }
  39. func (c *Category) PermissionRN() []string {
  40. return []string{"categories", strconv.Itoa(int(c.ID)), c.Version.Version}
  41. }