|
|
@ -7,43 +7,41 @@ package jinzhu
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"github.com/rocboss/paopao-ce/internal/core"
|
|
|
|
"github.com/rocboss/paopao-ce/internal/core"
|
|
|
|
"github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr"
|
|
|
|
"github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr"
|
|
|
|
|
|
|
|
"github.com/rocboss/paopao-ce/pkg/debug"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
var (
|
|
|
|
_ core.IndexPostsService = (*indexPostsServant)(nil)
|
|
|
|
_ core.IndexPostsService = (*friendIndexServant)(nil)
|
|
|
|
|
|
|
|
_ core.IndexPostsService = (*followIndexServant)(nil)
|
|
|
|
|
|
|
|
_ core.IndexPostsService = (*lightIndexServant)(nil)
|
|
|
|
_ core.IndexPostsService = (*simpleIndexPostsServant)(nil)
|
|
|
|
_ core.IndexPostsService = (*simpleIndexPostsServant)(nil)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type indexPostsServant struct {
|
|
|
|
type friendIndexServant struct {
|
|
|
|
ams core.AuthorizationManageService
|
|
|
|
ams core.AuthorizationManageService
|
|
|
|
ths core.TweetHelpService
|
|
|
|
ths core.TweetHelpService
|
|
|
|
db *gorm.DB
|
|
|
|
db *gorm.DB
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type simpleIndexPostsServant struct {
|
|
|
|
type followIndexServant struct {
|
|
|
|
ths core.TweetHelpService
|
|
|
|
ths core.TweetHelpService
|
|
|
|
db *gorm.DB
|
|
|
|
db *gorm.DB
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func newIndexPostsService(db *gorm.DB) core.IndexPostsService {
|
|
|
|
type lightIndexServant struct {
|
|
|
|
return &indexPostsServant{
|
|
|
|
ths core.TweetHelpService
|
|
|
|
ams: NewAuthorizationManageService(),
|
|
|
|
db *gorm.DB
|
|
|
|
ths: newTweetHelpService(db),
|
|
|
|
|
|
|
|
db: db,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func newSimpleIndexPostsService(db *gorm.DB) core.IndexPostsService {
|
|
|
|
type simpleIndexPostsServant struct {
|
|
|
|
return &simpleIndexPostsServant{
|
|
|
|
ths core.TweetHelpService
|
|
|
|
ths: newTweetHelpService(db),
|
|
|
|
db *gorm.DB
|
|
|
|
db: db,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的;
|
|
|
|
// IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的;
|
|
|
|
func (s *indexPostsServant) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
|
|
|
|
func (s *friendIndexServant) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
|
|
|
|
predicates := dbr.Predicates{
|
|
|
|
predicates := dbr.Predicates{
|
|
|
|
"ORDER": []any{"is_top DESC, latest_replied_on DESC"},
|
|
|
|
"ORDER": []any{"is_top DESC, latest_replied_on DESC"},
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -77,6 +75,45 @@ func (s *indexPostsServant) IndexPosts(user *core.User, offset int, limit int) (
|
|
|
|
}, nil
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// IndexPosts 根据userId查询广场推文列表
|
|
|
|
|
|
|
|
func (s *followIndexServant) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
return nil, debug.ErrNotImplemented
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// IndexPosts 根据userId查询广场推文列表,获取公开可见Tweet或者所属用户的私有Tweet
|
|
|
|
|
|
|
|
func (s *lightIndexServant) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
|
|
|
|
|
|
|
|
predicates := dbr.Predicates{
|
|
|
|
|
|
|
|
"ORDER": []any{"is_top DESC, latest_replied_on DESC"},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if user == nil {
|
|
|
|
|
|
|
|
predicates["visibility = ?"] = []any{dbr.PostVisitPublic}
|
|
|
|
|
|
|
|
} else if !user.IsAdmin {
|
|
|
|
|
|
|
|
args := []any{dbr.PostVisitPublic, dbr.PostVisitPrivate, user.ID}
|
|
|
|
|
|
|
|
predicates["visibility = ? OR (visibility = ? AND user_id = ?)"] = args
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
posts, err := (&dbr.Post{}).Fetch(s.db, predicates, offset, limit)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
logrus.Debugf("gormIndexPostsServant.IndexPosts err: %v", err)
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
formatPosts, err := s.ths.MergePosts(posts)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
total, err := (&dbr.Post{}).CountBy(s.db, predicates)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return &core.IndexTweetList{
|
|
|
|
|
|
|
|
Tweets: formatPosts,
|
|
|
|
|
|
|
|
Total: total,
|
|
|
|
|
|
|
|
}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// simpleCacheIndexGetPosts simpleCacheIndex 专属获取广场推文列表函数
|
|
|
|
// simpleCacheIndexGetPosts simpleCacheIndex 专属获取广场推文列表函数
|
|
|
|
func (s *simpleIndexPostsServant) IndexPosts(_user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
|
|
|
|
func (s *simpleIndexPostsServant) IndexPosts(_user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
|
|
|
|
predicates := dbr.Predicates{
|
|
|
|
predicates := dbr.Predicates{
|
|
|
@ -105,3 +142,32 @@ func (s *simpleIndexPostsServant) IndexPosts(_user *core.User, offset int, limit
|
|
|
|
Total: total,
|
|
|
|
Total: total,
|
|
|
|
}, nil
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func newFriendIndexService(db *gorm.DB, ams core.AuthorizationManageService, ths core.TweetHelpService) core.IndexPostsService {
|
|
|
|
|
|
|
|
return &friendIndexServant{
|
|
|
|
|
|
|
|
ams: ams,
|
|
|
|
|
|
|
|
ths: ths,
|
|
|
|
|
|
|
|
db: db,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func newFollowIndexService(db *gorm.DB, ths core.TweetHelpService) core.IndexPostsService {
|
|
|
|
|
|
|
|
return &followIndexServant{
|
|
|
|
|
|
|
|
ths: ths,
|
|
|
|
|
|
|
|
db: db,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func newLightIndexService(db *gorm.DB, ths core.TweetHelpService) core.IndexPostsService {
|
|
|
|
|
|
|
|
return &lightIndexServant{
|
|
|
|
|
|
|
|
ths: ths,
|
|
|
|
|
|
|
|
db: db,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func newSimpleIndexPostsService(db *gorm.DB, ths core.TweetHelpService) core.IndexPostsService {
|
|
|
|
|
|
|
|
return &simpleIndexPostsServant{
|
|
|
|
|
|
|
|
ths: ths,
|
|
|
|
|
|
|
|
db: db,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|