gorm: optimize core interface define

pull/351/head
Michael Li 2 years ago
parent 368eadf9e6
commit a101bcabc5
No known key found for this signature in database

@ -7,6 +7,7 @@ package core
import ( import (
"context" "context"
"github.com/rocboss/paopao-ce/internal/core/cs"
"github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr"
) )
@ -26,6 +27,11 @@ type IndexAction struct {
Post *dbr.Post Post *dbr.Post
} }
type IndexActionA struct {
Act IdxAct
Tweet *cs.TweetInfo
}
func (a IdxAct) String() string { func (a IdxAct) String() string {
switch a { switch a {
case IdxActNop: case IdxActNop:
@ -52,6 +58,13 @@ func NewIndexAction(act IdxAct, post *dbr.Post) *IndexAction {
} }
} }
func NewIndexActionA(act IdxAct, tweet *cs.TweetInfo) *IndexActionA {
return &IndexActionA{
Act: act,
Tweet: tweet,
}
}
// CacheIndexService cache index service interface // CacheIndexService cache index service interface
type CacheIndexService interface { type CacheIndexService interface {
IndexPostsService IndexPostsService
@ -59,6 +72,13 @@ type CacheIndexService interface {
SendAction(act IdxAct, post *dbr.Post) SendAction(act IdxAct, post *dbr.Post)
} }
// CacheIndexServantA cache index service interface
type CacheIndexServantA interface {
IndexPostsServantA
SendAction(act IdxAct, tweet *cs.TweetInfo)
}
// RedisCache memory cache by Redis // RedisCache memory cache by Redis
type RedisCache interface { type RedisCache interface {
SetPushToSearchJob(ctx context.Context) error SetPushToSearchJob(ctx context.Context) error

@ -8,12 +8,17 @@ import (
"github.com/rocboss/paopao-ce/internal/core/cs" "github.com/rocboss/paopao-ce/internal/core/cs"
) )
// TweetTimelineService 广场首页推文时间线服务 type IndexTweetList struct {
type TweetTimelineService interface { Tweets []*PostFormated
TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) Total int64
} }
// TweetTimelineServantA 广场首页推文时间线服务(版本A) // IndexPostsService 广场首页推文列表服务
type TweetTimelineServantA interface { type IndexPostsService interface {
TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) IndexPosts(user *User, offset int, limit int) (*IndexTweetList, error)
}
// IndexPostsServantA 广场首页推文列表服务(版本A)
type IndexPostsServantA interface {
IndexPosts(user *User, limit int, offset int) (*cs.TweetBox, error)
} }

@ -33,11 +33,6 @@ type (
Attachment = dbr.Attachment Attachment = dbr.Attachment
AttachmentType = dbr.AttachmentType AttachmentType = dbr.AttachmentType
PostContentT = dbr.PostContentT PostContentT = dbr.PostContentT
IndexTweetList struct {
Tweets []*PostFormated
Total int64
}
) )
// TweetService 推文检索服务 // TweetService 推文检索服务
@ -78,20 +73,15 @@ type TweetHelpService interface {
MergePosts(posts []*Post) ([]*PostFormated, error) MergePosts(posts []*Post) ([]*PostFormated, error)
} }
// IndexPostsService 广场首页推文列表服务
type IndexPostsService interface {
IndexPosts(user *User, offset int, limit int) (*IndexTweetList, error)
}
// TweetServantA 推文检索服务(版本A) // TweetServantA 推文检索服务(版本A)
type TweetServantA interface { type TweetServantA interface {
TweetInfoById(id int64) (*cs.TweetInfo, error) TweetInfoById(id int64) (*cs.TweetInfo, error)
TweetItemById(id int64) (*cs.TweetItem, error) TweetItemById(id int64) (*cs.TweetItem, error)
UserTweets(visitorId, userId int64) (cs.TweetList, error) UserTweets(visitorId, userId int64) (cs.TweetList, error)
ReactionByTweetId(userId int64, tweetId int64) (*cs.ReactionItem, error) ReactionByTweetId(userId int64, tweetId int64) (*cs.ReactionItem, error)
UserReactions(userId int64, offset int, limit int) (cs.ReactionList, error) UserReactions(userId int64, limit int, offset int) (cs.ReactionList, error)
FavoriteByTweetId(userId int64, tweetId int64) (*cs.FavoriteItem, error) FavoriteByTweetId(userId int64, tweetId int64) (*cs.FavoriteItem, error)
UserFavorites(userId int64, offset int, limit int) (cs.FavoriteList, error) UserFavorites(userId int64, limit int, offset int) (cs.FavoriteList, error)
AttachmentByTweetId(userId int64, tweetId int64) (*cs.AttachmentBill, error) AttachmentByTweetId(userId int64, tweetId int64) (*cs.AttachmentBill, error)
} }

@ -257,6 +257,7 @@ func (s *DaoServant) GetTweetList(conditions *core.ConditionsT, offset, limit in
func NewDaoServant() *DaoServant { func NewDaoServant() *DaoServant {
return &DaoServant{ return &DaoServant{
Redis: cache.NewRedisCache(), Redis: cache.NewRedisCache(),
Dsa: dao.WebDataServantA(),
Ds: dao.DataService(), Ds: dao.DataService(),
Ts: dao.TweetSearchService(), Ts: dao.TweetSearchService(),
} }

Loading…
Cancel
Save