123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- 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
- }
|