package view import ( "errors" "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"` // Artists []common.ArtistItem `json:"artist"` } 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 < (?)", curating_limit). 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 =(?)", specialBidsTitle). 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). 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). 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). Find(&_tokenSet.Explore).Error if errors.Is(err, gorm.ErrRecordNotFound) { return err, _tokenSet } // Get Artists List // _tokenSet.Artists = GetArtists(db) return nil, _tokenSet } func SelectArtistsItems(db *gorm.DB, limit int) (r []common.ArtistItem) { r = GetArtists(db, limit) return }