diff --git a/internal/core/authority.go b/internal/core/authority.go index 05e3742a..31a43be4 100644 --- a/internal/core/authority.go +++ b/internal/core/authority.go @@ -5,119 +5,13 @@ package core import ( - "github.com/rocboss/paopao-ce/pkg/types" + "github.com/rocboss/paopao-ce/internal/core/ms" ) -const ( - ActRegisterUser act = iota - ActCreatePublicTweet - ActCreatePublicAttachment - ActCreatePublicPicture - ActCreatePublicVideo - ActCreatePrivateTweet - ActCreatePrivateAttachment - ActCreatePrivatePicture - ActCreatePrivateVideo - ActCreateFriendTweet - ActCreateFriendAttachment - ActCreateFriendPicture - ActCreateFriendVideo - ActCreatePublicComment - ActCreatePublicPicureComment - ActCreateFriendComment - ActCreateFriendPicureComment - ActCreatePrivateComment - ActCreatePrivatePicureComment - ActStickTweet - ActTopTweet - ActLockTweet - ActVisibleTweet - ActDeleteTweet - ActCreateActivationCode -) - -type ( - act uint8 - - FriendFilter map[int64]types.Empty - FriendSet map[string]types.Empty - - Action struct { - Act act - UserId int64 - } -) - -func (f FriendFilter) IsFriend(userId int64) bool { - _, yeah := f[userId] - return yeah -} - -// IsAllow default true if user is admin -func (a act) IsAllow(user *User, userId int64, isFriend bool, isActivation bool) bool { - if user.IsAdmin { - return true - } - if user.ID == userId && isActivation { - switch a { - case ActCreatePublicTweet, - ActCreatePublicAttachment, - ActCreatePublicPicture, - ActCreatePublicVideo, - ActCreatePrivateTweet, - ActCreatePrivateAttachment, - ActCreatePrivatePicture, - ActCreatePrivateVideo, - ActCreateFriendTweet, - ActCreateFriendAttachment, - ActCreateFriendPicture, - ActCreateFriendVideo, - ActCreatePrivateComment, - ActCreatePrivatePicureComment, - ActStickTweet, - ActLockTweet, - ActVisibleTweet, - ActDeleteTweet: - return true - } - } - - if user.ID == userId && !isActivation { - switch a { - case ActCreatePrivateTweet, - ActCreatePrivateComment, - ActStickTweet, - ActLockTweet, - ActDeleteTweet: - return true - } - } - - if isFriend && isActivation { - switch a { - case ActCreatePublicComment, - ActCreatePublicPicureComment, - ActCreateFriendComment, - ActCreateFriendPicureComment: - return true - } - } - - if !isFriend && isActivation { - switch a { - case ActCreatePublicComment, - ActCreatePublicPicureComment: - return true - } - } - - return false -} - // AuthorizationManageService 授权管理服务 type AuthorizationManageService interface { - IsAllow(user *User, action *Action) bool - BeFriendFilter(userId int64) FriendFilter + IsAllow(user *ms.User, action *ms.Action) bool + BeFriendFilter(userId int64) ms.FriendFilter BeFriendIds(userId int64) ([]int64, error) - MyFriendSet(userId int64) FriendSet + MyFriendSet(userId int64) ms.FriendSet } diff --git a/internal/core/cache.go b/internal/core/cache.go index e6963c61..8d8c3b42 100644 --- a/internal/core/cache.go +++ b/internal/core/cache.go @@ -8,6 +8,7 @@ import ( "context" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" ) @@ -51,7 +52,7 @@ func (a IdxAct) String() string { } } -func NewIndexAction(act IdxAct, post *dbr.Post) *IndexAction { +func NewIndexAction(act IdxAct, post *ms.Post) *IndexAction { return &IndexAction{ Act: act, Post: post, diff --git a/internal/core/comments.go b/internal/core/comments.go index 88dcf432..cf917a82 100644 --- a/internal/core/comments.go +++ b/internal/core/comments.go @@ -6,35 +6,27 @@ package core import ( "github.com/rocboss/paopao-ce/internal/core/cs" - "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" -) - -type ( - Comment = dbr.Comment - CommentFormated = dbr.CommentFormated - CommentReply = dbr.CommentReply - CommentContent = dbr.CommentContent - CommentReplyFormated = dbr.CommentReplyFormated + "github.com/rocboss/paopao-ce/internal/core/ms" ) // CommentService 评论检索服务 type CommentService interface { - GetComments(conditions *ConditionsT, offset, limit int) ([]*Comment, error) - GetCommentByID(id int64) (*Comment, error) - GetCommentCount(conditions *ConditionsT) (int64, error) - GetCommentReplyByID(id int64) (*CommentReply, error) - GetCommentContentsByIDs(ids []int64) ([]*CommentContent, error) - GetCommentRepliesByID(ids []int64) ([]*CommentReplyFormated, error) + GetComments(conditions *ms.ConditionsT, offset, limit int) ([]*ms.Comment, error) + GetCommentByID(id int64) (*ms.Comment, error) + GetCommentCount(conditions *ms.ConditionsT) (int64, error) + GetCommentReplyByID(id int64) (*ms.CommentReply, error) + GetCommentContentsByIDs(ids []int64) ([]*ms.CommentContent, error) + GetCommentRepliesByID(ids []int64) ([]*ms.CommentReplyFormated, error) GetCommentThumbsMap(userId int64, tweetId int64) (cs.CommentThumbsMap, cs.CommentThumbsMap, error) } // CommentManageService 评论管理服务 type CommentManageService interface { - DeleteComment(comment *Comment) error - CreateComment(comment *Comment) (*Comment, error) - CreateCommentReply(reply *CommentReply) (*CommentReply, error) - DeleteCommentReply(reply *CommentReply) error - CreateCommentContent(content *CommentContent) (*CommentContent, error) + DeleteComment(comment *ms.Comment) error + CreateComment(comment *ms.Comment) (*ms.Comment, error) + CreateCommentReply(reply *ms.CommentReply) (*ms.CommentReply, error) + DeleteCommentReply(reply *ms.CommentReply) error + CreateCommentContent(content *ms.CommentContent) (*ms.CommentContent, error) ThumbsUpComment(userId int64, tweetId, commentId int64) error ThumbsDownComment(userId int64, tweetId, commentId int64) error ThumbsUpReply(userId int64, tweetId, commentId, replyId int64) error diff --git a/internal/core/messages.go b/internal/core/messages.go index 57816480..519e4e49 100644 --- a/internal/core/messages.go +++ b/internal/core/messages.go @@ -5,32 +5,15 @@ package core import ( - "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" -) - -const ( - MsgTypePost = dbr.MsgTypePost - MsgtypeComment = dbr.MsgtypeComment - MsgTypeReply = dbr.MsgTypeReply - MsgTypeWhisper = dbr.MsgTypeWhisper - MsgTypeRequestingFriend = dbr.MsgTypeRequestingFriend - MsgTypeSystem = dbr.MsgTypeSystem - - MsgStatusUnread = dbr.MsgStatusUnread - MsgStatusReaded = dbr.MsgStatusReaded -) - -type ( - Message = dbr.Message - MessageFormated = dbr.MessageFormated + "github.com/rocboss/paopao-ce/internal/core/ms" ) // MessageService 消息服务 type MessageService interface { - CreateMessage(msg *Message) (*Message, error) + CreateMessage(msg *ms.Message) (*ms.Message, error) GetUnreadCount(userID int64) (int64, error) - GetMessageByID(id int64) (*Message, error) - ReadMessage(message *Message) error - GetMessages(conditions *ConditionsT, offset, limit int) ([]*MessageFormated, error) - GetMessageCount(conditions *ConditionsT) (int64, error) + GetMessageByID(id int64) (*ms.Message, error) + ReadMessage(message *ms.Message) error + GetMessages(conditions *ms.ConditionsT, offset, limit int) ([]*ms.MessageFormated, error) + GetMessageCount(conditions *ms.ConditionsT) (int64, error) } diff --git a/internal/core/ms/authority.go b/internal/core/ms/authority.go new file mode 100644 index 00000000..d6378696 --- /dev/null +++ b/internal/core/ms/authority.go @@ -0,0 +1,115 @@ +// 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 ms + +import ( + "github.com/rocboss/paopao-ce/pkg/types" +) + +const ( + ActRegisterUser act = iota + ActCreatePublicTweet + ActCreatePublicAttachment + ActCreatePublicPicture + ActCreatePublicVideo + ActCreatePrivateTweet + ActCreatePrivateAttachment + ActCreatePrivatePicture + ActCreatePrivateVideo + ActCreateFriendTweet + ActCreateFriendAttachment + ActCreateFriendPicture + ActCreateFriendVideo + ActCreatePublicComment + ActCreatePublicPicureComment + ActCreateFriendComment + ActCreateFriendPicureComment + ActCreatePrivateComment + ActCreatePrivatePicureComment + ActStickTweet + ActTopTweet + ActLockTweet + ActVisibleTweet + ActDeleteTweet + ActCreateActivationCode +) + +type ( + act uint8 + + FriendFilter map[int64]types.Empty + FriendSet map[string]types.Empty + + Action struct { + Act act + UserId int64 + } +) + +func (f FriendFilter) IsFriend(userId int64) bool { + _, yeah := f[userId] + return yeah +} + +// IsAllow default true if user is admin +func (a act) IsAllow(user *User, userId int64, isFriend bool, isActivation bool) bool { + if user.IsAdmin { + return true + } + if user.ID == userId && isActivation { + switch a { + case ActCreatePublicTweet, + ActCreatePublicAttachment, + ActCreatePublicPicture, + ActCreatePublicVideo, + ActCreatePrivateTweet, + ActCreatePrivateAttachment, + ActCreatePrivatePicture, + ActCreatePrivateVideo, + ActCreateFriendTweet, + ActCreateFriendAttachment, + ActCreateFriendPicture, + ActCreateFriendVideo, + ActCreatePrivateComment, + ActCreatePrivatePicureComment, + ActStickTweet, + ActLockTweet, + ActVisibleTweet, + ActDeleteTweet: + return true + } + } + + if user.ID == userId && !isActivation { + switch a { + case ActCreatePrivateTweet, + ActCreatePrivateComment, + ActStickTweet, + ActLockTweet, + ActDeleteTweet: + return true + } + } + + if isFriend && isActivation { + switch a { + case ActCreatePublicComment, + ActCreatePublicPicureComment, + ActCreateFriendComment, + ActCreateFriendPicureComment: + return true + } + } + + if !isFriend && isActivation { + switch a { + case ActCreatePublicComment, + ActCreatePublicPicureComment: + return true + } + } + + return false +} diff --git a/internal/core/ms/comments.go b/internal/core/ms/comments.go new file mode 100644 index 00000000..87ef2473 --- /dev/null +++ b/internal/core/ms/comments.go @@ -0,0 +1,17 @@ +// 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 ms + +import ( + "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" +) + +type ( + Comment = dbr.Comment + CommentFormated = dbr.CommentFormated + CommentReply = dbr.CommentReply + CommentContent = dbr.CommentContent + CommentReplyFormated = dbr.CommentReplyFormated +) diff --git a/internal/core/ms/messages.go b/internal/core/ms/messages.go new file mode 100644 index 00000000..adf793f8 --- /dev/null +++ b/internal/core/ms/messages.go @@ -0,0 +1,26 @@ +// 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 ms + +import ( + "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" +) + +const ( + MsgTypePost = dbr.MsgTypePost + MsgtypeComment = dbr.MsgtypeComment + MsgTypeReply = dbr.MsgTypeReply + MsgTypeWhisper = dbr.MsgTypeWhisper + MsgTypeRequestingFriend = dbr.MsgTypeRequestingFriend + MsgTypeSystem = dbr.MsgTypeSystem + + MsgStatusUnread = dbr.MsgStatusUnread + MsgStatusReaded = dbr.MsgStatusReaded +) + +type ( + Message = dbr.Message + MessageFormated = dbr.MessageFormated +) diff --git a/internal/core/types.go b/internal/core/ms/ms.go similarity index 79% rename from internal/core/types.go rename to internal/core/ms/ms.go index 6ca95893..8993251f 100644 --- a/internal/core/types.go +++ b/internal/core/ms/ms.go @@ -1,8 +1,10 @@ -// Copyright 2022 ROC. All rights reserved. +// 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 core +// Package ms contain core data service interface type +// model define for gorm adapter +package ms import ( "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" diff --git a/internal/core/ms/security.go b/internal/core/ms/security.go new file mode 100644 index 00000000..a6610ca1 --- /dev/null +++ b/internal/core/ms/security.go @@ -0,0 +1,13 @@ +// 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 ms + +import ( + "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" +) + +type ( + Captcha = dbr.Captcha +) diff --git a/internal/core/ms/timeline.go b/internal/core/ms/timeline.go new file mode 100644 index 00000000..eb1169f4 --- /dev/null +++ b/internal/core/ms/timeline.go @@ -0,0 +1,10 @@ +// 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 ms + +type IndexTweetList struct { + Tweets []*PostFormated + Total int64 +} diff --git a/internal/core/ms/tweets.go b/internal/core/ms/tweets.go new file mode 100644 index 00000000..230775ff --- /dev/null +++ b/internal/core/ms/tweets.go @@ -0,0 +1,35 @@ +// 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 ms + +import ( + "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" +) + +const ( + AttachmentTypeImage = dbr.AttachmentTypeImage + AttachmentTypeVideo = dbr.AttachmentTypeVideo + AttachmentTypeOther = dbr.AttachmentTypeOther + + // 类型,1标题,2文字段落,3图片地址,4视频地址,5语音地址,6链接地址,7附件资源 + ContentTypeTitle = dbr.ContentTypeTitle + ContentTypeText = dbr.ContentTypeText + ContentTypeImage = dbr.ContentTypeImage + ContentTypeVideo = dbr.ContentTypeVideo + ContentTypeAudio = dbr.ContentTypeAudio + ContentTypeLink = dbr.ContentTypeLink + ContentTypeAttachment = dbr.ContentTypeAttachment + ContentTypeChargeAttachment = dbr.ContentTypeChargeAttachment +) + +type ( + PostStar = dbr.PostStar + PostCollection = dbr.PostCollection + PostAttachmentBill = dbr.PostAttachmentBill + PostContent = dbr.PostContent + Attachment = dbr.Attachment + AttachmentType = dbr.AttachmentType + PostContentT = dbr.PostContentT +) diff --git a/internal/core/ms/user.go b/internal/core/ms/user.go new file mode 100644 index 00000000..4c7ea8ab --- /dev/null +++ b/internal/core/ms/user.go @@ -0,0 +1,20 @@ +// 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 ms + +type ( + ContactItem struct { + UserId int64 `json:"user_id"` + UserName string `json:"username"` + Nickname string `json:"nickname"` + Avatar string `json:"avatar"` + Phone string `json:"phone"` + } + + ContactList struct { + Contacts []ContactItem `json:"contacts"` + Total int64 `json:"total"` + } +) diff --git a/internal/core/ms/wallet.go b/internal/core/ms/wallet.go new file mode 100644 index 00000000..5786fcac --- /dev/null +++ b/internal/core/ms/wallet.go @@ -0,0 +1,14 @@ +// 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 ms + +import ( + "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" +) + +type ( + WalletStatement = dbr.WalletStatement + WalletRecharge = dbr.WalletRecharge +) diff --git a/internal/core/search.go b/internal/core/search.go index 17b65fad..dc08e127 100644 --- a/internal/core/search.go +++ b/internal/core/search.go @@ -5,6 +5,7 @@ package core import ( + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" ) @@ -33,12 +34,12 @@ type ( } QueryResp struct { - Items []*PostFormated + Items []*ms.PostFormated Total int64 } TsDocItem struct { - Post *Post + Post *ms.Post Content string } ) @@ -48,5 +49,5 @@ type TweetSearchService interface { IndexName() string AddDocuments(data []TsDocItem, primaryKey ...string) (bool, error) DeleteDocuments(identifiers []string) error - Search(user *User, q *QueryReq, offset, limit int) (*QueryResp, error) + Search(user *ms.User, q *QueryReq, offset, limit int) (*QueryResp, error) } diff --git a/internal/core/security.go b/internal/core/security.go index ce313635..0643cc28 100644 --- a/internal/core/security.go +++ b/internal/core/security.go @@ -7,17 +7,13 @@ package core import ( "time" - "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" -) - -type ( - Captcha = dbr.Captcha + "github.com/rocboss/paopao-ce/internal/core/ms" ) // SecurityService 安全相关服务 type SecurityService interface { - GetLatestPhoneCaptcha(phone string) (*Captcha, error) - UsePhoneCaptcha(captcha *Captcha) error + GetLatestPhoneCaptcha(phone string) (*ms.Captcha, error) + UsePhoneCaptcha(captcha *ms.Captcha) error SendPhoneCaptcha(phone string) error } diff --git a/internal/core/timeline.go b/internal/core/timeline.go index 02de2b62..722e79f3 100644 --- a/internal/core/timeline.go +++ b/internal/core/timeline.go @@ -6,19 +6,15 @@ package core import ( "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" ) -type IndexTweetList struct { - Tweets []*PostFormated - Total int64 -} - // IndexPostsService 广场首页推文列表服务 type IndexPostsService interface { - IndexPosts(user *User, offset int, limit int) (*IndexTweetList, error) + IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) } // IndexPostsServantA 广场首页推文列表服务(版本A) type IndexPostsServantA interface { - IndexPosts(user *User, limit int, offset int) (*cs.TweetBox, error) + IndexPosts(user *ms.User, limit int, offset int) (*cs.TweetBox, error) } diff --git a/internal/core/tweets.go b/internal/core/tweets.go index 9c316257..4ea9126d 100644 --- a/internal/core/tweets.go +++ b/internal/core/tweets.go @@ -6,71 +6,45 @@ package core import ( "github.com/rocboss/paopao-ce/internal/core/cs" - "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" -) - -const ( - AttachmentTypeImage = dbr.AttachmentTypeImage - AttachmentTypeVideo = dbr.AttachmentTypeVideo - AttachmentTypeOther = dbr.AttachmentTypeOther - - // 类型,1标题,2文字段落,3图片地址,4视频地址,5语音地址,6链接地址,7附件资源 - ContentTypeTitle = dbr.ContentTypeTitle - ContentTypeText = dbr.ContentTypeText - ContentTypeImage = dbr.ContentTypeImage - ContentTypeVideo = dbr.ContentTypeVideo - ContentTypeAudio = dbr.ContentTypeAudio - ContentTypeLink = dbr.ContentTypeLink - ContentTypeAttachment = dbr.ContentTypeAttachment - ContentTypeChargeAttachment = dbr.ContentTypeChargeAttachment -) - -type ( - PostStar = dbr.PostStar - PostCollection = dbr.PostCollection - PostAttachmentBill = dbr.PostAttachmentBill - PostContent = dbr.PostContent - Attachment = dbr.Attachment - AttachmentType = dbr.AttachmentType - PostContentT = dbr.PostContentT + "github.com/rocboss/paopao-ce/internal/core/ms" ) // TweetService 推文检索服务 type TweetService interface { - GetPostByID(id int64) (*Post, error) - GetPosts(conditions *ConditionsT, offset, limit int) ([]*Post, error) - GetPostCount(conditions *ConditionsT) (int64, error) - GetUserPostStar(postID, userID int64) (*PostStar, error) - GetUserPostStars(userID int64, offset, limit int) ([]*PostStar, error) + GetPostByID(id int64) (*ms.Post, error) + GetPosts(conditions *ms.ConditionsT, offset, limit int) ([]*ms.Post, error) + GetPostCount(conditions *ms.ConditionsT) (int64, error) + GetUserPostStar(postID, userID int64) (*ms.PostStar, error) + GetUserPostStars(userID int64, offset, limit int) ([]*ms.PostStar, error) GetUserPostStarCount(userID int64) (int64, error) - GetUserPostCollection(postID, userID int64) (*PostCollection, error) - GetUserPostCollections(userID int64, offset, limit int) ([]*PostCollection, error) + GetUserPostCollection(postID, userID int64) (*ms.PostCollection, error) + GetUserPostCollections(userID int64, offset, limit int) ([]*ms.PostCollection, error) GetUserPostCollectionCount(userID int64) (int64, error) - GetPostAttatchmentBill(postID, userID int64) (*PostAttachmentBill, error) - GetPostContentsByIDs(ids []int64) ([]*PostContent, error) - GetPostContentByID(id int64) (*PostContent, error) + GetPostAttatchmentBill(postID, userID int64) (*ms.PostAttachmentBill, error) + GetPostContentsByIDs(ids []int64) ([]*ms.PostContent, error) + GetPostContentByID(id int64) (*ms.PostContent, error) } // TweetManageService 推文管理服务,包括创建/删除/更新推文 type TweetManageService interface { - CreatePost(post *Post) (*Post, error) - DeletePost(post *Post) ([]string, error) - LockPost(post *Post) error - StickPost(post *Post) error - VisiblePost(post *Post, visibility PostVisibleT) error - UpdatePost(post *Post) error - CreatePostStar(postID, userID int64) (*PostStar, error) - DeletePostStar(p *PostStar) error - CreatePostCollection(postID, userID int64) (*PostCollection, error) - DeletePostCollection(p *PostCollection) error - CreatePostContent(content *PostContent) (*PostContent, error) + CreatePost(post *ms.Post) (*ms.Post, error) + DeletePost(post *ms.Post) ([]string, error) + LockPost(post *ms.Post) error + StickPost(post *ms.Post) error + VisiblePost(post *ms.Post, visibility PostVisibleT) error + UpdatePost(post *ms.Post) error + CreatePostStar(postID, userID int64) (*ms.PostStar, error) + DeletePostStar(p *ms.PostStar) error + CreatePostCollection(postID, userID int64) (*ms.PostCollection, error) + DeletePostCollection(p *ms.PostCollection) error + CreatePostContent(content *ms.PostContent) (*ms.PostContent, error) CreateAttachment(obj *cs.Attachment) (int64, error) } // TweetHelpService 推文辅助服务 type TweetHelpService interface { - RevampPosts(posts []*PostFormated) ([]*PostFormated, error) - MergePosts(posts []*Post) ([]*PostFormated, error) + RevampPosts(posts []*ms.PostFormated) ([]*ms.PostFormated, error) + MergePosts(posts []*ms.Post) ([]*ms.PostFormated, error) } // TweetServantA 推文检索服务(版本A) diff --git a/internal/core/user.go b/internal/core/user.go index ed132dd3..04d30e23 100644 --- a/internal/core/user.go +++ b/internal/core/user.go @@ -4,30 +4,17 @@ package core -type ( - ContactItem struct { - UserId int64 `json:"user_id"` - UserName string `json:"username"` - Nickname string `json:"nickname"` - Avatar string `json:"avatar"` - Phone string `json:"phone"` - } - - ContactList struct { - Contacts []ContactItem `json:"contacts"` - Total int64 `json:"total"` - } -) +import "github.com/rocboss/paopao-ce/internal/core/ms" // UserManageService 用户管理服务 type UserManageService interface { - GetUserByID(id int64) (*User, error) - GetUserByUsername(username string) (*User, error) - GetUserByPhone(phone string) (*User, error) - GetUsersByIDs(ids []int64) ([]*User, error) - GetUsersByKeyword(keyword string) ([]*User, error) - CreateUser(user *User) (*User, error) - UpdateUser(user *User) error + GetUserByID(id int64) (*ms.User, error) + GetUserByUsername(username string) (*ms.User, error) + GetUserByPhone(phone string) (*ms.User, error) + GetUsersByIDs(ids []int64) ([]*ms.User, error) + GetUsersByKeyword(keyword string) ([]*ms.User, error) + CreateUser(user *ms.User) (*ms.User, error) + UpdateUser(user *ms.User) error } // ContactManageService 联系人管理服务 @@ -36,6 +23,6 @@ type ContactManageService interface { AddFriend(userId int64, friendId int64) error RejectFriend(userId int64, friendId int64) error DeleteFriend(userId int64, friendId int64) error - GetContacts(userId int64, offset int, limit int) (*ContactList, error) + GetContacts(userId int64, offset int, limit int) (*ms.ContactList, error) IsFriend(userID int64, friendID int64) bool } diff --git a/internal/core/wallet.go b/internal/core/wallet.go index c4792d3b..e452a3ad 100644 --- a/internal/core/wallet.go +++ b/internal/core/wallet.go @@ -5,20 +5,15 @@ package core import ( - "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" -) - -type ( - WalletStatement = dbr.WalletStatement - WalletRecharge = dbr.WalletRecharge + "github.com/rocboss/paopao-ce/internal/core/ms" ) // WalletService wallet service interface type WalletService interface { - GetUserWalletBills(userID int64, offset, limit int) ([]*WalletStatement, error) + GetUserWalletBills(userID int64, offset, limit int) ([]*ms.WalletStatement, error) GetUserWalletBillCount(userID int64) (int64, error) - GetRechargeByID(id int64) (*WalletRecharge, error) - CreateRecharge(userId, amount int64) (*WalletRecharge, error) - HandleRechargeSuccess(recharge *WalletRecharge, tradeNo string) error - HandlePostAttachmentBought(post *Post, user *User) error + GetRechargeByID(id int64) (*ms.WalletRecharge, error) + CreateRecharge(userId, amount int64) (*ms.WalletRecharge, error) + HandleRechargeSuccess(recharge *ms.WalletRecharge, tradeNo string) error + HandlePostAttachmentBought(post *ms.Post, user *ms.User) error } diff --git a/internal/dao/cache/base.go b/internal/dao/cache/base.go index f8f1e270..fe314683 100644 --- a/internal/dao/cache/base.go +++ b/internal/dao/cache/base.go @@ -15,6 +15,7 @@ import ( "github.com/Masterminds/semver/v3" "github.com/rocboss/paopao-ce/internal/conf" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/pkg/types" "github.com/sirupsen/logrus" ) @@ -30,7 +31,7 @@ var ( type postsEntry struct { key string - tweets *core.IndexTweetList + tweets *ms.IndexTweetList } type tweetsCache interface { @@ -54,7 +55,7 @@ type cacheIndexSrv struct { preventDuration time.Duration } -func (s *cacheIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *cacheIndexSrv) IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { key := s.keyFrom(user, offset, limit) posts, err := s.getPosts(key) if err == nil { @@ -70,7 +71,7 @@ func (s *cacheIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*cor return posts, nil } -func (s *cacheIndexSrv) getPosts(key string) (*core.IndexTweetList, error) { +func (s *cacheIndexSrv) getPosts(key string) (*ms.IndexTweetList, error) { data, err := s.cache.getTweetsBytes(key) if err != nil { logrus.Debugf("cacheIndexSrv.getPosts get posts by key: %s from cache err: %v", key, err) @@ -78,7 +79,7 @@ func (s *cacheIndexSrv) getPosts(key string) (*core.IndexTweetList, error) { } buf := bytes.NewBuffer(data) dec := gob.NewDecoder(buf) - var resp core.IndexTweetList + var resp ms.IndexTweetList if err := dec.Decode(&resp); err != nil { logrus.Debugf("cacheIndexSrv.getPosts get posts from cache in decode err: %v", err) return nil, err @@ -86,7 +87,7 @@ func (s *cacheIndexSrv) getPosts(key string) (*core.IndexTweetList, error) { return &resp, nil } -func (s *cacheIndexSrv) cachePosts(key string, tweets *core.IndexTweetList) { +func (s *cacheIndexSrv) cachePosts(key string, tweets *ms.IndexTweetList) { entry := &postsEntry{key: key, tweets: tweets} select { case s.cachePostsCh <- entry: @@ -112,7 +113,7 @@ func (s *cacheIndexSrv) setPosts(entry *postsEntry) { logrus.Debugf("cacheIndexSrv.setPosts setPosts set cache by key: %s", entry.key) } -func (s *cacheIndexSrv) keyFrom(user *core.User, offset int, limit int) string { +func (s *cacheIndexSrv) keyFrom(user *ms.User, offset int, limit int) string { var userId int64 = -1 if user != nil { userId = user.ID @@ -120,7 +121,7 @@ func (s *cacheIndexSrv) keyFrom(user *core.User, offset int, limit int) string { return fmt.Sprintf("%s:%d:%d:%d", _cacheIndexKey, userId, offset, limit) } -func (s *cacheIndexSrv) SendAction(act core.IdxAct, post *core.Post) { +func (s *cacheIndexSrv) SendAction(act core.IdxAct, post *ms.Post) { action := core.NewIndexAction(act, post) select { case s.indexActionCh <- action: @@ -168,7 +169,7 @@ func (s *cacheIndexSrv) handleIndexAction(action *core.IndexAction) { func (s *cacheIndexSrv) deleteCacheByUserId(id int64, oneself bool) { var keys []string userId := strconv.FormatInt(id, 10) - friendSet := core.FriendSet{} + friendSet := ms.FriendSet{} if !oneself { friendSet = s.ams.MyFriendSet(id) } diff --git a/internal/dao/cache/none.go b/internal/dao/cache/none.go index 350e776a..079c453b 100644 --- a/internal/dao/cache/none.go +++ b/internal/dao/cache/none.go @@ -8,6 +8,7 @@ import ( "github.com/Masterminds/semver/v3" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -20,7 +21,7 @@ type noneCacheIndexServant struct { ips core.IndexPostsService } -func (s *noneCacheIndexServant) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *noneCacheIndexServant) IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { return s.ips.IndexPosts(user, offset, limit) } @@ -29,7 +30,7 @@ func (s *noneCacheIndexServant) TweetTimeline(userId int64, offset int, limit in return nil, debug.ErrNotImplemented } -func (s *noneCacheIndexServant) SendAction(_act core.IdxAct, _post *core.Post) { +func (s *noneCacheIndexServant) SendAction(_act core.IdxAct, _post *ms.Post) { // empty } diff --git a/internal/dao/cache/simple.go b/internal/dao/cache/simple.go index fb704bfc..a1c230d3 100644 --- a/internal/dao/cache/simple.go +++ b/internal/dao/cache/simple.go @@ -11,6 +11,7 @@ import ( "github.com/Masterminds/semver/v3" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/pkg/debug" "github.com/sirupsen/logrus" ) @@ -24,21 +25,21 @@ type simpleCacheIndexServant struct { ips core.IndexPostsService indexActionCh chan core.IdxAct - indexPosts *core.IndexTweetList + indexPosts *ms.IndexTweetList atomicIndex atomic.Value maxIndexSize int checkTick *time.Ticker expireIndexTick *time.Ticker } -func (s *simpleCacheIndexServant) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { - cacheResp := s.atomicIndex.Load().(*core.IndexTweetList) +func (s *simpleCacheIndexServant) IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { + cacheResp := s.atomicIndex.Load().(*ms.IndexTweetList) end := offset + limit if cacheResp != nil { size := len(cacheResp.Tweets) logrus.Debugf("simpleCacheIndexServant.IndexPosts get index posts from cache posts: %d offset:%d limit:%d start:%d, end:%d", size, offset, limit, offset, end) if size >= end { - return &core.IndexTweetList{ + return &ms.IndexTweetList{ Tweets: cacheResp.Tweets[offset:end], Total: cacheResp.Total, }, nil @@ -54,7 +55,7 @@ func (s *simpleCacheIndexServant) TweetTimeline(userId int64, offset int, limit return nil, debug.ErrNotImplemented } -func (s *simpleCacheIndexServant) SendAction(act core.IdxAct, _post *core.Post) { +func (s *simpleCacheIndexServant) SendAction(act core.IdxAct, _post *ms.Post) { select { case s.indexActionCh <- act: logrus.Debugf("simpleCacheIndexServant.SendAction send indexAction by chan: %s", act) diff --git a/internal/dao/jinzhu/authority.go b/internal/dao/jinzhu/authority.go index 3480ceb0..9921f214 100644 --- a/internal/dao/jinzhu/authority.go +++ b/internal/dao/jinzhu/authority.go @@ -6,6 +6,7 @@ package jinzhu import ( "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/rocboss/paopao-ce/pkg/types" "gorm.io/gorm" @@ -25,7 +26,7 @@ func newAuthorizationManageService(db *gorm.DB) core.AuthorizationManageService } } -func (s *authorizationManageSrv) IsAllow(user *core.User, action *core.Action) bool { +func (s *authorizationManageSrv) IsAllow(user *ms.User, action *ms.Action) bool { // user is activation if had bind phone isActivation := (len(user.Phone) != 0) isFriend := s.isFriend(user.ID, action.UserId) @@ -33,26 +34,26 @@ func (s *authorizationManageSrv) IsAllow(user *core.User, action *core.Action) b return action.Act.IsAllow(user, action.UserId, isFriend, isActivation) } -func (s *authorizationManageSrv) MyFriendSet(userId int64) core.FriendSet { +func (s *authorizationManageSrv) MyFriendSet(userId int64) ms.FriendSet { ids, err := (&dbr.Contact{UserId: userId}).MyFriendIds(s.db) if err != nil { - return core.FriendSet{} + return ms.FriendSet{} } - resp := make(core.FriendSet, len(ids)) + resp := make(ms.FriendSet, len(ids)) for _, id := range ids { resp[id] = types.Empty{} } return resp } -func (s *authorizationManageSrv) BeFriendFilter(userId int64) core.FriendFilter { +func (s *authorizationManageSrv) BeFriendFilter(userId int64) ms.FriendFilter { ids, err := (&dbr.Contact{FriendId: userId}).BeFriendIds(s.db) if err != nil { - return core.FriendFilter{} + return ms.FriendFilter{} } - resp := make(core.FriendFilter, len(ids)) + resp := make(ms.FriendFilter, len(ids)) for _, id := range ids { resp[id] = types.Empty{} } diff --git a/internal/dao/jinzhu/comments.go b/internal/dao/jinzhu/comments.go index b796c0ec..4ac08e18 100644 --- a/internal/dao/jinzhu/comments.go +++ b/internal/dao/jinzhu/comments.go @@ -9,6 +9,7 @@ import ( "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/rocboss/paopao-ce/pkg/types" "gorm.io/gorm" @@ -59,11 +60,11 @@ func (s *commentSrv) GetCommentThumbsMap(userId int64, tweetId int64) (cs.Commen return commentThumbs, replyThumbs, nil } -func (s *commentSrv) GetComments(conditions *core.ConditionsT, offset, limit int) ([]*core.Comment, error) { +func (s *commentSrv) GetComments(conditions *ms.ConditionsT, offset, limit int) ([]*ms.Comment, error) { return (&dbr.Comment{}).List(s.db, conditions, offset, limit) } -func (s *commentSrv) GetCommentByID(id int64) (*core.Comment, error) { +func (s *commentSrv) GetCommentByID(id int64) (*ms.Comment, error) { comment := &dbr.Comment{ Model: &dbr.Model{ ID: id, @@ -72,7 +73,7 @@ func (s *commentSrv) GetCommentByID(id int64) (*core.Comment, error) { return comment.Get(s.db) } -func (s *commentSrv) GetCommentReplyByID(id int64) (*core.CommentReply, error) { +func (s *commentSrv) GetCommentReplyByID(id int64) (*ms.CommentReply, error) { reply := &dbr.CommentReply{ Model: &dbr.Model{ ID: id, @@ -81,18 +82,18 @@ func (s *commentSrv) GetCommentReplyByID(id int64) (*core.CommentReply, error) { return reply.Get(s.db) } -func (s *commentSrv) GetCommentCount(conditions *core.ConditionsT) (int64, error) { +func (s *commentSrv) GetCommentCount(conditions *ms.ConditionsT) (int64, error) { return (&dbr.Comment{}).Count(s.db, conditions) } -func (s *commentSrv) GetCommentContentsByIDs(ids []int64) ([]*core.CommentContent, error) { +func (s *commentSrv) GetCommentContentsByIDs(ids []int64) ([]*ms.CommentContent, error) { commentContent := &dbr.CommentContent{} return commentContent.List(s.db, &dbr.ConditionsT{ "comment_id IN ?": ids, }, 0, 0) } -func (s *commentSrv) GetCommentRepliesByID(ids []int64) ([]*core.CommentReplyFormated, error) { +func (s *commentSrv) GetCommentRepliesByID(ids []int64) ([]*ms.CommentReplyFormated, error) { CommentReply := &dbr.CommentReply{} replies, err := CommentReply.List(s.db, &dbr.ConditionsT{ "comment_id IN ?": ids, @@ -112,7 +113,7 @@ func (s *commentSrv) GetCommentRepliesByID(ids []int64) ([]*core.CommentReplyFor if err != nil { return nil, err } - repliesFormated := []*core.CommentReplyFormated{} + repliesFormated := []*ms.CommentReplyFormated{} for _, reply := range replies { replyFormated := reply.Format() for _, user := range users { @@ -130,7 +131,7 @@ func (s *commentSrv) GetCommentRepliesByID(ids []int64) ([]*core.CommentReplyFor return repliesFormated, nil } -func (s *commentManageSrv) DeleteComment(comment *core.Comment) error { +func (s *commentManageSrv) DeleteComment(comment *ms.Comment) error { db := s.db.Begin() defer db.Rollback() @@ -149,15 +150,15 @@ func (s *commentManageSrv) DeleteComment(comment *core.Comment) error { return nil } -func (s *commentManageSrv) CreateComment(comment *core.Comment) (*core.Comment, error) { +func (s *commentManageSrv) CreateComment(comment *ms.Comment) (*ms.Comment, error) { return comment.Create(s.db) } -func (s *commentManageSrv) CreateCommentReply(reply *core.CommentReply) (*core.CommentReply, error) { +func (s *commentManageSrv) CreateCommentReply(reply *ms.CommentReply) (*ms.CommentReply, error) { return reply.Create(s.db) } -func (s *commentManageSrv) DeleteCommentReply(reply *core.CommentReply) (err error) { +func (s *commentManageSrv) DeleteCommentReply(reply *ms.CommentReply) (err error) { db := s.db.Begin() defer db.Rollback() @@ -177,7 +178,7 @@ func (s *commentManageSrv) DeleteCommentReply(reply *core.CommentReply) (err err return } -func (s *commentManageSrv) CreateCommentContent(content *core.CommentContent) (*core.CommentContent, error) { +func (s *commentManageSrv) CreateCommentContent(content *ms.CommentContent) (*ms.CommentContent, error) { return content.Create(s.db) } diff --git a/internal/dao/jinzhu/contacts.go b/internal/dao/jinzhu/contacts.go index 824164bc..b44307fe 100644 --- a/internal/dao/jinzhu/contacts.go +++ b/internal/dao/jinzhu/contacts.go @@ -8,6 +8,7 @@ import ( "time" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/sirupsen/logrus" "gorm.io/gorm" @@ -226,7 +227,7 @@ func (s *contactManageSrv) DeleteFriend(userId int64, friendId int64) (err error return nil } -func (s *contactManageSrv) GetContacts(userId int64, offset int, limit int) (*core.ContactList, error) { +func (s *contactManageSrv) GetContacts(userId int64, offset int, limit int) (*ms.ContactList, error) { contact := &dbr.Contact{} condition := dbr.ConditionsT{ "user_id": userId, @@ -240,13 +241,13 @@ func (s *contactManageSrv) GetContacts(userId int64, offset int, limit int) (*co if err != nil { return nil, err } - resp := &core.ContactList{ - Contacts: make([]core.ContactItem, 0, len(contacts)), + resp := &ms.ContactList{ + Contacts: make([]ms.ContactItem, 0, len(contacts)), Total: total, } for _, c := range contacts { if c.User != nil { - resp.Contacts = append(resp.Contacts, core.ContactItem{ + resp.Contacts = append(resp.Contacts, ms.ContactItem{ UserId: c.FriendId, UserName: c.User.Username, Nickname: c.User.Nickname, diff --git a/internal/dao/jinzhu/messages.go b/internal/dao/jinzhu/messages.go index 2d10935f..00df949f 100644 --- a/internal/dao/jinzhu/messages.go +++ b/internal/dao/jinzhu/messages.go @@ -6,6 +6,7 @@ package jinzhu import ( "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "gorm.io/gorm" ) @@ -24,7 +25,7 @@ func newMessageService(db *gorm.DB) core.MessageService { } } -func (s *messageSrv) CreateMessage(msg *core.Message) (*core.Message, error) { +func (s *messageSrv) CreateMessage(msg *ms.Message) (*ms.Message, error) { return msg.Create(s.db) } @@ -35,7 +36,7 @@ func (s *messageSrv) GetUnreadCount(userID int64) (int64, error) { }) } -func (s *messageSrv) GetMessageByID(id int64) (*core.Message, error) { +func (s *messageSrv) GetMessageByID(id int64) (*ms.Message, error) { return (&dbr.Message{ Model: &dbr.Model{ ID: id, @@ -43,12 +44,12 @@ func (s *messageSrv) GetMessageByID(id int64) (*core.Message, error) { }).Get(s.db) } -func (s *messageSrv) ReadMessage(message *core.Message) error { +func (s *messageSrv) ReadMessage(message *ms.Message) error { message.IsRead = 1 return message.Update(s.db) } -func (s *messageSrv) GetMessages(conditions *core.ConditionsT, offset, limit int) ([]*core.MessageFormated, error) { +func (s *messageSrv) GetMessages(conditions *ms.ConditionsT, offset, limit int) ([]*ms.MessageFormated, error) { messages, err := (&dbr.Message{}).List(s.db, conditions, offset, limit) if err != nil { return nil, err @@ -63,6 +64,6 @@ func (s *messageSrv) GetMessages(conditions *core.ConditionsT, offset, limit int return mfs, nil } -func (s *messageSrv) GetMessageCount(conditions *core.ConditionsT) (int64, error) { +func (s *messageSrv) GetMessageCount(conditions *ms.ConditionsT) (int64, error) { return (&dbr.Message{}).Count(s.db, conditions) } diff --git a/internal/dao/jinzhu/security.go b/internal/dao/jinzhu/security.go index 128e8273..d4d99d0d 100644 --- a/internal/dao/jinzhu/security.go +++ b/internal/dao/jinzhu/security.go @@ -10,6 +10,7 @@ import ( "time" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "gorm.io/gorm" ) @@ -31,14 +32,14 @@ func newSecurityService(db *gorm.DB, phoneVerify core.PhoneVerifyService) core.S } // GetLatestPhoneCaptcha 获取最新短信验证码 -func (s *securitySrv) GetLatestPhoneCaptcha(phone string) (*core.Captcha, error) { +func (s *securitySrv) GetLatestPhoneCaptcha(phone string) (*ms.Captcha, error) { return (&dbr.Captcha{ Phone: phone, }).Get(s.db) } // UsePhoneCaptcha 更新短信验证码 -func (s *securitySrv) UsePhoneCaptcha(captcha *core.Captcha) error { +func (s *securitySrv) UsePhoneCaptcha(captcha *ms.Captcha) error { captcha.UseTimes++ return captcha.Update(s.db) } diff --git a/internal/dao/jinzhu/timeline.go b/internal/dao/jinzhu/timeline.go index fb6769a5..f81e3619 100644 --- a/internal/dao/jinzhu/timeline.go +++ b/internal/dao/jinzhu/timeline.go @@ -7,6 +7,7 @@ package jinzhu import ( "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/rocboss/paopao-ce/pkg/debug" "github.com/sirupsen/logrus" @@ -42,7 +43,7 @@ type simpleIndexPostsSrv struct { } // IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; -func (s *friendIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *friendIndexSrv) IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { predicates := dbr.Predicates{ "ORDER": []any{"is_top DESC, latest_replied_on DESC"}, } @@ -70,7 +71,7 @@ func (s *friendIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*co return nil, err } - return &core.IndexTweetList{ + return &ms.IndexTweetList{ Tweets: formatPosts, Total: total, }, nil @@ -82,7 +83,7 @@ func (s *friendIndexSrv) TweetTimeline(userId int64, offset int, limit int) (*cs } // IndexPosts 根据userId查询广场推文列表 -func (s *followIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *followIndexSrv) IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { // TODO return nil, debug.ErrNotImplemented } @@ -93,7 +94,7 @@ func (s *followIndexSrv) TweetTimeline(userId int64, offset int, limit int) (*cs } // IndexPosts 根据userId查询广场推文列表,获取公开可见Tweet或者所属用户的私有Tweet -func (s *lightIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *lightIndexSrv) IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { predicates := dbr.Predicates{ "ORDER": []any{"is_top DESC, latest_replied_on DESC"}, } @@ -119,7 +120,7 @@ func (s *lightIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*cor return nil, err } - return &core.IndexTweetList{ + return &ms.IndexTweetList{ Tweets: formatPosts, Total: total, }, nil @@ -131,7 +132,7 @@ func (s *lightIndexSrv) TweetTimeline(userId int64, offset int, limit int) (*cs. } // simpleCacheIndexGetPosts simpleCacheIndex 专属获取广场推文列表函数 -func (s *simpleIndexPostsSrv) IndexPosts(_user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *simpleIndexPostsSrv) IndexPosts(_user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { predicates := dbr.Predicates{ "visibility = ?": []any{dbr.PostVisitPublic}, "ORDER": []any{"is_top DESC, latest_replied_on DESC"}, @@ -153,7 +154,7 @@ func (s *simpleIndexPostsSrv) IndexPosts(_user *core.User, offset int, limit int return nil, err } - return &core.IndexTweetList{ + return &ms.IndexTweetList{ Tweets: formatPosts, Total: total, }, nil diff --git a/internal/dao/jinzhu/topics.go b/internal/dao/jinzhu/topics.go index ce70b052..de317164 100644 --- a/internal/dao/jinzhu/topics.go +++ b/internal/dao/jinzhu/topics.go @@ -10,6 +10,7 @@ import ( "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "gorm.io/gorm" ) @@ -73,16 +74,16 @@ func (s *topicSrv) DecrTagsById(ids []int64) (err error) { } func (s *topicSrv) ListTags(typ cs.TagType, offset, limit int) (res cs.TagList, err error) { - conditions := &core.ConditionsT{} + conditions := &ms.ConditionsT{} switch typ { case cs.TagTypeHot: // 热门标签 - conditions = &core.ConditionsT{ + conditions = &ms.ConditionsT{ "ORDER": "quote_num DESC", } case cs.TagTypeNew: // 最新标签 - conditions = &core.ConditionsT{ + conditions = &ms.ConditionsT{ "ORDER": "id DESC", } } @@ -90,7 +91,7 @@ func (s *topicSrv) ListTags(typ cs.TagType, offset, limit int) (res cs.TagList, } func (s *topicSrv) GetHotTags(userId int64, limit int, offset int) (cs.TagList, error) { - tags, err := s.listTags(&core.ConditionsT{ + tags, err := s.listTags(&ms.ConditionsT{ "ORDER": "quote_num DESC", }, limit, offset) if err != nil { @@ -100,7 +101,7 @@ func (s *topicSrv) GetHotTags(userId int64, limit int, offset int) (cs.TagList, } func (s *topicSrv) GetNewestTags(userId int64, limit int, offset int) (cs.TagList, error) { - tags, err := s.listTags(&core.ConditionsT{ + tags, err := s.listTags(&ms.ConditionsT{ "ORDER": "id DESC", }, limit, offset) if err != nil { @@ -149,7 +150,7 @@ func (s *topicSrv) GetFollowTags(userId int64, limit int, offset int) (cs.TagLis return res, nil } -func (s *topicSrv) listTags(conditions *core.ConditionsT, limit int, offset int) (res cs.TagList, err error) { +func (s *topicSrv) listTags(conditions *ms.ConditionsT, limit int, offset int) (res cs.TagList, err error) { // TODO: 优化查询方式,直接返回[]*core.Tag, 目前保持先转换一下 var ( tags []*dbr.Tag @@ -298,16 +299,16 @@ func (s *topicSrvA) DecrTagsById(ids []int64) (err error) { } func (s *topicSrvA) ListTags(typ cs.TagType, offset, limit int) (res cs.TagList, err error) { - conditions := &core.ConditionsT{} + conditions := &ms.ConditionsT{} switch typ { case cs.TagTypeHot: // 热门标签 - conditions = &core.ConditionsT{ + conditions = &ms.ConditionsT{ "ORDER": "quote_num DESC", } case cs.TagTypeNew: // 最新标签 - conditions = &core.ConditionsT{ + conditions = &ms.ConditionsT{ "ORDER": "id DESC", } } diff --git a/internal/dao/jinzhu/tweets.go b/internal/dao/jinzhu/tweets.go index f716ca9b..a9dc2a27 100644 --- a/internal/dao/jinzhu/tweets.go +++ b/internal/dao/jinzhu/tweets.go @@ -10,6 +10,7 @@ import ( "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/rocboss/paopao-ce/pkg/debug" "gorm.io/gorm" @@ -88,7 +89,7 @@ func newTweetHelpServantA(db *gorm.DB) core.TweetHelpServantA { } // MergePosts post数据整合 -func (s *tweetHelpSrv) MergePosts(posts []*core.Post) ([]*core.PostFormated, error) { +func (s *tweetHelpSrv) MergePosts(posts []*ms.Post) ([]*ms.PostFormated, error) { postIds := make([]int64, 0, len(posts)) userIds := make([]int64, 0, len(posts)) for _, post := range posts { @@ -128,7 +129,7 @@ func (s *tweetHelpSrv) MergePosts(posts []*core.Post) ([]*core.PostFormated, err } // RevampPosts post数据整形修复 -func (s *tweetHelpSrv) RevampPosts(posts []*core.PostFormated) ([]*core.PostFormated, error) { +func (s *tweetHelpSrv) RevampPosts(posts []*ms.PostFormated) ([]*ms.PostFormated, error) { postIds := make([]int64, 0, len(posts)) userIds := make([]int64, 0, len(posts)) for _, post := range posts { @@ -179,7 +180,7 @@ func (s *tweetHelpSrv) getUsersByIDs(ids []int64) ([]*dbr.User, error) { }, 0, 0) } -func (s *tweetManageSrv) CreatePostCollection(postID, userID int64) (*core.PostCollection, error) { +func (s *tweetManageSrv) CreatePostCollection(postID, userID int64) (*ms.PostCollection, error) { collection := &dbr.PostCollection{ PostID: postID, UserID: userID, @@ -188,11 +189,11 @@ func (s *tweetManageSrv) CreatePostCollection(postID, userID int64) (*core.PostC return collection.Create(s.db) } -func (s *tweetManageSrv) DeletePostCollection(p *core.PostCollection) error { +func (s *tweetManageSrv) DeletePostCollection(p *ms.PostCollection) error { return p.Delete(s.db) } -func (s *tweetManageSrv) CreatePostContent(content *core.PostContent) (*core.PostContent, error) { +func (s *tweetManageSrv) CreatePostContent(content *ms.PostContent) (*ms.PostContent, error) { return content.Create(s.db) } @@ -201,7 +202,7 @@ func (s *tweetManageSrv) CreateAttachment(obj *cs.Attachment) (int64, error) { return 0, debug.ErrNotImplemented } -func (s *tweetManageSrv) CreatePost(post *core.Post) (*core.Post, error) { +func (s *tweetManageSrv) CreatePost(post *ms.Post) (*ms.Post, error) { post.LatestRepliedOn = time.Now().Unix() p, err := post.Create(s.db) if err != nil { @@ -211,7 +212,7 @@ func (s *tweetManageSrv) CreatePost(post *core.Post) (*core.Post, error) { return p, nil } -func (s *tweetManageSrv) DeletePost(post *core.Post) ([]string, error) { +func (s *tweetManageSrv) DeletePost(post *ms.Post) ([]string, error) { var mediaContents []string postId := post.ID @@ -292,12 +293,12 @@ func (s *tweetManageSrv) deleteCommentByPostId(db *gorm.DB, postId int64) ([]str return mediaContents, nil } -func (s *tweetManageSrv) LockPost(post *core.Post) error { +func (s *tweetManageSrv) LockPost(post *ms.Post) error { post.IsLock = 1 - post.IsLock return post.Update(s.db) } -func (s *tweetManageSrv) StickPost(post *core.Post) error { +func (s *tweetManageSrv) StickPost(post *ms.Post) error { post.IsTop = 1 - post.IsTop if err := post.Update(s.db); err != nil { return err @@ -306,7 +307,7 @@ func (s *tweetManageSrv) StickPost(post *core.Post) error { return nil } -func (s *tweetManageSrv) VisiblePost(post *core.Post, visibility core.PostVisibleT) error { +func (s *tweetManageSrv) VisiblePost(post *ms.Post, visibility core.PostVisibleT) error { oldVisibility := post.Visibility post.Visibility = visibility // TODO: 这个判断是否可以不要呢 @@ -340,7 +341,7 @@ func (s *tweetManageSrv) VisiblePost(post *core.Post, visibility core.PostVisibl return nil } -func (s *tweetManageSrv) UpdatePost(post *core.Post) error { +func (s *tweetManageSrv) UpdatePost(post *ms.Post) error { if err := post.Update(s.db); err != nil { return err } @@ -348,7 +349,7 @@ func (s *tweetManageSrv) UpdatePost(post *core.Post) error { return nil } -func (s *tweetManageSrv) CreatePostStar(postID, userID int64) (*core.PostStar, error) { +func (s *tweetManageSrv) CreatePostStar(postID, userID int64) (*ms.PostStar, error) { star := &dbr.PostStar{ PostID: postID, UserID: userID, @@ -356,11 +357,11 @@ func (s *tweetManageSrv) CreatePostStar(postID, userID int64) (*core.PostStar, e return star.Create(s.db) } -func (s *tweetManageSrv) DeletePostStar(p *core.PostStar) error { +func (s *tweetManageSrv) DeletePostStar(p *ms.PostStar) error { return p.Delete(s.db) } -func (s *tweetSrv) GetPostByID(id int64) (*core.Post, error) { +func (s *tweetSrv) GetPostByID(id int64) (*ms.Post, error) { post := &dbr.Post{ Model: &dbr.Model{ ID: id, @@ -369,15 +370,15 @@ func (s *tweetSrv) GetPostByID(id int64) (*core.Post, error) { return post.Get(s.db) } -func (s *tweetSrv) GetPosts(conditions *core.ConditionsT, offset, limit int) ([]*core.Post, error) { +func (s *tweetSrv) GetPosts(conditions *ms.ConditionsT, offset, limit int) ([]*ms.Post, error) { return (&dbr.Post{}).List(s.db, conditions, offset, limit) } -func (s *tweetSrv) GetPostCount(conditions *core.ConditionsT) (int64, error) { +func (s *tweetSrv) GetPostCount(conditions *ms.ConditionsT) (int64, error) { return (&dbr.Post{}).Count(s.db, conditions) } -func (s *tweetSrv) GetUserPostStar(postID, userID int64) (*core.PostStar, error) { +func (s *tweetSrv) GetUserPostStar(postID, userID int64) (*ms.PostStar, error) { star := &dbr.PostStar{ PostID: postID, UserID: userID, @@ -385,7 +386,7 @@ func (s *tweetSrv) GetUserPostStar(postID, userID int64) (*core.PostStar, error) return star.Get(s.db) } -func (s *tweetSrv) GetUserPostStars(userID int64, offset, limit int) ([]*core.PostStar, error) { +func (s *tweetSrv) GetUserPostStars(userID int64, offset, limit int) ([]*ms.PostStar, error) { star := &dbr.PostStar{ UserID: userID, } @@ -402,7 +403,7 @@ func (s *tweetSrv) GetUserPostStarCount(userID int64) (int64, error) { return star.Count(s.db, &dbr.ConditionsT{}) } -func (s *tweetSrv) GetUserPostCollection(postID, userID int64) (*core.PostCollection, error) { +func (s *tweetSrv) GetUserPostCollection(postID, userID int64) (*ms.PostCollection, error) { star := &dbr.PostCollection{ PostID: postID, UserID: userID, @@ -410,7 +411,7 @@ func (s *tweetSrv) GetUserPostCollection(postID, userID int64) (*core.PostCollec return star.Get(s.db) } -func (s *tweetSrv) GetUserPostCollections(userID int64, offset, limit int) ([]*core.PostCollection, error) { +func (s *tweetSrv) GetUserPostCollections(userID int64, offset, limit int) ([]*ms.PostCollection, error) { collection := &dbr.PostCollection{ UserID: userID, } @@ -427,7 +428,7 @@ func (s *tweetSrv) GetUserPostCollectionCount(userID int64) (int64, error) { return collection.Count(s.db, &dbr.ConditionsT{}) } -func (s *tweetSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*core.WalletStatement, error) { +func (s *tweetSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*ms.WalletStatement, error) { statement := &dbr.WalletStatement{ UserID: userID, } @@ -444,7 +445,7 @@ func (s *tweetSrv) GetUserWalletBillCount(userID int64) (int64, error) { return statement.Count(s.db, &dbr.ConditionsT{}) } -func (s *tweetSrv) GetPostAttatchmentBill(postID, userID int64) (*core.PostAttachmentBill, error) { +func (s *tweetSrv) GetPostAttatchmentBill(postID, userID int64) (*ms.PostAttachmentBill, error) { bill := &dbr.PostAttachmentBill{ PostID: postID, UserID: userID, @@ -453,14 +454,14 @@ func (s *tweetSrv) GetPostAttatchmentBill(postID, userID int64) (*core.PostAttac return bill.Get(s.db) } -func (s *tweetSrv) GetPostContentsByIDs(ids []int64) ([]*core.PostContent, error) { +func (s *tweetSrv) GetPostContentsByIDs(ids []int64) ([]*ms.PostContent, error) { return (&dbr.PostContent{}).List(s.db, &dbr.ConditionsT{ "post_id IN ?": ids, "ORDER": "sort ASC", }, 0, 0) } -func (s *tweetSrv) GetPostContentByID(id int64) (*core.PostContent, error) { +func (s *tweetSrv) GetPostContentByID(id int64) (*ms.PostContent, error) { return (&dbr.PostContent{ Model: &dbr.Model{ ID: id, diff --git a/internal/dao/jinzhu/user.go b/internal/dao/jinzhu/user.go index b69338b7..6bc18de3 100644 --- a/internal/dao/jinzhu/user.go +++ b/internal/dao/jinzhu/user.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "gorm.io/gorm" ) @@ -26,7 +27,7 @@ func newUserManageService(db *gorm.DB) core.UserManageService { } } -func (s *userManageSrv) GetUserByID(id int64) (*core.User, error) { +func (s *userManageSrv) GetUserByID(id int64) (*ms.User, error) { user := &dbr.User{ Model: &dbr.Model{ ID: id, @@ -35,28 +36,28 @@ func (s *userManageSrv) GetUserByID(id int64) (*core.User, error) { return user.Get(s.db) } -func (s *userManageSrv) GetUserByUsername(username string) (*core.User, error) { +func (s *userManageSrv) GetUserByUsername(username string) (*ms.User, error) { user := &dbr.User{ Username: username, } return user.Get(s.db) } -func (s *userManageSrv) GetUserByPhone(phone string) (*core.User, error) { +func (s *userManageSrv) GetUserByPhone(phone string) (*ms.User, error) { user := &dbr.User{ Phone: phone, } return user.Get(s.db) } -func (s *userManageSrv) GetUsersByIDs(ids []int64) ([]*core.User, error) { +func (s *userManageSrv) GetUsersByIDs(ids []int64) ([]*ms.User, error) { user := &dbr.User{} return user.List(s.db, &dbr.ConditionsT{ "id IN ?": ids, }, 0, 0) } -func (s *userManageSrv) GetUsersByKeyword(keyword string) ([]*core.User, error) { +func (s *userManageSrv) GetUsersByKeyword(keyword string) ([]*ms.User, error) { user := &dbr.User{} keyword = strings.Trim(keyword, " ") + "%" if keyword == "%" { @@ -70,10 +71,10 @@ func (s *userManageSrv) GetUsersByKeyword(keyword string) ([]*core.User, error) } } -func (s *userManageSrv) CreateUser(user *dbr.User) (*core.User, error) { +func (s *userManageSrv) CreateUser(user *dbr.User) (*ms.User, error) { return user.Create(s.db) } -func (s *userManageSrv) UpdateUser(user *core.User) error { +func (s *userManageSrv) UpdateUser(user *ms.User) error { return user.Update(s.db) } diff --git a/internal/dao/jinzhu/wallet.go b/internal/dao/jinzhu/wallet.go index 6e3196e5..e657deca 100644 --- a/internal/dao/jinzhu/wallet.go +++ b/internal/dao/jinzhu/wallet.go @@ -7,6 +7,7 @@ package jinzhu import ( "github.com/rocboss/paopao-ce/internal/conf" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "gorm.io/gorm" ) @@ -25,7 +26,7 @@ func newWalletService(db *gorm.DB) core.WalletService { } } -func (s *walletSrv) GetRechargeByID(id int64) (*core.WalletRecharge, error) { +func (s *walletSrv) GetRechargeByID(id int64) (*ms.WalletRecharge, error) { recharge := &dbr.WalletRecharge{ Model: &dbr.Model{ ID: id, @@ -34,7 +35,7 @@ func (s *walletSrv) GetRechargeByID(id int64) (*core.WalletRecharge, error) { return recharge.Get(s.db) } -func (s *walletSrv) CreateRecharge(userId, amount int64) (*core.WalletRecharge, error) { +func (s *walletSrv) CreateRecharge(userId, amount int64) (*ms.WalletRecharge, error) { recharge := &dbr.WalletRecharge{ UserID: userId, Amount: amount, @@ -43,7 +44,7 @@ func (s *walletSrv) CreateRecharge(userId, amount int64) (*core.WalletRecharge, return recharge.Create(s.db) } -func (s *walletSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*core.WalletStatement, error) { +func (s *walletSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*ms.WalletStatement, error) { statement := &dbr.WalletStatement{ UserID: userID, } @@ -60,7 +61,7 @@ func (s *walletSrv) GetUserWalletBillCount(userID int64) (int64, error) { return statement.Count(s.db, &dbr.ConditionsT{}) } -func (s *walletSrv) HandleRechargeSuccess(recharge *core.WalletRecharge, tradeNo string) error { +func (s *walletSrv) HandleRechargeSuccess(recharge *ms.WalletRecharge, tradeNo string) error { user, _ := (&dbr.User{ Model: &dbr.Model{ ID: recharge.UserID, @@ -97,7 +98,7 @@ func (s *walletSrv) HandleRechargeSuccess(recharge *core.WalletRecharge, tradeNo }) } -func (s *walletSrv) HandlePostAttachmentBought(post *core.Post, user *core.User) error { +func (s *walletSrv) HandlePostAttachmentBought(post *ms.Post, user *ms.User) 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 { diff --git a/internal/dao/sakila/authority.go b/internal/dao/sakila/authority.go index c595b84d..688068cc 100644 --- a/internal/dao/sakila/authority.go +++ b/internal/dao/sakila/authority.go @@ -7,6 +7,7 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -20,19 +21,19 @@ type authorizationManageSrv struct { q *cc.AuthorizationManage } -func (s *authorizationManageSrv) IsAllow(user *core.User, action *core.Action) bool { +func (s *authorizationManageSrv) IsAllow(user *ms.User, action *ms.Action) bool { // TODO debug.NotImplemented() return false } -func (s *authorizationManageSrv) MyFriendSet(userId int64) core.FriendSet { +func (s *authorizationManageSrv) MyFriendSet(userId int64) ms.FriendSet { // TODO debug.NotImplemented() return nil } -func (s *authorizationManageSrv) BeFriendFilter(userId int64) core.FriendFilter { +func (s *authorizationManageSrv) BeFriendFilter(userId int64) ms.FriendFilter { // TODO debug.NotImplemented() return nil diff --git a/internal/dao/sakila/comments.go b/internal/dao/sakila/comments.go index c2858115..dc27c690 100644 --- a/internal/dao/sakila/comments.go +++ b/internal/dao/sakila/comments.go @@ -8,6 +8,7 @@ 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/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -27,31 +28,31 @@ type commentManageSrv struct { q *cc.CommentManage } -func (s *commentSrv) GetComments(conditions *core.ConditionsT, offset, limit int) ([]*core.Comment, error) { +func (s *commentSrv) GetComments(conditions *ms.ConditionsT, offset, limit int) ([]*ms.Comment, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *commentSrv) GetCommentByID(id int64) (*core.Comment, error) { +func (s *commentSrv) GetCommentByID(id int64) (*ms.Comment, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *commentSrv) GetCommentReplyByID(id int64) (*core.CommentReply, error) { +func (s *commentSrv) GetCommentReplyByID(id int64) (*ms.CommentReply, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *commentSrv) GetCommentCount(conditions *core.ConditionsT) (int64, error) { +func (s *commentSrv) GetCommentCount(conditions *ms.ConditionsT) (int64, error) { // TODO debug.NotImplemented() return 0, nil } -func (s *commentSrv) GetCommentContentsByIDs(ids []int64) ([]*core.CommentContent, error) { +func (s *commentSrv) GetCommentContentsByIDs(ids []int64) ([]*ms.CommentContent, error) { // TODO debug.NotImplemented() return nil, nil @@ -62,37 +63,37 @@ func (s *commentSrv) GetCommentThumbsMap(userId int64, tweetId int64) (cs.Commen return nil, nil, debug.ErrNotImplemented } -func (s *commentSrv) GetCommentRepliesByID(ids []int64) ([]*core.CommentReplyFormated, error) { +func (s *commentSrv) GetCommentRepliesByID(ids []int64) ([]*ms.CommentReplyFormated, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *commentManageSrv) DeleteComment(comment *core.Comment) error { +func (s *commentManageSrv) DeleteComment(comment *ms.Comment) error { // TODO debug.NotImplemented() return nil } -func (s *commentManageSrv) CreateComment(comment *core.Comment) (*core.Comment, error) { +func (s *commentManageSrv) CreateComment(comment *ms.Comment) (*ms.Comment, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *commentManageSrv) CreateCommentReply(reply *core.CommentReply) (*core.CommentReply, error) { +func (s *commentManageSrv) CreateCommentReply(reply *ms.CommentReply) (*ms.CommentReply, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *commentManageSrv) DeleteCommentReply(reply *core.CommentReply) error { +func (s *commentManageSrv) DeleteCommentReply(reply *ms.CommentReply) error { // TODO debug.NotImplemented() return nil } -func (s *commentManageSrv) CreateCommentContent(content *core.CommentContent) (*core.CommentContent, error) { +func (s *commentManageSrv) CreateCommentContent(content *ms.CommentContent) (*ms.CommentContent, error) { // TODO debug.NotImplemented() return nil, nil diff --git a/internal/dao/sakila/contacts.go b/internal/dao/sakila/contacts.go index d969496e..f37dc872 100644 --- a/internal/dao/sakila/contacts.go +++ b/internal/dao/sakila/contacts.go @@ -7,6 +7,7 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -44,7 +45,7 @@ func (s *contactManageSrv) DeleteFriend(userId int64, friendId int64) (err error return nil } -func (s *contactManageSrv) GetContacts(userId int64, offset int, limit int) (*core.ContactList, error) { +func (s *contactManageSrv) GetContacts(userId int64, offset int, limit int) (*ms.ContactList, error) { // TODO debug.NotImplemented() return nil, nil diff --git a/internal/dao/sakila/messages.go b/internal/dao/sakila/messages.go index cc1b70a7..5f62b6a3 100644 --- a/internal/dao/sakila/messages.go +++ b/internal/dao/sakila/messages.go @@ -7,6 +7,7 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -20,7 +21,7 @@ type messageSrv struct { q *cc.Message } -func (s *messageSrv) CreateMessage(msg *core.Message) (*core.Message, error) { +func (s *messageSrv) CreateMessage(msg *ms.Message) (*ms.Message, error) { // TODO debug.NotImplemented() return nil, nil @@ -32,25 +33,25 @@ func (s *messageSrv) GetUnreadCount(userID int64) (int64, error) { return 0, nil } -func (s *messageSrv) GetMessageByID(id int64) (*core.Message, error) { +func (s *messageSrv) GetMessageByID(id int64) (*ms.Message, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *messageSrv) ReadMessage(message *core.Message) error { +func (s *messageSrv) ReadMessage(message *ms.Message) error { // TODO debug.NotImplemented() return nil } -func (s *messageSrv) GetMessages(conditions *core.ConditionsT, offset, limit int) ([]*core.MessageFormated, error) { +func (s *messageSrv) GetMessages(conditions *ms.ConditionsT, offset, limit int) ([]*ms.MessageFormated, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *messageSrv) GetMessageCount(conditions *core.ConditionsT) (int64, error) { +func (s *messageSrv) GetMessageCount(conditions *ms.ConditionsT) (int64, error) { // TODO debug.NotImplemented() return 0, nil diff --git a/internal/dao/sakila/security.go b/internal/dao/sakila/security.go index 4a959519..02154ee5 100644 --- a/internal/dao/sakila/security.go +++ b/internal/dao/sakila/security.go @@ -7,6 +7,7 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -21,14 +22,14 @@ type securitySrv struct { } // GetLatestPhoneCaptcha 获取最新短信验证码 -func (s *securitySrv) GetLatestPhoneCaptcha(phone string) (*core.Captcha, error) { +func (s *securitySrv) GetLatestPhoneCaptcha(phone string) (*ms.Captcha, error) { // TODO debug.NotImplemented() return nil, nil } // UsePhoneCaptcha 更新短信验证码 -func (s *securitySrv) UsePhoneCaptcha(captcha *core.Captcha) error { +func (s *securitySrv) UsePhoneCaptcha(captcha *ms.Captcha) error { // TODO debug.NotImplemented() return nil diff --git a/internal/dao/sakila/timeline.go b/internal/dao/sakila/timeline.go index 1c5d3016..92941312 100644 --- a/internal/dao/sakila/timeline.go +++ b/internal/dao/sakila/timeline.go @@ -8,6 +8,7 @@ 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/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -75,49 +76,49 @@ type simpleIndexPostsSrvA struct { } // IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; -func (s *friendIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *friendIndexSrv) IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { // TODO return nil, debug.ErrNotImplemented } // IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; -func (s *followIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *followIndexSrv) IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { // TODO return nil, debug.ErrNotImplemented } // IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; -func (s *lightIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *lightIndexSrv) IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { // TODO return nil, debug.ErrNotImplemented } // simpleCacheIndexGetPosts simpleCacheIndex 专属获取广场推文列表函数 -func (s *simpleIndexPostsSrv) IndexPosts(_user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *simpleIndexPostsSrv) IndexPosts(_user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { // TODO return nil, debug.ErrNotImplemented } // IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; -func (s *friendIndexSrvA) IndexPosts(user *core.User, limit int, offset int) (*cs.TweetBox, error) { +func (s *friendIndexSrvA) IndexPosts(user *ms.User, limit int, offset int) (*cs.TweetBox, error) { // TODO return nil, debug.ErrNotImplemented } // IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; -func (s *followIndexSrvA) IndexPosts(user *core.User, limit int, offset int) (*cs.TweetBox, error) { +func (s *followIndexSrvA) IndexPosts(user *ms.User, limit int, offset int) (*cs.TweetBox, error) { // TODO return nil, debug.ErrNotImplemented } // IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; -func (s *lightIndexSrvA) IndexPosts(user *core.User, limit int, offset int) (*cs.TweetBox, error) { +func (s *lightIndexSrvA) IndexPosts(user *ms.User, limit int, offset int) (*cs.TweetBox, error) { // TODO return nil, debug.ErrNotImplemented } // IndexPosts simpleCacheIndex 专属获取广场推文列表函数 -func (s *simpleIndexPostsSrvA) IndexPosts(_user *core.User, limit int, offset int) (*cs.TweetBox, error) { +func (s *simpleIndexPostsSrvA) IndexPosts(_user *ms.User, limit int, offset int) (*cs.TweetBox, error) { // TODO return nil, debug.ErrNotImplemented } diff --git a/internal/dao/sakila/tweets.go b/internal/dao/sakila/tweets.go index f97d0cc6..e9272026 100644 --- a/internal/dao/sakila/tweets.go +++ b/internal/dao/sakila/tweets.go @@ -8,6 +8,7 @@ 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/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" @@ -56,14 +57,14 @@ type tweetHelpSrvA struct { } // MergePosts post数据整合 -func (s *tweetHelpSrv) MergePosts(posts []*core.Post) ([]*core.PostFormated, error) { +func (s *tweetHelpSrv) MergePosts(posts []*ms.Post) ([]*ms.PostFormated, error) { // TODO debug.NotImplemented() return nil, nil } // RevampPosts post数据整形修复 -func (s *tweetHelpSrv) RevampPosts(posts []*core.PostFormated) ([]*core.PostFormated, error) { +func (s *tweetHelpSrv) RevampPosts(posts []*ms.PostFormated) ([]*ms.PostFormated, error) { // TODO debug.NotImplemented() return nil, nil @@ -81,19 +82,19 @@ func (s *tweetHelpSrv) getUsersByIDs(ids []int64) ([]*dbr.User, error) { return nil, nil } -func (s *tweetManageSrv) CreatePostCollection(postID, userID int64) (*core.PostCollection, error) { +func (s *tweetManageSrv) CreatePostCollection(postID, userID int64) (*ms.PostCollection, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *tweetManageSrv) DeletePostCollection(p *core.PostCollection) error { +func (s *tweetManageSrv) DeletePostCollection(p *ms.PostCollection) error { // TODO debug.NotImplemented() return nil } -func (s *tweetManageSrv) CreatePostContent(content *core.PostContent) (*core.PostContent, error) { +func (s *tweetManageSrv) CreatePostContent(content *ms.PostContent) (*ms.PostContent, error) { // TODO debug.NotImplemented() return nil, nil @@ -104,79 +105,79 @@ func (s *tweetManageSrv) CreateAttachment(obj *cs.Attachment) (int64, error) { return 0, debug.ErrNotImplemented } -func (s *tweetManageSrv) CreatePost(post *core.Post) (*core.Post, error) { +func (s *tweetManageSrv) CreatePost(post *ms.Post) (*ms.Post, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *tweetManageSrv) DeletePost(post *core.Post) ([]string, error) { +func (s *tweetManageSrv) DeletePost(post *ms.Post) ([]string, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *tweetManageSrv) LockPost(post *core.Post) error { +func (s *tweetManageSrv) LockPost(post *ms.Post) error { // TODO debug.NotImplemented() return nil } -func (s *tweetManageSrv) StickPost(post *core.Post) error { +func (s *tweetManageSrv) StickPost(post *ms.Post) error { // TODO debug.NotImplemented() return nil } -func (s *tweetManageSrv) VisiblePost(post *core.Post, visibility core.PostVisibleT) error { +func (s *tweetManageSrv) VisiblePost(post *ms.Post, visibility core.PostVisibleT) error { // TODO debug.NotImplemented() return nil } -func (s *tweetManageSrv) UpdatePost(post *core.Post) error { +func (s *tweetManageSrv) UpdatePost(post *ms.Post) error { // TODO debug.NotImplemented() return nil } -func (s *tweetManageSrv) CreatePostStar(postID, userID int64) (*core.PostStar, error) { +func (s *tweetManageSrv) CreatePostStar(postID, userID int64) (*ms.PostStar, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *tweetManageSrv) DeletePostStar(p *core.PostStar) error { +func (s *tweetManageSrv) DeletePostStar(p *ms.PostStar) error { // TODO debug.NotImplemented() return nil } -func (s *tweetSrv) GetPostByID(id int64) (*core.Post, error) { +func (s *tweetSrv) GetPostByID(id int64) (*ms.Post, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *tweetSrv) GetPosts(conditions *core.ConditionsT, offset, limit int) ([]*core.Post, error) { +func (s *tweetSrv) GetPosts(conditions *ms.ConditionsT, offset, limit int) ([]*ms.Post, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *tweetSrv) GetPostCount(conditions *core.ConditionsT) (int64, error) { +func (s *tweetSrv) GetPostCount(conditions *ms.ConditionsT) (int64, error) { // TODO debug.NotImplemented() return 0, nil } -func (s *tweetSrv) GetUserPostStar(postID, userID int64) (*core.PostStar, error) { +func (s *tweetSrv) GetUserPostStar(postID, userID int64) (*ms.PostStar, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *tweetSrv) GetUserPostStars(userID int64, offset, limit int) ([]*core.PostStar, error) { +func (s *tweetSrv) GetUserPostStars(userID int64, offset, limit int) ([]*ms.PostStar, error) { // TODO debug.NotImplemented() return nil, nil @@ -188,13 +189,13 @@ func (s *tweetSrv) GetUserPostStarCount(userID int64) (int64, error) { return 0, nil } -func (s *tweetSrv) GetUserPostCollection(postID, userID int64) (*core.PostCollection, error) { +func (s *tweetSrv) GetUserPostCollection(postID, userID int64) (*ms.PostCollection, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *tweetSrv) GetUserPostCollections(userID int64, offset, limit int) ([]*core.PostCollection, error) { +func (s *tweetSrv) GetUserPostCollections(userID int64, offset, limit int) ([]*ms.PostCollection, error) { // TODO debug.NotImplemented() return nil, nil @@ -206,7 +207,7 @@ func (s *tweetSrv) GetUserPostCollectionCount(userID int64) (int64, error) { return 0, nil } -func (s *tweetSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*core.WalletStatement, error) { +func (s *tweetSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*ms.WalletStatement, error) { // TODO debug.NotImplemented() return nil, nil @@ -218,19 +219,19 @@ func (s *tweetSrv) GetUserWalletBillCount(userID int64) (int64, error) { return 0, nil } -func (s *tweetSrv) GetPostAttatchmentBill(postID, userID int64) (*core.PostAttachmentBill, error) { +func (s *tweetSrv) GetPostAttatchmentBill(postID, userID int64) (*ms.PostAttachmentBill, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *tweetSrv) GetPostContentsByIDs(ids []int64) ([]*core.PostContent, error) { +func (s *tweetSrv) GetPostContentsByIDs(ids []int64) ([]*ms.PostContent, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *tweetSrv) GetPostContentByID(id int64) (*core.PostContent, error) { +func (s *tweetSrv) GetPostContentByID(id int64) (*ms.PostContent, error) { // TODO debug.NotImplemented() return nil, nil diff --git a/internal/dao/sakila/user.go b/internal/dao/sakila/user.go index c063fc81..9611b498 100644 --- a/internal/dao/sakila/user.go +++ b/internal/dao/sakila/user.go @@ -7,6 +7,7 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -20,43 +21,43 @@ type userManageSrv struct { q *cc.UserManage } -func (s *userManageSrv) GetUserByID(id int64) (*core.User, error) { +func (s *userManageSrv) GetUserByID(id int64) (*ms.User, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *userManageSrv) GetUserByUsername(username string) (*core.User, error) { +func (s *userManageSrv) GetUserByUsername(username string) (*ms.User, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *userManageSrv) GetUserByPhone(phone string) (*core.User, error) { +func (s *userManageSrv) GetUserByPhone(phone string) (*ms.User, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *userManageSrv) GetUsersByIDs(ids []int64) ([]*core.User, error) { +func (s *userManageSrv) GetUsersByIDs(ids []int64) ([]*ms.User, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *userManageSrv) GetUsersByKeyword(keyword string) ([]*core.User, error) { +func (s *userManageSrv) GetUsersByKeyword(keyword string) ([]*ms.User, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *userManageSrv) CreateUser(user *core.User) (*core.User, error) { +func (s *userManageSrv) CreateUser(user *ms.User) (*ms.User, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *userManageSrv) UpdateUser(user *core.User) error { +func (s *userManageSrv) UpdateUser(user *ms.User) error { // TODO debug.NotImplemented() return nil diff --git a/internal/dao/sakila/wallet.go b/internal/dao/sakila/wallet.go index c733965a..42649113 100644 --- a/internal/dao/sakila/wallet.go +++ b/internal/dao/sakila/wallet.go @@ -7,6 +7,7 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -20,18 +21,18 @@ type walletSrv struct { q *cc.Wallet } -func (s *walletSrv) GetRechargeByID(id int64) (*core.WalletRecharge, error) { +func (s *walletSrv) GetRechargeByID(id int64) (*ms.WalletRecharge, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *walletSrv) CreateRecharge(userId, amount int64) (*core.WalletRecharge, error) { +func (s *walletSrv) CreateRecharge(userId, amount int64) (*ms.WalletRecharge, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *walletSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*core.WalletStatement, error) { +func (s *walletSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*ms.WalletStatement, error) { // TODO debug.NotImplemented() return nil, nil @@ -43,13 +44,13 @@ func (s *walletSrv) GetUserWalletBillCount(userID int64) (int64, error) { return 0, nil } -func (s *walletSrv) HandleRechargeSuccess(recharge *core.WalletRecharge, tradeNo string) error { +func (s *walletSrv) HandleRechargeSuccess(recharge *ms.WalletRecharge, tradeNo string) error { // TODO debug.NotImplemented() return nil } -func (s *walletSrv) HandlePostAttachmentBought(post *core.Post, user *core.User) error { +func (s *walletSrv) HandlePostAttachmentBought(post *ms.Post, user *ms.User) error { // TODO debug.NotImplemented() return nil diff --git a/internal/dao/search/bridge.go b/internal/dao/search/bridge.go index f23aaa25..bc4eb039 100644 --- a/internal/dao/search/bridge.go +++ b/internal/dao/search/bridge.go @@ -8,6 +8,7 @@ import ( "time" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/sirupsen/logrus" ) @@ -46,7 +47,7 @@ func (s *bridgeTweetSearchServant) DeleteDocuments(identifiers []string) error { return nil } -func (s *bridgeTweetSearchServant) Search(user *core.User, q *core.QueryReq, offset, limit int) (*core.QueryResp, error) { +func (s *bridgeTweetSearchServant) Search(user *ms.User, q *core.QueryReq, offset, limit int) (*core.QueryResp, error) { return s.ts.Search(user, q, offset, limit) } diff --git a/internal/dao/search/filter.go b/internal/dao/search/filter.go index 5840e189..a601c46f 100644 --- a/internal/dao/search/filter.go +++ b/internal/dao/search/filter.go @@ -6,6 +6,7 @@ package search import ( "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/pkg/types" ) @@ -13,13 +14,13 @@ type tweetSearchFilter struct { ams core.AuthorizationManageService } -func (s *tweetSearchFilter) filterResp(user *core.User, resp *core.QueryResp) { +func (s *tweetSearchFilter) filterResp(user *ms.User, resp *core.QueryResp) { // 管理员不过滤 if user != nil && user.IsAdmin { return } - var item *core.PostFormated + var item *ms.PostFormated items := resp.Items latestIndex := len(items) - 1 if user == nil { diff --git a/internal/dao/search/meili.go b/internal/dao/search/meili.go index fc19e358..74391ef3 100644 --- a/internal/dao/search/meili.go +++ b/internal/dao/search/meili.go @@ -11,6 +11,7 @@ import ( "github.com/Masterminds/semver/v3" "github.com/meilisearch/meilisearch-go" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/pkg/json" "github.com/sirupsen/logrus" ) @@ -81,7 +82,7 @@ func (s *meiliTweetSearchServant) DeleteDocuments(identifiers []string) error { return nil } -func (s *meiliTweetSearchServant) Search(user *core.User, q *core.QueryReq, offset, limit int) (resp *core.QueryResp, err error) { +func (s *meiliTweetSearchServant) Search(user *ms.User, q *core.QueryReq, offset, limit int) (resp *core.QueryResp, err error) { if q.Type == core.SearchTypeDefault && q.Query != "" { resp, err = s.queryByContent(user, q, offset, limit) } else if q.Type == core.SearchTypeTag && q.Query != "" { @@ -99,7 +100,7 @@ func (s *meiliTweetSearchServant) Search(user *core.User, q *core.QueryReq, offs return } -func (s *meiliTweetSearchServant) queryByContent(user *core.User, q *core.QueryReq, offset, limit int) (*core.QueryResp, error) { +func (s *meiliTweetSearchServant) queryByContent(user *ms.User, q *core.QueryReq, offset, limit int) (*core.QueryResp, error) { request := &meilisearch.SearchRequest{ Offset: int64(offset), Limit: int64(limit), @@ -120,7 +121,7 @@ func (s *meiliTweetSearchServant) queryByContent(user *core.User, q *core.QueryR return s.postsFrom(resp) } -func (s *meiliTweetSearchServant) queryByTag(user *core.User, q *core.QueryReq, offset, limit int) (*core.QueryResp, error) { +func (s *meiliTweetSearchServant) queryByTag(user *ms.User, q *core.QueryReq, offset, limit int) (*core.QueryResp, error) { request := &meilisearch.SearchRequest{ Offset: int64(offset), Limit: int64(limit), @@ -144,7 +145,7 @@ func (s *meiliTweetSearchServant) queryByTag(user *core.User, q *core.QueryReq, return s.postsFrom(resp) } -func (s *meiliTweetSearchServant) queryAny(user *core.User, offset, limit int) (*core.QueryResp, error) { +func (s *meiliTweetSearchServant) queryAny(user *ms.User, offset, limit int) (*core.QueryResp, error) { request := &meilisearch.SearchRequest{ Offset: int64(offset), Limit: int64(limit), @@ -164,7 +165,7 @@ func (s *meiliTweetSearchServant) queryAny(user *core.User, offset, limit int) ( return s.postsFrom(resp) } -func (s *meiliTweetSearchServant) filterList(user *core.User) string { +func (s *meiliTweetSearchServant) filterList(user *ms.User) string { if user == nil { return s.publicFilter } @@ -177,7 +178,7 @@ func (s *meiliTweetSearchServant) filterList(user *core.User) string { } func (s *meiliTweetSearchServant) postsFrom(resp *meilisearch.SearchResponse) (*core.QueryResp, error) { - posts := make([]*core.PostFormated, 0, len(resp.Hits)) + posts := make([]*ms.PostFormated, 0, len(resp.Hits)) for _, hit := range resp.Hits { raw, err := json.Marshal(hit) if err != nil { @@ -187,7 +188,7 @@ func (s *meiliTweetSearchServant) postsFrom(resp *meilisearch.SearchResponse) (* if err = json.Unmarshal(raw, p); err != nil { return nil, err } - posts = append(posts, &core.PostFormated{ + posts = append(posts, &ms.PostFormated{ ID: p.ID, UserID: p.UserID, CommentCount: p.CommentCount, diff --git a/internal/dao/search/zinc.go b/internal/dao/search/zinc.go index ea9a7fa5..91f74b42 100644 --- a/internal/dao/search/zinc.go +++ b/internal/dao/search/zinc.go @@ -9,6 +9,7 @@ import ( "github.com/Masterminds/semver/v3" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/pkg/json" "github.com/rocboss/paopao-ce/pkg/zinc" "github.com/sirupsen/logrus" @@ -76,7 +77,7 @@ func (s *zincTweetSearchServant) DeleteDocuments(identifiers []string) error { return nil } -func (s *zincTweetSearchServant) Search(user *core.User, q *core.QueryReq, offset, limit int) (resp *core.QueryResp, err error) { +func (s *zincTweetSearchServant) Search(user *ms.User, q *core.QueryReq, offset, limit int) (resp *core.QueryResp, err error) { if q.Type == core.SearchTypeDefault && q.Query != "" { resp, err = s.queryByContent(user, q, offset, limit) } else if q.Type == core.SearchTypeTag && q.Query != "" { @@ -94,7 +95,7 @@ func (s *zincTweetSearchServant) Search(user *core.User, q *core.QueryReq, offse return } -func (s *zincTweetSearchServant) queryByContent(user *core.User, q *core.QueryReq, offset, limit int) (*core.QueryResp, error) { +func (s *zincTweetSearchServant) queryByContent(user *ms.User, q *core.QueryReq, offset, limit int) (*core.QueryResp, error) { resp, err := s.client.EsQuery(s.indexName, map[string]any{ "query": map[string]any{ "match_phrase": map[string]any{ @@ -111,7 +112,7 @@ func (s *zincTweetSearchServant) queryByContent(user *core.User, q *core.QueryRe return s.postsFrom(resp) } -func (s *zincTweetSearchServant) queryByTag(user *core.User, q *core.QueryReq, offset, limit int) (*core.QueryResp, error) { +func (s *zincTweetSearchServant) queryByTag(user *ms.User, q *core.QueryReq, offset, limit int) (*core.QueryResp, error) { resp, err := s.client.ApiQuery(s.indexName, map[string]any{ "search_type": "querystring", "query": map[string]any{ @@ -127,7 +128,7 @@ func (s *zincTweetSearchServant) queryByTag(user *core.User, q *core.QueryReq, o return s.postsFrom(resp) } -func (s *zincTweetSearchServant) queryAny(user *core.User, offset, limit int) (*core.QueryResp, error) { +func (s *zincTweetSearchServant) queryAny(user *ms.User, offset, limit int) (*core.QueryResp, error) { queryMap := map[string]any{ "query": map[string]any{ "match_all": map[string]string{}, @@ -144,9 +145,9 @@ func (s *zincTweetSearchServant) queryAny(user *core.User, offset, limit int) (* } func (s *zincTweetSearchServant) postsFrom(resp *zinc.QueryResultT) (*core.QueryResp, error) { - posts := make([]*core.PostFormated, 0, len(resp.Hits.Hits)) + posts := make([]*ms.PostFormated, 0, len(resp.Hits.Hits)) for _, hit := range resp.Hits.Hits { - item := &core.PostFormated{} + item := &ms.PostFormated{} raw, err := json.Marshal(hit.Source) if err != nil { return nil, err diff --git a/internal/model/web/priv.go b/internal/model/web/priv.go index d0c57caf..665ea665 100644 --- a/internal/model/web/priv.go +++ b/internal/model/web/priv.go @@ -11,6 +11,7 @@ import ( "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" ) type TweetCommentThumbsReq struct { @@ -27,9 +28,9 @@ type TweetReplyThumbsReq struct { } type PostContentItem struct { - Content string `json:"content" binding:"required"` - Type core.PostContentT `json:"type" binding:"required"` - Sort int64 `json:"sort" binding:"required"` + Content string `json:"content" binding:"required"` + Type ms.PostContentT `json:"type" binding:"required"` + Sort int64 `json:"sort" binding:"required"` } type CreateTweetReq struct { @@ -42,7 +43,7 @@ type CreateTweetReq struct { ClientIP string `json:"-" binding:"-"` } -type CreateTweetResp core.PostFormated +type CreateTweetResp ms.PostFormated type DeleteTweetReq struct { BaseInfo `json:"-" binding:"-"` @@ -103,7 +104,7 @@ type CreateCommentReq struct { ClientIP string `json:"-" binding:"-"` } -type CreateCommentResp core.Comment +type CreateCommentResp ms.Comment type CreateCommentReplyReq struct { SimpleInfo `json:"-" binding:"-"` @@ -113,7 +114,7 @@ type CreateCommentReplyReq struct { ClientIP string `json:"-" binding:"-"` } -type CreateCommentReplyResp core.CommentReply +type CreateCommentReplyResp ms.CommentReply type DeleteCommentReq struct { BaseInfo `json:"-" binding:"-"` @@ -182,13 +183,13 @@ type UnfollowTopicReq struct { // Check 检查PostContentItem属性 func (p *PostContentItem) Check(acs core.AttachmentCheckService) error { // 检查附件是否是本站资源 - if p.Type == core.ContentTypeImage || p.Type == core.ContentTypeVideo || p.Type == core.ContentTypeAttachment { + if p.Type == ms.ContentTypeImage || p.Type == ms.ContentTypeVideo || p.Type == ms.ContentTypeAttachment { if err := acs.CheckAttachment(p.Content); err != nil { return err } } // 检查链接是否合法 - if p.Type == core.ContentTypeLink { + if p.Type == ms.ContentTypeLink { if strings.Index(p.Content, "http://") != 0 && strings.Index(p.Content, "https://") != 0 { return fmt.Errorf("链接不合法") } diff --git a/internal/model/web/pub.go b/internal/model/web/pub.go index 422249cf..058288e8 100644 --- a/internal/model/web/pub.go +++ b/internal/model/web/pub.go @@ -5,7 +5,7 @@ package web import ( - "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/pkg/version" ) @@ -13,7 +13,7 @@ type TweetDetailReq struct { TweetId int64 `form:"id"` } -type TweetDetailResp core.PostFormated +type TweetDetailResp ms.PostFormated type GetCaptchaResp struct { Id string `json:"id"` diff --git a/internal/model/web/web.go b/internal/model/web/web.go index bec917fa..a8a7c59c 100644 --- a/internal/model/web/web.go +++ b/internal/model/web/web.go @@ -7,14 +7,14 @@ package web import ( "github.com/alimy/mir/v3" "github.com/gin-gonic/gin" - "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/servants/base" "github.com/rocboss/paopao-ce/pkg/app" "github.com/rocboss/paopao-ce/pkg/xerror" ) type BaseInfo struct { - User *core.User + User *ms.User } type SimpleInfo struct { @@ -27,7 +27,7 @@ type BasePageReq struct { PageSize int } -func (b *BaseInfo) SetUser(user *core.User) { +func (b *BaseInfo) SetUser(user *ms.User) { b.User = user } diff --git a/internal/servants/base/base.go b/internal/servants/base/base.go index d17ae139..34a78589 100644 --- a/internal/servants/base/base.go +++ b/internal/servants/base/base.go @@ -17,6 +17,7 @@ import ( "github.com/gin-gonic/gin" "github.com/rocboss/paopao-ce/internal/conf" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao" "github.com/rocboss/paopao-ce/internal/dao/cache" "github.com/rocboss/paopao-ce/pkg/app" @@ -49,7 +50,7 @@ type SentryHubSetter interface { } type UserSetter interface { - SetUser(*core.User) + SetUser(*ms.User) } type UserIdSetter interface { @@ -60,9 +61,9 @@ type PageInfoSetter interface { SetPageInfo(page, pageSize int) } -func UserFrom(c *gin.Context) (*core.User, bool) { +func UserFrom(c *gin.Context) (*ms.User, bool) { if u, exists := c.Get("USER"); exists { - user, ok := u.(*core.User) + user, ok := u.(*ms.User) return user, ok } return nil, false @@ -157,7 +158,7 @@ func RenderAny(c *gin.Context, data any, err mir.Error) { } } -func (s *DaoServant) GetTweetBy(id int64) (*core.PostFormated, error) { +func (s *DaoServant) GetTweetBy(id int64) (*ms.PostFormated, error) { post, err := s.Ds.GetPostByID(id) if err != nil { return nil, err @@ -188,20 +189,20 @@ func (s *DaoServant) PushPostsToSearch(c context.Context) { defer s.Redis.DelPushToSearchJob(c) splitNum := 1000 - totalRows, _ := s.Ds.GetPostCount(&core.ConditionsT{ + totalRows, _ := s.Ds.GetPostCount(&ms.ConditionsT{ "visibility IN ?": []core.PostVisibleT{core.PostVisitPublic, core.PostVisitFriend}, }) pages := math.Ceil(float64(totalRows) / float64(splitNum)) nums := int(pages) for i := 0; i < nums; i++ { - posts, postsFormated, err := s.GetTweetList(&core.ConditionsT{}, i*splitNum, splitNum) + posts, postsFormated, err := s.GetTweetList(&ms.ConditionsT{}, i*splitNum, splitNum) if err != nil || len(posts) != len(postsFormated) { continue } for i, pf := range postsFormated { contentFormated := "" for _, content := range pf.Contents { - if content.Type == core.ContentTypeText || content.Type == core.ContentTypeTitle { + if content.Type == ms.ContentTypeText || content.Type == ms.ContentTypeTitle { contentFormated = contentFormated + content.Content + "\n" } } @@ -217,9 +218,9 @@ func (s *DaoServant) PushPostsToSearch(c context.Context) { } } -func (s *DaoServant) PushPostToSearch(post *core.Post) { +func (s *DaoServant) PushPostToSearch(post *ms.Post) { postFormated := post.Format() - postFormated.User = &core.UserFormated{ + postFormated.User = &ms.UserFormated{ ID: post.UserID, } contents, _ := s.Ds.GetPostContentsByIDs([]int64{post.ID}) @@ -229,7 +230,7 @@ func (s *DaoServant) PushPostToSearch(post *core.Post) { contentFormated := "" for _, content := range postFormated.Contents { - if content.Type == core.ContentTypeText || content.Type == core.ContentTypeTitle { + if content.Type == ms.ContentTypeText || content.Type == ms.ContentTypeTitle { contentFormated = contentFormated + content.Content + "\n" } } @@ -241,11 +242,11 @@ func (s *DaoServant) PushPostToSearch(post *core.Post) { s.Ts.AddDocuments(docs, fmt.Sprintf("%d", post.ID)) } -func (s *DaoServant) DeleteSearchPost(post *core.Post) error { +func (s *DaoServant) DeleteSearchPost(post *ms.Post) error { return s.Ts.DeleteDocuments([]string{fmt.Sprintf("%d", post.ID)}) } -func (s *DaoServant) GetTweetList(conditions *core.ConditionsT, offset, limit int) ([]*core.Post, []*core.PostFormated, error) { +func (s *DaoServant) GetTweetList(conditions *ms.ConditionsT, offset, limit int) ([]*ms.Post, []*ms.PostFormated, error) { posts, err := s.Ds.GetPosts(conditions, offset, limit) if err != nil { return nil, nil, err diff --git a/internal/servants/chain/admin.go b/internal/servants/chain/admin.go index 4660baa8..37a6e4c7 100644 --- a/internal/servants/chain/admin.go +++ b/internal/servants/chain/admin.go @@ -6,15 +6,15 @@ package chain import ( "github.com/gin-gonic/gin" - "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/pkg/app" ) func Admin() gin.HandlerFunc { return func(c *gin.Context) { if user, exist := c.Get("USER"); exist { - if userModel, ok := user.(*core.User); ok { - if userModel.Status == core.UserStatusNormal && userModel.IsAdmin { + if userModel, ok := user.(*ms.User); ok { + if userModel.Status == ms.UserStatusNormal && userModel.IsAdmin { c.Next() return } diff --git a/internal/servants/chain/priv.go b/internal/servants/chain/priv.go index c2a017ca..420c3a9c 100644 --- a/internal/servants/chain/priv.go +++ b/internal/servants/chain/priv.go @@ -7,7 +7,7 @@ package chain import ( "github.com/alimy/cfg" "github.com/gin-gonic/gin" - "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/pkg/app" ) @@ -15,8 +15,8 @@ func Priv() gin.HandlerFunc { if cfg.If("PhoneBind") { return func(c *gin.Context) { if u, exist := c.Get("USER"); exist { - if user, ok := u.(*core.User); ok { - if user.Status == core.UserStatusNormal { + if user, ok := u.(*ms.User); ok { + if user.Status == ms.UserStatusNormal { if user.Phone == "" { response := app.NewResponse(c) response.ToErrorResponse(_errAccountNoPhoneBind) @@ -35,7 +35,7 @@ func Priv() gin.HandlerFunc { } else { return func(c *gin.Context) { if u, exist := c.Get("USER"); exist { - if user, ok := u.(*core.User); ok && user.Status == core.UserStatusNormal { + if user, ok := u.(*ms.User); ok && user.Status == ms.UserStatusNormal { c.Next() return } diff --git a/internal/servants/web/core.go b/internal/servants/web/core.go index c4f60af3..52552c25 100644 --- a/internal/servants/web/core.go +++ b/internal/servants/web/core.go @@ -14,6 +14,7 @@ import ( "github.com/gin-gonic/gin" api "github.com/rocboss/paopao-ce/auto/api/v1" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/model/web" "github.com/rocboss/paopao-ce/internal/servants/base" "github.com/rocboss/paopao-ce/internal/servants/chain" @@ -159,7 +160,7 @@ func (s *coreSrv) GetUnreadMsgCount(req *web.GetUnreadMsgCountReq) (*web.GetUnre } func (s *coreSrv) GetMessages(req *web.GetMessagesReq) (*web.GetMessagesResp, mir.Error) { - conditions := &core.ConditionsT{ + conditions := &ms.ConditionsT{ "receiver_user_id": req.UserId, "ORDER": "id DESC", } @@ -172,7 +173,7 @@ func (s *coreSrv) GetMessages(req *web.GetMessagesReq) (*web.GetMessagesResp, mi } } // 好友申请消息不需要获取其他信息 - if mf.Type == core.MsgTypeRequestingFriend { + if mf.Type == ms.MsgTypeRequestingFriend { continue } if mf.PostID > 0 { @@ -231,10 +232,10 @@ func (s *coreSrv) SendUserWhisper(req *web.SendWhisperReq) mir.Error { } // 创建私信 - _, err := s.Ds.CreateMessage(&core.Message{ + _, err := s.Ds.CreateMessage(&ms.Message{ SenderUserID: req.Uid, ReceiverUserID: req.UserID, - Type: core.MsgTypeWhisper, + Type: ms.MsgTypeWhisper, Brief: "给你发送新私信了", Content: req.Content, }) @@ -261,7 +262,7 @@ func (s *coreSrv) GetCollections(req *web.GetCollectionsReq) (*web.GetCollection return nil, _errGetCollectionsFailed } - var posts []*core.Post + var posts []*ms.Post for _, collection := range collections { posts = append(posts, collection.Post) } @@ -324,7 +325,7 @@ func (s *coreSrv) GetStars(req *web.GetStarsReq) (*web.GetStarsResp, mir.Error) return nil, _errGetStarsFailed } - var posts []*core.Post + var posts []*ms.Post for _, star := range stars { posts = append(posts, star.Post) } diff --git a/internal/servants/web/loose.go b/internal/servants/web/loose.go index 3c0dda80..cb6327f0 100644 --- a/internal/servants/web/loose.go +++ b/internal/servants/web/loose.go @@ -10,6 +10,7 @@ import ( api "github.com/rocboss/paopao-ce/auto/api/v1" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/rocboss/paopao-ce/internal/model/web" "github.com/rocboss/paopao-ce/internal/servants/base" @@ -106,7 +107,7 @@ func (s *looseSrv) GetUserTweets(req *web.GetUserTweetsReq) (*web.GetUserTweetsR visibilities = append(visibilities, core.PostVisitFriend) } } - conditions := &core.ConditionsT{ + conditions := &ms.ConditionsT{ "user_id": other.ID, "visibility IN ?": visibilities, "ORDER": "latest_replied_on DESC", @@ -191,7 +192,7 @@ func (s *looseSrv) TweetComments(req *web.TweetCommentsReq) (*web.TweetCommentsR if req.SortStrategy == "newest" { sort = "id DESC" } - conditions := &core.ConditionsT{ + conditions := &ms.ConditionsT{ "post_id": req.TweetId, "ORDER": sort, } @@ -245,7 +246,7 @@ func (s *looseSrv) TweetComments(req *web.TweetCommentsReq) (*web.TweetCommentsR } } - commentsFormated := []*core.CommentFormated{} + commentsFormated := []*ms.CommentFormated{} for _, comment := range comments { commentFormated := comment.Format() if thumbs, exist := commentThumbs[comment.ID]; exist { diff --git a/internal/servants/web/priv.go b/internal/servants/web/priv.go index 8dc7a2b7..25400252 100644 --- a/internal/servants/web/priv.go +++ b/internal/servants/web/priv.go @@ -17,6 +17,7 @@ import ( "github.com/rocboss/paopao-ce/internal/conf" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/model/web" "github.com/rocboss/paopao-ce/internal/servants/base" "github.com/rocboss/paopao-ce/internal/servants/chain" @@ -252,7 +253,7 @@ func (s *privSrv) DownloadAttachmentPrecheck(req *web.DownloadAttachmentPrecheck return nil, _errInvalidDownloadReq } resp := &web.DownloadAttachmentPrecheckResp{Paid: true} - if content.Type == core.ContentTypeChargeAttachment { + if content.Type == ms.ContentTypeChargeAttachment { tweet, err := s.GetTweetBy(content.PostID) if err != nil { logrus.Errorf("get tweet err: %v", err) @@ -275,7 +276,7 @@ func (s *privSrv) DownloadAttachment(req *web.DownloadAttachmentReq) (*web.Downl return nil, _errInvalidDownloadReq } // 收费附件 - if content.Type == core.ContentTypeChargeAttachment { + if content.Type == ms.ContentTypeChargeAttachment { post, err := s.GetTweetBy(content.PostID) if err != nil { logrus.Errorf("s.GetTweetBy err: %v", err) @@ -288,8 +289,8 @@ func (s *privSrv) DownloadAttachment(req *web.DownloadAttachmentReq) (*web.Downl } // 未购买,则尝试购买 if !paidFlag { - err := s.buyPostAttachment(&core.Post{ - Model: &core.Model{ + err := s.buyPostAttachment(&ms.Post{ + Model: &ms.Model{ ID: post.ID, }, UserID: post.UserID, @@ -326,7 +327,7 @@ func (s *privSrv) CreateTweet(req *web.CreateTweetReq) (_ *web.CreateTweetResp, } mediaContents = contents tags := tagsFrom(req.Tags) - post := &core.Post{ + post := &ms.Post{ UserID: req.User.ID, Tags: strings.Join(tags, ","), IP: req.ClientIP, @@ -347,10 +348,10 @@ func (s *privSrv) CreateTweet(req *web.CreateTweetReq) (_ *web.CreateTweetResp, logrus.Infof("contents check err: %s", err) continue } - if item.Type == core.ContentTypeAttachment && req.AttachmentPrice > 0 { - item.Type = core.ContentTypeChargeAttachment + if item.Type == ms.ContentTypeAttachment && req.AttachmentPrice > 0 { + item.Type = ms.ContentTypeChargeAttachment } - postContent := &core.PostContent{ + postContent := &ms.PostContent{ PostID: post.ID, UserID: req.User.ID, Content: item.Content, @@ -377,10 +378,10 @@ func (s *privSrv) CreateTweet(req *web.CreateTweetReq) (_ *web.CreateTweetResp, // 创建消息提醒 // TODO: 优化消息提醒处理机制 - go s.Ds.CreateMessage(&core.Message{ + go s.Ds.CreateMessage(&ms.Message{ SenderUserID: req.User.ID, ReceiverUserID: user.ID, - Type: core.MsgTypePost, + Type: ms.MsgTypePost, Brief: "在新发布的泡泡动态中@了你", PostID: post.ID, }) @@ -388,7 +389,7 @@ func (s *privSrv) CreateTweet(req *web.CreateTweetReq) (_ *web.CreateTweetResp, } // 推送Search s.PushPostToSearch(post) - formatedPosts, err := s.Ds.RevampPosts([]*core.PostFormated{post.Format()}) + formatedPosts, err := s.Ds.RevampPosts([]*ms.PostFormated{post.Format()}) if err != nil { logrus.Infof("Ds.RevampPosts err: %s", err) return nil, _errCreatePostFailed @@ -444,8 +445,8 @@ func (s *privSrv) DeleteCommentReply(req *web.DeleteCommentReplyReq) mir.Error { func (s *privSrv) CreateCommentReply(req *web.CreateCommentReplyReq) (*web.CreateCommentReplyResp, mir.Error) { var ( - post *core.Post - comment *core.Comment + post *ms.Post + comment *ms.Comment atUserID int64 err error ) @@ -455,7 +456,7 @@ func (s *privSrv) CreateCommentReply(req *web.CreateCommentReplyReq) (*web.Creat } // 创建评论 - reply := &core.CommentReply{ + reply := &ms.CommentReply{ CommentID: req.CommentID, UserID: req.Uid, Content: req.Content, @@ -480,10 +481,10 @@ func (s *privSrv) CreateCommentReply(req *web.CreateCommentReplyReq) (*web.Creat // 创建用户消息提醒 commentMaster, err := s.Ds.GetUserByID(comment.UserID) if err == nil && commentMaster.ID != req.Uid { - go s.Ds.CreateMessage(&core.Message{ + go s.Ds.CreateMessage(&ms.Message{ SenderUserID: req.Uid, ReceiverUserID: commentMaster.ID, - Type: core.MsgTypeReply, + Type: ms.MsgTypeReply, Brief: "在泡泡评论下回复了你", PostID: post.ID, CommentID: comment.ID, @@ -492,10 +493,10 @@ func (s *privSrv) CreateCommentReply(req *web.CreateCommentReplyReq) (*web.Creat } postMaster, err := s.Ds.GetUserByID(post.UserID) if err == nil && postMaster.ID != req.Uid && commentMaster.ID != postMaster.ID { - go s.Ds.CreateMessage(&core.Message{ + go s.Ds.CreateMessage(&ms.Message{ SenderUserID: req.Uid, ReceiverUserID: postMaster.ID, - Type: core.MsgTypeReply, + Type: ms.MsgTypeReply, Brief: "在泡泡评论下发布了新回复", PostID: post.ID, CommentID: comment.ID, @@ -506,10 +507,10 @@ func (s *privSrv) CreateCommentReply(req *web.CreateCommentReplyReq) (*web.Creat user, err := s.Ds.GetUserByID(atUserID) if err == nil && user.ID != req.Uid && commentMaster.ID != user.ID && postMaster.ID != user.ID { // 创建消息提醒 - go s.Ds.CreateMessage(&core.Message{ + go s.Ds.CreateMessage(&ms.Message{ SenderUserID: req.Uid, ReceiverUserID: user.ID, - Type: core.MsgTypeReply, + Type: ms.MsgTypeReply, Brief: "在泡泡评论的回复中@了你", PostID: post.ID, CommentID: comment.ID, @@ -572,7 +573,7 @@ func (s *privSrv) CreateComment(req *web.CreateCommentReq) (_ *web.CreateComment if post.CommentCount >= conf.AppSetting.MaxCommentCount { return nil, _errMaxCommentCount } - comment := &core.Comment{ + comment := &ms.Comment{ PostID: post.ID, UserID: req.Uid, IP: req.ClientIP, @@ -586,12 +587,12 @@ func (s *privSrv) CreateComment(req *web.CreateCommentReq) (_ *web.CreateComment for _, item := range req.Contents { // 检查附件是否是本站资源 - if item.Type == core.ContentTypeImage || item.Type == core.ContentTypeVideo || item.Type == core.ContentTypeAttachment { + if item.Type == ms.ContentTypeImage || item.Type == ms.ContentTypeVideo || item.Type == ms.ContentTypeAttachment { if err := s.Ds.CheckAttachment(item.Content); err != nil { continue } } - postContent := &core.CommentContent{ + postContent := &ms.CommentContent{ CommentID: comment.ID, UserID: req.Uid, Content: item.Content, @@ -612,10 +613,10 @@ func (s *privSrv) CreateComment(req *web.CreateCommentReq) (_ *web.CreateComment // 创建用户消息提醒 postMaster, err := s.Ds.GetUserByID(post.UserID) if err == nil && postMaster.ID != req.Uid { - go s.Ds.CreateMessage(&core.Message{ + go s.Ds.CreateMessage(&ms.Message{ SenderUserID: req.Uid, ReceiverUserID: postMaster.ID, - Type: core.MsgtypeComment, + Type: ms.MsgtypeComment, Brief: "在泡泡中评论了你", PostID: post.ID, CommentID: comment.ID, @@ -628,10 +629,10 @@ func (s *privSrv) CreateComment(req *web.CreateCommentReq) (_ *web.CreateComment } // 创建消息提醒 - go s.Ds.CreateMessage(&core.Message{ + go s.Ds.CreateMessage(&ms.Message{ SenderUserID: req.Uid, ReceiverUserID: user.ID, - Type: core.MsgtypeComment, + Type: ms.MsgtypeComment, Brief: "在泡泡评论中@了你", PostID: post.ID, CommentID: comment.ID, @@ -741,7 +742,7 @@ func (s *privSrv) LockTweet(req *web.LockTweetReq) (*web.LockTweetResp, mir.Erro }, nil } -func (s *privSrv) deletePostCommentReply(reply *core.CommentReply) error { +func (s *privSrv) deletePostCommentReply(reply *ms.CommentReply) error { err := s.Ds.DeleteCommentReply(reply) if err != nil { return err @@ -765,7 +766,7 @@ func (s *privSrv) deletePostCommentReply(reply *core.CommentReply) error { return nil } -func (s *privSrv) createPostPreHandler(commentID int64, userID, atUserID int64) (*core.Post, *core.Comment, int64, +func (s *privSrv) createPostPreHandler(commentID int64, userID, atUserID int64) (*ms.Post, *ms.Comment, int64, error) { // 加载Comment comment, err := s.Ds.GetCommentByID(commentID) @@ -798,7 +799,7 @@ func (s *privSrv) createPostPreHandler(commentID int64, userID, atUserID int64) return post, comment, atUserID, nil } -func (s *privSrv) createPostStar(postID, userID int64) (*core.PostStar, mir.Error) { +func (s *privSrv) createPostStar(postID, userID int64) (*ms.PostStar, mir.Error) { post, err := s.Ds.GetPostByID(postID) if err != nil { return nil, xerror.ServerError @@ -824,7 +825,7 @@ func (s *privSrv) createPostStar(postID, userID int64) (*core.PostStar, mir.Erro return star, nil } -func (s *privSrv) deletePostStar(star *core.PostStar) mir.Error { +func (s *privSrv) deletePostStar(star *ms.PostStar) mir.Error { post, err := s.Ds.GetPostByID(star.PostID) if err != nil { return xerror.ServerError @@ -849,7 +850,7 @@ func (s *privSrv) deletePostStar(star *core.PostStar) mir.Error { return nil } -func (s *privSrv) createPostCollection(postID, userID int64) (*core.PostCollection, mir.Error) { +func (s *privSrv) createPostCollection(postID, userID int64) (*ms.PostCollection, mir.Error) { post, err := s.Ds.GetPostByID(postID) if err != nil { return nil, xerror.ServerError @@ -875,7 +876,7 @@ func (s *privSrv) createPostCollection(postID, userID int64) (*core.PostCollecti return collection, nil } -func (s *privSrv) deletePostCollection(collection *core.PostCollection) mir.Error { +func (s *privSrv) deletePostCollection(collection *ms.PostCollection) mir.Error { post, err := s.Ds.GetPostByID(collection.PostID) if err != nil { return xerror.ServerError @@ -904,7 +905,7 @@ func (s *privSrv) checkPostAttachmentIsPaid(postID, userID int64) bool { return err == nil && bill.Model != nil && bill.ID > 0 } -func (s *privSrv) buyPostAttachment(post *core.Post, user *core.User) mir.Error { +func (s *privSrv) buyPostAttachment(post *ms.Post, user *ms.User) mir.Error { if user.Balance < post.AttachmentPrice { return _errInsuffientDownloadMoney } diff --git a/internal/servants/web/pub.go b/internal/servants/web/pub.go index 6c58de3c..53bfe167 100644 --- a/internal/servants/web/pub.go +++ b/internal/servants/web/pub.go @@ -17,7 +17,7 @@ import ( "github.com/alimy/mir/v3" "github.com/gofrs/uuid" api "github.com/rocboss/paopao-ce/auto/api/v1" - "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/model/web" "github.com/rocboss/paopao-ce/internal/servants/base" "github.com/rocboss/paopao-ce/internal/servants/web/assets" @@ -141,13 +141,13 @@ func (s *pubSrv) Register(req *web.RegisterReq) (*web.RegisterResp, mir.Error) { return nil, _errUserRegisterFailed } password, salt := encryptPasswordAndSalt(req.Password) - user := &core.User{ + user := &ms.User{ Nickname: req.Username, Username: req.Username, Password: password, Avatar: getRandomAvatar(), Salt: salt, - Status: core.UserStatusNormal, + Status: ms.UserStatusNormal, } user, err := s.Ds.CreateUser(user) if err != nil { @@ -174,7 +174,7 @@ func (s *pubSrv) Login(req *web.LoginReq) (*web.LoginResp, mir.Error) { } // 对比密码是否正确 if validPassword(user.Password, req.Password, user.Salt) { - if user.Status == core.UserStatusClosed { + if user.Status == ms.UserStatusClosed { return nil, _errUserHasBeenBanned } // 清空登录计数 diff --git a/internal/servants/web/utils.go b/internal/servants/web/utils.go index b4dc77b8..db2f3ab7 100644 --- a/internal/servants/web/utils.go +++ b/internal/servants/web/utils.go @@ -14,6 +14,7 @@ import ( "github.com/alimy/mir/v3" "github.com/gofrs/uuid" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/model/web" "github.com/rocboss/paopao-ce/pkg/utils" "github.com/rocboss/paopao-ce/pkg/xerror" @@ -119,11 +120,11 @@ func persistMediaContents(oss core.ObjectStorageService, contents []*web.PostCon items = make([]string, 0, len(contents)) for _, item := range contents { switch item.Type { - case core.ContentTypeImage, - core.ContentTypeVideo, - core.ContentTypeAudio, - core.ContentTypeAttachment, - core.ContentTypeChargeAttachment: + case ms.ContentTypeImage, + ms.ContentTypeVideo, + ms.ContentTypeAudio, + ms.ContentTypeAttachment, + ms.ContentTypeChargeAttachment: items = append(items, item.Content) if err != nil { continue @@ -200,7 +201,7 @@ func tagsFrom(originTags []string) []string { } // checkPermision 检查是否拥有者或管理员 -func checkPermision(user *core.User, targetUserId int64) mir.Error { +func checkPermision(user *ms.User, targetUserId int64) mir.Error { if user == nil || (user.ID != targetUserId && !user.IsAdmin) { return _errNoPermission } diff --git a/pkg/app/jwt.go b/pkg/app/jwt.go index b9759e07..a861faa2 100644 --- a/pkg/app/jwt.go +++ b/pkg/app/jwt.go @@ -9,7 +9,7 @@ import ( "github.com/golang-jwt/jwt/v4" "github.com/rocboss/paopao-ce/internal/conf" - "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" ) type Claims struct { @@ -22,7 +22,7 @@ func GetJWTSecret() []byte { return []byte(conf.JWTSetting.Secret) } -func GenerateToken(User *core.User) (string, error) { +func GenerateToken(User *ms.User) (string, error) { expireTime := time.Now().Add(conf.JWTSetting.Expire) claims := Claims{ UID: User.ID,