From 8eb294154a166cbb1231d92c290d191db6bb4986 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Sun, 6 Aug 2023 00:43:54 +0800 Subject: [PATCH] optimize core service define --- internal/core/authority.go | 114 +------------------- internal/core/cache.go | 3 +- internal/core/comments.go | 32 +++--- internal/core/cs/contact.go | 26 +++++ internal/core/cs/tweets.go | 4 +- internal/core/messages.go | 29 ++---- internal/core/ms/authority.go | 115 +++++++++++++++++++++ internal/core/ms/comments.go | 17 +++ internal/core/ms/messages.go | 26 +++++ internal/core/{types.go => ms/ms.go} | 6 +- internal/core/ms/security.go | 13 +++ internal/core/ms/timeline.go | 10 ++ internal/core/ms/tweets.go | 43 ++++++++ internal/core/ms/user.go | 20 ++++ internal/core/ms/wallet.go | 14 +++ internal/core/search.go | 7 +- internal/core/security.go | 10 +- internal/core/timeline.go | 10 +- internal/core/tweets.go | 76 +++++--------- internal/core/user.go | 31 ++---- internal/core/wallet.go | 17 ++- internal/dao/cache/base.go | 17 +-- internal/dao/cache/none.go | 5 +- internal/dao/cache/simple.go | 11 +- internal/dao/jinzhu/authority.go | 15 +-- internal/dao/jinzhu/comments.go | 25 ++--- internal/dao/jinzhu/contacts.go | 9 +- internal/dao/jinzhu/dbr/comment.go | 2 +- internal/dao/jinzhu/dbr/comment_reply.go | 12 +-- internal/dao/jinzhu/dbr/post.go | 8 +- internal/dao/jinzhu/dbr/post_collection.go | 4 +- internal/dao/jinzhu/dbr/post_content.go | 2 +- internal/dao/jinzhu/dbr/user.go | 2 +- internal/dao/jinzhu/messages.go | 11 +- internal/dao/jinzhu/security.go | 10 +- internal/dao/jinzhu/timeline.go | 15 +-- internal/dao/jinzhu/topics.go | 19 ++-- internal/dao/jinzhu/tweets.go | 55 +++++----- internal/dao/jinzhu/user.go | 15 +-- internal/dao/jinzhu/wallet.go | 11 +- internal/dao/search/bridge.go | 3 +- internal/dao/search/filter.go | 5 +- internal/dao/search/meili.go | 15 +-- internal/dao/search/zinc.go | 13 +-- internal/model/web/priv.go | 20 ++-- internal/model/web/pub.go | 4 +- internal/model/web/web.go | 6 +- internal/servants/base/base.go | 28 ++--- internal/servants/chain/admin.go | 6 +- internal/servants/chain/priv.go | 8 +- internal/servants/web/core.go | 13 +-- internal/servants/web/loose.go | 9 +- internal/servants/web/priv.go | 83 ++++++++------- internal/servants/web/pub.go | 8 +- internal/servants/web/utils.go | 13 +-- mirc/gen.go | 4 +- pkg/app/jwt.go | 4 +- pkg/naming/naming_test.go | 4 + 58 files changed, 628 insertions(+), 489 deletions(-) create mode 100644 internal/core/cs/contact.go create mode 100644 internal/core/ms/authority.go create mode 100644 internal/core/ms/comments.go create mode 100644 internal/core/ms/messages.go rename internal/core/{types.go => ms/ms.go} (79%) create mode 100644 internal/core/ms/security.go create mode 100644 internal/core/ms/timeline.go create mode 100644 internal/core/ms/tweets.go create mode 100644 internal/core/ms/user.go create mode 100644 internal/core/ms/wallet.go 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/cs/contact.go b/internal/core/cs/contact.go new file mode 100644 index 00000000..ed774631 --- /dev/null +++ b/internal/core/cs/contact.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 cs + +const ( + ContactStatusRequesting int8 = iota + 1 + ContactStatusAgree + ContactStatusReject + ContactStatusDeleted +) + +type Contact struct { + ID int64 `db:"id" json:"id"` + UserId int64 `db:"user_id" json:"user_id"` + FriendId int64 `db:"friend_id" json:"friend_id"` + GroupId int64 `json:"group_id"` + Remark string `json:"remark"` + Status int8 `json:"status"` // 1请求好友, 2已同意好友, 3已拒绝好友, 4已删除好友 + IsTop int8 `json:"is_top"` + IsBlack int8 `json:"is_black"` + NoticeEnable int8 `json:"notice_enable"` + IsDel int8 `json:"-"` + DeletedOn int64 `db:"-" json:"-"` +} diff --git a/internal/core/cs/tweets.go b/internal/core/cs/tweets.go index 5c0e3603..34060030 100644 --- a/internal/core/cs/tweets.go +++ b/internal/core/cs/tweets.go @@ -88,8 +88,8 @@ type TweetInfo struct { type TweetItem struct { ID int64 `json:"id"` UserID int64 `json:"user_id"` - User *UserInfo `json:"user"` - Contents []*TweetBlock `json:"contents"` + User *UserInfo `db:"user" json:"user"` + Contents []*TweetBlock `db:"-" json:"contents"` CommentCount int64 `json:"comment_count"` CollectionCount int64 `json:"collection_count"` UpvoteCount int64 `json:"upvote_count"` 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..eab6d85c --- /dev/null +++ b/internal/core/ms/tweets.go @@ -0,0 +1,43 @@ +// 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 +) + +const ( + PostVisitPublic PostVisibleT = iota + PostVisitPrivate + PostVisitFriend + PostVisitInvalid +) + +type ( + PostStar = dbr.PostStar + PostCollection = dbr.PostCollection + PostAttachmentBill = dbr.PostAttachmentBill + PostContent = dbr.PostContent + Attachment = dbr.Attachment + AttachmentType = dbr.AttachmentType + PostContentT = dbr.PostContentT + PostVisibleT = dbr.PostVisibleT +) diff --git a/internal/core/ms/user.go b/internal/core/ms/user.go new file mode 100644 index 00000000..88cc6e73 --- /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 `db:"username" 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..97fda8e3 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) - CreateAttachment(obj *cs.Attachment) (int64, 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 *ms.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/dbr/comment.go b/internal/dao/jinzhu/dbr/comment.go index 6f2f33c3..4f673336 100644 --- a/internal/dao/jinzhu/dbr/comment.go +++ b/internal/dao/jinzhu/dbr/comment.go @@ -79,7 +79,7 @@ func (c *Comment) List(db *gorm.DB, conditions *ConditionsT, offset, limit int) db = db.Offset(offset).Limit(limit) } if c.PostID > 0 { - db = db.Where("id = ?", c.PostID) + db = db.Where("post_id = ?", c.PostID) } for k, v := range *conditions { diff --git a/internal/dao/jinzhu/dbr/comment_reply.go b/internal/dao/jinzhu/dbr/comment_reply.go index a1c562f6..dcdfde21 100644 --- a/internal/dao/jinzhu/dbr/comment_reply.go +++ b/internal/dao/jinzhu/dbr/comment_reply.go @@ -13,9 +13,9 @@ import ( type CommentReply struct { *Model - CommentID int64 `json:"comment_id"` - UserID int64 `json:"user_id"` - AtUserID int64 `json:"at_user_id"` + CommentID int64 `db:"comment_id" json:"comment_id"` + UserID int64 `db:"user_id" json:"user_id"` + AtUserID int64 `db:"at_user_id" json:"at_user_id"` Content string `json:"content"` IP string `json:"ip"` IPLoc string `json:"ip_loc"` @@ -25,10 +25,10 @@ type CommentReply struct { type CommentReplyFormated struct { ID int64 `json:"id"` - CommentID int64 `json:"comment_id"` - UserID int64 `json:"user_id"` + CommentID int64 `db:"comment_id" json:"comment_id"` + UserID int64 `db:"user_id" json:"user_id"` User *UserFormated `json:"user"` - AtUserID int64 `json:"at_user_id"` + AtUserID int64 `db:"at_user_id" json:"at_user_id"` AtUser *UserFormated `json:"at_user"` Content string `json:"content"` IPLoc string `json:"ip_loc"` diff --git a/internal/dao/jinzhu/dbr/post.go b/internal/dao/jinzhu/dbr/post.go index e206872b..be4582c6 100644 --- a/internal/dao/jinzhu/dbr/post.go +++ b/internal/dao/jinzhu/dbr/post.go @@ -120,7 +120,7 @@ func (p *Post) Get(db *gorm.DB) (*Post, error) { return &post, nil } -func (p *Post) List(db *gorm.DB, conditions *ConditionsT, offset, limit int) ([]*Post, error) { +func (p *Post) List(db *gorm.DB, conditions ConditionsT, offset, limit int) ([]*Post, error) { var posts []*Post var err error if offset >= 0 && limit > 0 { @@ -129,7 +129,7 @@ func (p *Post) List(db *gorm.DB, conditions *ConditionsT, offset, limit int) ([] if p.UserID > 0 { db = db.Where("user_id = ?", p.UserID) } - for k, v := range *conditions { + for k, v := range conditions { if k == "ORDER" { db = db.Order(v) } else { @@ -178,12 +178,12 @@ func (p *Post) CountBy(db *gorm.DB, predicates Predicates) (count int64, err err return } -func (p *Post) Count(db *gorm.DB, conditions *ConditionsT) (int64, error) { +func (p *Post) Count(db *gorm.DB, conditions ConditionsT) (int64, error) { var count int64 if p.UserID > 0 { db = db.Where("user_id = ?", p.UserID) } - for k, v := range *conditions { + for k, v := range conditions { if k != "ORDER" { db = db.Where(k, v) } diff --git a/internal/dao/jinzhu/dbr/post_collection.go b/internal/dao/jinzhu/dbr/post_collection.go index 8ac6c113..23604ff1 100644 --- a/internal/dao/jinzhu/dbr/post_collection.go +++ b/internal/dao/jinzhu/dbr/post_collection.go @@ -14,8 +14,8 @@ import ( type PostCollection struct { *Model Post *Post `json:"-"` - PostID int64 `json:"post_id"` - UserID int64 `json:"user_id"` + PostID int64 `db:"post_id" json:"post_id"` + UserID int64 `db:"user_id" json:"user_id"` } func (p *PostCollection) Get(db *gorm.DB) (*PostCollection, error) { diff --git a/internal/dao/jinzhu/dbr/post_content.go b/internal/dao/jinzhu/dbr/post_content.go index 672cc57e..5f257630 100644 --- a/internal/dao/jinzhu/dbr/post_content.go +++ b/internal/dao/jinzhu/dbr/post_content.go @@ -44,7 +44,7 @@ type PostContent struct { } type PostContentFormated struct { - ID int64 `json:"id"` + ID int64 `db:"id" json:"id"` PostID int64 `json:"post_id"` Content string `json:"content"` Type PostContentT `json:"type"` diff --git a/internal/dao/jinzhu/dbr/user.go b/internal/dao/jinzhu/dbr/user.go index a6ef63ef..7297e39f 100644 --- a/internal/dao/jinzhu/dbr/user.go +++ b/internal/dao/jinzhu/dbr/user.go @@ -28,7 +28,7 @@ type User struct { } type UserFormated struct { - ID int64 `json:"id"` + ID int64 `db:"id" json:"id"` Nickname string `json:"nickname"` Username string `json:"username"` Status int `json:"status"` 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..18a8ccae 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" ) @@ -20,25 +21,27 @@ var ( type securitySrv struct { db *gorm.DB + rand *rand.Rand phoneVerify core.PhoneVerifyService } func newSecurityService(db *gorm.DB, phoneVerify core.PhoneVerifyService) core.SecurityService { return &securitySrv{ db: db, + rand: rand.New(rand.NewSource(time.Now().UnixNano())), phoneVerify: phoneVerify, } } // 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) } @@ -48,8 +51,7 @@ func (s *securitySrv) SendPhoneCaptcha(phone string) error { expire := time.Duration(5) // 发送验证码 - rand.Seed(time.Now().UnixNano()) - captcha := strconv.Itoa(rand.Intn(900000) + 100000) + captcha := strconv.Itoa(s.rand.Intn(900000) + 100000) if err := s.phoneVerify.SendPhoneCaptcha(phone, captcha, expire); err != nil { return err } 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..d661831d 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,20 +189,20 @@ 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) } -func (s *tweetManageSrv) CreateAttachment(obj *cs.Attachment) (int64, error) { - // TODO - return 0, debug.ErrNotImplemented +func (s *tweetManageSrv) CreateAttachment(obj *ms.Attachment) (int64, error) { + attachment, err := obj.Create(s.db) + return attachment.ID, err } -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/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 ae84a267..c35c4617 100644 --- a/internal/model/web/priv.go +++ b/internal/model/web/priv.go @@ -12,7 +12,7 @@ import ( "github.com/alimy/mir/v4" "github.com/gin-gonic/gin" "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/servants/base" "github.com/rocboss/paopao-ce/pkg/convert" "github.com/rocboss/paopao-ce/pkg/xerror" @@ -32,9 +32,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 { @@ -47,7 +47,7 @@ type CreateTweetReq struct { ClientIP string `json:"-" binding:"-"` } -type CreateTweetResp core.PostFormated +type CreateTweetResp ms.PostFormated type DeleteTweetReq struct { BaseInfo `json:"-" binding:"-"` @@ -108,7 +108,7 @@ type CreateCommentReq struct { ClientIP string `json:"-" binding:"-"` } -type CreateCommentResp core.Comment +type CreateCommentResp ms.Comment type CreateCommentReplyReq struct { SimpleInfo `json:"-" binding:"-"` @@ -118,7 +118,7 @@ type CreateCommentReplyReq struct { ClientIP string `json:"-" binding:"-"` } -type CreateCommentReplyResp core.CommentReply +type CreateCommentReplyResp ms.CommentReply type DeleteCommentReq struct { BaseInfo `json:"-" binding:"-"` @@ -143,7 +143,7 @@ type UploadAttachmentResp struct { FileSize int64 `json:"file_size"` ImgWidth int `json:"img_width"` ImgHeight int `json:"img_height"` - Type cs.AttachmentType `json:"type"` + Type ms.AttachmentType `json:"type"` Content string `json:"content"` } @@ -187,13 +187,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 d9c416bb..d197bb19 100644 --- a/internal/model/web/web.go +++ b/internal/model/web/web.go @@ -7,7 +7,7 @@ package web import ( "github.com/alimy/mir/v4" "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" @@ -18,7 +18,7 @@ var ( ) type BaseInfo struct { - User *core.User + User *ms.User } type SimpleInfo struct { @@ -31,7 +31,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 c03333ca..1825fe98 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" @@ -48,7 +49,7 @@ type SentryHubSetter interface { } type UserSetter interface { - SetUser(*core.User) + SetUser(*ms.User) } type UserIdSetter interface { @@ -59,9 +60,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 @@ -175,7 +176,7 @@ func (s *BaseServant) Render(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 @@ -206,20 +207,21 @@ func (s *DaoServant) PushPostsToSearch(c context.Context) { defer s.Redis.DelPushToSearchJob(c) splitNum := 1000 - totalRows, _ := s.Ds.GetPostCount(&core.ConditionsT{ + conditions := ms.ConditionsT{ "visibility IN ?": []core.PostVisibleT{core.PostVisitPublic, core.PostVisitFriend}, - }) + } + totalRows, _ := s.Ds.GetPostCount(conditions) 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(conditions, 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" } } @@ -235,9 +237,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}) @@ -247,7 +249,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" } } @@ -259,11 +261,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 8532b391..923b0261 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" @@ -85,7 +86,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", } @@ -98,7 +99,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 { @@ -157,10 +158,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, }) @@ -187,7 +188,7 @@ func (s *coreSrv) GetCollections(req *web.GetCollectionsReq) (*web.GetCollection return nil, web.ErrGetCollectionsFailed } - var posts []*core.Post + var posts []*ms.Post for _, collection := range collections { posts = append(posts, collection.Post) } @@ -250,7 +251,7 @@ func (s *coreSrv) GetStars(req *web.GetStarsReq) (*web.GetStarsResp, mir.Error) return nil, web.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 282b34d1..81875441 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" @@ -121,7 +122,7 @@ func (s *looseSrv) getSelfStarTweets(req *web.GetUserTweetsReq) (*web.GetUserTwe logrus.Errorf("Ds.GetUserPostStars err: %s", err) return nil, web.ErrGetStarsFailed } - var posts []*core.Post + var posts []*ms.Post for _, star := range stars { posts = append(posts, star.Post) } @@ -151,7 +152,7 @@ func (s *looseSrv) getUserPostTweets(req *web.GetUserTweetsReq) (*web.GetUserTwe visibilities = append(visibilities, core.PostVisitFriend) } } - conditions := &core.ConditionsT{ + conditions := ms.ConditionsT{ "user_id": other.ID, "visibility IN ?": visibilities, "ORDER": "latest_replied_on DESC", @@ -236,7 +237,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, } @@ -290,7 +291,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 d01ae288..e4e04a20 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" @@ -28,7 +29,13 @@ import ( var ( _ api.Priv = (*privSrv)(nil) - _uploadAttachmentTypeMap = map[string]cs.AttachmentType{ + _uploadAttachmentTypeMap = map[string]ms.AttachmentType{ + "public/image": ms.AttachmentTypeImage, + "public/avatar": ms.AttachmentTypeImage, + "public/video": ms.AttachmentTypeVideo, + "attachment": ms.AttachmentTypeOther, + } + _uploadAttachmentTypes = map[string]cs.AttachmentType{ "public/image": cs.AttachmentTypeImage, "public/avatar": cs.AttachmentTypeImage, "public/video": cs.AttachmentTypeVideo, @@ -119,20 +126,20 @@ func (s *privSrv) UploadAttachment(req *web.UploadAttachmentReq) (*web.UploadAtt } // 构造附件Model - attachment := &cs.Attachment{ + attachment := &ms.Attachment{ UserID: req.Uid, FileSize: req.FileSize, Content: objectUrl, Type: _uploadAttachmentTypeMap[req.UploadType], } - if attachment.Type == cs.AttachmentTypeImage { + if attachment.Type == ms.AttachmentTypeImage { var src image.Image src, err = imaging.Decode(req.File) if err == nil { attachment.ImgWidth, attachment.ImgHeight = getImageSize(src.Bounds()) } } - attachment.ID, err = s.Dsa.CreateAttachment(attachment) + attachment.ID, err = s.Ds.CreateAttachment(attachment) if err != nil { logrus.Errorf("Ds.CreateAttachment err: %s", err) return nil, web.ErrFileUploadFailed @@ -155,7 +162,7 @@ func (s *privSrv) DownloadAttachmentPrecheck(req *web.DownloadAttachmentPrecheck return nil, web.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) @@ -178,7 +185,7 @@ func (s *privSrv) DownloadAttachment(req *web.DownloadAttachmentReq) (*web.Downl return nil, web.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) @@ -191,8 +198,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, @@ -229,7 +236,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, @@ -250,10 +257,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, @@ -280,10 +287,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, }) @@ -291,7 +298,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, web.ErrCreatePostFailed @@ -347,8 +354,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 ) @@ -358,7 +365,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, @@ -383,10 +390,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, @@ -395,10 +402,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, @@ -409,10 +416,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, @@ -475,7 +482,7 @@ func (s *privSrv) CreateComment(req *web.CreateCommentReq) (_ *web.CreateComment if post.CommentCount >= conf.AppSetting.MaxCommentCount { return nil, web.ErrMaxCommentCount } - comment := &core.Comment{ + comment := &ms.Comment{ PostID: post.ID, UserID: req.Uid, IP: req.ClientIP, @@ -489,12 +496,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, @@ -515,10 +522,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, @@ -531,10 +538,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, @@ -644,7 +651,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 @@ -668,7 +675,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) @@ -701,7 +708,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 @@ -727,7 +734,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 @@ -752,7 +759,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 @@ -778,7 +785,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 @@ -807,7 +814,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 web.ErrInsuffientDownloadMoney } diff --git a/internal/servants/web/pub.go b/internal/servants/web/pub.go index d34f074f..f12f74ee 100644 --- a/internal/servants/web/pub.go +++ b/internal/servants/web/pub.go @@ -17,7 +17,7 @@ import ( "github.com/alimy/mir/v4" "github.com/gofrs/uuid/v5" 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" @@ -131,13 +131,13 @@ func (s *pubSrv) Register(req *web.RegisterReq) (*web.RegisterResp, mir.Error) { return nil, web.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 { @@ -164,7 +164,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, web.ErrUserHasBeenBanned } // 清空登录计数 diff --git a/internal/servants/web/utils.go b/internal/servants/web/utils.go index b54fbd50..0e2696e3 100644 --- a/internal/servants/web/utils.go +++ b/internal/servants/web/utils.go @@ -14,6 +14,7 @@ import ( "github.com/alimy/mir/v4" "github.com/gofrs/uuid/v5" "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 web.ErrNoPermission } diff --git a/mirc/gen.go b/mirc/gen.go index b2ebe43d..dcd402ac 100644 --- a/mirc/gen.go +++ b/mirc/gen.go @@ -23,7 +23,7 @@ import ( //go:generate go run $GOFILE func main() { - log.Println("generate code start") + log.Println("[Mir] generate code start") opts := Options{ UseGin(), SinkPath("../auto"), @@ -34,5 +34,5 @@ func main() { if err := Generate(opts); err != nil { log.Fatal(err) } - log.Println("generate code finish") + log.Println("[Mir] generate code finish") } 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, diff --git a/pkg/naming/naming_test.go b/pkg/naming/naming_test.go index ee688822..fb89aa97 100644 --- a/pkg/naming/naming_test.go +++ b/pkg/naming/naming_test.go @@ -19,8 +19,12 @@ func TestSnakeNamingStrategy_Naming(t *testing.T) { {name: "RESTfulAPI", expected: "res_tful_api"}, {name: "HTTPS_API", expected: "https_api"}, {name: "PKG_Name", expected: "pkg_name"}, + {name: "UserID", expected: "user_id"}, + {name: "UserId", expected: "user_id"}, + {name: "IPLoc", expected: "ip_loc"}, {name: "API", expected: "api"}, {name: "HTTP", expected: "http"}, + {name: "IP", expected: "ip"}, } { result := ns.Naming(cs.name) if result != cs.expected {