home.go-- 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package view
  2. import (
  3. "errors"
  4. "github.com/metarare/metarare_api/api/constant"
  5. "github.com/metarare/metarare_api/common"
  6. "gorm.io/gorm"
  7. )
  8. type TokenSet struct {
  9. CuratingList []common.ExpItem `json:"curating_list"`
  10. SpecialBids []common.ExpItem `json:"special_bids"`
  11. HotBids []common.ExpItem `json:"hot_bids"`
  12. TimeAuctions []common.ExpItem `json:"time_auctions"`
  13. Collections []CollectionInfo `json:"collections"`
  14. Explore []common.ExpItem `json:"explore"`
  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 < (?) AND sale.id NOT IN (?)", curating_limit, constant.HideFromListIds).
  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 =(?) AND sale.id NOT IN (?)", specialBidsTitle, constant.HideFromListIds).
  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. Where("sale.id NOT IN (?)", constant.HideFromListIds).
  50. Order("sale.updated_at desc").
  51. Find(&_tokenSet.HotBids).Error
  52. if errors.Is(err, gorm.ErrRecordNotFound) {
  53. return err, _tokenSet
  54. }
  55. // Time Auction
  56. _filter.Limit = 50
  57. _filter.SaleType = "time"
  58. err = GetExploreItemQuery(db, _filter, userID).
  59. Where("AND sale.id NOT IN (?)", constant.HideFromListIds).
  60. Order("sale.updated_at desc").
  61. Find(&_tokenSet.TimeAuctions).Error
  62. if errors.Is(err, gorm.ErrRecordNotFound) {
  63. return err, _tokenSet
  64. }
  65. // Collection
  66. _filter.Limit = 50
  67. _filter.SaleType = ""
  68. var collectionIDs []uint64
  69. db.Table("collection").Select("id").Order("rand()").Limit(20).Find(&collectionIDs)
  70. _tokenSet.Collections, err = GetCollectionInfomation(db, collectionIDs, userID)
  71. if errors.Is(err, gorm.ErrRecordNotFound) {
  72. return err, _tokenSet
  73. }
  74. //Exp
  75. err = GetExploreItemQuery(db, _filter, userID).
  76. Where("AND sale.id NOT IN (?)", constant.HideFromListIds).
  77. Find(&_tokenSet.Explore).Error
  78. if errors.Is(err, gorm.ErrRecordNotFound) {
  79. return err, _tokenSet
  80. }
  81. return nil, _tokenSet
  82. }