home.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package view
  2. import (
  3. "errors"
  4. "github.com/metarare/metarare_api/common"
  5. "gorm.io/gorm"
  6. )
  7. type TokenSet struct {
  8. CuratingList []common.ExpItem `json:"curating_list"`
  9. SpecialBids []common.ExpItem `json:"special_bids"`
  10. HotBids []common.ExpItem `json:"hot_bids"`
  11. TimeAuctions []common.ExpItem `json:"time_auctions"`
  12. Collections []CollectionInfo `json:"collections"`
  13. Explore []common.ExpItem `json:"explore"`
  14. // Artists []common.ArtistItem `json:"artist"`
  15. }
  16. func SelectHomeItems(db *gorm.DB, userID uint64) (error, TokenSet) {
  17. var _tokenSet TokenSet
  18. const curating_limit = 25
  19. // CuratingList
  20. _filter := common.Filter{
  21. Offset: 0,
  22. Limit: 25,
  23. }
  24. err := GetExploreItemQuery(db, _filter, userID).
  25. Where("collection.curating_number > 0 AND collection.curating_number < (?)", curating_limit).
  26. Group("collection.curating_number").
  27. Find(&_tokenSet.CuratingList).Error
  28. if errors.Is(err, gorm.ErrRecordNotFound) {
  29. return err, _tokenSet
  30. }
  31. // Special bids
  32. var specialBidsTitle = ""
  33. err = db.Table("setting").Select("special_collection").Find(&specialBidsTitle).Error
  34. if errors.Is(err, gorm.ErrRecordNotFound) {
  35. return err, _tokenSet
  36. }
  37. _filter.Limit = 50
  38. err = GetExploreItemQuery(db, _filter, userID).
  39. Where("collection_profile.name =(?)", specialBidsTitle).
  40. Order("token.lastest_price desc").
  41. Find(&_tokenSet.SpecialBids).Error
  42. if errors.Is(err, gorm.ErrRecordNotFound) {
  43. return err, _tokenSet
  44. }
  45. //Auction
  46. _filter.Limit = 50
  47. _filter.SaleType = "auction"
  48. err = GetExploreItemQuery(db, _filter, userID).
  49. Order("sale.updated_at desc").
  50. Find(&_tokenSet.HotBids).Error
  51. if errors.Is(err, gorm.ErrRecordNotFound) {
  52. return err, _tokenSet
  53. }
  54. // Time Auction
  55. _filter.Limit = 50
  56. _filter.SaleType = "time"
  57. err = GetExploreItemQuery(db, _filter, userID).
  58. Order("sale.updated_at desc").
  59. Find(&_tokenSet.TimeAuctions).Error
  60. if errors.Is(err, gorm.ErrRecordNotFound) {
  61. return err, _tokenSet
  62. }
  63. // Collection
  64. _filter.Limit = 50
  65. _filter.SaleType = ""
  66. var collectionIDs []uint64
  67. db.Table("collection").Select("id").Order("rand()").Limit(20).Find(&collectionIDs)
  68. _tokenSet.Collections, err = GetCollectionInfomation(db, collectionIDs, userID)
  69. if errors.Is(err, gorm.ErrRecordNotFound) {
  70. return err, _tokenSet
  71. }
  72. //Exp
  73. err = GetExploreItemQuery(db, _filter, userID).
  74. Find(&_tokenSet.Explore).Error
  75. if errors.Is(err, gorm.ErrRecordNotFound) {
  76. return err, _tokenSet
  77. }
  78. // Get Artists List
  79. // _tokenSet.Artists = GetArtists(db)
  80. return nil, _tokenSet
  81. }
  82. func SelectArtistsItems(db *gorm.DB, limit int) (r []common.ArtistItem) {
  83. r = GetArtists(db, limit)
  84. return
  85. }