12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- package view
- import (
- "errors"
- "fmt"
- "github.com/metarare/metarare_api/common"
- "github.com/metarare/metarare_api/models"
- "gorm.io/gorm"
- )
- type ResultSet struct {
- *models.CollectionProfile
- IsOfficial bool `json:"is_official"`
- }
- func SelectCollectionListByKeyword(db *gorm.DB, _filter common.Filter) (error, []ResultSet) {
- var infos []ResultSet
- err := fmt.Errorf("")
- if _filter.CollectionName == "" {
- err = db.Table("collection_profile").
- Select(`
- collection.is_official as is_official,
- collection_profile.id,
- collection_profile.collection_id,
- collection_profile.created_at,
- collection_profile.updated_at,
- collection_profile.deleted_at,
- collection_profile.name,
- collection_profile.description,
- collection_profile.thumbnail_image,
- collection_profile.cover_image
- `).
- Joins(" left join (select token.collection_id, sum(price) as tvl from sale left join token on sale.token_id = token.id group by token.collection_id) as stats on stats.collection_id = collection_profile.collection_id").
- Joins("left join collection on collection_profile.collection_id = collection.id").
- Order("tvl desc").Limit(10000).Find(&infos).Error
- } else {
- keyword := "%" + _filter.CollectionName + "%"
- err = db.Table("collection_profile").Where("LOWER(name) like LOWER(?)", keyword).Find(&infos).Error
- }
- if errors.Is(err, gorm.ErrRecordNotFound) {
- fmt.Println(err.Error())
- return err, []ResultSet{}
- }
- return nil, infos
- }
- func SelectExploreItems(db *gorm.DB, _filter common.Filter, authUserID uint64) (error, []common.ExpItem) {
- var _items []common.ExpItem
- err := GetExploreItemQuery(db, _filter, authUserID).Find(&_items).Error
- if errors.Is(err, gorm.ErrRecordNotFound) {
- fmt.Println(err.Error())
- return err, []common.ExpItem{}
- }
- return nil, _items
- }
- func SelectExploreItemsByTokenName(db *gorm.DB, _filter common.Filter, authUserID uint64) (error, common.SearchExpItems) {
- _searchItem := common.SearchExpItems{}
- keyword := "%" + _filter.TokenName + "%"
- err := GetExploreItemQuery(db, _filter, authUserID).Where("LOWER(token.name) like LOWER(?)", keyword).Find(&_searchItem.Result).Error
- GetSuggestionSearch(db, _filter).Limit(10).Find(&_searchItem.Suggestion)
- if errors.Is(err, gorm.ErrRecordNotFound) {
- fmt.Println(err.Error())
- return err, common.SearchExpItems{}
- }
- return nil, _searchItem
- }
- func HintQueryByToken(db *gorm.DB, _filter common.Filter) (error, []string) {
- var _items []string
- keyword := "%" + _filter.TokenName + "%"
- err := GetHintExploreQuery(db, _filter, keyword).Limit(10).Find(&_items).Error
- if errors.Is(err, gorm.ErrRecordNotFound) {
- fmt.Println(err.Error())
- return err, []string{}
- }
- return nil, _items
- }
|