feed.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package model
  2. import (
  3. artmdl "go-common/app/interface/openplatform/article/model"
  4. "go-common/app/service/main/archive/api"
  5. "go-common/app/service/main/archive/model/archive"
  6. "go-common/library/time"
  7. )
  8. // feed type
  9. const (
  10. ArchiveType = 0
  11. BangumiType = 1
  12. TypeApp = iota
  13. TypeWeb
  14. TypeArt
  15. )
  16. // FeedType return feed type
  17. func FeedType(app bool) int {
  18. if app {
  19. return TypeApp
  20. }
  21. return TypeWeb
  22. }
  23. // Feed struct of Feed
  24. type Feed struct {
  25. Type int64 `json:"type"`
  26. // Data is *api.Arc or *Bangumi
  27. Archive *api.Arc `json:"archive"`
  28. Bangumi *Bangumi `json:"bangumi"`
  29. // ID is aid or SeasonID
  30. ID int64 `json:"id"`
  31. PubDate time.Time `json:"pubdate"`
  32. Fold []*api.Arc `json:"fold"`
  33. }
  34. type Feeds []*Feed
  35. func (as Feeds) Len() int { return len(as) }
  36. func (as Feeds) Less(i, j int) bool {
  37. if as[i].PubDate != as[j].PubDate {
  38. return as[i].PubDate > as[j].PubDate
  39. }
  40. return as[i].ID > as[j].ID
  41. }
  42. func (as Feeds) Swap(i, j int) { as[i], as[j] = as[j], as[i] }
  43. type ArticleFeeds []*artmdl.Meta
  44. func (as ArticleFeeds) Len() int { return len(as) }
  45. func (as ArticleFeeds) Less(i, j int) bool {
  46. if as[i].PublishTime != as[j].PublishTime {
  47. return as[i].PublishTime > as[j].PublishTime
  48. }
  49. return as[i].ID > as[j].ID
  50. }
  51. func (as ArticleFeeds) Swap(i, j int) { as[i], as[j] = as[j], as[i] }
  52. // Arcs AidPubTime slice
  53. type Arcs []*archive.AidPubTime
  54. func (as Arcs) Len() int { return len(as) }
  55. func (as Arcs) Less(i, j int) bool {
  56. if as[i].PubDate != as[j].PubDate {
  57. return as[i].PubDate > as[j].PubDate
  58. }
  59. return as[i].Aid > as[j].Aid
  60. }
  61. func (as Arcs) Swap(i, j int) { as[i], as[j] = as[j], as[i] }