token.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package view
  2. import (
  3. "time"
  4. "github.com/metarare/metarare_api/models"
  5. "gorm.io/gorm"
  6. )
  7. type TokenOwnerList struct {
  8. TokenID uint64 `json:"token_id"`
  9. ThumbnailImage string `json:"thumbnail_image"`
  10. Name string `json:"name"`
  11. TotalCount int `json:"total_count"`
  12. Index int `json:"index"`
  13. UpdatedAt time.Time `json:"updated_at"`
  14. IsOfficial bool `json:"is_official"`
  15. }
  16. type ResaleBaseData struct {
  17. CollectionID uint64 `json:"collection_id"`
  18. TokenID uint64 `json:"token_id"`
  19. Network string `json:"network"`
  20. Type string `json:"type"`
  21. ContentURL string `json:"content_url"`
  22. Name string `json:"name"`
  23. Description string `json:"description"`
  24. Royalties int32 `json:"royalties"`
  25. TotalCount int `json:"total_count"`
  26. CollectionName string `json:"collection_name"`
  27. CollectionThumbnailImage string `json:"collection_thumbnail_image"`
  28. CollectionIsOfficial bool `json:"collection_is_official"`
  29. Commission float64 `json:"commission"`
  30. }
  31. type TokenResaleData struct {
  32. Token ResaleBaseData `json:"token"`
  33. Traits []models.Traits `json:"traits"`
  34. }
  35. type TokenDetailData struct {
  36. Token TokenBaseData `json:"token"`
  37. Traits []models.Traits `json:"traits"`
  38. }
  39. type TokenBaseData struct {
  40. ID uint64 `json:"id"`
  41. UID string `json:"uid"`
  42. Name string `json:"name"`
  43. Description string `json:"description"`
  44. Type string `json:"type"`
  45. Royalties uint32 `json:"royalties"`
  46. ArtistProfileImage string `json:"artist_profile_image"`
  47. ArtistName string `json:"artist_name"`
  48. ArtistIsOfficial bool `json:"artist_is_official"`
  49. CollectionThumbnailImage string `json:"collection_thumbnail_image"`
  50. CollectionName string `json:"collection_name"`
  51. CollectionIsOfficial bool `json:"collection_is_official"`
  52. UserProfileImage string `json:"user_profile_image"`
  53. UserName string `json:"user_name"`
  54. OwnerIsOfficial bool `json:"owner_is_official"`
  55. Network string `json:"network"`
  56. ContentURL string `json:"content_url"`
  57. LikeCount uint32 `json:"like_count"`
  58. IsOwner bool `json:"is_owner"`
  59. Index uint32 `json:"index"`
  60. TotalCount uint32 `json:"total_count"`
  61. IsLike bool `json:"is_like"`
  62. }
  63. func GetTokenDetail(db *gorm.DB, userID uint64) *gorm.DB {
  64. querySet := db.Select(`token.id, token.uid, token.name, token.description, token.type, token.royalties,
  65. 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,
  66. collection_profile.thumbnail_image AS collection_thumbnail_image, collection_profile.name AS collection_name, collection.is_official AS collection_is_official,
  67. 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,
  68. collection.network, token.content_url, token.like_count, token.total_count, token.index,
  69. 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").
  70. Joins("INNER JOIN user_wallet AS artist_wallet ON artist_wallet.address = token.creator_address").
  71. Joins("INNER JOIN user_profile AS artist_user_profile ON artist_user_profile.user_id = artist_wallet.user_id").
  72. Joins("LEFT JOIN artist_profile AS artist_artist_profile ON artist_artist_profile.user_id = artist_wallet.user_id").
  73. Joins("INNER JOIN collection ON collection.id = token.collection_id").
  74. Joins("INNER JOIN collection_profile ON collection_profile.collection_id = collection.id").
  75. Joins("INNER JOIN user_wallet ON user_wallet.address = token.owner_address").
  76. Joins("INNER JOIN user_profile ON user_profile.user_id = user_wallet.user_id").
  77. Joins("LEFT JOIN artist_profile ON artist_profile.user_id = user_wallet.user_id").
  78. Joins("LEFT JOIN user_wallet AS owner ON owner.user_id = ? AND owner.address = token.owner_address", userID).
  79. Joins("LEFT JOIN user_like ON user_like.user_id = ? AND user_like.token_id = token.id", userID)
  80. return querySet
  81. }
  82. func GetOwnerList(db *gorm.DB) *gorm.DB {
  83. querySet := db.Select(`token.id AS token_id, user_profile.thumbnail_image, user_profile.name,
  84. token.total_count, token.index, token.updated_at,
  85. IF(artist_profile.id IS NULL, false, true) AS is_official`).Table("token").
  86. Joins("INNER JOIN user_wallet ON user_wallet.address = token.owner_address").
  87. Joins("INNER JOIN user_profile ON user_profile.user_id = user_wallet.user_id").
  88. Joins("LEFT JOIN artist_profile ON artist_profile.user_id = user_wallet.user_id")
  89. return querySet
  90. }
  91. func GetResaleInfo(db *gorm.DB) *gorm.DB {
  92. querySet := db.Select(`collection.network, token.id AS token_id, collection.id AS collection_id, token.type, token.content_url,
  93. token.name, token.description, token.royalties, token.total_count, collection_profile.name AS collection_name,
  94. collection_profile.thumbnail_image AS collection_thumbnail_image, collection.is_official AS collection_is_official`).Table("token").
  95. Joins("INNER JOIN collection ON collection.id = token.collection_id").
  96. Joins("INNER JOIN collection_profile ON collection_profile.collection_id = collection.id")
  97. return querySet
  98. }