just optimize data logic servant define

pull/351/head
Michael Li 2 years ago
parent 6e6ab81c1c
commit e25faa8a3c
No known key found for this signature in database

@ -35,3 +35,14 @@ type DataService interface {
SecurityService SecurityService
AttachmentCheckService AttachmentCheckService
} }
// DataServantA 数据服务集成(版本A)
type DataServantA interface {
// 话题服务
TopicServantA
// 推文服务
TweetServantA
TweetManageServantA
TweetHelpServantA
}

@ -12,3 +12,8 @@ import (
type TweetTimelineService interface { type TweetTimelineService interface {
TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error)
} }
// TweetTimelineServantA 广场首页推文时间线服务(版本A)
type TweetTimelineServantA interface {
TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error)
}

@ -15,3 +15,11 @@ type TopicService interface {
ListTags(typ cs.TagType, limit int, offset int) (cs.TagList, error) ListTags(typ cs.TagType, limit int, offset int) (cs.TagList, error)
TagsByKeyword(keyword string) (cs.TagInfoList, error) TagsByKeyword(keyword string) (cs.TagInfoList, error)
} }
// TopicServantA 话题服务(版本A)
type TopicServantA interface {
UpsertTags(userId int64, tags []string) (cs.TagInfoList, error)
DecrTagsById(ids []int64) error
ListTags(typ cs.TagType, limit int, offset int) (cs.TagList, error)
TagsByKeyword(keyword string) (cs.TagInfoList, error)
}

@ -40,7 +40,8 @@ type (
} }
) )
type oldTweetService interface { // TweetService 推文检索服务
type TweetService interface {
GetPostByID(id int64) (*Post, error) GetPostByID(id int64) (*Post, error)
GetPosts(conditions *ConditionsT, offset, limit int) ([]*Post, error) GetPosts(conditions *ConditionsT, offset, limit int) ([]*Post, error)
GetPostCount(conditions *ConditionsT) (int64, error) GetPostCount(conditions *ConditionsT) (int64, error)
@ -55,21 +56,8 @@ type oldTweetService interface {
GetPostContentByID(id int64) (*PostContent, error) GetPostContentByID(id int64) (*PostContent, error)
} }
// TweetService 推文检索服务 // TweetManageService 推文管理服务,包括创建/删除/更新推文
type TweetService interface { type TweetManageService interface {
oldTweetService
TweetInfoById(id int64) (*cs.TweetInfo, error)
TweetItemById(id int64) (*cs.TweetItem, error)
UserTweets(visitorId, userId int64) (cs.TweetList, error)
ReactionByTweetId(userId int64, tweetId int64) (*cs.ReactionItem, error)
UserReactions(userId int64, offset int, limit int) (cs.ReactionList, error)
FavoriteByTweetId(userId int64, tweetId int64) (*cs.FavoriteItem, error)
UserFavorites(userId int64, offset int, limit int) (cs.FavoriteList, error)
AttachmentByTweetId(userId int64, tweetId int64) (*cs.AttachmentBill, error)
}
type oldTweetManageService interface {
CreatePost(post *Post) (*Post, error) CreatePost(post *Post) (*Post, error)
DeletePost(post *Post) ([]string, error) DeletePost(post *Post) ([]string, error)
LockPost(post *Post) error LockPost(post *Post) error
@ -81,12 +69,34 @@ type oldTweetManageService interface {
CreatePostCollection(postID, userID int64) (*PostCollection, error) CreatePostCollection(postID, userID int64) (*PostCollection, error)
DeletePostCollection(p *PostCollection) error DeletePostCollection(p *PostCollection) error
CreatePostContent(content *PostContent) (*PostContent, error) CreatePostContent(content *PostContent) (*PostContent, error)
CreateAttachment(obj *cs.Attachment) (int64, error)
} }
// TweetManageService 推文管理服务,包括创建/删除/更新推文 // TweetHelpService 推文辅助服务
type TweetManageService interface { type TweetHelpService interface {
oldTweetManageService RevampPosts(posts []*PostFormated) ([]*PostFormated, error)
MergePosts(posts []*Post) ([]*PostFormated, error)
}
// IndexPostsService 广场首页推文列表服务
type IndexPostsService interface {
IndexPosts(user *User, offset int, limit int) (*IndexTweetList, error)
}
// TweetServantA 推文检索服务(版本A)
type TweetServantA interface {
TweetInfoById(id int64) (*cs.TweetInfo, error)
TweetItemById(id int64) (*cs.TweetItem, error)
UserTweets(visitorId, userId int64) (cs.TweetList, error)
ReactionByTweetId(userId int64, tweetId int64) (*cs.ReactionItem, error)
UserReactions(userId int64, offset int, limit int) (cs.ReactionList, error)
FavoriteByTweetId(userId int64, tweetId int64) (*cs.FavoriteItem, error)
UserFavorites(userId int64, offset int, limit int) (cs.FavoriteList, error)
AttachmentByTweetId(userId int64, tweetId int64) (*cs.AttachmentBill, error)
}
// TweetManageServantA 推文管理服务,包括创建/删除/更新推文(版本A)
type TweetManageServantA interface {
CreateAttachment(obj *cs.Attachment) (int64, error) CreateAttachment(obj *cs.Attachment) (int64, error)
CreateTweet(userId int64, req *cs.NewTweetReq) (*cs.TweetItem, error) CreateTweet(userId int64, req *cs.NewTweetReq) (*cs.TweetItem, error)
DeleteTweet(userId int64, tweetId int64) ([]string, error) DeleteTweet(userId int64, tweetId int64) ([]string, error)
@ -99,25 +109,8 @@ type TweetManageService interface {
DeleteFavorite(userId int64, favoriteId int64) error DeleteFavorite(userId int64, favoriteId int64) error
} }
type oldTweetHelpService interface { // TweetHelpServantA 推文辅助服务(版本A)
RevampPosts(posts []*PostFormated) ([]*PostFormated, error) type TweetHelpServantA interface {
MergePosts(posts []*Post) ([]*PostFormated, error)
}
// TweetHelpService 推文辅助服务
type TweetHelpService interface {
oldTweetHelpService
RevampTweets(tweets cs.TweetList) (cs.TweetList, error) RevampTweets(tweets cs.TweetList) (cs.TweetList, error)
MergeTweets(tweets cs.TweetInfo) (cs.TweetList, error) MergeTweets(tweets cs.TweetInfo) (cs.TweetList, error)
} }
type oldIndexPostsService interface {
IndexPosts(user *User, offset int, limit int) (*IndexTweetList, error)
}
// IndexPostsService 广场首页推文列表服务
type IndexPostsService interface {
oldIndexPostsService
TweetTimelineService
}

@ -12,20 +12,20 @@ import (
) )
var ( var (
_ core.AuthorizationManageService = (*authorizationManageServant)(nil) _ core.AuthorizationManageService = (*authorizationManageSrv)(nil)
) )
type authorizationManageServant struct { type authorizationManageSrv struct {
db *gorm.DB db *gorm.DB
} }
func newAuthorizationManageService(db *gorm.DB) core.AuthorizationManageService { func newAuthorizationManageService(db *gorm.DB) core.AuthorizationManageService {
return &authorizationManageServant{ return &authorizationManageSrv{
db: db, db: db,
} }
} }
func (s *authorizationManageServant) IsAllow(user *core.User, action *core.Action) bool { func (s *authorizationManageSrv) IsAllow(user *core.User, action *core.Action) bool {
// user is activation if had bind phone // user is activation if had bind phone
isActivation := (len(user.Phone) != 0) isActivation := (len(user.Phone) != 0)
isFriend := s.isFriend(user.ID, action.UserId) isFriend := s.isFriend(user.ID, action.UserId)
@ -33,7 +33,7 @@ func (s *authorizationManageServant) IsAllow(user *core.User, action *core.Actio
return action.Act.IsAllow(user, action.UserId, isFriend, isActivation) return action.Act.IsAllow(user, action.UserId, isFriend, isActivation)
} }
func (s *authorizationManageServant) MyFriendSet(userId int64) core.FriendSet { func (s *authorizationManageSrv) MyFriendSet(userId int64) core.FriendSet {
ids, err := (&dbr.Contact{UserId: userId}).MyFriendIds(s.db) ids, err := (&dbr.Contact{UserId: userId}).MyFriendIds(s.db)
if err != nil { if err != nil {
return core.FriendSet{} return core.FriendSet{}
@ -46,7 +46,7 @@ func (s *authorizationManageServant) MyFriendSet(userId int64) core.FriendSet {
return resp return resp
} }
func (s *authorizationManageServant) BeFriendFilter(userId int64) core.FriendFilter { func (s *authorizationManageSrv) BeFriendFilter(userId int64) core.FriendFilter {
ids, err := (&dbr.Contact{FriendId: userId}).BeFriendIds(s.db) ids, err := (&dbr.Contact{FriendId: userId}).BeFriendIds(s.db)
if err != nil { if err != nil {
return core.FriendFilter{} return core.FriendFilter{}
@ -59,11 +59,11 @@ func (s *authorizationManageServant) BeFriendFilter(userId int64) core.FriendFil
return resp return resp
} }
func (s *authorizationManageServant) BeFriendIds(userId int64) ([]int64, error) { func (s *authorizationManageSrv) BeFriendIds(userId int64) ([]int64, error) {
return (&dbr.Contact{FriendId: userId}).BeFriendIds(s.db) return (&dbr.Contact{FriendId: userId}).BeFriendIds(s.db)
} }
func (s *authorizationManageServant) isFriend(userId int64, friendId int64) bool { func (s *authorizationManageSrv) isFriend(userId int64, friendId int64) bool {
contact, err := (&dbr.Contact{UserId: friendId, FriendId: userId}).GetByUserFriend(s.db) contact, err := (&dbr.Contact{UserId: friendId, FriendId: userId}).GetByUserFriend(s.db)
if err == nil || contact.Status == dbr.ContactStatusAgree { if err == nil || contact.Status == dbr.ContactStatusAgree {
return true return true

@ -11,35 +11,35 @@ import (
) )
var ( var (
_ core.CommentService = (*commentServant)(nil) _ core.CommentService = (*commentSrv)(nil)
_ core.CommentManageService = (*commentManageServant)(nil) _ core.CommentManageService = (*commentManageSrv)(nil)
) )
type commentServant struct { type commentSrv struct {
db *gorm.DB db *gorm.DB
} }
type commentManageServant struct { type commentManageSrv struct {
db *gorm.DB db *gorm.DB
} }
func newCommentService(db *gorm.DB) core.CommentService { func newCommentService(db *gorm.DB) core.CommentService {
return &commentServant{ return &commentSrv{
db: db, db: db,
} }
} }
func newCommentManageService(db *gorm.DB) core.CommentManageService { func newCommentManageService(db *gorm.DB) core.CommentManageService {
return &commentManageServant{ return &commentManageSrv{
db: db, db: db,
} }
} }
func (s *commentServant) GetComments(conditions *core.ConditionsT, offset, limit int) ([]*core.Comment, error) { func (s *commentSrv) GetComments(conditions *core.ConditionsT, offset, limit int) ([]*core.Comment, error) {
return (&dbr.Comment{}).List(s.db, conditions, offset, limit) return (&dbr.Comment{}).List(s.db, conditions, offset, limit)
} }
func (s *commentServant) GetCommentByID(id int64) (*core.Comment, error) { func (s *commentSrv) GetCommentByID(id int64) (*core.Comment, error) {
comment := &dbr.Comment{ comment := &dbr.Comment{
Model: &dbr.Model{ Model: &dbr.Model{
ID: id, ID: id,
@ -48,7 +48,7 @@ func (s *commentServant) GetCommentByID(id int64) (*core.Comment, error) {
return comment.Get(s.db) return comment.Get(s.db)
} }
func (s *commentServant) GetCommentReplyByID(id int64) (*core.CommentReply, error) { func (s *commentSrv) GetCommentReplyByID(id int64) (*core.CommentReply, error) {
reply := &dbr.CommentReply{ reply := &dbr.CommentReply{
Model: &dbr.Model{ Model: &dbr.Model{
ID: id, ID: id,
@ -57,18 +57,18 @@ func (s *commentServant) GetCommentReplyByID(id int64) (*core.CommentReply, erro
return reply.Get(s.db) return reply.Get(s.db)
} }
func (s *commentServant) GetCommentCount(conditions *core.ConditionsT) (int64, error) { func (s *commentSrv) GetCommentCount(conditions *core.ConditionsT) (int64, error) {
return (&dbr.Comment{}).Count(s.db, conditions) return (&dbr.Comment{}).Count(s.db, conditions)
} }
func (s *commentServant) GetCommentContentsByIDs(ids []int64) ([]*core.CommentContent, error) { func (s *commentSrv) GetCommentContentsByIDs(ids []int64) ([]*core.CommentContent, error) {
commentContent := &dbr.CommentContent{} commentContent := &dbr.CommentContent{}
return commentContent.List(s.db, &dbr.ConditionsT{ return commentContent.List(s.db, &dbr.ConditionsT{
"comment_id IN ?": ids, "comment_id IN ?": ids,
}, 0, 0) }, 0, 0)
} }
func (s *commentServant) GetCommentRepliesByID(ids []int64) ([]*core.CommentReplyFormated, error) { func (s *commentSrv) GetCommentRepliesByID(ids []int64) ([]*core.CommentReplyFormated, error) {
CommentReply := &dbr.CommentReply{} CommentReply := &dbr.CommentReply{}
replies, err := CommentReply.List(s.db, &dbr.ConditionsT{ replies, err := CommentReply.List(s.db, &dbr.ConditionsT{
"comment_id IN ?": ids, "comment_id IN ?": ids,
@ -105,22 +105,22 @@ func (s *commentServant) GetCommentRepliesByID(ids []int64) ([]*core.CommentRepl
return repliesFormated, nil return repliesFormated, nil
} }
func (s *commentManageServant) DeleteComment(comment *core.Comment) error { func (s *commentManageSrv) DeleteComment(comment *core.Comment) error {
return comment.Delete(s.db) return comment.Delete(s.db)
} }
func (s *commentManageServant) CreateComment(comment *core.Comment) (*core.Comment, error) { func (s *commentManageSrv) CreateComment(comment *core.Comment) (*core.Comment, error) {
return comment.Create(s.db) return comment.Create(s.db)
} }
func (s *commentManageServant) CreateCommentReply(reply *core.CommentReply) (*core.CommentReply, error) { func (s *commentManageSrv) CreateCommentReply(reply *core.CommentReply) (*core.CommentReply, error) {
return reply.Create(s.db) return reply.Create(s.db)
} }
func (s *commentManageServant) DeleteCommentReply(reply *core.CommentReply) error { func (s *commentManageSrv) DeleteCommentReply(reply *core.CommentReply) error {
return reply.Delete(s.db) return reply.Delete(s.db)
} }
func (s *commentManageServant) CreateCommentContent(content *core.CommentContent) (*core.CommentContent, error) { func (s *commentManageSrv) CreateCommentContent(content *core.CommentContent) (*core.CommentContent, error) {
return content.Create(s.db) return content.Create(s.db)
} }

@ -14,20 +14,20 @@ import (
) )
var ( var (
_ core.ContactManageService = (*contactManageServant)(nil) _ core.ContactManageService = (*contactManageSrv)(nil)
) )
type contactManageServant struct { type contactManageSrv struct {
db *gorm.DB db *gorm.DB
} }
func newContactManageService(db *gorm.DB) core.ContactManageService { func newContactManageService(db *gorm.DB) core.ContactManageService {
return &contactManageServant{ return &contactManageSrv{
db: db, db: db,
} }
} }
func (s *contactManageServant) fetchOrNewContact(db *gorm.DB, userId int64, friendId int64, status int8) (*dbr.Contact, error) { func (s *contactManageSrv) fetchOrNewContact(db *gorm.DB, userId int64, friendId int64, status int8) (*dbr.Contact, error) {
contact := &dbr.Contact{ contact := &dbr.Contact{
UserId: userId, UserId: userId,
FriendId: friendId, FriendId: friendId,
@ -40,14 +40,14 @@ func (s *contactManageServant) fetchOrNewContact(db *gorm.DB, userId int64, frie
Status: status, Status: status,
} }
if contact, err = contact.Create(db); err != nil { if contact, err = contact.Create(db); err != nil {
logrus.Errorf("contactManageServant.fetchOrNewContact create new contact err:%s", err) logrus.Errorf("contactManageSrv.fetchOrNewContact create new contact err:%s", err)
return nil, err return nil, err
} }
} }
return contact, nil return contact, nil
} }
func (s *contactManageServant) RequestingFriend(userId int64, friendId int64, greetings string) (err error) { func (s *contactManageSrv) RequestingFriend(userId int64, friendId int64, greetings string) (err error) {
db := s.db.Begin() db := s.db.Begin()
defer func() { defer func() {
if err == nil { if err == nil {
@ -70,7 +70,7 @@ func (s *contactManageServant) RequestingFriend(userId int64, friendId int64, gr
contact.Status = dbr.ContactStatusRequesting contact.Status = dbr.ContactStatusRequesting
contact.IsDel = 0 // remove deleted flag if needed contact.IsDel = 0 // remove deleted flag if needed
if err = contact.UpdateInUnscoped(db); err != nil { if err = contact.UpdateInUnscoped(db); err != nil {
logrus.Errorf("contactManageServant.RequestingFriend update exsit contact err:%s", err) logrus.Errorf("contactManageSrv.RequestingFriend update exsit contact err:%s", err)
return return
} }
} }
@ -84,13 +84,13 @@ func (s *contactManageServant) RequestingFriend(userId int64, friendId int64, gr
ReplyID: int64(dbr.ContactStatusRequesting), ReplyID: int64(dbr.ContactStatusRequesting),
} }
if _, err = msg.Create(db); err != nil { if _, err = msg.Create(db); err != nil {
logrus.Errorf("contactManageServant.RequestingFriend create message err:%s", err) logrus.Errorf("contactManageSrv.RequestingFriend create message err:%s", err)
return return
} }
return nil return nil
} }
func (s *contactManageServant) AddFriend(userId int64, friendId int64) (err error) { func (s *contactManageSrv) AddFriend(userId int64, friendId int64) (err error) {
db := s.db.Begin() db := s.db.Begin()
defer func() { defer func() {
if err == nil { if err == nil {
@ -109,7 +109,7 @@ func (s *contactManageServant) AddFriend(userId int64, friendId int64) (err erro
} }
// 如果还不是请求好友,啥也不干 // 如果还不是请求好友,啥也不干
if contact.Status != dbr.ContactStatusRequesting { if contact.Status != dbr.ContactStatusRequesting {
logrus.Debugf("contactManageServant.AddFriend not reuesting status now so skip") logrus.Debugf("contactManageSrv.AddFriend not reuesting status now so skip")
return nil return nil
} }
contact.Status = dbr.ContactStatusAgree contact.Status = dbr.ContactStatusAgree
@ -127,7 +127,7 @@ func (s *contactManageServant) AddFriend(userId int64, friendId int64) (err erro
contact.Status = dbr.ContactStatusAgree contact.Status = dbr.ContactStatusAgree
contact.IsDel = 0 // remove deleted flag contact.IsDel = 0 // remove deleted flag
if err = contact.UpdateInUnscoped(db); err != nil { if err = contact.UpdateInUnscoped(db); err != nil {
logrus.Errorf("contactManageServant.AddFriend update contact err:%s", err) logrus.Errorf("contactManageSrv.AddFriend update contact err:%s", err)
return return
} }
} }
@ -149,7 +149,7 @@ func (s *contactManageServant) AddFriend(userId int64, friendId int64) (err erro
return nil return nil
} }
func (s *contactManageServant) RejectFriend(userId int64, friendId int64) (err error) { func (s *contactManageSrv) RejectFriend(userId int64, friendId int64) (err error) {
db := s.db.Begin() db := s.db.Begin()
defer func() { defer func() {
if err == nil { if err == nil {
@ -192,7 +192,7 @@ func (s *contactManageServant) RejectFriend(userId int64, friendId int64) (err e
return nil return nil
} }
func (s *contactManageServant) DeleteFriend(userId int64, friendId int64) (err error) { func (s *contactManageSrv) DeleteFriend(userId int64, friendId int64) (err error) {
db := s.db.Begin() db := s.db.Begin()
defer func() { defer func() {
if err == nil { if err == nil {
@ -226,7 +226,7 @@ func (s *contactManageServant) DeleteFriend(userId int64, friendId int64) (err e
return nil return nil
} }
func (s *contactManageServant) GetContacts(userId int64, offset int, limit int) (*core.ContactList, error) { func (s *contactManageSrv) GetContacts(userId int64, offset int, limit int) (*core.ContactList, error) {
contact := &dbr.Contact{} contact := &dbr.Contact{}
condition := dbr.ConditionsT{ condition := dbr.ConditionsT{
"user_id": userId, "user_id": userId,
@ -258,7 +258,7 @@ func (s *contactManageServant) GetContacts(userId int64, offset int, limit int)
return resp, nil return resp, nil
} }
func (s *contactManageServant) IsFriend(userId int64, friendId int64) bool { func (s *contactManageSrv) IsFriend(userId int64, friendId int64) bool {
contact := &dbr.Contact{ contact := &dbr.Contact{
UserId: friendId, UserId: friendId,
FriendId: userId, FriendId: userId,

@ -11,31 +11,31 @@ import (
) )
var ( var (
_ core.MessageService = (*messageServant)(nil) _ core.MessageService = (*messageSrv)(nil)
) )
type messageServant struct { type messageSrv struct {
db *gorm.DB db *gorm.DB
} }
func newMessageService(db *gorm.DB) core.MessageService { func newMessageService(db *gorm.DB) core.MessageService {
return &messageServant{ return &messageSrv{
db: db, db: db,
} }
} }
func (s *messageServant) CreateMessage(msg *core.Message) (*core.Message, error) { func (s *messageSrv) CreateMessage(msg *core.Message) (*core.Message, error) {
return msg.Create(s.db) return msg.Create(s.db)
} }
func (s *messageServant) GetUnreadCount(userID int64) (int64, error) { func (s *messageSrv) GetUnreadCount(userID int64) (int64, error) {
return (&dbr.Message{}).Count(s.db, &dbr.ConditionsT{ return (&dbr.Message{}).Count(s.db, &dbr.ConditionsT{
"receiver_user_id": userID, "receiver_user_id": userID,
"is_read": dbr.MsgStatusUnread, "is_read": dbr.MsgStatusUnread,
}) })
} }
func (s *messageServant) GetMessageByID(id int64) (*core.Message, error) { func (s *messageSrv) GetMessageByID(id int64) (*core.Message, error) {
return (&dbr.Message{ return (&dbr.Message{
Model: &dbr.Model{ Model: &dbr.Model{
ID: id, ID: id,
@ -43,12 +43,12 @@ func (s *messageServant) GetMessageByID(id int64) (*core.Message, error) {
}).Get(s.db) }).Get(s.db)
} }
func (s *messageServant) ReadMessage(message *core.Message) error { func (s *messageSrv) ReadMessage(message *core.Message) error {
message.IsRead = 1 message.IsRead = 1
return message.Update(s.db) return message.Update(s.db)
} }
func (s *messageServant) GetMessages(conditions *core.ConditionsT, offset, limit int) ([]*core.MessageFormated, error) { func (s *messageSrv) GetMessages(conditions *core.ConditionsT, offset, limit int) ([]*core.MessageFormated, error) {
messages, err := (&dbr.Message{}).List(s.db, conditions, offset, limit) messages, err := (&dbr.Message{}).List(s.db, conditions, offset, limit)
if err != nil { if err != nil {
return nil, err return nil, err
@ -63,6 +63,6 @@ func (s *messageServant) GetMessages(conditions *core.ConditionsT, offset, limit
return mfs, nil return mfs, nil
} }
func (s *messageServant) GetMessageCount(conditions *core.ConditionsT) (int64, error) { func (s *messageSrv) GetMessageCount(conditions *core.ConditionsT) (int64, error) {
return (&dbr.Message{}).Count(s.db, conditions) return (&dbr.Message{}).Count(s.db, conditions)
} }

@ -15,36 +15,36 @@ import (
) )
var ( var (
_ core.SecurityService = (*securityServant)(nil) _ core.SecurityService = (*securitySrv)(nil)
) )
type securityServant struct { type securitySrv struct {
db *gorm.DB db *gorm.DB
phoneVerify core.PhoneVerifyService phoneVerify core.PhoneVerifyService
} }
func newSecurityService(db *gorm.DB, phoneVerify core.PhoneVerifyService) core.SecurityService { func newSecurityService(db *gorm.DB, phoneVerify core.PhoneVerifyService) core.SecurityService {
return &securityServant{ return &securitySrv{
db: db, db: db,
phoneVerify: phoneVerify, phoneVerify: phoneVerify,
} }
} }
// GetLatestPhoneCaptcha 获取最新短信验证码 // GetLatestPhoneCaptcha 获取最新短信验证码
func (s *securityServant) GetLatestPhoneCaptcha(phone string) (*core.Captcha, error) { func (s *securitySrv) GetLatestPhoneCaptcha(phone string) (*core.Captcha, error) {
return (&dbr.Captcha{ return (&dbr.Captcha{
Phone: phone, Phone: phone,
}).Get(s.db) }).Get(s.db)
} }
// UsePhoneCaptcha 更新短信验证码 // UsePhoneCaptcha 更新短信验证码
func (s *securityServant) UsePhoneCaptcha(captcha *core.Captcha) error { func (s *securitySrv) UsePhoneCaptcha(captcha *core.Captcha) error {
captcha.UseTimes++ captcha.UseTimes++
return captcha.Update(s.db) return captcha.Update(s.db)
} }
// SendPhoneCaptcha 发送短信验证码 // SendPhoneCaptcha 发送短信验证码
func (s *securityServant) SendPhoneCaptcha(phone string) error { func (s *securitySrv) SendPhoneCaptcha(phone string) error {
expire := time.Duration(5) expire := time.Duration(5)
// 发送验证码 // 发送验证码

@ -14,35 +14,35 @@ import (
) )
var ( var (
_ core.IndexPostsService = (*friendIndexServant)(nil) _ core.IndexPostsService = (*friendIndexSrv)(nil)
_ core.IndexPostsService = (*followIndexServant)(nil) _ core.IndexPostsService = (*followIndexSrv)(nil)
_ core.IndexPostsService = (*lightIndexServant)(nil) _ core.IndexPostsService = (*lightIndexSrv)(nil)
_ core.IndexPostsService = (*simpleIndexPostsServant)(nil) _ core.IndexPostsService = (*simpleIndexPostsSrv)(nil)
) )
type friendIndexServant struct { type friendIndexSrv struct {
ams core.AuthorizationManageService ams core.AuthorizationManageService
ths core.TweetHelpService ths core.TweetHelpService
db *gorm.DB db *gorm.DB
} }
type followIndexServant struct { type followIndexSrv struct {
ths core.TweetHelpService ths core.TweetHelpService
db *gorm.DB db *gorm.DB
} }
type lightIndexServant struct { type lightIndexSrv struct {
ths core.TweetHelpService ths core.TweetHelpService
db *gorm.DB db *gorm.DB
} }
type simpleIndexPostsServant struct { type simpleIndexPostsSrv struct {
ths core.TweetHelpService ths core.TweetHelpService
db *gorm.DB db *gorm.DB
} }
// IndexPosts 根据userId查询广场推文列表简单做到不同用户的主页都是不同的 // IndexPosts 根据userId查询广场推文列表简单做到不同用户的主页都是不同的
func (s *friendIndexServant) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { func (s *friendIndexSrv) 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"},
} }
@ -57,7 +57,7 @@ func (s *friendIndexServant) IndexPosts(user *core.User, offset int, limit int)
posts, err := (&dbr.Post{}).Fetch(s.db, predicates, offset, limit) posts, err := (&dbr.Post{}).Fetch(s.db, predicates, offset, limit)
if err != nil { if err != nil {
logrus.Debugf("gormIndexPostsServant.IndexPosts err: %v", err) logrus.Debugf("gormIndexPostsSrv.IndexPosts err: %v", err)
return nil, err return nil, err
} }
formatPosts, err := s.ths.MergePosts(posts) formatPosts, err := s.ths.MergePosts(posts)
@ -76,24 +76,24 @@ func (s *friendIndexServant) IndexPosts(user *core.User, offset int, limit int)
}, nil }, nil
} }
func (s *friendIndexServant) TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) { func (s *friendIndexSrv) TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) {
// TODO // TODO
return nil, debug.ErrNotImplemented return nil, debug.ErrNotImplemented
} }
// IndexPosts 根据userId查询广场推文列表 // IndexPosts 根据userId查询广场推文列表
func (s *followIndexServant) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { func (s *followIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
// TODO // TODO
return nil, debug.ErrNotImplemented return nil, debug.ErrNotImplemented
} }
func (s *followIndexServant) TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) { func (s *followIndexSrv) TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) {
// TODO // TODO
return nil, debug.ErrNotImplemented return nil, debug.ErrNotImplemented
} }
// IndexPosts 根据userId查询广场推文列表获取公开可见Tweet或者所属用户的私有Tweet // IndexPosts 根据userId查询广场推文列表获取公开可见Tweet或者所属用户的私有Tweet
func (s *lightIndexServant) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { func (s *lightIndexSrv) 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"},
} }
@ -106,7 +106,7 @@ func (s *lightIndexServant) IndexPosts(user *core.User, offset int, limit int) (
posts, err := (&dbr.Post{}).Fetch(s.db, predicates, offset, limit) posts, err := (&dbr.Post{}).Fetch(s.db, predicates, offset, limit)
if err != nil { if err != nil {
logrus.Debugf("gormIndexPostsServant.IndexPosts err: %v", err) logrus.Debugf("gormIndexPostsSrv.IndexPosts err: %v", err)
return nil, err return nil, err
} }
formatPosts, err := s.ths.MergePosts(posts) formatPosts, err := s.ths.MergePosts(posts)
@ -125,13 +125,13 @@ func (s *lightIndexServant) IndexPosts(user *core.User, offset int, limit int) (
}, nil }, nil
} }
func (s *lightIndexServant) TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) { func (s *lightIndexSrv) TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) {
// TODO // TODO
return nil, debug.ErrNotImplemented return nil, debug.ErrNotImplemented
} }
// simpleCacheIndexGetPosts simpleCacheIndex 专属获取广场推文列表函数 // simpleCacheIndexGetPosts simpleCacheIndex 专属获取广场推文列表函数
func (s *simpleIndexPostsServant) IndexPosts(_user *core.User, offset int, limit int) (*core.IndexTweetList, error) { func (s *simpleIndexPostsSrv) IndexPosts(_user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
predicates := dbr.Predicates{ predicates := dbr.Predicates{
"visibility = ?": []any{dbr.PostVisitPublic}, "visibility = ?": []any{dbr.PostVisitPublic},
"ORDER": []any{"is_top DESC, latest_replied_on DESC"}, "ORDER": []any{"is_top DESC, latest_replied_on DESC"},
@ -139,7 +139,7 @@ func (s *simpleIndexPostsServant) IndexPosts(_user *core.User, offset int, limit
posts, err := (&dbr.Post{}).Fetch(s.db, predicates, offset, limit) posts, err := (&dbr.Post{}).Fetch(s.db, predicates, offset, limit)
if err != nil { if err != nil {
logrus.Debugf("gormSimpleIndexPostsServant.IndexPosts err: %v", err) logrus.Debugf("gormSimpleIndexPostsSrv.IndexPosts err: %v", err)
return nil, err return nil, err
} }
@ -159,13 +159,13 @@ func (s *simpleIndexPostsServant) IndexPosts(_user *core.User, offset int, limit
}, nil }, nil
} }
func (s *simpleIndexPostsServant) TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) { func (s *simpleIndexPostsSrv) TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) {
// TODO // TODO
return nil, debug.ErrNotImplemented return nil, debug.ErrNotImplemented
} }
func newFriendIndexService(db *gorm.DB, ams core.AuthorizationManageService, ths core.TweetHelpService) core.IndexPostsService { func newFriendIndexService(db *gorm.DB, ams core.AuthorizationManageService, ths core.TweetHelpService) core.IndexPostsService {
return &friendIndexServant{ return &friendIndexSrv{
ams: ams, ams: ams,
ths: ths, ths: ths,
db: db, db: db,
@ -173,21 +173,21 @@ func newFriendIndexService(db *gorm.DB, ams core.AuthorizationManageService, ths
} }
func newFollowIndexService(db *gorm.DB, ths core.TweetHelpService) core.IndexPostsService { func newFollowIndexService(db *gorm.DB, ths core.TweetHelpService) core.IndexPostsService {
return &followIndexServant{ return &followIndexSrv{
ths: ths, ths: ths,
db: db, db: db,
} }
} }
func newLightIndexService(db *gorm.DB, ths core.TweetHelpService) core.IndexPostsService { func newLightIndexService(db *gorm.DB, ths core.TweetHelpService) core.IndexPostsService {
return &lightIndexServant{ return &lightIndexSrv{
ths: ths, ths: ths,
db: db, db: db,
} }
} }
func newSimpleIndexPostsService(db *gorm.DB, ths core.TweetHelpService) core.IndexPostsService { func newSimpleIndexPostsService(db *gorm.DB, ths core.TweetHelpService) core.IndexPostsService {
return &simpleIndexPostsServant{ return &simpleIndexPostsSrv{
ths: ths, ths: ths,
db: db, db: db,
} }

@ -14,20 +14,133 @@ import (
) )
var ( var (
_ core.TopicService = (*topicServant)(nil) _ core.TopicService = (*topicSrv)(nil)
_ core.TopicServantA = (*topicSrvA)(nil)
) )
type topicServant struct { type topicSrv struct {
db *gorm.DB
}
type topicSrvA struct {
db *gorm.DB db *gorm.DB
} }
func newTopicService(db *gorm.DB) core.TopicService { func newTopicService(db *gorm.DB) core.TopicService {
return &topicServant{ return &topicSrv{
db: db,
}
}
func newTopicServantA(db *gorm.DB) core.TopicServantA {
return &topicSrvA{
db: db, db: db,
} }
} }
func (s *topicServant) UpsertTags(userId int64, tags []string) (_ cs.TagInfoList, err error) { func (s *topicSrv) UpsertTags(userId int64, tags []string) (_ cs.TagInfoList, err error) {
db := s.db.Begin()
defer func() {
if err == nil {
db.Commit()
} else {
db.Rollback()
}
}()
return createTags(db, userId, tags)
}
func (s *topicSrv) DecrTagsById(ids []int64) (err error) {
db := s.db.Begin()
defer func() {
if err == nil {
db.Commit()
} else {
db.Rollback()
}
}()
return decrTagsByIds(db, ids)
}
func (s *topicSrv) ListTags(typ cs.TagType, offset, limit int) (res cs.TagList, err error) {
conditions := &core.ConditionsT{}
switch typ {
case cs.TagTypeHot:
// 热门标签
conditions = &core.ConditionsT{
"ORDER": "quote_num DESC",
}
case cs.TagTypeNew:
// 最新标签
conditions = &core.ConditionsT{
"ORDER": "id DESC",
}
}
// TODO: 优化查询方式,直接返回[]*core.Tag, 目前保持先转换一下
var (
tags []*dbr.Tag
item *cs.TagItem
)
if tags, err = (&dbr.Tag{}).List(s.db, conditions, offset, limit); err == nil {
if len(tags) == 0 {
return
}
tagMap := make(map[int64][]*cs.TagItem, len(tags))
for _, tag := range tags {
item = &cs.TagItem{
ID: tag.ID,
UserID: tag.UserID,
Tag: tag.Tag,
QuoteNum: tag.QuoteNum,
}
tagMap[item.UserID] = append(tagMap[item.UserID], item)
res = append(res, item)
}
ids := make([]int64, len(tagMap))
for userId := range tagMap {
ids = append(ids, userId)
}
userInfos, err := (&dbr.User{}).ListUserInfoById(s.db, ids)
if err != nil {
return nil, err
}
for _, userInfo := range userInfos {
for _, item = range tagMap[userInfo.ID] {
item.User = userInfo
}
}
}
return
}
func (s *topicSrv) TagsByKeyword(keyword string) (res cs.TagInfoList, err error) {
keyword = "%" + strings.Trim(keyword, " ") + "%"
tag := &dbr.Tag{}
var tags []*dbr.Tag
if keyword == "%%" {
tags, err = tag.List(s.db, &dbr.ConditionsT{
"ORDER": "quote_num DESC",
}, 0, 6)
} else {
tags, err = tag.List(s.db, &dbr.ConditionsT{
"tag LIKE ?": keyword,
"ORDER": "quote_num DESC",
}, 0, 6)
}
if err == nil {
for _, tag := range tags {
res = append(res, &cs.TagInfo{
ID: tag.ID,
UserID: tag.UserID,
Tag: tag.Tag,
QuoteNum: tag.QuoteNum,
})
}
}
return
}
func (s *topicSrvA) UpsertTags(userId int64, tags []string) (_ cs.TagInfoList, err error) {
db := s.db.Begin() db := s.db.Begin()
defer func() { defer func() {
if err == nil { if err == nil {
@ -39,7 +152,7 @@ func (s *topicServant) UpsertTags(userId int64, tags []string) (_ cs.TagInfoList
return createTags(db, userId, tags) return createTags(db, userId, tags)
} }
func (s *topicServant) DecrTagsById(ids []int64) (err error) { func (s *topicSrvA) DecrTagsById(ids []int64) (err error) {
db := s.db.Begin() db := s.db.Begin()
defer func() { defer func() {
if err == nil { if err == nil {
@ -51,7 +164,7 @@ func (s *topicServant) DecrTagsById(ids []int64) (err error) {
return decrTagsByIds(db, ids) return decrTagsByIds(db, ids)
} }
func (s *topicServant) ListTags(typ cs.TagType, offset, limit int) (res cs.TagList, err error) { func (s *topicSrvA) ListTags(typ cs.TagType, offset, limit int) (res cs.TagList, err error) {
conditions := &core.ConditionsT{} conditions := &core.ConditionsT{}
switch typ { switch typ {
case cs.TagTypeHot: case cs.TagTypeHot:
@ -102,7 +215,7 @@ func (s *topicServant) ListTags(typ cs.TagType, offset, limit int) (res cs.TagLi
return return
} }
func (s *topicServant) TagsByKeyword(keyword string) (res cs.TagInfoList, err error) { func (s *topicSrvA) TagsByKeyword(keyword string) (res cs.TagInfoList, err error) {
keyword = "%" + strings.Trim(keyword, " ") + "%" keyword = "%" + strings.Trim(keyword, " ") + "%"
tag := &dbr.Tag{} tag := &dbr.Tag{}
var tags []*dbr.Tag var tags []*dbr.Tag

@ -16,45 +16,62 @@ import (
) )
var ( var (
_ core.TweetService = (*tweetServant)(nil) _ core.TweetService = (*tweetSrv)(nil)
_ core.TweetManageService = (*tweetManageServant)(nil) _ core.TweetManageService = (*tweetManageSrv)(nil)
_ core.TweetHelpService = (*tweetHelpServant)(nil) _ core.TweetHelpService = (*tweetHelpSrv)(nil)
_ core.TweetServantA = (*tweetSrvA)(nil)
_ core.TweetManageServantA = (*tweetManageSrvA)(nil)
_ core.TweetHelpServantA = (*tweetHelpSrvA)(nil)
) )
type tweetServant struct { type tweetSrv struct {
db *gorm.DB db *gorm.DB
} }
type tweetManageServant struct { type tweetManageSrv struct {
cacheIndex core.CacheIndexService cacheIndex core.CacheIndexService
db *gorm.DB db *gorm.DB
} }
type tweetHelpServant struct { type tweetHelpSrv struct {
db *gorm.DB
}
type tweetSrvA struct {
db *gorm.DB
}
type tweetManageSrvA struct {
cacheIndex core.CacheIndexService
db *gorm.DB
}
type tweetHelpSrvA struct {
db *gorm.DB db *gorm.DB
} }
func newTweetService(db *gorm.DB) core.TweetService { func newTweetService(db *gorm.DB) core.TweetService {
return &tweetServant{ return &tweetSrv{
db: db, db: db,
} }
} }
func newTweetManageService(db *gorm.DB, cacheIndex core.CacheIndexService) core.TweetManageService { func newTweetManageService(db *gorm.DB, cacheIndex core.CacheIndexService) core.TweetManageService {
return &tweetManageServant{ return &tweetManageSrv{
cacheIndex: cacheIndex, cacheIndex: cacheIndex,
db: db, db: db,
} }
} }
func newTweetHelpService(db *gorm.DB) core.TweetHelpService { func newTweetHelpService(db *gorm.DB) core.TweetHelpService {
return &tweetHelpServant{ return &tweetHelpSrv{
db: db, db: db,
} }
} }
// MergePosts post数据整合 // MergePosts post数据整合
func (s *tweetHelpServant) MergePosts(posts []*core.Post) ([]*core.PostFormated, error) { func (s *tweetHelpSrv) MergePosts(posts []*core.Post) ([]*core.PostFormated, error) {
postIds := make([]int64, 0, len(posts)) postIds := make([]int64, 0, len(posts))
userIds := make([]int64, 0, len(posts)) userIds := make([]int64, 0, len(posts))
for _, post := range posts { for _, post := range posts {
@ -94,7 +111,7 @@ func (s *tweetHelpServant) MergePosts(posts []*core.Post) ([]*core.PostFormated,
} }
// RevampPosts post数据整形修复 // RevampPosts post数据整形修复
func (s *tweetHelpServant) RevampPosts(posts []*core.PostFormated) ([]*core.PostFormated, error) { func (s *tweetHelpSrv) RevampPosts(posts []*core.PostFormated) ([]*core.PostFormated, error) {
postIds := make([]int64, 0, len(posts)) postIds := make([]int64, 0, len(posts))
userIds := make([]int64, 0, len(posts)) userIds := make([]int64, 0, len(posts))
for _, post := range posts { for _, post := range posts {
@ -130,24 +147,14 @@ func (s *tweetHelpServant) RevampPosts(posts []*core.PostFormated) ([]*core.Post
return posts, nil return posts, nil
} }
func (s *tweetHelpServant) RevampTweets(tweets cs.TweetList) (cs.TweetList, error) { func (s *tweetHelpSrv) getPostContentsByIDs(ids []int64) ([]*dbr.PostContent, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetHelpServant) MergeTweets(tweets cs.TweetInfo) (cs.TweetList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetHelpServant) getPostContentsByIDs(ids []int64) ([]*dbr.PostContent, error) {
return (&dbr.PostContent{}).List(s.db, &dbr.ConditionsT{ return (&dbr.PostContent{}).List(s.db, &dbr.ConditionsT{
"post_id IN ?": ids, "post_id IN ?": ids,
"ORDER": "sort ASC", "ORDER": "sort ASC",
}, 0, 0) }, 0, 0)
} }
func (s *tweetHelpServant) getUsersByIDs(ids []int64) ([]*dbr.User, error) { func (s *tweetHelpSrv) getUsersByIDs(ids []int64) ([]*dbr.User, error) {
user := &dbr.User{} user := &dbr.User{}
return user.List(s.db, &dbr.ConditionsT{ return user.List(s.db, &dbr.ConditionsT{
@ -155,7 +162,7 @@ func (s *tweetHelpServant) getUsersByIDs(ids []int64) ([]*dbr.User, error) {
}, 0, 0) }, 0, 0)
} }
func (s *tweetManageServant) CreatePostCollection(postID, userID int64) (*core.PostCollection, error) { func (s *tweetManageSrv) CreatePostCollection(postID, userID int64) (*core.PostCollection, error) {
collection := &dbr.PostCollection{ collection := &dbr.PostCollection{
PostID: postID, PostID: postID,
UserID: userID, UserID: userID,
@ -164,20 +171,20 @@ func (s *tweetManageServant) CreatePostCollection(postID, userID int64) (*core.P
return collection.Create(s.db) return collection.Create(s.db)
} }
func (s *tweetManageServant) DeletePostCollection(p *core.PostCollection) error { func (s *tweetManageSrv) DeletePostCollection(p *core.PostCollection) error {
return p.Delete(s.db) return p.Delete(s.db)
} }
func (s *tweetManageServant) CreatePostContent(content *core.PostContent) (*core.PostContent, error) { func (s *tweetManageSrv) CreatePostContent(content *core.PostContent) (*core.PostContent, error) {
return content.Create(s.db) return content.Create(s.db)
} }
func (s *tweetManageServant) CreateAttachment(obj *cs.Attachment) (int64, error) { func (s *tweetManageSrv) CreateAttachment(obj *cs.Attachment) (int64, error) {
// TODO // TODO
return 0, debug.ErrNotImplemented return 0, debug.ErrNotImplemented
} }
func (s *tweetManageServant) CreatePost(post *core.Post) (*core.Post, error) { func (s *tweetManageSrv) CreatePost(post *core.Post) (*core.Post, error) {
post.LatestRepliedOn = time.Now().Unix() post.LatestRepliedOn = time.Now().Unix()
p, err := post.Create(s.db) p, err := post.Create(s.db)
if err != nil { if err != nil {
@ -187,7 +194,7 @@ func (s *tweetManageServant) CreatePost(post *core.Post) (*core.Post, error) {
return p, nil return p, nil
} }
func (s *tweetManageServant) DeletePost(post *core.Post) ([]string, error) { func (s *tweetManageSrv) DeletePost(post *core.Post) ([]string, error) {
var mediaContents []string var mediaContents []string
postId := post.ID postId := post.ID
@ -234,7 +241,7 @@ func (s *tweetManageServant) DeletePost(post *core.Post) ([]string, error) {
return mediaContents, nil return mediaContents, nil
} }
func (s *tweetManageServant) deleteCommentByPostId(db *gorm.DB, postId int64) ([]string, error) { func (s *tweetManageSrv) deleteCommentByPostId(db *gorm.DB, postId int64) ([]string, error) {
comment := &dbr.Comment{} comment := &dbr.Comment{}
commentContent := &dbr.CommentContent{} commentContent := &dbr.CommentContent{}
@ -268,12 +275,12 @@ func (s *tweetManageServant) deleteCommentByPostId(db *gorm.DB, postId int64) ([
return mediaContents, nil return mediaContents, nil
} }
func (s *tweetManageServant) LockPost(post *core.Post) error { func (s *tweetManageSrv) LockPost(post *core.Post) error {
post.IsLock = 1 - post.IsLock post.IsLock = 1 - post.IsLock
return post.Update(s.db) return post.Update(s.db)
} }
func (s *tweetManageServant) StickPost(post *core.Post) error { func (s *tweetManageSrv) StickPost(post *core.Post) error {
post.IsTop = 1 - post.IsTop post.IsTop = 1 - post.IsTop
if err := post.Update(s.db); err != nil { if err := post.Update(s.db); err != nil {
return err return err
@ -282,7 +289,7 @@ func (s *tweetManageServant) StickPost(post *core.Post) error {
return nil return nil
} }
func (s *tweetManageServant) VisiblePost(post *core.Post, visibility core.PostVisibleT) error { func (s *tweetManageSrv) VisiblePost(post *core.Post, visibility core.PostVisibleT) error {
oldVisibility := post.Visibility oldVisibility := post.Visibility
post.Visibility = visibility post.Visibility = visibility
// TODO: 这个判断是否可以不要呢 // TODO: 这个判断是否可以不要呢
@ -316,7 +323,7 @@ func (s *tweetManageServant) VisiblePost(post *core.Post, visibility core.PostVi
return nil return nil
} }
func (s *tweetManageServant) UpdatePost(post *core.Post) error { func (s *tweetManageSrv) UpdatePost(post *core.Post) error {
if err := post.Update(s.db); err != nil { if err := post.Update(s.db); err != nil {
return err return err
} }
@ -324,7 +331,7 @@ func (s *tweetManageServant) UpdatePost(post *core.Post) error {
return nil return nil
} }
func (s *tweetManageServant) CreatePostStar(postID, userID int64) (*core.PostStar, error) { func (s *tweetManageSrv) CreatePostStar(postID, userID int64) (*core.PostStar, error) {
star := &dbr.PostStar{ star := &dbr.PostStar{
PostID: postID, PostID: postID,
UserID: userID, UserID: userID,
@ -332,56 +339,11 @@ func (s *tweetManageServant) CreatePostStar(postID, userID int64) (*core.PostSta
return star.Create(s.db) return star.Create(s.db)
} }
func (s *tweetManageServant) DeletePostStar(p *core.PostStar) error { func (s *tweetManageSrv) DeletePostStar(p *core.PostStar) error {
return p.Delete(s.db) return p.Delete(s.db)
} }
func (s *tweetManageServant) CreateTweet(userId int64, req *cs.NewTweetReq) (*cs.TweetItem, error) { func (s *tweetSrv) GetPostByID(id int64) (*core.Post, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetManageServant) DeleteTweet(userId int64, tweetId int64) ([]string, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetManageServant) LockTweet(userId int64, tweetId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageServant) StickTweet(userId int64, tweetId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageServant) VisibleTweet(userId int64, visibility cs.TweetVisibleType) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageServant) CreateReaction(userId int64, tweetId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageServant) DeleteReaction(userId int64, reactionId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageServant) CreateFavorite(userId int64, tweetId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageServant) DeleteFavorite(userId int64, favoriteId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetServant) GetPostByID(id int64) (*core.Post, error) {
post := &dbr.Post{ post := &dbr.Post{
Model: &dbr.Model{ Model: &dbr.Model{
ID: id, ID: id,
@ -390,15 +352,15 @@ func (s *tweetServant) GetPostByID(id int64) (*core.Post, error) {
return post.Get(s.db) return post.Get(s.db)
} }
func (s *tweetServant) GetPosts(conditions *core.ConditionsT, offset, limit int) ([]*core.Post, error) { func (s *tweetSrv) GetPosts(conditions *core.ConditionsT, offset, limit int) ([]*core.Post, error) {
return (&dbr.Post{}).List(s.db, conditions, offset, limit) return (&dbr.Post{}).List(s.db, conditions, offset, limit)
} }
func (s *tweetServant) GetPostCount(conditions *core.ConditionsT) (int64, error) { func (s *tweetSrv) GetPostCount(conditions *core.ConditionsT) (int64, error) {
return (&dbr.Post{}).Count(s.db, conditions) return (&dbr.Post{}).Count(s.db, conditions)
} }
func (s *tweetServant) GetUserPostStar(postID, userID int64) (*core.PostStar, error) { func (s *tweetSrv) GetUserPostStar(postID, userID int64) (*core.PostStar, error) {
star := &dbr.PostStar{ star := &dbr.PostStar{
PostID: postID, PostID: postID,
UserID: userID, UserID: userID,
@ -406,7 +368,7 @@ func (s *tweetServant) GetUserPostStar(postID, userID int64) (*core.PostStar, er
return star.Get(s.db) return star.Get(s.db)
} }
func (s *tweetServant) GetUserPostStars(userID int64, offset, limit int) ([]*core.PostStar, error) { func (s *tweetSrv) GetUserPostStars(userID int64, offset, limit int) ([]*core.PostStar, error) {
star := &dbr.PostStar{ star := &dbr.PostStar{
UserID: userID, UserID: userID,
} }
@ -416,14 +378,14 @@ func (s *tweetServant) GetUserPostStars(userID int64, offset, limit int) ([]*cor
}, offset, limit) }, offset, limit)
} }
func (s *tweetServant) GetUserPostStarCount(userID int64) (int64, error) { func (s *tweetSrv) GetUserPostStarCount(userID int64) (int64, error) {
star := &dbr.PostStar{ star := &dbr.PostStar{
UserID: userID, UserID: userID,
} }
return star.Count(s.db, &dbr.ConditionsT{}) return star.Count(s.db, &dbr.ConditionsT{})
} }
func (s *tweetServant) GetUserPostCollection(postID, userID int64) (*core.PostCollection, error) { func (s *tweetSrv) GetUserPostCollection(postID, userID int64) (*core.PostCollection, error) {
star := &dbr.PostCollection{ star := &dbr.PostCollection{
PostID: postID, PostID: postID,
UserID: userID, UserID: userID,
@ -431,7 +393,7 @@ func (s *tweetServant) GetUserPostCollection(postID, userID int64) (*core.PostCo
return star.Get(s.db) return star.Get(s.db)
} }
func (s *tweetServant) GetUserPostCollections(userID int64, offset, limit int) ([]*core.PostCollection, error) { func (s *tweetSrv) GetUserPostCollections(userID int64, offset, limit int) ([]*core.PostCollection, error) {
collection := &dbr.PostCollection{ collection := &dbr.PostCollection{
UserID: userID, UserID: userID,
} }
@ -441,14 +403,14 @@ func (s *tweetServant) GetUserPostCollections(userID int64, offset, limit int) (
}, offset, limit) }, offset, limit)
} }
func (s *tweetServant) GetUserPostCollectionCount(userID int64) (int64, error) { func (s *tweetSrv) GetUserPostCollectionCount(userID int64) (int64, error) {
collection := &dbr.PostCollection{ collection := &dbr.PostCollection{
UserID: userID, UserID: userID,
} }
return collection.Count(s.db, &dbr.ConditionsT{}) return collection.Count(s.db, &dbr.ConditionsT{})
} }
func (s *tweetServant) GetUserWalletBills(userID int64, offset, limit int) ([]*core.WalletStatement, error) { func (s *tweetSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*core.WalletStatement, error) {
statement := &dbr.WalletStatement{ statement := &dbr.WalletStatement{
UserID: userID, UserID: userID,
} }
@ -458,14 +420,14 @@ func (s *tweetServant) GetUserWalletBills(userID int64, offset, limit int) ([]*c
}, offset, limit) }, offset, limit)
} }
func (s *tweetServant) GetUserWalletBillCount(userID int64) (int64, error) { func (s *tweetSrv) GetUserWalletBillCount(userID int64) (int64, error) {
statement := &dbr.WalletStatement{ statement := &dbr.WalletStatement{
UserID: userID, UserID: userID,
} }
return statement.Count(s.db, &dbr.ConditionsT{}) return statement.Count(s.db, &dbr.ConditionsT{})
} }
func (s *tweetServant) GetPostAttatchmentBill(postID, userID int64) (*core.PostAttachmentBill, error) { func (s *tweetSrv) GetPostAttatchmentBill(postID, userID int64) (*core.PostAttachmentBill, error) {
bill := &dbr.PostAttachmentBill{ bill := &dbr.PostAttachmentBill{
PostID: postID, PostID: postID,
UserID: userID, UserID: userID,
@ -474,14 +436,14 @@ func (s *tweetServant) GetPostAttatchmentBill(postID, userID int64) (*core.PostA
return bill.Get(s.db) return bill.Get(s.db)
} }
func (s *tweetServant) GetPostContentsByIDs(ids []int64) ([]*core.PostContent, error) { func (s *tweetSrv) GetPostContentsByIDs(ids []int64) ([]*core.PostContent, error) {
return (&dbr.PostContent{}).List(s.db, &dbr.ConditionsT{ return (&dbr.PostContent{}).List(s.db, &dbr.ConditionsT{
"post_id IN ?": ids, "post_id IN ?": ids,
"ORDER": "sort ASC", "ORDER": "sort ASC",
}, 0, 0) }, 0, 0)
} }
func (s *tweetServant) GetPostContentByID(id int64) (*core.PostContent, error) { func (s *tweetSrv) GetPostContentByID(id int64) (*core.PostContent, error) {
return (&dbr.PostContent{ return (&dbr.PostContent{
Model: &dbr.Model{ Model: &dbr.Model{
ID: id, ID: id,
@ -489,42 +451,102 @@ func (s *tweetServant) GetPostContentByID(id int64) (*core.PostContent, error) {
}).Get(s.db) }).Get(s.db)
} }
func (s *tweetServant) TweetInfoById(id int64) (*cs.TweetInfo, error) { func (s *tweetSrvA) TweetInfoById(id int64) (*cs.TweetInfo, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetSrvA) TweetItemById(id int64) (*cs.TweetItem, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetSrvA) UserTweets(visitorId, userId int64) (cs.TweetList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetSrvA) ReactionByTweetId(userId int64, tweetId int64) (*cs.ReactionItem, error) {
// TODO // TODO
return nil, debug.ErrNotImplemented return nil, debug.ErrNotImplemented
} }
func (s *tweetServant) TweetItemById(id int64) (*cs.TweetItem, error) { func (s *tweetSrvA) UserReactions(userId int64, offset int, limit int) (cs.ReactionList, error) {
// TODO // TODO
return nil, debug.ErrNotImplemented return nil, debug.ErrNotImplemented
} }
func (s *tweetServant) UserTweets(visitorId, userId int64) (cs.TweetList, error) { func (s *tweetSrvA) FavoriteByTweetId(userId int64, tweetId int64) (*cs.FavoriteItem, error) {
// TODO // TODO
return nil, debug.ErrNotImplemented return nil, debug.ErrNotImplemented
} }
func (s *tweetServant) ReactionByTweetId(userId int64, tweetId int64) (*cs.ReactionItem, error) { func (s *tweetSrvA) UserFavorites(userId int64, offset int, limit int) (cs.FavoriteList, error) {
// TODO // TODO
return nil, debug.ErrNotImplemented return nil, debug.ErrNotImplemented
} }
func (s *tweetServant) UserReactions(userId int64, offset int, limit int) (cs.ReactionList, error) { func (s *tweetSrvA) AttachmentByTweetId(userId int64, tweetId int64) (*cs.AttachmentBill, error) {
// TODO // TODO
return nil, debug.ErrNotImplemented return nil, debug.ErrNotImplemented
} }
func (s *tweetServant) FavoriteByTweetId(userId int64, tweetId int64) (*cs.FavoriteItem, error) { func (s *tweetManageSrvA) CreateAttachment(obj *cs.Attachment) (int64, error) {
// TODO
return 0, debug.ErrNotImplemented
}
func (s *tweetManageSrvA) CreateTweet(userId int64, req *cs.NewTweetReq) (*cs.TweetItem, error) {
// TODO // TODO
return nil, debug.ErrNotImplemented return nil, debug.ErrNotImplemented
} }
func (s *tweetServant) UserFavorites(userId int64, offset int, limit int) (cs.FavoriteList, error) { func (s *tweetManageSrvA) DeleteTweet(userId int64, tweetId int64) ([]string, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetManageSrvA) LockTweet(userId int64, tweetId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageSrvA) StickTweet(userId int64, tweetId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageSrvA) VisibleTweet(userId int64, visibility cs.TweetVisibleType) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageSrvA) CreateReaction(userId int64, tweetId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageSrvA) DeleteReaction(userId int64, reactionId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageSrvA) CreateFavorite(userId int64, tweetId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageSrvA) DeleteFavorite(userId int64, favoriteId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetHelpSrvA) RevampTweets(tweets cs.TweetList) (cs.TweetList, error) {
// TODO // TODO
return nil, debug.ErrNotImplemented return nil, debug.ErrNotImplemented
} }
func (s *tweetServant) AttachmentByTweetId(userId int64, tweetId int64) (*cs.AttachmentBill, error) { func (s *tweetHelpSrvA) MergeTweets(tweets cs.TweetInfo) (cs.TweetList, error) {
// TODO // TODO
return nil, debug.ErrNotImplemented return nil, debug.ErrNotImplemented
} }

@ -13,20 +13,20 @@ import (
) )
var ( var (
_ core.UserManageService = (*userManageServant)(nil) _ core.UserManageService = (*userManageSrv)(nil)
) )
type userManageServant struct { type userManageSrv struct {
db *gorm.DB db *gorm.DB
} }
func newUserManageService(db *gorm.DB) core.UserManageService { func newUserManageService(db *gorm.DB) core.UserManageService {
return &userManageServant{ return &userManageSrv{
db: db, db: db,
} }
} }
func (s *userManageServant) GetUserByID(id int64) (*core.User, error) { func (s *userManageSrv) GetUserByID(id int64) (*core.User, error) {
user := &dbr.User{ user := &dbr.User{
Model: &dbr.Model{ Model: &dbr.Model{
ID: id, ID: id,
@ -35,28 +35,28 @@ func (s *userManageServant) GetUserByID(id int64) (*core.User, error) {
return user.Get(s.db) return user.Get(s.db)
} }
func (s *userManageServant) GetUserByUsername(username string) (*core.User, error) { func (s *userManageSrv) GetUserByUsername(username string) (*core.User, error) {
user := &dbr.User{ user := &dbr.User{
Username: username, Username: username,
} }
return user.Get(s.db) return user.Get(s.db)
} }
func (s *userManageServant) GetUserByPhone(phone string) (*core.User, error) { func (s *userManageSrv) GetUserByPhone(phone string) (*core.User, error) {
user := &dbr.User{ user := &dbr.User{
Phone: phone, Phone: phone,
} }
return user.Get(s.db) return user.Get(s.db)
} }
func (s *userManageServant) GetUsersByIDs(ids []int64) ([]*core.User, error) { func (s *userManageSrv) GetUsersByIDs(ids []int64) ([]*core.User, error) {
user := &dbr.User{} user := &dbr.User{}
return user.List(s.db, &dbr.ConditionsT{ return user.List(s.db, &dbr.ConditionsT{
"id IN ?": ids, "id IN ?": ids,
}, 0, 0) }, 0, 0)
} }
func (s *userManageServant) GetUsersByKeyword(keyword string) ([]*core.User, error) { func (s *userManageSrv) GetUsersByKeyword(keyword string) ([]*core.User, error) {
user := &dbr.User{} user := &dbr.User{}
keyword = strings.Trim(keyword, " ") + "%" keyword = strings.Trim(keyword, " ") + "%"
if keyword == "%" { if keyword == "%" {
@ -70,10 +70,10 @@ func (s *userManageServant) GetUsersByKeyword(keyword string) ([]*core.User, err
} }
} }
func (s *userManageServant) CreateUser(user *dbr.User) (*core.User, error) { func (s *userManageSrv) CreateUser(user *dbr.User) (*core.User, error) {
return user.Create(s.db) return user.Create(s.db)
} }
func (s *userManageServant) UpdateUser(user *core.User) error { func (s *userManageSrv) UpdateUser(user *core.User) error {
return user.Update(s.db) return user.Update(s.db)
} }

@ -12,20 +12,20 @@ import (
) )
var ( var (
_ core.WalletService = (*walletServant)(nil) _ core.WalletService = (*walletSrv)(nil)
) )
type walletServant struct { type walletSrv struct {
db *gorm.DB db *gorm.DB
} }
func newWalletService(db *gorm.DB) core.WalletService { func newWalletService(db *gorm.DB) core.WalletService {
return &walletServant{ return &walletSrv{
db: db, db: db,
} }
} }
func (s *walletServant) GetRechargeByID(id int64) (*core.WalletRecharge, error) { func (s *walletSrv) GetRechargeByID(id int64) (*core.WalletRecharge, error) {
recharge := &dbr.WalletRecharge{ recharge := &dbr.WalletRecharge{
Model: &dbr.Model{ Model: &dbr.Model{
ID: id, ID: id,
@ -34,7 +34,7 @@ func (s *walletServant) GetRechargeByID(id int64) (*core.WalletRecharge, error)
return recharge.Get(s.db) return recharge.Get(s.db)
} }
func (s *walletServant) CreateRecharge(userId, amount int64) (*core.WalletRecharge, error) { func (s *walletSrv) CreateRecharge(userId, amount int64) (*core.WalletRecharge, error) {
recharge := &dbr.WalletRecharge{ recharge := &dbr.WalletRecharge{
UserID: userId, UserID: userId,
Amount: amount, Amount: amount,
@ -43,7 +43,7 @@ func (s *walletServant) CreateRecharge(userId, amount int64) (*core.WalletRechar
return recharge.Create(s.db) return recharge.Create(s.db)
} }
func (s *walletServant) GetUserWalletBills(userID int64, offset, limit int) ([]*core.WalletStatement, error) { func (s *walletSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*core.WalletStatement, error) {
statement := &dbr.WalletStatement{ statement := &dbr.WalletStatement{
UserID: userID, UserID: userID,
} }
@ -53,14 +53,14 @@ func (s *walletServant) GetUserWalletBills(userID int64, offset, limit int) ([]*
}, offset, limit) }, offset, limit)
} }
func (s *walletServant) GetUserWalletBillCount(userID int64) (int64, error) { func (s *walletSrv) GetUserWalletBillCount(userID int64) (int64, error) {
statement := &dbr.WalletStatement{ statement := &dbr.WalletStatement{
UserID: userID, UserID: userID,
} }
return statement.Count(s.db, &dbr.ConditionsT{}) return statement.Count(s.db, &dbr.ConditionsT{})
} }
func (s *walletServant) HandleRechargeSuccess(recharge *core.WalletRecharge, tradeNo string) error { func (s *walletSrv) HandleRechargeSuccess(recharge *core.WalletRecharge, tradeNo string) error {
user, _ := (&dbr.User{ user, _ := (&dbr.User{
Model: &dbr.Model{ Model: &dbr.Model{
ID: recharge.UserID, ID: recharge.UserID,
@ -97,7 +97,7 @@ func (s *walletServant) HandleRechargeSuccess(recharge *core.WalletRecharge, tra
}) })
} }
func (s *walletServant) HandlePostAttachmentBought(post *core.Post, user *core.User) error { func (s *walletSrv) HandlePostAttachmentBought(post *core.Post, user *core.User) error {
return s.db.Transaction(func(tx *gorm.DB) error { return s.db.Transaction(func(tx *gorm.DB) error {
// 扣除金额 // 扣除金额
if err := tx.Model(user).Update("balance", gorm.Expr("balance - ?", post.AttachmentPrice)).Error; err != nil { if err := tx.Model(user).Update("balance", gorm.Expr("balance - ?", post.AttachmentPrice)).Error; err != nil {

@ -1,59 +0,0 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package sakila
import (
"github.com/jmoiron/sqlx"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/pkg/debug"
)
var (
_ core.AuthorizationManageService = (*authorizationManageServant)(nil)
)
type authorizationManageServant struct {
*sqlxServant
stmtIdx *sqlx.Stmt
stmtUpdateFriend *sqlx.Stmt
}
func (s *authorizationManageServant) IsAllow(user *core.User, action *core.Action) bool {
// TODO
debug.NotImplemented()
return false
}
func (s *authorizationManageServant) MyFriendSet(userId int64) core.FriendSet {
// TODO
debug.NotImplemented()
return nil
}
func (s *authorizationManageServant) BeFriendFilter(userId int64) core.FriendFilter {
// TODO
debug.NotImplemented()
return nil
}
func (s *authorizationManageServant) BeFriendIds(userId int64) ([]int64, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *authorizationManageServant) isFriend(userId int64, friendId int64) bool {
// TODO
debug.NotImplemented()
return false
}
func newAuthorizationManageService(db *sqlx.DB) core.AuthorizationManageService {
return &authorizationManageServant{
sqlxServant: newSqlxServant(db),
stmtIdx: c(`SELECT * FROM @person WHERE first_name=?`),
stmtUpdateFriend: c(`SELECT * FROM @person WHERE first_name=?`),
}
}

@ -1,110 +0,0 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package sakila
import (
"github.com/jmoiron/sqlx"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/pkg/debug"
)
var (
_ core.CommentService = (*commentServant)(nil)
_ core.CommentManageService = (*commentManageServant)(nil)
)
type commentServant struct {
*sqlxServant
stmtGetComments *sqlx.Stmt
stmtGetReply *sqlx.Stmt
}
type commentManageServant struct {
*sqlxServant
stmtDelComments *sqlx.Stmt
stmtAddComents *sqlx.Stmt
}
func (s *commentServant) GetComments(conditions *core.ConditionsT, offset, limit int) ([]*core.Comment, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *commentServant) GetCommentByID(id int64) (*core.Comment, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *commentServant) GetCommentReplyByID(id int64) (*core.CommentReply, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *commentServant) GetCommentCount(conditions *core.ConditionsT) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
}
func (s *commentServant) GetCommentContentsByIDs(ids []int64) ([]*core.CommentContent, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *commentServant) GetCommentRepliesByID(ids []int64) ([]*core.CommentReplyFormated, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *commentManageServant) DeleteComment(comment *core.Comment) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *commentManageServant) CreateComment(comment *core.Comment) (*core.Comment, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *commentManageServant) CreateCommentReply(reply *core.CommentReply) (*core.CommentReply, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *commentManageServant) DeleteCommentReply(reply *core.CommentReply) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *commentManageServant) CreateCommentContent(content *core.CommentContent) (*core.CommentContent, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func newCommentService(db *sqlx.DB) core.CommentService {
return &commentServant{
sqlxServant: newSqlxServant(db),
stmtGetComments: c(`SELECT * FROM @person WHERE first_name=?`),
stmtGetReply: c(`SELECT * FROM @person WHERE first_name=?`),
}
}
func newCommentManageService(db *sqlx.DB) core.CommentManageService {
return &commentManageServant{
sqlxServant: newSqlxServant(db),
stmtAddComents: c(`SELECT * FROM @person WHERE first_name=?`),
stmtDelComments: c(`SELECT * FROM @person WHERE first_name=?`),
}
}

@ -1,65 +0,0 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package sakila
import (
"github.com/jmoiron/sqlx"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/pkg/debug"
)
var (
_ core.ContactManageService = (*contactManageServant)(nil)
)
type contactManageServant struct {
*sqlxServant
stmtAddFriend *sqlx.Stmt
stmtDelFriend *sqlx.Stmt
}
func (s *contactManageServant) RequestingFriend(userId int64, friendId int64, greetings string) (err error) {
// TODO
debug.NotImplemented()
return nil
}
func (s *contactManageServant) AddFriend(userId int64, friendId int64) (err error) {
// TODO
debug.NotImplemented()
return nil
}
func (s *contactManageServant) RejectFriend(userId int64, friendId int64) (err error) {
// TODO
debug.NotImplemented()
return nil
}
func (s *contactManageServant) DeleteFriend(userId int64, friendId int64) (err error) {
// TODO
debug.NotImplemented()
return nil
}
func (s *contactManageServant) GetContacts(userId int64, offset int, limit int) (*core.ContactList, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *contactManageServant) IsFriend(userId int64, friendId int64) bool {
// TODO
debug.NotImplemented()
return false
}
func newContactManageService(db *sqlx.DB) core.ContactManageService {
return &contactManageServant{
sqlxServant: newSqlxServant(db),
stmtAddFriend: c(`SELECT * FROM @person WHERE first_name=?`),
stmtDelFriend: c(`SELECT * FROM @person WHERE first_name=?`),
}
}

@ -1,67 +0,0 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package sakila
import (
"github.com/jmoiron/sqlx"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/pkg/debug"
)
var (
_ core.MessageService = (*messageServant)(nil)
)
type messageServant struct {
*sqlxServant
stmtAddMsg *sqlx.Stmt
stmtGetMsg *sqlx.Stmt
stmtReadMsg *sqlx.Stmt
}
func (s *messageServant) CreateMessage(msg *core.Message) (*core.Message, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *messageServant) GetUnreadCount(userID int64) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
}
func (s *messageServant) GetMessageByID(id int64) (*core.Message, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *messageServant) ReadMessage(message *core.Message) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *messageServant) GetMessages(conditions *core.ConditionsT, offset, limit int) ([]*core.MessageFormated, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *messageServant) GetMessageCount(conditions *core.ConditionsT) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
}
func newMessageService(db *sqlx.DB) core.MessageService {
return &messageServant{
sqlxServant: newSqlxServant(db),
stmtAddMsg: c(`SELECT * FROM @person WHERE first_name=?`),
stmtGetMsg: c(`SELECT * FROM @person WHERE first_name=?`),
stmtReadMsg: c(`SELECT * FROM @person WHERE first_name=?`),
}
}

@ -1,114 +1,23 @@
// Copyright 2023 ROC. All rights reserved. // Copyright 2022 ROC. All rights reserved.
// Use of this source code is governed by a MIT style // Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// Core service implement base sqlx+mysql. All sub-service
// will declare here and provide initial function.
package sakila package sakila
import ( import (
"sync"
"github.com/Masterminds/semver/v3"
"github.com/alimy/cfg"
"github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/dao/cache"
"github.com/rocboss/paopao-ce/internal/dao/security"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
var (
_ core.DataService = (*dataServant)(nil)
_ core.VersionInfo = (*dataServant)(nil)
_onceInitial sync.Once
)
type dataServant struct {
core.IndexPostsService
core.WalletService
core.MessageService
core.TopicService
core.TweetService
core.TweetManageService
core.TweetHelpService
core.CommentService
core.CommentManageService
core.UserManageService
core.ContactManageService
core.SecurityService
core.AttachmentCheckService
}
func NewDataService() (core.DataService, core.VersionInfo) { func NewDataService() (core.DataService, core.VersionInfo) {
lazyInitial() logrus.Fatal("not support now")
return nil, nil
var (
v core.VersionInfo
cis core.CacheIndexService
ips core.IndexPostsService
)
pvs := security.NewPhoneVerifyService()
ams := NewAuthorizationManageService()
ths := newTweetHelpService(_db)
// initialize core.IndexPostsService
if cfg.If("Friendship") {
ips = newFriendIndexService(_db, ams, ths)
} else if cfg.If("Followship") {
ips = newFollowIndexService(_db, ths)
} else if cfg.If("Lightship") {
ips = newLightIndexService(_db, ths)
} else {
// default use lightship post index service
ips = newLightIndexService(_db, ths)
}
// initialize core.CacheIndexService
if cfg.If("SimpleCacheIndex") {
// simpleCache use special post index service
ips = newSimpleIndexPostsService(_db, ths)
cis, v = cache.NewSimpleCacheIndexService(ips)
} else if cfg.If("BigCacheIndex") {
// TODO: make cache index post in different scence like friendship/followship/lightship
cis, v = cache.NewBigCacheIndexService(ips, ams)
} else {
cis, v = cache.NewNoneCacheIndexService(ips)
}
logrus.Infof("use %s as cache index service by version: %s", v.Name(), v.Version())
ds := &dataServant{
IndexPostsService: cis,
WalletService: newWalletService(_db),
MessageService: newMessageService(_db),
TopicService: newTopicService(_db),
TweetService: newTweetService(_db),
TweetManageService: newTweetManageService(_db, cis),
TweetHelpService: newTweetHelpService(_db),
CommentService: newCommentService(_db),
CommentManageService: newCommentManageService(_db),
UserManageService: newUserManageService(_db),
ContactManageService: newContactManageService(_db),
SecurityService: newSecurityService(_db, pvs),
AttachmentCheckService: security.NewAttachmentCheckService(),
}
return ds, ds
} }
func NewAuthorizationManageService() core.AuthorizationManageService { func NewAuthorizationManageService() core.AuthorizationManageService {
lazyInitial() logrus.Fatal("not support now")
return newAuthorizationManageService(_db) return nil
}
func (s *dataServant) Name() string {
return "Sqlx"
}
func (s *dataServant) Version() *semver.Version {
return semver.MustParse("v0.1.0")
}
// lazyInitial do some package lazy initialize for performance
func lazyInitial() {
_onceInitial.Do(func() {
initSqlxDB()
})
} }

@ -1,52 +0,0 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package sakila
import (
"github.com/jmoiron/sqlx"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/pkg/debug"
)
var (
_ core.SecurityService = (*securityServant)(nil)
)
type securityServant struct {
*sqlxServant
phoneVerify core.PhoneVerifyService
stmtAddCaptcha *sqlx.Stmt
stmtGetCaptcha *sqlx.Stmt
}
// GetLatestPhoneCaptcha 获取最新短信验证码
func (s *securityServant) GetLatestPhoneCaptcha(phone string) (*core.Captcha, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
// UsePhoneCaptcha 更新短信验证码
func (s *securityServant) UsePhoneCaptcha(captcha *core.Captcha) error {
// TODO
debug.NotImplemented()
return nil
}
// SendPhoneCaptcha 发送短信验证码
func (s *securityServant) SendPhoneCaptcha(phone string) error {
// TODO
debug.NotImplemented()
return nil
}
func newSecurityService(db *sqlx.DB, phoneVerify core.PhoneVerifyService) core.SecurityService {
return &securityServant{
sqlxServant: newSqlxServant(db),
phoneVerify: phoneVerify,
stmtAddCaptcha: c(`SELECT * FROM @person WHERE first_name=?`),
stmtGetCaptcha: c(`SELECT * FROM @person WHERE first_name=?`),
}
}

@ -1,114 +0,0 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package sakila
import (
"context"
"database/sql"
"strings"
"github.com/jmoiron/sqlx"
"github.com/rocboss/paopao-ce/internal/conf"
"github.com/sirupsen/logrus"
)
var (
_db *sqlx.DB
)
type sqlxServant struct {
db *sqlx.DB
}
func (s *sqlxServant) with(handle func(tx *sqlx.Tx) error) error {
tx, err := s.db.Beginx()
if err != nil {
return err
}
defer tx.Rollback()
if err = handle(tx); err != nil {
return err
}
return tx.Commit()
}
func (s *sqlxServant) withTx(ctx context.Context, opts *sql.TxOptions, handle func(*sqlx.Tx) error) error {
tx, err := s.db.BeginTxx(ctx, opts)
if err != nil {
return err
}
defer tx.Rollback()
if err = handle(tx); err != nil {
return err
}
return tx.Commit()
}
func (s *sqlxServant) in(query string, args ...any) (string, []any, error) {
q, params, err := sqlx.In(query, args...)
if err != nil {
return "", nil, err
}
return s.db.Rebind(q), params, nil
}
func (s *sqlxServant) inExec(execer sqlx.Execer, query string, args ...any) (sql.Result, error) {
q, params, err := sqlx.In(query, args...)
if err != nil {
return nil, err
}
return execer.Exec(s.db.Rebind(q), params...)
}
func (s *sqlxServant) inSelect(queryer sqlx.Queryer, dest any, query string, args ...any) error {
q, params, err := sqlx.In(query, args...)
if err != nil {
return err
}
return sqlx.Select(queryer, dest, s.db.Rebind(q), params...)
}
func (s *sqlxServant) inGet(queryer sqlx.Queryer, dest any, query string, args ...any) error {
q, params, err := sqlx.In(query, args...)
if err != nil {
return err
}
return sqlx.Get(queryer, dest, s.db.Rebind(q), params...)
}
func newSqlxServant(db *sqlx.DB) *sqlxServant {
return &sqlxServant{
db: db,
}
}
func r(query string) string {
return _db.Rebind(t(query))
}
func c(query string) *sqlx.Stmt {
stmt, err := _db.Preparex(_db.Rebind(t(query)))
if err != nil {
logrus.Fatalf("prepare query(%s) error: %s", query, err)
}
return stmt
}
func n(query string) *sqlx.NamedStmt {
stmt, err := _db.PrepareNamed(t(query))
if err != nil {
logrus.Fatalf("prepare named query(%s) error: %s", query, err)
}
return stmt
}
// t repace table prefix for query
func t(query string) string {
return strings.Replace(query, "@", conf.DatabaseSetting.TablePrefix, -1)
}
func initSqlxDB() {
_db = conf.MustSqlxDB()
}

@ -1,120 +0,0 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package sakila
import (
"github.com/jmoiron/sqlx"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/core/cs"
"github.com/rocboss/paopao-ce/pkg/debug"
)
var (
_ core.IndexPostsService = (*friendIndexServant)(nil)
_ core.IndexPostsService = (*followIndexServant)(nil)
_ core.IndexPostsService = (*lightIndexServant)(nil)
_ core.IndexPostsService = (*simpleIndexPostsServant)(nil)
)
type friendIndexServant struct {
*sqlxServant
ams core.AuthorizationManageService
ths core.TweetHelpService
stmtIndex *sqlx.Stmt
}
type followIndexServant struct {
*sqlxServant
ths core.TweetHelpService
stmtIndex *sqlx.Stmt
}
type lightIndexServant struct {
*sqlxServant
ths core.TweetHelpService
stmtIndex *sqlx.Stmt
}
type simpleIndexPostsServant struct {
*sqlxServant
ths core.TweetHelpService
stmtIndex *sqlx.Stmt
}
// IndexPosts 根据userId查询广场推文列表简单做到不同用户的主页都是不同的
func (s *friendIndexServant) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *friendIndexServant) TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) {
// TODO
return nil, debug.ErrNotImplemented
}
// IndexPosts 根据userId查询广场推文列表简单做到不同用户的主页都是不同的
func (s *followIndexServant) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *followIndexServant) TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) {
// TODO
return nil, debug.ErrNotImplemented
}
// IndexPosts 根据userId查询广场推文列表简单做到不同用户的主页都是不同的
func (s *lightIndexServant) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *lightIndexServant) TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) {
// TODO
return nil, debug.ErrNotImplemented
}
// simpleCacheIndexGetPosts simpleCacheIndex 专属获取广场推文列表函数
func (s *simpleIndexPostsServant) IndexPosts(_user *core.User, offset int, limit int) (*core.IndexTweetList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *simpleIndexPostsServant) TweetTimeline(userId int64, offset int, limit int) (*cs.TweetBox, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func newFriendIndexService(db *sqlx.DB, ams core.AuthorizationManageService, ths core.TweetHelpService) core.IndexPostsService {
return &friendIndexServant{
ams: ams,
sqlxServant: newSqlxServant(db),
stmtIndex: c(`SELECT * FROM @person WHERE first_name=?`),
}
}
func newFollowIndexService(db *sqlx.DB, ths core.TweetHelpService) core.IndexPostsService {
return &followIndexServant{
ths: ths,
sqlxServant: newSqlxServant(db),
stmtIndex: c(`SELECT * FROM @person WHERE first_name=?`),
}
}
func newLightIndexService(db *sqlx.DB, ths core.TweetHelpService) core.IndexPostsService {
return &lightIndexServant{
ths: ths,
sqlxServant: newSqlxServant(db),
stmtIndex: c(`SELECT * FROM @person WHERE first_name=?`),
}
}
func newSimpleIndexPostsService(db *sqlx.DB, ths core.TweetHelpService) core.IndexPostsService {
return &simpleIndexPostsServant{
ths: ths,
sqlxServant: newSqlxServant(db),
stmtIndex: c(`SELECT * FROM @person WHERE first_name=?`),
}
}

@ -1,137 +0,0 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package sakila
import (
"strings"
"time"
"github.com/jmoiron/sqlx"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/core/cs"
)
var (
_ core.TopicService = (*topicServant)(nil)
)
type topicServant struct {
*sqlxServant
stmtNewestTags *sqlx.Stmt
stmtHotTags *sqlx.Stmt
stmtTagsByKeywordA *sqlx.Stmt
stmtTagsByKeywordB *sqlx.Stmt
stmtInsertTag *sqlx.Stmt
sqlTagsByIdA string
sqlTagsByIdB string
sqlDecrTagsById string
sqlTagsForIncr string
sqlIncrTagsById string
}
func (s *topicServant) UpsertTags(userId int64, tags []string) (res cs.TagInfoList, xerr error) {
if len(tags) == 0 {
return nil, nil
}
xerr = s.with(func(tx *sqlx.Tx) error {
var upTags cs.TagInfoList
if err := s.inSelect(tx, &upTags, s.sqlTagsForIncr, tags); err != nil {
return err
}
now := time.Now().Unix()
if len(upTags) > 0 {
var ids []int64
for _, t := range upTags {
ids = append(ids, t.ID)
t.QuoteNum++
// prepare remain tags just delete updated tag
// notice ensure tags slice is distinct elements
for i, name := range tags {
if name == t.Tag {
lastIdx := len(tags) - 1
tags[i] = tags[lastIdx]
tags = tags[:lastIdx]
break
}
}
}
if _, err := s.inExec(tx, s.sqlIncrTagsById, now, ids); err != nil {
return err
}
res = append(res, upTags...)
}
// process remain tags if tags is not empty
if len(tags) == 0 {
return nil
}
var ids []int64
for _, tag := range tags {
res, err := s.stmtInsertTag.Exec(userId, tag, now, now)
if err != nil {
return err
}
id, err := res.LastInsertId()
if err != nil {
return err
}
ids = append(ids, id)
}
var newTags cs.TagInfoList
if err := s.inSelect(tx, &newTags, s.sqlTagsByIdB, ids); err != nil {
return err
}
res = append(res, newTags...)
return nil
})
return
}
func (s *topicServant) DecrTagsById(ids []int64) error {
return s.with(func(tx *sqlx.Tx) error {
var ids []int64
err := s.inSelect(tx, &ids, s.sqlTagsByIdA, ids)
if err != nil {
return err
}
_, err = s.inExec(tx, s.sqlDecrTagsById, time.Now().Unix(), ids)
return err
})
}
func (s *topicServant) ListTags(typ cs.TagType, limit int, offset int) (res cs.TagList, err error) {
switch typ {
case cs.TagTypeHot:
err = s.stmtHotTags.Select(&res, limit, offset)
case cs.TagTypeNew:
err = s.stmtNewestTags.Select(&res, limit, offset)
}
return
}
func (s *topicServant) TagsByKeyword(keyword string) (res cs.TagInfoList, err error) {
keyword = "%" + strings.Trim(keyword, " ") + "%"
if keyword == "%%" {
err = s.stmtTagsByKeywordA.Select(&res)
} else {
err = s.stmtTagsByKeywordB.Select(&res)
}
return
}
func newTopicService(db *sqlx.DB) core.TopicService {
return &topicServant{
sqlxServant: newSqlxServant(db),
stmtNewestTags: c(`SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.id DESC LIMIT ? OFFSET ?`),
stmtHotTags: c(`SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.quote_num DESC LIMIT ? OFFSET ?`),
stmtTagsByKeywordA: c(`SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6`),
stmtTagsByKeywordB: c(`SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6`),
stmtInsertTag: c(`INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1)`),
sqlTagsByIdA: t(`SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0`),
sqlTagsByIdB: t(`SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?)`),
sqlDecrTagsById: t(`UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?)`),
sqlTagsForIncr: t(`SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)`),
sqlIncrTagsById: t(`UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?)`),
}
}

@ -1,352 +0,0 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package sakila
import (
"github.com/jmoiron/sqlx"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/core/cs"
"github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr"
"github.com/rocboss/paopao-ce/pkg/debug"
"gorm.io/gorm"
)
var (
_ core.TweetService = (*tweetServant)(nil)
_ core.TweetManageService = (*tweetManageServant)(nil)
_ core.TweetHelpService = (*tweetHelpServant)(nil)
)
type tweetServant struct {
*sqlxServant
stmtGetTweet *sqlx.Stmt
stmtListTweet *sqlx.Stmt
stmtListStar *sqlx.Stmt
}
type tweetManageServant struct {
*sqlxServant
cacheIndex core.CacheIndexService
stmtAddTweet *sqlx.Stmt
stmtDelTweet *sqlx.Stmt
stmtStickTweet *sqlx.Stmt
}
type tweetHelpServant struct {
*sqlxServant
stmtAddTag *sqlx.Stmt
stmtDelTag *sqlx.Stmt
stmtListTag *sqlx.Stmt
}
// MergePosts post数据整合
func (s *tweetHelpServant) MergePosts(posts []*core.Post) ([]*core.PostFormated, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
// RevampPosts post数据整形修复
func (s *tweetHelpServant) RevampPosts(posts []*core.PostFormated) ([]*core.PostFormated, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetHelpServant) RevampTweets(tweets cs.TweetList) (cs.TweetList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetHelpServant) MergeTweets(tweets cs.TweetInfo) (cs.TweetList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetHelpServant) getPostContentsByIDs(ids []int64) ([]*dbr.PostContent, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetHelpServant) getUsersByIDs(ids []int64) ([]*dbr.User, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetManageServant) CreatePostCollection(postID, userID int64) (*core.PostCollection, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetManageServant) DeletePostCollection(p *core.PostCollection) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *tweetManageServant) CreatePostContent(content *core.PostContent) (*core.PostContent, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetManageServant) CreateAttachment(obj *cs.Attachment) (int64, error) {
// TODO
return 0, debug.ErrNotImplemented
}
func (s *tweetManageServant) CreatePost(post *core.Post) (*core.Post, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetManageServant) DeletePost(post *core.Post) ([]string, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetManageServant) deleteCommentByPostId(db *gorm.DB, postId int64) ([]string, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetManageServant) LockPost(post *core.Post) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *tweetManageServant) StickPost(post *core.Post) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *tweetManageServant) VisiblePost(post *core.Post, visibility core.PostVisibleT) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *tweetManageServant) UpdatePost(post *core.Post) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *tweetManageServant) CreatePostStar(postID, userID int64) (*core.PostStar, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetManageServant) DeletePostStar(p *core.PostStar) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *tweetManageServant) CreateTweet(userId int64, req *cs.NewTweetReq) (*cs.TweetItem, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetManageServant) DeleteTweet(userId int64, tweetId int64) ([]string, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetManageServant) LockTweet(userId int64, tweetId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageServant) StickTweet(userId int64, tweetId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageServant) VisibleTweet(userId int64, visibility cs.TweetVisibleType) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageServant) CreateReaction(userId int64, tweetId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageServant) DeleteReaction(userId int64, reactionId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageServant) CreateFavorite(userId int64, tweetId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetManageServant) DeleteFavorite(userId int64, favoriteId int64) error {
// TODO
return debug.ErrNotImplemented
}
func (s *tweetServant) GetPostByID(id int64) (*core.Post, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetServant) GetPosts(conditions *core.ConditionsT, offset, limit int) ([]*core.Post, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetServant) GetPostCount(conditions *core.ConditionsT) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
}
func (s *tweetServant) GetUserPostStar(postID, userID int64) (*core.PostStar, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetServant) GetUserPostStars(userID int64, offset, limit int) ([]*core.PostStar, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetServant) GetUserPostStarCount(userID int64) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
}
func (s *tweetServant) GetUserPostCollection(postID, userID int64) (*core.PostCollection, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetServant) GetUserPostCollections(userID int64, offset, limit int) ([]*core.PostCollection, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetServant) GetUserPostCollectionCount(userID int64) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
}
func (s *tweetServant) GetUserWalletBills(userID int64, offset, limit int) ([]*core.WalletStatement, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetServant) GetUserWalletBillCount(userID int64) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
}
func (s *tweetServant) GetPostAttatchmentBill(postID, userID int64) (*core.PostAttachmentBill, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetServant) GetPostContentsByIDs(ids []int64) ([]*core.PostContent, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetServant) GetPostContentByID(id int64) (*core.PostContent, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *tweetServant) TweetInfoById(id int64) (*cs.TweetInfo, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetServant) TweetItemById(id int64) (*cs.TweetItem, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetServant) UserTweets(visitorId, userId int64) (cs.TweetList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetServant) ReactionByTweetId(userId int64, tweetId int64) (*cs.ReactionItem, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetServant) UserReactions(userId int64, offset int, limit int) (cs.ReactionList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetServant) FavoriteByTweetId(userId int64, tweetId int64) (*cs.FavoriteItem, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetServant) UserFavorites(userId int64, offset int, limit int) (cs.FavoriteList, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func (s *tweetServant) AttachmentByTweetId(userId int64, tweetId int64) (*cs.AttachmentBill, error) {
// TODO
return nil, debug.ErrNotImplemented
}
func newTweetService(db *sqlx.DB) core.TweetService {
return &tweetServant{
sqlxServant: newSqlxServant(db),
stmtGetTweet: c(`SELECT * FROM @person WHERE first_name=?`),
stmtListTweet: c(`SELECT * FROM @person WHERE first_name=?`),
stmtListStar: c(`SELECT * FROM @person WHERE first_name=?`),
}
}
func newTweetManageService(db *sqlx.DB, cacheIndex core.CacheIndexService) core.TweetManageService {
return &tweetManageServant{
sqlxServant: newSqlxServant(db),
cacheIndex: cacheIndex,
stmtAddTweet: c(`SELECT * FROM @person WHERE first_name=?`),
stmtDelTweet: c(`SELECT * FROM @person WHERE first_name=?`),
stmtStickTweet: c(`SELECT * FROM @person WHERE first_name=?`),
}
}
func newTweetHelpService(db *sqlx.DB) core.TweetHelpService {
return &tweetHelpServant{
sqlxServant: newSqlxServant(db),
stmtAddTag: c(`SELECT * FROM @person WHERE first_name=?`),
stmtDelTag: c(`SELECT * FROM @person WHERE first_name=?`),
stmtListTag: c(`SELECT * FROM @person WHERE first_name=?`),
}
}

@ -1,73 +0,0 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package sakila
import (
"github.com/jmoiron/sqlx"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/pkg/debug"
)
var (
_ core.UserManageService = (*userManageServant)(nil)
)
type userManageServant struct {
*sqlxServant
stmtAddUser *sqlx.Stmt
stmtUpdateUser *sqlx.Stmt
stmtGetUser *sqlx.Stmt
}
func (s *userManageServant) GetUserByID(id int64) (*core.User, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *userManageServant) GetUserByUsername(username string) (*core.User, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *userManageServant) GetUserByPhone(phone string) (*core.User, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *userManageServant) GetUsersByIDs(ids []int64) ([]*core.User, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *userManageServant) GetUsersByKeyword(keyword string) ([]*core.User, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *userManageServant) CreateUser(user *core.User) (*core.User, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *userManageServant) UpdateUser(user *core.User) error {
// TODO
debug.NotImplemented()
return nil
}
func newUserManageService(db *sqlx.DB) core.UserManageService {
return &userManageServant{
sqlxServant: newSqlxServant(db),
stmtAddUser: c(`SELECT * FROM @person WHERE first_name=?`),
stmtUpdateUser: c(`SELECT * FROM @person WHERE first_name=?`),
stmtGetUser: c(`SELECT * FROM @person WHERE first_name=?`),
}
}

@ -1,66 +0,0 @@
// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package sakila
import (
"github.com/jmoiron/sqlx"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/pkg/debug"
)
var (
_ core.WalletService = (*walletServant)(nil)
)
type walletServant struct {
*sqlxServant
stmtAddRecharge *sqlx.Stmt
stmtGetRecharge *sqlx.Stmt
stmtGetBills *sqlx.Stmt
}
func (s *walletServant) GetRechargeByID(id int64) (*core.WalletRecharge, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *walletServant) CreateRecharge(userId, amount int64) (*core.WalletRecharge, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *walletServant) GetUserWalletBills(userID int64, offset, limit int) ([]*core.WalletStatement, error) {
// TODO
debug.NotImplemented()
return nil, nil
}
func (s *walletServant) GetUserWalletBillCount(userID int64) (int64, error) {
// TODO
debug.NotImplemented()
return 0, nil
}
func (s *walletServant) HandleRechargeSuccess(recharge *core.WalletRecharge, tradeNo string) error {
// TODO
debug.NotImplemented()
return nil
}
func (s *walletServant) HandlePostAttachmentBought(post *core.Post, user *core.User) error {
// TODO
debug.NotImplemented()
return nil
}
func newWalletService(db *sqlx.DB) core.WalletService {
return &walletServant{
sqlxServant: newSqlxServant(db),
stmtAddRecharge: c(`SELECT * FROM @person WHERE first_name=?`),
stmtGetRecharge: c(`SELECT * FROM @person WHERE first_name=?`),
stmtGetBills: c(`SELECT * FROM @person WHERE first_name=?`),
}
}
Loading…
Cancel
Save