123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- package view
- import (
- "time"
- "github.com/metarare/metarare_api/models"
- "gorm.io/gorm"
- )
- type DetailSaleData struct {
- Sale Sale `json:"sale"`
- Traits []models.Traits `json:"traits"`
- }
- type Sale struct {
- ID uint64 `json:"id"`
- TokenID uint64 `json:"token_id"`
- TokenUID string `json:"token_uid"`
- TokenType string `json:"token_type"`
- ContentURL string `json:"content_url"`
- Name string `json:"name"`
- Description string `json:"description"`
- SaleType string `json:"sale_type"`
- Status string `json:"status"`
- Price float64 `json:"price"`
- HighestPrice float64 `json:"highest_price"` // 서브쿼리
- MyBiddingPrice float64 `json:"my_bidding_price"`
- StartPrice float64 `json:"start_price"`
- StartAt time.Time `json:"start_at"`
- EndAt time.Time `json:"end_at"`
- Royalties uint32 `json:"royalties"`
- ArtistProfileImage string `json:"artist_profile_image"`
- ArtistName string `json:"artist_name"`
- ArtistIsOfficial bool `json:"artist_is_official"`
- LikeCount int `json:"like_count"`
- CollectionThumbnailImage string `json:"collection_thumbnail_image"`
- CollectionName string `json:"collection_name"`
- UserProfileImage string `json:"user_profile_image"`
- UserName string `json:"user_name"`
- OwnerIsOfficial bool `json:"owner_is_official"`
- Network string `json:"network"`
- Currency string `json:"currency"`
- IsOwner bool `json:"is_owner"`
- IsLike bool `json:"is_like"`
- TotalCount int `json:"total_count"`
- Index int `json:"index"`
- CollectionIsOfficial bool `json:"collection_is_official"`
- }
- type Owner struct {
- IsOwner bool `json:"is_owner"`
- }
- type BidList struct {
- ThumbnailImage string `json:"thumbnail_image"`
- Name string `json:"name"`
- Price float64 `json:"price"`
- IsCancel bool `json:"is_cancel"`
- Currency string `json:"currency"`
- CreatedAt time.Time `json:"created_at"`
- IsOfficial bool `json:"is_official"`
- }
- func GetSaleData(db *gorm.DB, address string, userID uint64, saleID string) *gorm.DB {
- querySet := db.Select(`sale.id, token.id AS token_id, token.uid AS token_uid, token.type AS token_type, token.content_url, token.name, token.description, sale.sale_type, sale.status, sale.price,
- (select price from bid_log where bid_log.is_cancel = false AND sale_id = sale.id order by id desc LIMIT 1) AS highest_price,
- IF(bl.id IS NOT NULL, bl.price, 0) AS my_bidding_price, sale.start_price, sale.start_at, sale.end_at, token.total_count, token.index,
- token.royalties, artist.thumbnail_image AS artist_profile_image, artist.name AS artist_name, token.like_count, IF(artist_profile_user.id IS NULL, false, true) AS artist_is_official,
- collection_profile.thumbnail_image AS collection_thumbnail_image, collection_profile.name AS collection_name, collection.is_official AS collection_is_official,
- user_profile.thumbnail_image AS user_profile_image, user_profile.name AS user_name, collection.network, sale.currency, IF(artist_profile.id IS NULL, false, true) AS owner_is_official,
- IF(user_like.id IS NOT NULL AND user_like.is_like = 1, true, false) AS is_like, IF(token.owner_address = ?, true, false) AS is_owner`, address).Table("sale").
- Joins("INNER JOIN token ON token.id = sale.token_id").
- Joins("INNER JOIN collection ON collection.id = token.collection_id").
- Joins("INNER JOIN collection_profile ON collection_profile.collection_id = collection.id").
- Joins("INNER JOIN user_wallet AS artist_wallet ON artist_wallet.address = token.creator_address").
- Joins("INNER JOIN user_profile AS artist ON artist.user_id = artist_wallet.user_id").
- Joins("INNER JOIN user_wallet ON user_wallet.address = token.owner_address").
- Joins("INNER JOIN user_profile ON user_profile.user_id = user_wallet.user_id").
- Joins("LEFT JOIN artist_profile AS artist_profile_user ON artist_profile_user.user_id = artist.user_id").
- Joins("LEFT JOIN artist_profile ON artist_profile.user_id = user_wallet.user_id").
- Joins("LEFT JOIN bid_log AS bl ON bl.address = ? AND bl.sale_id = ? AND is_cancel = 0", address, saleID).
- Joins("LEFT JOIN user_like ON user_like.token_id = token.id AND user_like.user_id = ?", userID)
- return querySet
- }
- func IsOwner(db *gorm.DB, userID uint64) *gorm.DB {
- querySet := db.Select("IF(user_wallet.address = token.owner_address, true, false) AS is_owner").Table("sale").
- Joins("INNER JOIN token ON token.id = sale.token_id").
- Joins("INNER JOIN user ON user.id = ?", userID).
- Joins("INNER JOIN user_wallet ON user_wallet.user_id = user.id")
- return querySet
- }
- func GetBidList(db *gorm.DB) *gorm.DB {
- querySet := db.Select(`user_profile.thumbnail_image, user_profile.name, bid_log.price, bid_log.is_cancel, sale.currency, bid_log.created_at,
- IF(artist_profile.id IS NOT NULL, true, false) AS is_official`).Table("bid_log").
- Joins("INNER JOIN sale ON sale.id = bid_log.sale_id").
- Joins("INNER JOIN user_wallet ON user_wallet.address = bid_log.address").
- Joins("INNER JOIN user_profile ON user_profile.user_id = user_wallet.user_id").
- Joins("LEFT JOIN artist_profile ON artist_profile.user_id = user_wallet.user_id")
- return querySet
- }
|