123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- package view
- import (
- "time"
- "github.com/metarare/metarare_api/models"
- "gorm.io/gorm"
- )
- type TokenOwnerList struct {
- TokenID uint64 `json:"token_id"`
- ThumbnailImage string `json:"thumbnail_image"`
- Name string `json:"name"`
- TotalCount int `json:"total_count"`
- Index int `json:"index"`
- UpdatedAt time.Time `json:"updated_at"`
- IsOfficial bool `json:"is_official"`
- }
- type ResaleBaseData struct {
- CollectionID uint64 `json:"collection_id"`
- TokenID uint64 `json:"token_id"`
- Network string `json:"network"`
- Type string `json:"type"`
- ContentURL string `json:"content_url"`
- Name string `json:"name"`
- Description string `json:"description"`
- Royalties int32 `json:"royalties"`
- TotalCount int `json:"total_count"`
- CollectionName string `json:"collection_name"`
- CollectionThumbnailImage string `json:"collection_thumbnail_image"`
- CollectionIsOfficial bool `json:"collection_is_official"`
- Commission float64 `json:"commission"`
- }
- type TokenResaleData struct {
- Token ResaleBaseData `json:"token"`
- Traits []models.Traits `json:"traits"`
- }
- type TokenDetailData struct {
- Token TokenBaseData `json:"token"`
- Traits []models.Traits `json:"traits"`
- }
- type TokenBaseData struct {
- ID uint64 `json:"id"`
- UID string `json:"uid"`
- Name string `json:"name"`
- Description string `json:"description"`
- Type string `json:"type"`
- Royalties uint32 `json:"royalties"`
- ArtistProfileImage string `json:"artist_profile_image"`
- ArtistName string `json:"artist_name"`
- ArtistIsOfficial bool `json:"artist_is_official"`
- CollectionThumbnailImage string `json:"collection_thumbnail_image"`
- CollectionName string `json:"collection_name"`
- CollectionIsOfficial bool `json:"collection_is_official"`
- UserProfileImage string `json:"user_profile_image"`
- UserName string `json:"user_name"`
- OwnerIsOfficial bool `json:"owner_is_official"`
- Network string `json:"network"`
- ContentURL string `json:"content_url"`
- LikeCount uint32 `json:"like_count"`
- IsOwner bool `json:"is_owner"`
- Index uint32 `json:"index"`
- TotalCount uint32 `json:"total_count"`
- IsLike bool `json:"is_like"`
- }
- func GetTokenDetail(db *gorm.DB, userID uint64) *gorm.DB {
- querySet := db.Select(`token.id, token.uid, token.name, token.description, token.type, token.royalties,
- artist_user_profile.thumbnail_image AS artist_profile_image, artist_user_profile.name AS artist_name, IF(artist_artist_profile.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, IF(artist_profile.id IS NULL, false, true) AS owner_is_official,
- collection.network, token.content_url, token.like_count, token.total_count, token.index,
- IF(owner.id IS NULL, false, true) AS is_owner, IF(user_like.id IS NOT NULL AND user_like.is_like = true, true, false) AS is_like`).Table("token").
- Joins("INNER JOIN user_wallet AS artist_wallet ON artist_wallet.address = token.creator_address").
- Joins("INNER JOIN user_profile AS artist_user_profile ON artist_user_profile.user_id = artist_wallet.user_id").
- Joins("LEFT JOIN artist_profile AS artist_artist_profile ON artist_artist_profile.user_id = artist_wallet.user_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 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 ON artist_profile.user_id = user_wallet.user_id").
- Joins("LEFT JOIN user_wallet AS owner ON owner.user_id = ? AND owner.address = token.owner_address", userID).
- Joins("LEFT JOIN user_like ON user_like.user_id = ? AND user_like.token_id = token.id", userID)
- return querySet
- }
- func GetOwnerList(db *gorm.DB) *gorm.DB {
- querySet := db.Select(`token.id AS token_id, user_profile.thumbnail_image, user_profile.name,
- token.total_count, token.index, token.updated_at,
- IF(artist_profile.id IS NULL, false, true) AS is_official`).Table("token").
- 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 ON artist_profile.user_id = user_wallet.user_id")
- return querySet
- }
- func GetResaleInfo(db *gorm.DB) *gorm.DB {
- querySet := db.Select(`collection.network, token.id AS token_id, collection.id AS collection_id, token.type, token.content_url,
- token.name, token.description, token.royalties, token.total_count, collection_profile.name AS collection_name,
- collection_profile.thumbnail_image AS collection_thumbnail_image, collection.is_official AS collection_is_official`).Table("token").
- Joins("INNER JOIN collection ON collection.id = token.collection_id").
- Joins("INNER JOIN collection_profile ON collection_profile.collection_id = collection.id")
- return querySet
- }
|