product.go 1.1 KB

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