mirror of https://github.com/rocboss/paopao-ce
parent
82735c5592
commit
20cec3faa3
@ -0,0 +1,13 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
GetHighQualityRankingResp = dbr.GetHighQualityRankingResp
|
||||||
|
)
|
||||||
|
|
||||||
|
type RankService interface {
|
||||||
|
GetHighQualityRanking() ([]*GetHighQualityRankingResp, error)
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package dbr
|
||||||
|
|
||||||
|
type Rank struct {
|
||||||
|
UserName string `json:"user_name"`
|
||||||
|
ShareKey string `json:"share_key"`
|
||||||
|
AllDownLoadCount int `json:"all_download_count"`
|
||||||
|
DownloadCountPerWeek int `json:"download_count_per_week"`
|
||||||
|
DownloadCountPerMonth int `json:"download_count_per_month"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type HighQualityRanking struct {
|
||||||
|
UserName string `json:"user_name"`
|
||||||
|
UserId int `json:"user_id"`
|
||||||
|
Avatar string `json:"avatar"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetHighQualityRankingResp 优质榜单返回数据
|
||||||
|
type GetHighQualityRankingResp struct {
|
||||||
|
UserName string `json:"name"`
|
||||||
|
Avatar string `json:"avatar"`
|
||||||
|
PostCount int64 `json:"post_count"`
|
||||||
|
LikesCount int64 `json:"likes"`
|
||||||
|
ComprehensiveScore int64 `json:"comprehensive_score"`
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
package web
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/alimy/mir/v4"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
api "github.com/rocboss/paopao-ce/auto/api/v1"
|
||||||
|
"github.com/rocboss/paopao-ce/internal/model/web"
|
||||||
|
"github.com/rocboss/paopao-ce/internal/servants/base"
|
||||||
|
"github.com/rocboss/paopao-ce/internal/servants/chain"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ api.Rank = (*rankSrv)(nil)
|
||||||
|
)
|
||||||
|
|
||||||
|
type rankSrv struct {
|
||||||
|
api.UnimplementedRankServant
|
||||||
|
*base.DaoServant
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *rankSrv) Chain() gin.HandlersChain {
|
||||||
|
return gin.HandlersChain{chain.JWT()}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *rankSrv) GetHighQuality() ([]*web.GetHighQualityRankingResp, mir.Error) {
|
||||||
|
if s.Ds == nil {
|
||||||
|
logrus.Errorf("GetKeyDetail err: %s", web.ErrDsNil)
|
||||||
|
return nil, web.ErrDsNil
|
||||||
|
} else {
|
||||||
|
logrus.Info("GetKeyDetail success")
|
||||||
|
}
|
||||||
|
//调用数据源的方式查询所有的rank信息
|
||||||
|
ranks, err := s.Ds.GetHighQualityRanking()
|
||||||
|
if err != nil {
|
||||||
|
return nil, web.ErrGetHighQualityRankingFailed
|
||||||
|
}
|
||||||
|
|
||||||
|
//将查询到的rank信息转换为GetHighQualityRankingResp结构体
|
||||||
|
var rankInfos []*web.GetHighQualityRankingResp
|
||||||
|
for _, rank := range ranks {
|
||||||
|
rankInfos = append(rankInfos, &web.GetHighQualityRankingResp{
|
||||||
|
UserName: rank.UserName,
|
||||||
|
Avatar: rank.Avatar,
|
||||||
|
PostCount: rank.PostCount,
|
||||||
|
LikesCount: rank.LikesCount,
|
||||||
|
ComprehensiveScore: rank.ComprehensiveScore,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return rankInfos, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRankServant(ds *base.DaoServant) api.Rank {
|
||||||
|
return &rankSrv{
|
||||||
|
DaoServant: ds,
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue