123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- package view
- import (
- "errors"
- "github.com/metarare/metarare_api/api/constant"
- "github.com/metarare/metarare_api/common"
- "gorm.io/gorm"
- )
- type TokenSet struct {
- CuratingList []common.ExpItem `json:"curating_list"`
- SpecialBids []common.ExpItem `json:"special_bids"`
- HotBids []common.ExpItem `json:"hot_bids"`
- TimeAuctions []common.ExpItem `json:"time_auctions"`
- Collections []CollectionInfo `json:"collections"`
- Explore []common.ExpItem `json:"explore"`
- }
- func SelectHomeItems(db *gorm.DB, userID uint64) (error, TokenSet) {
- var _tokenSet TokenSet
- const curating_limit = 25
- // CuratingList
- _filter := common.Filter{
- Offset: 0,
- Limit: 25,
- }
- err := GetExploreItemQuery(db, _filter, userID).
- Where("collection.curating_number > 0 AND collection.curating_number < (?) AND sale.id NOT IN (?)", curating_limit, constant.HideFromListIds).
- Group("collection.curating_number").
- Find(&_tokenSet.CuratingList).Error
- if errors.Is(err, gorm.ErrRecordNotFound) {
- return err, _tokenSet
- }
- // Special bids
- var specialBidsTitle = ""
- err = db.Table("setting").Select("special_collection").Find(&specialBidsTitle).Error
- if errors.Is(err, gorm.ErrRecordNotFound) {
- return err, _tokenSet
- }
- _filter.Limit = 50
- err = GetExploreItemQuery(db, _filter, userID).
- Where("collection_profile.name =(?) AND sale.id NOT IN (?)", specialBidsTitle, constant.HideFromListIds).
- Order("token.lastest_price desc").
- Find(&_tokenSet.SpecialBids).Error
- if errors.Is(err, gorm.ErrRecordNotFound) {
- return err, _tokenSet
- }
- //Auction
- _filter.Limit = 50
- _filter.SaleType = "auction"
- err = GetExploreItemQuery(db, _filter, userID).
- Where("sale.id NOT IN (?)", constant.HideFromListIds).
- Order("sale.updated_at desc").
- Find(&_tokenSet.HotBids).Error
- if errors.Is(err, gorm.ErrRecordNotFound) {
- return err, _tokenSet
- }
- // Time Auction
- _filter.Limit = 50
- _filter.SaleType = "time"
- err = GetExploreItemQuery(db, _filter, userID).
- Where("AND sale.id NOT IN (?)", constant.HideFromListIds).
- Order("sale.updated_at desc").
- Find(&_tokenSet.TimeAuctions).Error
- if errors.Is(err, gorm.ErrRecordNotFound) {
- return err, _tokenSet
- }
- // Collection
- _filter.Limit = 50
- _filter.SaleType = ""
- var collectionIDs []uint64
- db.Table("collection").Select("id").Order("rand()").Limit(20).Find(&collectionIDs)
- _tokenSet.Collections, err = GetCollectionInfomation(db, collectionIDs, userID)
- if errors.Is(err, gorm.ErrRecordNotFound) {
- return err, _tokenSet
- }
- //Exp
- err = GetExploreItemQuery(db, _filter, userID).
- Where("AND sale.id NOT IN (?)", constant.HideFromListIds).
- Find(&_tokenSet.Explore).Error
- if errors.Is(err, gorm.ErrRecordNotFound) {
- return err, _tokenSet
- }
- return nil, _tokenSet
- }
|