From 67530109292cf0364ff5e4654907950ff6304fa9 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Fri, 2 Jun 2023 20:54:36 +0800 Subject: [PATCH 01/19] ajust internal/core interface related model type to split package --- internal/core/authority.go | 114 +------------------------- internal/core/cache.go | 3 +- internal/core/comments.go | 32 +++----- 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 | 35 ++++++++ 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 | 74 ++++++----------- 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/messages.go | 11 +-- internal/dao/jinzhu/security.go | 5 +- internal/dao/jinzhu/timeline.go | 15 ++-- internal/dao/jinzhu/topics.go | 19 ++--- internal/dao/jinzhu/tweets.go | 49 ++++++------ internal/dao/jinzhu/user.go | 15 ++-- internal/dao/jinzhu/wallet.go | 11 +-- internal/dao/sakila/authority.go | 7 +- internal/dao/sakila/comments.go | 23 +++--- internal/dao/sakila/contacts.go | 3 +- internal/dao/sakila/messages.go | 11 +-- internal/dao/sakila/security.go | 5 +- internal/dao/sakila/timeline.go | 17 ++-- internal/dao/sakila/tweets.go | 49 ++++++------ internal/dao/sakila/user.go | 15 ++-- internal/dao/sakila/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 | 17 ++-- internal/model/web/pub.go | 4 +- internal/model/web/web.go | 6 +- internal/servants/base/base.go | 25 +++--- internal/servants/chain/admin.go | 6 +- internal/servants/chain/priv.go | 8 +- internal/servants/web/core.go | 13 +-- internal/servants/web/loose.go | 7 +- internal/servants/web/priv.go | 69 ++++++++-------- internal/servants/web/pub.go | 8 +- internal/servants/web/utils.go | 13 +-- pkg/app/jwt.go | 4 +- 57 files changed, 625 insertions(+), 522 deletions(-) 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/messages.go b/internal/core/messages.go index 57816480..519e4e49 100644 --- a/internal/core/messages.go +++ b/internal/core/messages.go @@ -5,32 +5,15 @@ package core import ( - "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" -) - -const ( - MsgTypePost = dbr.MsgTypePost - MsgtypeComment = dbr.MsgtypeComment - MsgTypeReply = dbr.MsgTypeReply - MsgTypeWhisper = dbr.MsgTypeWhisper - MsgTypeRequestingFriend = dbr.MsgTypeRequestingFriend - MsgTypeSystem = dbr.MsgTypeSystem - - MsgStatusUnread = dbr.MsgStatusUnread - MsgStatusReaded = dbr.MsgStatusReaded -) - -type ( - Message = dbr.Message - MessageFormated = dbr.MessageFormated + "github.com/rocboss/paopao-ce/internal/core/ms" ) // MessageService 消息服务 type MessageService interface { - CreateMessage(msg *Message) (*Message, error) + CreateMessage(msg *ms.Message) (*ms.Message, error) GetUnreadCount(userID int64) (int64, error) - GetMessageByID(id int64) (*Message, error) - ReadMessage(message *Message) error - GetMessages(conditions *ConditionsT, offset, limit int) ([]*MessageFormated, error) - GetMessageCount(conditions *ConditionsT) (int64, error) + GetMessageByID(id int64) (*ms.Message, error) + ReadMessage(message *ms.Message) error + GetMessages(conditions *ms.ConditionsT, offset, limit int) ([]*ms.MessageFormated, error) + GetMessageCount(conditions *ms.ConditionsT) (int64, error) } diff --git a/internal/core/ms/authority.go b/internal/core/ms/authority.go new file mode 100644 index 00000000..d6378696 --- /dev/null +++ b/internal/core/ms/authority.go @@ -0,0 +1,115 @@ +// Copyright 2023 ROC. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +package ms + +import ( + "github.com/rocboss/paopao-ce/pkg/types" +) + +const ( + ActRegisterUser act = iota + ActCreatePublicTweet + ActCreatePublicAttachment + ActCreatePublicPicture + ActCreatePublicVideo + ActCreatePrivateTweet + ActCreatePrivateAttachment + ActCreatePrivatePicture + ActCreatePrivateVideo + ActCreateFriendTweet + ActCreateFriendAttachment + ActCreateFriendPicture + ActCreateFriendVideo + ActCreatePublicComment + ActCreatePublicPicureComment + ActCreateFriendComment + ActCreateFriendPicureComment + ActCreatePrivateComment + ActCreatePrivatePicureComment + ActStickTweet + ActTopTweet + ActLockTweet + ActVisibleTweet + ActDeleteTweet + ActCreateActivationCode +) + +type ( + act uint8 + + FriendFilter map[int64]types.Empty + FriendSet map[string]types.Empty + + Action struct { + Act act + UserId int64 + } +) + +func (f FriendFilter) IsFriend(userId int64) bool { + _, yeah := f[userId] + return yeah +} + +// IsAllow default true if user is admin +func (a act) IsAllow(user *User, userId int64, isFriend bool, isActivation bool) bool { + if user.IsAdmin { + return true + } + if user.ID == userId && isActivation { + switch a { + case ActCreatePublicTweet, + ActCreatePublicAttachment, + ActCreatePublicPicture, + ActCreatePublicVideo, + ActCreatePrivateTweet, + ActCreatePrivateAttachment, + ActCreatePrivatePicture, + ActCreatePrivateVideo, + ActCreateFriendTweet, + ActCreateFriendAttachment, + ActCreateFriendPicture, + ActCreateFriendVideo, + ActCreatePrivateComment, + ActCreatePrivatePicureComment, + ActStickTweet, + ActLockTweet, + ActVisibleTweet, + ActDeleteTweet: + return true + } + } + + if user.ID == userId && !isActivation { + switch a { + case ActCreatePrivateTweet, + ActCreatePrivateComment, + ActStickTweet, + ActLockTweet, + ActDeleteTweet: + return true + } + } + + if isFriend && isActivation { + switch a { + case ActCreatePublicComment, + ActCreatePublicPicureComment, + ActCreateFriendComment, + ActCreateFriendPicureComment: + return true + } + } + + if !isFriend && isActivation { + switch a { + case ActCreatePublicComment, + ActCreatePublicPicureComment: + return true + } + } + + return false +} diff --git a/internal/core/ms/comments.go b/internal/core/ms/comments.go new file mode 100644 index 00000000..87ef2473 --- /dev/null +++ b/internal/core/ms/comments.go @@ -0,0 +1,17 @@ +// Copyright 2023 ROC. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +package ms + +import ( + "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" +) + +type ( + Comment = dbr.Comment + CommentFormated = dbr.CommentFormated + CommentReply = dbr.CommentReply + CommentContent = dbr.CommentContent + CommentReplyFormated = dbr.CommentReplyFormated +) diff --git a/internal/core/ms/messages.go b/internal/core/ms/messages.go new file mode 100644 index 00000000..adf793f8 --- /dev/null +++ b/internal/core/ms/messages.go @@ -0,0 +1,26 @@ +// Copyright 2023 ROC. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +package ms + +import ( + "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" +) + +const ( + MsgTypePost = dbr.MsgTypePost + MsgtypeComment = dbr.MsgtypeComment + MsgTypeReply = dbr.MsgTypeReply + MsgTypeWhisper = dbr.MsgTypeWhisper + MsgTypeRequestingFriend = dbr.MsgTypeRequestingFriend + MsgTypeSystem = dbr.MsgTypeSystem + + MsgStatusUnread = dbr.MsgStatusUnread + MsgStatusReaded = dbr.MsgStatusReaded +) + +type ( + Message = dbr.Message + MessageFormated = dbr.MessageFormated +) diff --git a/internal/core/types.go b/internal/core/ms/ms.go similarity index 79% rename from internal/core/types.go rename to internal/core/ms/ms.go index 6ca95893..8993251f 100644 --- a/internal/core/types.go +++ b/internal/core/ms/ms.go @@ -1,8 +1,10 @@ -// Copyright 2022 ROC. All rights reserved. +// Copyright 2023 ROC. All rights reserved. // Use of this source code is governed by a MIT style // license that can be found in the LICENSE file. -package core +// Package ms contain core data service interface type +// model define for gorm adapter +package ms import ( "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" diff --git a/internal/core/ms/security.go b/internal/core/ms/security.go new file mode 100644 index 00000000..a6610ca1 --- /dev/null +++ b/internal/core/ms/security.go @@ -0,0 +1,13 @@ +// Copyright 2023 ROC. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +package ms + +import ( + "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" +) + +type ( + Captcha = dbr.Captcha +) diff --git a/internal/core/ms/timeline.go b/internal/core/ms/timeline.go new file mode 100644 index 00000000..eb1169f4 --- /dev/null +++ b/internal/core/ms/timeline.go @@ -0,0 +1,10 @@ +// Copyright 2023 ROC. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +package ms + +type IndexTweetList struct { + Tweets []*PostFormated + Total int64 +} diff --git a/internal/core/ms/tweets.go b/internal/core/ms/tweets.go new file mode 100644 index 00000000..230775ff --- /dev/null +++ b/internal/core/ms/tweets.go @@ -0,0 +1,35 @@ +// Copyright 2023 ROC. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +package ms + +import ( + "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" +) + +const ( + AttachmentTypeImage = dbr.AttachmentTypeImage + AttachmentTypeVideo = dbr.AttachmentTypeVideo + AttachmentTypeOther = dbr.AttachmentTypeOther + + // 类型,1标题,2文字段落,3图片地址,4视频地址,5语音地址,6链接地址,7附件资源 + ContentTypeTitle = dbr.ContentTypeTitle + ContentTypeText = dbr.ContentTypeText + ContentTypeImage = dbr.ContentTypeImage + ContentTypeVideo = dbr.ContentTypeVideo + ContentTypeAudio = dbr.ContentTypeAudio + ContentTypeLink = dbr.ContentTypeLink + ContentTypeAttachment = dbr.ContentTypeAttachment + ContentTypeChargeAttachment = dbr.ContentTypeChargeAttachment +) + +type ( + PostStar = dbr.PostStar + PostCollection = dbr.PostCollection + PostAttachmentBill = dbr.PostAttachmentBill + PostContent = dbr.PostContent + Attachment = dbr.Attachment + AttachmentType = dbr.AttachmentType + PostContentT = dbr.PostContentT +) diff --git a/internal/core/ms/user.go b/internal/core/ms/user.go new file mode 100644 index 00000000..4c7ea8ab --- /dev/null +++ b/internal/core/ms/user.go @@ -0,0 +1,20 @@ +// Copyright 2023 ROC. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +package ms + +type ( + ContactItem struct { + UserId int64 `json:"user_id"` + UserName string `json:"username"` + Nickname string `json:"nickname"` + Avatar string `json:"avatar"` + Phone string `json:"phone"` + } + + ContactList struct { + Contacts []ContactItem `json:"contacts"` + Total int64 `json:"total"` + } +) diff --git a/internal/core/ms/wallet.go b/internal/core/ms/wallet.go new file mode 100644 index 00000000..5786fcac --- /dev/null +++ b/internal/core/ms/wallet.go @@ -0,0 +1,14 @@ +// Copyright 2023 ROC. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +package ms + +import ( + "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" +) + +type ( + WalletStatement = dbr.WalletStatement + WalletRecharge = dbr.WalletRecharge +) diff --git a/internal/core/search.go b/internal/core/search.go index 17b65fad..dc08e127 100644 --- a/internal/core/search.go +++ b/internal/core/search.go @@ -5,6 +5,7 @@ package core import ( + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" ) @@ -33,12 +34,12 @@ type ( } QueryResp struct { - Items []*PostFormated + Items []*ms.PostFormated Total int64 } TsDocItem struct { - Post *Post + Post *ms.Post Content string } ) @@ -48,5 +49,5 @@ type TweetSearchService interface { IndexName() string AddDocuments(data []TsDocItem, primaryKey ...string) (bool, error) DeleteDocuments(identifiers []string) error - Search(user *User, q *QueryReq, offset, limit int) (*QueryResp, error) + Search(user *ms.User, q *QueryReq, offset, limit int) (*QueryResp, error) } diff --git a/internal/core/security.go b/internal/core/security.go index ce313635..0643cc28 100644 --- a/internal/core/security.go +++ b/internal/core/security.go @@ -7,17 +7,13 @@ package core import ( "time" - "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" -) - -type ( - Captcha = dbr.Captcha + "github.com/rocboss/paopao-ce/internal/core/ms" ) // SecurityService 安全相关服务 type SecurityService interface { - GetLatestPhoneCaptcha(phone string) (*Captcha, error) - UsePhoneCaptcha(captcha *Captcha) error + GetLatestPhoneCaptcha(phone string) (*ms.Captcha, error) + UsePhoneCaptcha(captcha *ms.Captcha) error SendPhoneCaptcha(phone string) error } diff --git a/internal/core/timeline.go b/internal/core/timeline.go index 02de2b62..722e79f3 100644 --- a/internal/core/timeline.go +++ b/internal/core/timeline.go @@ -6,19 +6,15 @@ package core import ( "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" ) -type IndexTweetList struct { - Tweets []*PostFormated - Total int64 -} - // IndexPostsService 广场首页推文列表服务 type IndexPostsService interface { - IndexPosts(user *User, offset int, limit int) (*IndexTweetList, error) + IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) } // IndexPostsServantA 广场首页推文列表服务(版本A) type IndexPostsServantA interface { - IndexPosts(user *User, limit int, offset int) (*cs.TweetBox, error) + IndexPosts(user *ms.User, limit int, offset int) (*cs.TweetBox, error) } diff --git a/internal/core/tweets.go b/internal/core/tweets.go index 9c316257..4ea9126d 100644 --- a/internal/core/tweets.go +++ b/internal/core/tweets.go @@ -6,71 +6,45 @@ package core import ( "github.com/rocboss/paopao-ce/internal/core/cs" - "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" -) - -const ( - AttachmentTypeImage = dbr.AttachmentTypeImage - AttachmentTypeVideo = dbr.AttachmentTypeVideo - AttachmentTypeOther = dbr.AttachmentTypeOther - - // 类型,1标题,2文字段落,3图片地址,4视频地址,5语音地址,6链接地址,7附件资源 - ContentTypeTitle = dbr.ContentTypeTitle - ContentTypeText = dbr.ContentTypeText - ContentTypeImage = dbr.ContentTypeImage - ContentTypeVideo = dbr.ContentTypeVideo - ContentTypeAudio = dbr.ContentTypeAudio - ContentTypeLink = dbr.ContentTypeLink - ContentTypeAttachment = dbr.ContentTypeAttachment - ContentTypeChargeAttachment = dbr.ContentTypeChargeAttachment -) - -type ( - PostStar = dbr.PostStar - PostCollection = dbr.PostCollection - PostAttachmentBill = dbr.PostAttachmentBill - PostContent = dbr.PostContent - Attachment = dbr.Attachment - AttachmentType = dbr.AttachmentType - PostContentT = dbr.PostContentT + "github.com/rocboss/paopao-ce/internal/core/ms" ) // TweetService 推文检索服务 type TweetService interface { - GetPostByID(id int64) (*Post, error) - GetPosts(conditions *ConditionsT, offset, limit int) ([]*Post, error) - GetPostCount(conditions *ConditionsT) (int64, error) - GetUserPostStar(postID, userID int64) (*PostStar, error) - GetUserPostStars(userID int64, offset, limit int) ([]*PostStar, error) + GetPostByID(id int64) (*ms.Post, error) + GetPosts(conditions *ms.ConditionsT, offset, limit int) ([]*ms.Post, error) + GetPostCount(conditions *ms.ConditionsT) (int64, error) + GetUserPostStar(postID, userID int64) (*ms.PostStar, error) + GetUserPostStars(userID int64, offset, limit int) ([]*ms.PostStar, error) GetUserPostStarCount(userID int64) (int64, error) - GetUserPostCollection(postID, userID int64) (*PostCollection, error) - GetUserPostCollections(userID int64, offset, limit int) ([]*PostCollection, error) + GetUserPostCollection(postID, userID int64) (*ms.PostCollection, error) + GetUserPostCollections(userID int64, offset, limit int) ([]*ms.PostCollection, error) GetUserPostCollectionCount(userID int64) (int64, error) - GetPostAttatchmentBill(postID, userID int64) (*PostAttachmentBill, error) - GetPostContentsByIDs(ids []int64) ([]*PostContent, error) - GetPostContentByID(id int64) (*PostContent, error) + GetPostAttatchmentBill(postID, userID int64) (*ms.PostAttachmentBill, error) + GetPostContentsByIDs(ids []int64) ([]*ms.PostContent, error) + GetPostContentByID(id int64) (*ms.PostContent, error) } // TweetManageService 推文管理服务,包括创建/删除/更新推文 type TweetManageService interface { - CreatePost(post *Post) (*Post, error) - DeletePost(post *Post) ([]string, error) - LockPost(post *Post) error - StickPost(post *Post) error - VisiblePost(post *Post, visibility PostVisibleT) error - UpdatePost(post *Post) error - CreatePostStar(postID, userID int64) (*PostStar, error) - DeletePostStar(p *PostStar) error - CreatePostCollection(postID, userID int64) (*PostCollection, error) - DeletePostCollection(p *PostCollection) error - CreatePostContent(content *PostContent) (*PostContent, error) + CreatePost(post *ms.Post) (*ms.Post, error) + DeletePost(post *ms.Post) ([]string, error) + LockPost(post *ms.Post) error + StickPost(post *ms.Post) error + VisiblePost(post *ms.Post, visibility PostVisibleT) error + UpdatePost(post *ms.Post) error + CreatePostStar(postID, userID int64) (*ms.PostStar, error) + DeletePostStar(p *ms.PostStar) error + CreatePostCollection(postID, userID int64) (*ms.PostCollection, error) + DeletePostCollection(p *ms.PostCollection) error + CreatePostContent(content *ms.PostContent) (*ms.PostContent, error) CreateAttachment(obj *cs.Attachment) (int64, error) } // TweetHelpService 推文辅助服务 type TweetHelpService interface { - RevampPosts(posts []*PostFormated) ([]*PostFormated, error) - MergePosts(posts []*Post) ([]*PostFormated, error) + RevampPosts(posts []*ms.PostFormated) ([]*ms.PostFormated, error) + MergePosts(posts []*ms.Post) ([]*ms.PostFormated, error) } // TweetServantA 推文检索服务(版本A) diff --git a/internal/core/user.go b/internal/core/user.go index ed132dd3..04d30e23 100644 --- a/internal/core/user.go +++ b/internal/core/user.go @@ -4,30 +4,17 @@ package core -type ( - ContactItem struct { - UserId int64 `json:"user_id"` - UserName string `json:"username"` - Nickname string `json:"nickname"` - Avatar string `json:"avatar"` - Phone string `json:"phone"` - } - - ContactList struct { - Contacts []ContactItem `json:"contacts"` - Total int64 `json:"total"` - } -) +import "github.com/rocboss/paopao-ce/internal/core/ms" // UserManageService 用户管理服务 type UserManageService interface { - GetUserByID(id int64) (*User, error) - GetUserByUsername(username string) (*User, error) - GetUserByPhone(phone string) (*User, error) - GetUsersByIDs(ids []int64) ([]*User, error) - GetUsersByKeyword(keyword string) ([]*User, error) - CreateUser(user *User) (*User, error) - UpdateUser(user *User) error + GetUserByID(id int64) (*ms.User, error) + GetUserByUsername(username string) (*ms.User, error) + GetUserByPhone(phone string) (*ms.User, error) + GetUsersByIDs(ids []int64) ([]*ms.User, error) + GetUsersByKeyword(keyword string) ([]*ms.User, error) + CreateUser(user *ms.User) (*ms.User, error) + UpdateUser(user *ms.User) error } // ContactManageService 联系人管理服务 @@ -36,6 +23,6 @@ type ContactManageService interface { AddFriend(userId int64, friendId int64) error RejectFriend(userId int64, friendId int64) error DeleteFriend(userId int64, friendId int64) error - GetContacts(userId int64, offset int, limit int) (*ContactList, error) + GetContacts(userId int64, offset int, limit int) (*ms.ContactList, error) IsFriend(userID int64, friendID int64) bool } diff --git a/internal/core/wallet.go b/internal/core/wallet.go index c4792d3b..e452a3ad 100644 --- a/internal/core/wallet.go +++ b/internal/core/wallet.go @@ -5,20 +5,15 @@ package core import ( - "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" -) - -type ( - WalletStatement = dbr.WalletStatement - WalletRecharge = dbr.WalletRecharge + "github.com/rocboss/paopao-ce/internal/core/ms" ) // WalletService wallet service interface type WalletService interface { - GetUserWalletBills(userID int64, offset, limit int) ([]*WalletStatement, error) + GetUserWalletBills(userID int64, offset, limit int) ([]*ms.WalletStatement, error) GetUserWalletBillCount(userID int64) (int64, error) - GetRechargeByID(id int64) (*WalletRecharge, error) - CreateRecharge(userId, amount int64) (*WalletRecharge, error) - HandleRechargeSuccess(recharge *WalletRecharge, tradeNo string) error - HandlePostAttachmentBought(post *Post, user *User) error + GetRechargeByID(id int64) (*ms.WalletRecharge, error) + CreateRecharge(userId, amount int64) (*ms.WalletRecharge, error) + HandleRechargeSuccess(recharge *ms.WalletRecharge, tradeNo string) error + HandlePostAttachmentBought(post *ms.Post, user *ms.User) error } diff --git a/internal/dao/cache/base.go b/internal/dao/cache/base.go index f8f1e270..fe314683 100644 --- a/internal/dao/cache/base.go +++ b/internal/dao/cache/base.go @@ -15,6 +15,7 @@ import ( "github.com/Masterminds/semver/v3" "github.com/rocboss/paopao-ce/internal/conf" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/pkg/types" "github.com/sirupsen/logrus" ) @@ -30,7 +31,7 @@ var ( type postsEntry struct { key string - tweets *core.IndexTweetList + tweets *ms.IndexTweetList } type tweetsCache interface { @@ -54,7 +55,7 @@ type cacheIndexSrv struct { preventDuration time.Duration } -func (s *cacheIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *cacheIndexSrv) IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { key := s.keyFrom(user, offset, limit) posts, err := s.getPosts(key) if err == nil { @@ -70,7 +71,7 @@ func (s *cacheIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*cor return posts, nil } -func (s *cacheIndexSrv) getPosts(key string) (*core.IndexTweetList, error) { +func (s *cacheIndexSrv) getPosts(key string) (*ms.IndexTweetList, error) { data, err := s.cache.getTweetsBytes(key) if err != nil { logrus.Debugf("cacheIndexSrv.getPosts get posts by key: %s from cache err: %v", key, err) @@ -78,7 +79,7 @@ func (s *cacheIndexSrv) getPosts(key string) (*core.IndexTweetList, error) { } buf := bytes.NewBuffer(data) dec := gob.NewDecoder(buf) - var resp core.IndexTweetList + var resp ms.IndexTweetList if err := dec.Decode(&resp); err != nil { logrus.Debugf("cacheIndexSrv.getPosts get posts from cache in decode err: %v", err) return nil, err @@ -86,7 +87,7 @@ func (s *cacheIndexSrv) getPosts(key string) (*core.IndexTweetList, error) { return &resp, nil } -func (s *cacheIndexSrv) cachePosts(key string, tweets *core.IndexTweetList) { +func (s *cacheIndexSrv) cachePosts(key string, tweets *ms.IndexTweetList) { entry := &postsEntry{key: key, tweets: tweets} select { case s.cachePostsCh <- entry: @@ -112,7 +113,7 @@ func (s *cacheIndexSrv) setPosts(entry *postsEntry) { logrus.Debugf("cacheIndexSrv.setPosts setPosts set cache by key: %s", entry.key) } -func (s *cacheIndexSrv) keyFrom(user *core.User, offset int, limit int) string { +func (s *cacheIndexSrv) keyFrom(user *ms.User, offset int, limit int) string { var userId int64 = -1 if user != nil { userId = user.ID @@ -120,7 +121,7 @@ func (s *cacheIndexSrv) keyFrom(user *core.User, offset int, limit int) string { return fmt.Sprintf("%s:%d:%d:%d", _cacheIndexKey, userId, offset, limit) } -func (s *cacheIndexSrv) SendAction(act core.IdxAct, post *core.Post) { +func (s *cacheIndexSrv) SendAction(act core.IdxAct, post *ms.Post) { action := core.NewIndexAction(act, post) select { case s.indexActionCh <- action: @@ -168,7 +169,7 @@ func (s *cacheIndexSrv) handleIndexAction(action *core.IndexAction) { func (s *cacheIndexSrv) deleteCacheByUserId(id int64, oneself bool) { var keys []string userId := strconv.FormatInt(id, 10) - friendSet := core.FriendSet{} + friendSet := ms.FriendSet{} if !oneself { friendSet = s.ams.MyFriendSet(id) } diff --git a/internal/dao/cache/none.go b/internal/dao/cache/none.go index 350e776a..079c453b 100644 --- a/internal/dao/cache/none.go +++ b/internal/dao/cache/none.go @@ -8,6 +8,7 @@ import ( "github.com/Masterminds/semver/v3" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -20,7 +21,7 @@ type noneCacheIndexServant struct { ips core.IndexPostsService } -func (s *noneCacheIndexServant) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *noneCacheIndexServant) IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { return s.ips.IndexPosts(user, offset, limit) } @@ -29,7 +30,7 @@ func (s *noneCacheIndexServant) TweetTimeline(userId int64, offset int, limit in return nil, debug.ErrNotImplemented } -func (s *noneCacheIndexServant) SendAction(_act core.IdxAct, _post *core.Post) { +func (s *noneCacheIndexServant) SendAction(_act core.IdxAct, _post *ms.Post) { // empty } diff --git a/internal/dao/cache/simple.go b/internal/dao/cache/simple.go index fb704bfc..a1c230d3 100644 --- a/internal/dao/cache/simple.go +++ b/internal/dao/cache/simple.go @@ -11,6 +11,7 @@ import ( "github.com/Masterminds/semver/v3" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/pkg/debug" "github.com/sirupsen/logrus" ) @@ -24,21 +25,21 @@ type simpleCacheIndexServant struct { ips core.IndexPostsService indexActionCh chan core.IdxAct - indexPosts *core.IndexTweetList + indexPosts *ms.IndexTweetList atomicIndex atomic.Value maxIndexSize int checkTick *time.Ticker expireIndexTick *time.Ticker } -func (s *simpleCacheIndexServant) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { - cacheResp := s.atomicIndex.Load().(*core.IndexTweetList) +func (s *simpleCacheIndexServant) IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { + cacheResp := s.atomicIndex.Load().(*ms.IndexTweetList) end := offset + limit if cacheResp != nil { size := len(cacheResp.Tweets) logrus.Debugf("simpleCacheIndexServant.IndexPosts get index posts from cache posts: %d offset:%d limit:%d start:%d, end:%d", size, offset, limit, offset, end) if size >= end { - return &core.IndexTweetList{ + return &ms.IndexTweetList{ Tweets: cacheResp.Tweets[offset:end], Total: cacheResp.Total, }, nil @@ -54,7 +55,7 @@ func (s *simpleCacheIndexServant) TweetTimeline(userId int64, offset int, limit return nil, debug.ErrNotImplemented } -func (s *simpleCacheIndexServant) SendAction(act core.IdxAct, _post *core.Post) { +func (s *simpleCacheIndexServant) SendAction(act core.IdxAct, _post *ms.Post) { select { case s.indexActionCh <- act: logrus.Debugf("simpleCacheIndexServant.SendAction send indexAction by chan: %s", act) diff --git a/internal/dao/jinzhu/authority.go b/internal/dao/jinzhu/authority.go index 3480ceb0..9921f214 100644 --- a/internal/dao/jinzhu/authority.go +++ b/internal/dao/jinzhu/authority.go @@ -6,6 +6,7 @@ package jinzhu import ( "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/rocboss/paopao-ce/pkg/types" "gorm.io/gorm" @@ -25,7 +26,7 @@ func newAuthorizationManageService(db *gorm.DB) core.AuthorizationManageService } } -func (s *authorizationManageSrv) IsAllow(user *core.User, action *core.Action) bool { +func (s *authorizationManageSrv) IsAllow(user *ms.User, action *ms.Action) bool { // user is activation if had bind phone isActivation := (len(user.Phone) != 0) isFriend := s.isFriend(user.ID, action.UserId) @@ -33,26 +34,26 @@ func (s *authorizationManageSrv) IsAllow(user *core.User, action *core.Action) b return action.Act.IsAllow(user, action.UserId, isFriend, isActivation) } -func (s *authorizationManageSrv) MyFriendSet(userId int64) core.FriendSet { +func (s *authorizationManageSrv) MyFriendSet(userId int64) ms.FriendSet { ids, err := (&dbr.Contact{UserId: userId}).MyFriendIds(s.db) if err != nil { - return core.FriendSet{} + return ms.FriendSet{} } - resp := make(core.FriendSet, len(ids)) + resp := make(ms.FriendSet, len(ids)) for _, id := range ids { resp[id] = types.Empty{} } return resp } -func (s *authorizationManageSrv) BeFriendFilter(userId int64) core.FriendFilter { +func (s *authorizationManageSrv) BeFriendFilter(userId int64) ms.FriendFilter { ids, err := (&dbr.Contact{FriendId: userId}).BeFriendIds(s.db) if err != nil { - return core.FriendFilter{} + return ms.FriendFilter{} } - resp := make(core.FriendFilter, len(ids)) + resp := make(ms.FriendFilter, len(ids)) for _, id := range ids { resp[id] = types.Empty{} } diff --git a/internal/dao/jinzhu/comments.go b/internal/dao/jinzhu/comments.go index b796c0ec..4ac08e18 100644 --- a/internal/dao/jinzhu/comments.go +++ b/internal/dao/jinzhu/comments.go @@ -9,6 +9,7 @@ import ( "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/rocboss/paopao-ce/pkg/types" "gorm.io/gorm" @@ -59,11 +60,11 @@ func (s *commentSrv) GetCommentThumbsMap(userId int64, tweetId int64) (cs.Commen return commentThumbs, replyThumbs, nil } -func (s *commentSrv) GetComments(conditions *core.ConditionsT, offset, limit int) ([]*core.Comment, error) { +func (s *commentSrv) GetComments(conditions *ms.ConditionsT, offset, limit int) ([]*ms.Comment, error) { return (&dbr.Comment{}).List(s.db, conditions, offset, limit) } -func (s *commentSrv) GetCommentByID(id int64) (*core.Comment, error) { +func (s *commentSrv) GetCommentByID(id int64) (*ms.Comment, error) { comment := &dbr.Comment{ Model: &dbr.Model{ ID: id, @@ -72,7 +73,7 @@ func (s *commentSrv) GetCommentByID(id int64) (*core.Comment, error) { return comment.Get(s.db) } -func (s *commentSrv) GetCommentReplyByID(id int64) (*core.CommentReply, error) { +func (s *commentSrv) GetCommentReplyByID(id int64) (*ms.CommentReply, error) { reply := &dbr.CommentReply{ Model: &dbr.Model{ ID: id, @@ -81,18 +82,18 @@ func (s *commentSrv) GetCommentReplyByID(id int64) (*core.CommentReply, error) { return reply.Get(s.db) } -func (s *commentSrv) GetCommentCount(conditions *core.ConditionsT) (int64, error) { +func (s *commentSrv) GetCommentCount(conditions *ms.ConditionsT) (int64, error) { return (&dbr.Comment{}).Count(s.db, conditions) } -func (s *commentSrv) GetCommentContentsByIDs(ids []int64) ([]*core.CommentContent, error) { +func (s *commentSrv) GetCommentContentsByIDs(ids []int64) ([]*ms.CommentContent, error) { commentContent := &dbr.CommentContent{} return commentContent.List(s.db, &dbr.ConditionsT{ "comment_id IN ?": ids, }, 0, 0) } -func (s *commentSrv) GetCommentRepliesByID(ids []int64) ([]*core.CommentReplyFormated, error) { +func (s *commentSrv) GetCommentRepliesByID(ids []int64) ([]*ms.CommentReplyFormated, error) { CommentReply := &dbr.CommentReply{} replies, err := CommentReply.List(s.db, &dbr.ConditionsT{ "comment_id IN ?": ids, @@ -112,7 +113,7 @@ func (s *commentSrv) GetCommentRepliesByID(ids []int64) ([]*core.CommentReplyFor if err != nil { return nil, err } - repliesFormated := []*core.CommentReplyFormated{} + repliesFormated := []*ms.CommentReplyFormated{} for _, reply := range replies { replyFormated := reply.Format() for _, user := range users { @@ -130,7 +131,7 @@ func (s *commentSrv) GetCommentRepliesByID(ids []int64) ([]*core.CommentReplyFor return repliesFormated, nil } -func (s *commentManageSrv) DeleteComment(comment *core.Comment) error { +func (s *commentManageSrv) DeleteComment(comment *ms.Comment) error { db := s.db.Begin() defer db.Rollback() @@ -149,15 +150,15 @@ func (s *commentManageSrv) DeleteComment(comment *core.Comment) error { return nil } -func (s *commentManageSrv) CreateComment(comment *core.Comment) (*core.Comment, error) { +func (s *commentManageSrv) CreateComment(comment *ms.Comment) (*ms.Comment, error) { return comment.Create(s.db) } -func (s *commentManageSrv) CreateCommentReply(reply *core.CommentReply) (*core.CommentReply, error) { +func (s *commentManageSrv) CreateCommentReply(reply *ms.CommentReply) (*ms.CommentReply, error) { return reply.Create(s.db) } -func (s *commentManageSrv) DeleteCommentReply(reply *core.CommentReply) (err error) { +func (s *commentManageSrv) DeleteCommentReply(reply *ms.CommentReply) (err error) { db := s.db.Begin() defer db.Rollback() @@ -177,7 +178,7 @@ func (s *commentManageSrv) DeleteCommentReply(reply *core.CommentReply) (err err return } -func (s *commentManageSrv) CreateCommentContent(content *core.CommentContent) (*core.CommentContent, error) { +func (s *commentManageSrv) CreateCommentContent(content *ms.CommentContent) (*ms.CommentContent, error) { return content.Create(s.db) } diff --git a/internal/dao/jinzhu/contacts.go b/internal/dao/jinzhu/contacts.go index 824164bc..b44307fe 100644 --- a/internal/dao/jinzhu/contacts.go +++ b/internal/dao/jinzhu/contacts.go @@ -8,6 +8,7 @@ import ( "time" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/sirupsen/logrus" "gorm.io/gorm" @@ -226,7 +227,7 @@ func (s *contactManageSrv) DeleteFriend(userId int64, friendId int64) (err error return nil } -func (s *contactManageSrv) GetContacts(userId int64, offset int, limit int) (*core.ContactList, error) { +func (s *contactManageSrv) GetContacts(userId int64, offset int, limit int) (*ms.ContactList, error) { contact := &dbr.Contact{} condition := dbr.ConditionsT{ "user_id": userId, @@ -240,13 +241,13 @@ func (s *contactManageSrv) GetContacts(userId int64, offset int, limit int) (*co if err != nil { return nil, err } - resp := &core.ContactList{ - Contacts: make([]core.ContactItem, 0, len(contacts)), + resp := &ms.ContactList{ + Contacts: make([]ms.ContactItem, 0, len(contacts)), Total: total, } for _, c := range contacts { if c.User != nil { - resp.Contacts = append(resp.Contacts, core.ContactItem{ + resp.Contacts = append(resp.Contacts, ms.ContactItem{ UserId: c.FriendId, UserName: c.User.Username, Nickname: c.User.Nickname, diff --git a/internal/dao/jinzhu/messages.go b/internal/dao/jinzhu/messages.go index 2d10935f..00df949f 100644 --- a/internal/dao/jinzhu/messages.go +++ b/internal/dao/jinzhu/messages.go @@ -6,6 +6,7 @@ package jinzhu import ( "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "gorm.io/gorm" ) @@ -24,7 +25,7 @@ func newMessageService(db *gorm.DB) core.MessageService { } } -func (s *messageSrv) CreateMessage(msg *core.Message) (*core.Message, error) { +func (s *messageSrv) CreateMessage(msg *ms.Message) (*ms.Message, error) { return msg.Create(s.db) } @@ -35,7 +36,7 @@ func (s *messageSrv) GetUnreadCount(userID int64) (int64, error) { }) } -func (s *messageSrv) GetMessageByID(id int64) (*core.Message, error) { +func (s *messageSrv) GetMessageByID(id int64) (*ms.Message, error) { return (&dbr.Message{ Model: &dbr.Model{ ID: id, @@ -43,12 +44,12 @@ func (s *messageSrv) GetMessageByID(id int64) (*core.Message, error) { }).Get(s.db) } -func (s *messageSrv) ReadMessage(message *core.Message) error { +func (s *messageSrv) ReadMessage(message *ms.Message) error { message.IsRead = 1 return message.Update(s.db) } -func (s *messageSrv) GetMessages(conditions *core.ConditionsT, offset, limit int) ([]*core.MessageFormated, error) { +func (s *messageSrv) GetMessages(conditions *ms.ConditionsT, offset, limit int) ([]*ms.MessageFormated, error) { messages, err := (&dbr.Message{}).List(s.db, conditions, offset, limit) if err != nil { return nil, err @@ -63,6 +64,6 @@ func (s *messageSrv) GetMessages(conditions *core.ConditionsT, offset, limit int return mfs, nil } -func (s *messageSrv) GetMessageCount(conditions *core.ConditionsT) (int64, error) { +func (s *messageSrv) GetMessageCount(conditions *ms.ConditionsT) (int64, error) { return (&dbr.Message{}).Count(s.db, conditions) } diff --git a/internal/dao/jinzhu/security.go b/internal/dao/jinzhu/security.go index 128e8273..d4d99d0d 100644 --- a/internal/dao/jinzhu/security.go +++ b/internal/dao/jinzhu/security.go @@ -10,6 +10,7 @@ import ( "time" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "gorm.io/gorm" ) @@ -31,14 +32,14 @@ func newSecurityService(db *gorm.DB, phoneVerify core.PhoneVerifyService) core.S } // GetLatestPhoneCaptcha 获取最新短信验证码 -func (s *securitySrv) GetLatestPhoneCaptcha(phone string) (*core.Captcha, error) { +func (s *securitySrv) GetLatestPhoneCaptcha(phone string) (*ms.Captcha, error) { return (&dbr.Captcha{ Phone: phone, }).Get(s.db) } // UsePhoneCaptcha 更新短信验证码 -func (s *securitySrv) UsePhoneCaptcha(captcha *core.Captcha) error { +func (s *securitySrv) UsePhoneCaptcha(captcha *ms.Captcha) error { captcha.UseTimes++ return captcha.Update(s.db) } diff --git a/internal/dao/jinzhu/timeline.go b/internal/dao/jinzhu/timeline.go index fb6769a5..f81e3619 100644 --- a/internal/dao/jinzhu/timeline.go +++ b/internal/dao/jinzhu/timeline.go @@ -7,6 +7,7 @@ package jinzhu import ( "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/rocboss/paopao-ce/pkg/debug" "github.com/sirupsen/logrus" @@ -42,7 +43,7 @@ type simpleIndexPostsSrv struct { } // IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; -func (s *friendIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *friendIndexSrv) IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { predicates := dbr.Predicates{ "ORDER": []any{"is_top DESC, latest_replied_on DESC"}, } @@ -70,7 +71,7 @@ func (s *friendIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*co return nil, err } - return &core.IndexTweetList{ + return &ms.IndexTweetList{ Tweets: formatPosts, Total: total, }, nil @@ -82,7 +83,7 @@ func (s *friendIndexSrv) TweetTimeline(userId int64, offset int, limit int) (*cs } // IndexPosts 根据userId查询广场推文列表 -func (s *followIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *followIndexSrv) IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { // TODO return nil, debug.ErrNotImplemented } @@ -93,7 +94,7 @@ func (s *followIndexSrv) TweetTimeline(userId int64, offset int, limit int) (*cs } // IndexPosts 根据userId查询广场推文列表,获取公开可见Tweet或者所属用户的私有Tweet -func (s *lightIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *lightIndexSrv) IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { predicates := dbr.Predicates{ "ORDER": []any{"is_top DESC, latest_replied_on DESC"}, } @@ -119,7 +120,7 @@ func (s *lightIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*cor return nil, err } - return &core.IndexTweetList{ + return &ms.IndexTweetList{ Tweets: formatPosts, Total: total, }, nil @@ -131,7 +132,7 @@ func (s *lightIndexSrv) TweetTimeline(userId int64, offset int, limit int) (*cs. } // simpleCacheIndexGetPosts simpleCacheIndex 专属获取广场推文列表函数 -func (s *simpleIndexPostsSrv) IndexPosts(_user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *simpleIndexPostsSrv) IndexPosts(_user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { predicates := dbr.Predicates{ "visibility = ?": []any{dbr.PostVisitPublic}, "ORDER": []any{"is_top DESC, latest_replied_on DESC"}, @@ -153,7 +154,7 @@ func (s *simpleIndexPostsSrv) IndexPosts(_user *core.User, offset int, limit int return nil, err } - return &core.IndexTweetList{ + return &ms.IndexTweetList{ Tweets: formatPosts, Total: total, }, nil diff --git a/internal/dao/jinzhu/topics.go b/internal/dao/jinzhu/topics.go index ce70b052..de317164 100644 --- a/internal/dao/jinzhu/topics.go +++ b/internal/dao/jinzhu/topics.go @@ -10,6 +10,7 @@ import ( "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "gorm.io/gorm" ) @@ -73,16 +74,16 @@ func (s *topicSrv) DecrTagsById(ids []int64) (err error) { } func (s *topicSrv) ListTags(typ cs.TagType, offset, limit int) (res cs.TagList, err error) { - conditions := &core.ConditionsT{} + conditions := &ms.ConditionsT{} switch typ { case cs.TagTypeHot: // 热门标签 - conditions = &core.ConditionsT{ + conditions = &ms.ConditionsT{ "ORDER": "quote_num DESC", } case cs.TagTypeNew: // 最新标签 - conditions = &core.ConditionsT{ + conditions = &ms.ConditionsT{ "ORDER": "id DESC", } } @@ -90,7 +91,7 @@ func (s *topicSrv) ListTags(typ cs.TagType, offset, limit int) (res cs.TagList, } func (s *topicSrv) GetHotTags(userId int64, limit int, offset int) (cs.TagList, error) { - tags, err := s.listTags(&core.ConditionsT{ + tags, err := s.listTags(&ms.ConditionsT{ "ORDER": "quote_num DESC", }, limit, offset) if err != nil { @@ -100,7 +101,7 @@ func (s *topicSrv) GetHotTags(userId int64, limit int, offset int) (cs.TagList, } func (s *topicSrv) GetNewestTags(userId int64, limit int, offset int) (cs.TagList, error) { - tags, err := s.listTags(&core.ConditionsT{ + tags, err := s.listTags(&ms.ConditionsT{ "ORDER": "id DESC", }, limit, offset) if err != nil { @@ -149,7 +150,7 @@ func (s *topicSrv) GetFollowTags(userId int64, limit int, offset int) (cs.TagLis return res, nil } -func (s *topicSrv) listTags(conditions *core.ConditionsT, limit int, offset int) (res cs.TagList, err error) { +func (s *topicSrv) listTags(conditions *ms.ConditionsT, limit int, offset int) (res cs.TagList, err error) { // TODO: 优化查询方式,直接返回[]*core.Tag, 目前保持先转换一下 var ( tags []*dbr.Tag @@ -298,16 +299,16 @@ func (s *topicSrvA) DecrTagsById(ids []int64) (err error) { } func (s *topicSrvA) ListTags(typ cs.TagType, offset, limit int) (res cs.TagList, err error) { - conditions := &core.ConditionsT{} + conditions := &ms.ConditionsT{} switch typ { case cs.TagTypeHot: // 热门标签 - conditions = &core.ConditionsT{ + conditions = &ms.ConditionsT{ "ORDER": "quote_num DESC", } case cs.TagTypeNew: // 最新标签 - conditions = &core.ConditionsT{ + conditions = &ms.ConditionsT{ "ORDER": "id DESC", } } diff --git a/internal/dao/jinzhu/tweets.go b/internal/dao/jinzhu/tweets.go index f716ca9b..a9dc2a27 100644 --- a/internal/dao/jinzhu/tweets.go +++ b/internal/dao/jinzhu/tweets.go @@ -10,6 +10,7 @@ import ( "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/rocboss/paopao-ce/pkg/debug" "gorm.io/gorm" @@ -88,7 +89,7 @@ func newTweetHelpServantA(db *gorm.DB) core.TweetHelpServantA { } // MergePosts post数据整合 -func (s *tweetHelpSrv) MergePosts(posts []*core.Post) ([]*core.PostFormated, error) { +func (s *tweetHelpSrv) MergePosts(posts []*ms.Post) ([]*ms.PostFormated, error) { postIds := make([]int64, 0, len(posts)) userIds := make([]int64, 0, len(posts)) for _, post := range posts { @@ -128,7 +129,7 @@ func (s *tweetHelpSrv) MergePosts(posts []*core.Post) ([]*core.PostFormated, err } // RevampPosts post数据整形修复 -func (s *tweetHelpSrv) RevampPosts(posts []*core.PostFormated) ([]*core.PostFormated, error) { +func (s *tweetHelpSrv) RevampPosts(posts []*ms.PostFormated) ([]*ms.PostFormated, error) { postIds := make([]int64, 0, len(posts)) userIds := make([]int64, 0, len(posts)) for _, post := range posts { @@ -179,7 +180,7 @@ func (s *tweetHelpSrv) getUsersByIDs(ids []int64) ([]*dbr.User, error) { }, 0, 0) } -func (s *tweetManageSrv) CreatePostCollection(postID, userID int64) (*core.PostCollection, error) { +func (s *tweetManageSrv) CreatePostCollection(postID, userID int64) (*ms.PostCollection, error) { collection := &dbr.PostCollection{ PostID: postID, UserID: userID, @@ -188,11 +189,11 @@ func (s *tweetManageSrv) CreatePostCollection(postID, userID int64) (*core.PostC return collection.Create(s.db) } -func (s *tweetManageSrv) DeletePostCollection(p *core.PostCollection) error { +func (s *tweetManageSrv) DeletePostCollection(p *ms.PostCollection) error { return p.Delete(s.db) } -func (s *tweetManageSrv) CreatePostContent(content *core.PostContent) (*core.PostContent, error) { +func (s *tweetManageSrv) CreatePostContent(content *ms.PostContent) (*ms.PostContent, error) { return content.Create(s.db) } @@ -201,7 +202,7 @@ func (s *tweetManageSrv) CreateAttachment(obj *cs.Attachment) (int64, error) { return 0, debug.ErrNotImplemented } -func (s *tweetManageSrv) CreatePost(post *core.Post) (*core.Post, error) { +func (s *tweetManageSrv) CreatePost(post *ms.Post) (*ms.Post, error) { post.LatestRepliedOn = time.Now().Unix() p, err := post.Create(s.db) if err != nil { @@ -211,7 +212,7 @@ func (s *tweetManageSrv) CreatePost(post *core.Post) (*core.Post, error) { return p, nil } -func (s *tweetManageSrv) DeletePost(post *core.Post) ([]string, error) { +func (s *tweetManageSrv) DeletePost(post *ms.Post) ([]string, error) { var mediaContents []string postId := post.ID @@ -292,12 +293,12 @@ func (s *tweetManageSrv) deleteCommentByPostId(db *gorm.DB, postId int64) ([]str return mediaContents, nil } -func (s *tweetManageSrv) LockPost(post *core.Post) error { +func (s *tweetManageSrv) LockPost(post *ms.Post) error { post.IsLock = 1 - post.IsLock return post.Update(s.db) } -func (s *tweetManageSrv) StickPost(post *core.Post) error { +func (s *tweetManageSrv) StickPost(post *ms.Post) error { post.IsTop = 1 - post.IsTop if err := post.Update(s.db); err != nil { return err @@ -306,7 +307,7 @@ func (s *tweetManageSrv) StickPost(post *core.Post) error { return nil } -func (s *tweetManageSrv) VisiblePost(post *core.Post, visibility core.PostVisibleT) error { +func (s *tweetManageSrv) VisiblePost(post *ms.Post, visibility core.PostVisibleT) error { oldVisibility := post.Visibility post.Visibility = visibility // TODO: 这个判断是否可以不要呢 @@ -340,7 +341,7 @@ func (s *tweetManageSrv) VisiblePost(post *core.Post, visibility core.PostVisibl return nil } -func (s *tweetManageSrv) UpdatePost(post *core.Post) error { +func (s *tweetManageSrv) UpdatePost(post *ms.Post) error { if err := post.Update(s.db); err != nil { return err } @@ -348,7 +349,7 @@ func (s *tweetManageSrv) UpdatePost(post *core.Post) error { return nil } -func (s *tweetManageSrv) CreatePostStar(postID, userID int64) (*core.PostStar, error) { +func (s *tweetManageSrv) CreatePostStar(postID, userID int64) (*ms.PostStar, error) { star := &dbr.PostStar{ PostID: postID, UserID: userID, @@ -356,11 +357,11 @@ func (s *tweetManageSrv) CreatePostStar(postID, userID int64) (*core.PostStar, e return star.Create(s.db) } -func (s *tweetManageSrv) DeletePostStar(p *core.PostStar) error { +func (s *tweetManageSrv) DeletePostStar(p *ms.PostStar) error { return p.Delete(s.db) } -func (s *tweetSrv) GetPostByID(id int64) (*core.Post, error) { +func (s *tweetSrv) GetPostByID(id int64) (*ms.Post, error) { post := &dbr.Post{ Model: &dbr.Model{ ID: id, @@ -369,15 +370,15 @@ func (s *tweetSrv) GetPostByID(id int64) (*core.Post, error) { return post.Get(s.db) } -func (s *tweetSrv) GetPosts(conditions *core.ConditionsT, offset, limit int) ([]*core.Post, error) { +func (s *tweetSrv) GetPosts(conditions *ms.ConditionsT, offset, limit int) ([]*ms.Post, error) { return (&dbr.Post{}).List(s.db, conditions, offset, limit) } -func (s *tweetSrv) GetPostCount(conditions *core.ConditionsT) (int64, error) { +func (s *tweetSrv) GetPostCount(conditions *ms.ConditionsT) (int64, error) { return (&dbr.Post{}).Count(s.db, conditions) } -func (s *tweetSrv) GetUserPostStar(postID, userID int64) (*core.PostStar, error) { +func (s *tweetSrv) GetUserPostStar(postID, userID int64) (*ms.PostStar, error) { star := &dbr.PostStar{ PostID: postID, UserID: userID, @@ -385,7 +386,7 @@ func (s *tweetSrv) GetUserPostStar(postID, userID int64) (*core.PostStar, error) return star.Get(s.db) } -func (s *tweetSrv) GetUserPostStars(userID int64, offset, limit int) ([]*core.PostStar, error) { +func (s *tweetSrv) GetUserPostStars(userID int64, offset, limit int) ([]*ms.PostStar, error) { star := &dbr.PostStar{ UserID: userID, } @@ -402,7 +403,7 @@ func (s *tweetSrv) GetUserPostStarCount(userID int64) (int64, error) { return star.Count(s.db, &dbr.ConditionsT{}) } -func (s *tweetSrv) GetUserPostCollection(postID, userID int64) (*core.PostCollection, error) { +func (s *tweetSrv) GetUserPostCollection(postID, userID int64) (*ms.PostCollection, error) { star := &dbr.PostCollection{ PostID: postID, UserID: userID, @@ -410,7 +411,7 @@ func (s *tweetSrv) GetUserPostCollection(postID, userID int64) (*core.PostCollec return star.Get(s.db) } -func (s *tweetSrv) GetUserPostCollections(userID int64, offset, limit int) ([]*core.PostCollection, error) { +func (s *tweetSrv) GetUserPostCollections(userID int64, offset, limit int) ([]*ms.PostCollection, error) { collection := &dbr.PostCollection{ UserID: userID, } @@ -427,7 +428,7 @@ func (s *tweetSrv) GetUserPostCollectionCount(userID int64) (int64, error) { return collection.Count(s.db, &dbr.ConditionsT{}) } -func (s *tweetSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*core.WalletStatement, error) { +func (s *tweetSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*ms.WalletStatement, error) { statement := &dbr.WalletStatement{ UserID: userID, } @@ -444,7 +445,7 @@ func (s *tweetSrv) GetUserWalletBillCount(userID int64) (int64, error) { return statement.Count(s.db, &dbr.ConditionsT{}) } -func (s *tweetSrv) GetPostAttatchmentBill(postID, userID int64) (*core.PostAttachmentBill, error) { +func (s *tweetSrv) GetPostAttatchmentBill(postID, userID int64) (*ms.PostAttachmentBill, error) { bill := &dbr.PostAttachmentBill{ PostID: postID, UserID: userID, @@ -453,14 +454,14 @@ func (s *tweetSrv) GetPostAttatchmentBill(postID, userID int64) (*core.PostAttac return bill.Get(s.db) } -func (s *tweetSrv) GetPostContentsByIDs(ids []int64) ([]*core.PostContent, error) { +func (s *tweetSrv) GetPostContentsByIDs(ids []int64) ([]*ms.PostContent, error) { return (&dbr.PostContent{}).List(s.db, &dbr.ConditionsT{ "post_id IN ?": ids, "ORDER": "sort ASC", }, 0, 0) } -func (s *tweetSrv) GetPostContentByID(id int64) (*core.PostContent, error) { +func (s *tweetSrv) GetPostContentByID(id int64) (*ms.PostContent, error) { return (&dbr.PostContent{ Model: &dbr.Model{ ID: id, diff --git a/internal/dao/jinzhu/user.go b/internal/dao/jinzhu/user.go index b69338b7..6bc18de3 100644 --- a/internal/dao/jinzhu/user.go +++ b/internal/dao/jinzhu/user.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "gorm.io/gorm" ) @@ -26,7 +27,7 @@ func newUserManageService(db *gorm.DB) core.UserManageService { } } -func (s *userManageSrv) GetUserByID(id int64) (*core.User, error) { +func (s *userManageSrv) GetUserByID(id int64) (*ms.User, error) { user := &dbr.User{ Model: &dbr.Model{ ID: id, @@ -35,28 +36,28 @@ func (s *userManageSrv) GetUserByID(id int64) (*core.User, error) { return user.Get(s.db) } -func (s *userManageSrv) GetUserByUsername(username string) (*core.User, error) { +func (s *userManageSrv) GetUserByUsername(username string) (*ms.User, error) { user := &dbr.User{ Username: username, } return user.Get(s.db) } -func (s *userManageSrv) GetUserByPhone(phone string) (*core.User, error) { +func (s *userManageSrv) GetUserByPhone(phone string) (*ms.User, error) { user := &dbr.User{ Phone: phone, } return user.Get(s.db) } -func (s *userManageSrv) GetUsersByIDs(ids []int64) ([]*core.User, error) { +func (s *userManageSrv) GetUsersByIDs(ids []int64) ([]*ms.User, error) { user := &dbr.User{} return user.List(s.db, &dbr.ConditionsT{ "id IN ?": ids, }, 0, 0) } -func (s *userManageSrv) GetUsersByKeyword(keyword string) ([]*core.User, error) { +func (s *userManageSrv) GetUsersByKeyword(keyword string) ([]*ms.User, error) { user := &dbr.User{} keyword = strings.Trim(keyword, " ") + "%" if keyword == "%" { @@ -70,10 +71,10 @@ func (s *userManageSrv) GetUsersByKeyword(keyword string) ([]*core.User, error) } } -func (s *userManageSrv) CreateUser(user *dbr.User) (*core.User, error) { +func (s *userManageSrv) CreateUser(user *dbr.User) (*ms.User, error) { return user.Create(s.db) } -func (s *userManageSrv) UpdateUser(user *core.User) error { +func (s *userManageSrv) UpdateUser(user *ms.User) error { return user.Update(s.db) } diff --git a/internal/dao/jinzhu/wallet.go b/internal/dao/jinzhu/wallet.go index 6e3196e5..e657deca 100644 --- a/internal/dao/jinzhu/wallet.go +++ b/internal/dao/jinzhu/wallet.go @@ -7,6 +7,7 @@ package jinzhu import ( "github.com/rocboss/paopao-ce/internal/conf" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "gorm.io/gorm" ) @@ -25,7 +26,7 @@ func newWalletService(db *gorm.DB) core.WalletService { } } -func (s *walletSrv) GetRechargeByID(id int64) (*core.WalletRecharge, error) { +func (s *walletSrv) GetRechargeByID(id int64) (*ms.WalletRecharge, error) { recharge := &dbr.WalletRecharge{ Model: &dbr.Model{ ID: id, @@ -34,7 +35,7 @@ func (s *walletSrv) GetRechargeByID(id int64) (*core.WalletRecharge, error) { return recharge.Get(s.db) } -func (s *walletSrv) CreateRecharge(userId, amount int64) (*core.WalletRecharge, error) { +func (s *walletSrv) CreateRecharge(userId, amount int64) (*ms.WalletRecharge, error) { recharge := &dbr.WalletRecharge{ UserID: userId, Amount: amount, @@ -43,7 +44,7 @@ func (s *walletSrv) CreateRecharge(userId, amount int64) (*core.WalletRecharge, return recharge.Create(s.db) } -func (s *walletSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*core.WalletStatement, error) { +func (s *walletSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*ms.WalletStatement, error) { statement := &dbr.WalletStatement{ UserID: userID, } @@ -60,7 +61,7 @@ func (s *walletSrv) GetUserWalletBillCount(userID int64) (int64, error) { return statement.Count(s.db, &dbr.ConditionsT{}) } -func (s *walletSrv) HandleRechargeSuccess(recharge *core.WalletRecharge, tradeNo string) error { +func (s *walletSrv) HandleRechargeSuccess(recharge *ms.WalletRecharge, tradeNo string) error { user, _ := (&dbr.User{ Model: &dbr.Model{ ID: recharge.UserID, @@ -97,7 +98,7 @@ func (s *walletSrv) HandleRechargeSuccess(recharge *core.WalletRecharge, tradeNo }) } -func (s *walletSrv) HandlePostAttachmentBought(post *core.Post, user *core.User) error { +func (s *walletSrv) HandlePostAttachmentBought(post *ms.Post, user *ms.User) error { return s.db.Transaction(func(tx *gorm.DB) error { // 扣除金额 if err := tx.Model(user).Update("balance", gorm.Expr("balance - ?", post.AttachmentPrice)).Error; err != nil { diff --git a/internal/dao/sakila/authority.go b/internal/dao/sakila/authority.go index c595b84d..688068cc 100644 --- a/internal/dao/sakila/authority.go +++ b/internal/dao/sakila/authority.go @@ -7,6 +7,7 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -20,19 +21,19 @@ type authorizationManageSrv struct { q *cc.AuthorizationManage } -func (s *authorizationManageSrv) IsAllow(user *core.User, action *core.Action) bool { +func (s *authorizationManageSrv) IsAllow(user *ms.User, action *ms.Action) bool { // TODO debug.NotImplemented() return false } -func (s *authorizationManageSrv) MyFriendSet(userId int64) core.FriendSet { +func (s *authorizationManageSrv) MyFriendSet(userId int64) ms.FriendSet { // TODO debug.NotImplemented() return nil } -func (s *authorizationManageSrv) BeFriendFilter(userId int64) core.FriendFilter { +func (s *authorizationManageSrv) BeFriendFilter(userId int64) ms.FriendFilter { // TODO debug.NotImplemented() return nil diff --git a/internal/dao/sakila/comments.go b/internal/dao/sakila/comments.go index c2858115..dc27c690 100644 --- a/internal/dao/sakila/comments.go +++ b/internal/dao/sakila/comments.go @@ -8,6 +8,7 @@ import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -27,31 +28,31 @@ type commentManageSrv struct { q *cc.CommentManage } -func (s *commentSrv) GetComments(conditions *core.ConditionsT, offset, limit int) ([]*core.Comment, error) { +func (s *commentSrv) GetComments(conditions *ms.ConditionsT, offset, limit int) ([]*ms.Comment, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *commentSrv) GetCommentByID(id int64) (*core.Comment, error) { +func (s *commentSrv) GetCommentByID(id int64) (*ms.Comment, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *commentSrv) GetCommentReplyByID(id int64) (*core.CommentReply, error) { +func (s *commentSrv) GetCommentReplyByID(id int64) (*ms.CommentReply, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *commentSrv) GetCommentCount(conditions *core.ConditionsT) (int64, error) { +func (s *commentSrv) GetCommentCount(conditions *ms.ConditionsT) (int64, error) { // TODO debug.NotImplemented() return 0, nil } -func (s *commentSrv) GetCommentContentsByIDs(ids []int64) ([]*core.CommentContent, error) { +func (s *commentSrv) GetCommentContentsByIDs(ids []int64) ([]*ms.CommentContent, error) { // TODO debug.NotImplemented() return nil, nil @@ -62,37 +63,37 @@ func (s *commentSrv) GetCommentThumbsMap(userId int64, tweetId int64) (cs.Commen return nil, nil, debug.ErrNotImplemented } -func (s *commentSrv) GetCommentRepliesByID(ids []int64) ([]*core.CommentReplyFormated, error) { +func (s *commentSrv) GetCommentRepliesByID(ids []int64) ([]*ms.CommentReplyFormated, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *commentManageSrv) DeleteComment(comment *core.Comment) error { +func (s *commentManageSrv) DeleteComment(comment *ms.Comment) error { // TODO debug.NotImplemented() return nil } -func (s *commentManageSrv) CreateComment(comment *core.Comment) (*core.Comment, error) { +func (s *commentManageSrv) CreateComment(comment *ms.Comment) (*ms.Comment, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *commentManageSrv) CreateCommentReply(reply *core.CommentReply) (*core.CommentReply, error) { +func (s *commentManageSrv) CreateCommentReply(reply *ms.CommentReply) (*ms.CommentReply, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *commentManageSrv) DeleteCommentReply(reply *core.CommentReply) error { +func (s *commentManageSrv) DeleteCommentReply(reply *ms.CommentReply) error { // TODO debug.NotImplemented() return nil } -func (s *commentManageSrv) CreateCommentContent(content *core.CommentContent) (*core.CommentContent, error) { +func (s *commentManageSrv) CreateCommentContent(content *ms.CommentContent) (*ms.CommentContent, error) { // TODO debug.NotImplemented() return nil, nil diff --git a/internal/dao/sakila/contacts.go b/internal/dao/sakila/contacts.go index d969496e..f37dc872 100644 --- a/internal/dao/sakila/contacts.go +++ b/internal/dao/sakila/contacts.go @@ -7,6 +7,7 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -44,7 +45,7 @@ func (s *contactManageSrv) DeleteFriend(userId int64, friendId int64) (err error return nil } -func (s *contactManageSrv) GetContacts(userId int64, offset int, limit int) (*core.ContactList, error) { +func (s *contactManageSrv) GetContacts(userId int64, offset int, limit int) (*ms.ContactList, error) { // TODO debug.NotImplemented() return nil, nil diff --git a/internal/dao/sakila/messages.go b/internal/dao/sakila/messages.go index cc1b70a7..5f62b6a3 100644 --- a/internal/dao/sakila/messages.go +++ b/internal/dao/sakila/messages.go @@ -7,6 +7,7 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -20,7 +21,7 @@ type messageSrv struct { q *cc.Message } -func (s *messageSrv) CreateMessage(msg *core.Message) (*core.Message, error) { +func (s *messageSrv) CreateMessage(msg *ms.Message) (*ms.Message, error) { // TODO debug.NotImplemented() return nil, nil @@ -32,25 +33,25 @@ func (s *messageSrv) GetUnreadCount(userID int64) (int64, error) { return 0, nil } -func (s *messageSrv) GetMessageByID(id int64) (*core.Message, error) { +func (s *messageSrv) GetMessageByID(id int64) (*ms.Message, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *messageSrv) ReadMessage(message *core.Message) error { +func (s *messageSrv) ReadMessage(message *ms.Message) error { // TODO debug.NotImplemented() return nil } -func (s *messageSrv) GetMessages(conditions *core.ConditionsT, offset, limit int) ([]*core.MessageFormated, error) { +func (s *messageSrv) GetMessages(conditions *ms.ConditionsT, offset, limit int) ([]*ms.MessageFormated, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *messageSrv) GetMessageCount(conditions *core.ConditionsT) (int64, error) { +func (s *messageSrv) GetMessageCount(conditions *ms.ConditionsT) (int64, error) { // TODO debug.NotImplemented() return 0, nil diff --git a/internal/dao/sakila/security.go b/internal/dao/sakila/security.go index 4a959519..02154ee5 100644 --- a/internal/dao/sakila/security.go +++ b/internal/dao/sakila/security.go @@ -7,6 +7,7 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -21,14 +22,14 @@ type securitySrv struct { } // GetLatestPhoneCaptcha 获取最新短信验证码 -func (s *securitySrv) GetLatestPhoneCaptcha(phone string) (*core.Captcha, error) { +func (s *securitySrv) GetLatestPhoneCaptcha(phone string) (*ms.Captcha, error) { // TODO debug.NotImplemented() return nil, nil } // UsePhoneCaptcha 更新短信验证码 -func (s *securitySrv) UsePhoneCaptcha(captcha *core.Captcha) error { +func (s *securitySrv) UsePhoneCaptcha(captcha *ms.Captcha) error { // TODO debug.NotImplemented() return nil diff --git a/internal/dao/sakila/timeline.go b/internal/dao/sakila/timeline.go index 1c5d3016..92941312 100644 --- a/internal/dao/sakila/timeline.go +++ b/internal/dao/sakila/timeline.go @@ -8,6 +8,7 @@ import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -75,49 +76,49 @@ type simpleIndexPostsSrvA struct { } // IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; -func (s *friendIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *friendIndexSrv) IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { // TODO return nil, debug.ErrNotImplemented } // IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; -func (s *followIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *followIndexSrv) IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { // TODO return nil, debug.ErrNotImplemented } // IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; -func (s *lightIndexSrv) IndexPosts(user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *lightIndexSrv) IndexPosts(user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { // TODO return nil, debug.ErrNotImplemented } // simpleCacheIndexGetPosts simpleCacheIndex 专属获取广场推文列表函数 -func (s *simpleIndexPostsSrv) IndexPosts(_user *core.User, offset int, limit int) (*core.IndexTweetList, error) { +func (s *simpleIndexPostsSrv) IndexPosts(_user *ms.User, offset int, limit int) (*ms.IndexTweetList, error) { // TODO return nil, debug.ErrNotImplemented } // IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; -func (s *friendIndexSrvA) IndexPosts(user *core.User, limit int, offset int) (*cs.TweetBox, error) { +func (s *friendIndexSrvA) IndexPosts(user *ms.User, limit int, offset int) (*cs.TweetBox, error) { // TODO return nil, debug.ErrNotImplemented } // IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; -func (s *followIndexSrvA) IndexPosts(user *core.User, limit int, offset int) (*cs.TweetBox, error) { +func (s *followIndexSrvA) IndexPosts(user *ms.User, limit int, offset int) (*cs.TweetBox, error) { // TODO return nil, debug.ErrNotImplemented } // IndexPosts 根据userId查询广场推文列表,简单做到不同用户的主页都是不同的; -func (s *lightIndexSrvA) IndexPosts(user *core.User, limit int, offset int) (*cs.TweetBox, error) { +func (s *lightIndexSrvA) IndexPosts(user *ms.User, limit int, offset int) (*cs.TweetBox, error) { // TODO return nil, debug.ErrNotImplemented } // IndexPosts simpleCacheIndex 专属获取广场推文列表函数 -func (s *simpleIndexPostsSrvA) IndexPosts(_user *core.User, limit int, offset int) (*cs.TweetBox, error) { +func (s *simpleIndexPostsSrvA) IndexPosts(_user *ms.User, limit int, offset int) (*cs.TweetBox, error) { // TODO return nil, debug.ErrNotImplemented } diff --git a/internal/dao/sakila/tweets.go b/internal/dao/sakila/tweets.go index f97d0cc6..e9272026 100644 --- a/internal/dao/sakila/tweets.go +++ b/internal/dao/sakila/tweets.go @@ -8,6 +8,7 @@ import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" @@ -56,14 +57,14 @@ type tweetHelpSrvA struct { } // MergePosts post数据整合 -func (s *tweetHelpSrv) MergePosts(posts []*core.Post) ([]*core.PostFormated, error) { +func (s *tweetHelpSrv) MergePosts(posts []*ms.Post) ([]*ms.PostFormated, error) { // TODO debug.NotImplemented() return nil, nil } // RevampPosts post数据整形修复 -func (s *tweetHelpSrv) RevampPosts(posts []*core.PostFormated) ([]*core.PostFormated, error) { +func (s *tweetHelpSrv) RevampPosts(posts []*ms.PostFormated) ([]*ms.PostFormated, error) { // TODO debug.NotImplemented() return nil, nil @@ -81,19 +82,19 @@ func (s *tweetHelpSrv) getUsersByIDs(ids []int64) ([]*dbr.User, error) { return nil, nil } -func (s *tweetManageSrv) CreatePostCollection(postID, userID int64) (*core.PostCollection, error) { +func (s *tweetManageSrv) CreatePostCollection(postID, userID int64) (*ms.PostCollection, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *tweetManageSrv) DeletePostCollection(p *core.PostCollection) error { +func (s *tweetManageSrv) DeletePostCollection(p *ms.PostCollection) error { // TODO debug.NotImplemented() return nil } -func (s *tweetManageSrv) CreatePostContent(content *core.PostContent) (*core.PostContent, error) { +func (s *tweetManageSrv) CreatePostContent(content *ms.PostContent) (*ms.PostContent, error) { // TODO debug.NotImplemented() return nil, nil @@ -104,79 +105,79 @@ func (s *tweetManageSrv) CreateAttachment(obj *cs.Attachment) (int64, error) { return 0, debug.ErrNotImplemented } -func (s *tweetManageSrv) CreatePost(post *core.Post) (*core.Post, error) { +func (s *tweetManageSrv) CreatePost(post *ms.Post) (*ms.Post, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *tweetManageSrv) DeletePost(post *core.Post) ([]string, error) { +func (s *tweetManageSrv) DeletePost(post *ms.Post) ([]string, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *tweetManageSrv) LockPost(post *core.Post) error { +func (s *tweetManageSrv) LockPost(post *ms.Post) error { // TODO debug.NotImplemented() return nil } -func (s *tweetManageSrv) StickPost(post *core.Post) error { +func (s *tweetManageSrv) StickPost(post *ms.Post) error { // TODO debug.NotImplemented() return nil } -func (s *tweetManageSrv) VisiblePost(post *core.Post, visibility core.PostVisibleT) error { +func (s *tweetManageSrv) VisiblePost(post *ms.Post, visibility core.PostVisibleT) error { // TODO debug.NotImplemented() return nil } -func (s *tweetManageSrv) UpdatePost(post *core.Post) error { +func (s *tweetManageSrv) UpdatePost(post *ms.Post) error { // TODO debug.NotImplemented() return nil } -func (s *tweetManageSrv) CreatePostStar(postID, userID int64) (*core.PostStar, error) { +func (s *tweetManageSrv) CreatePostStar(postID, userID int64) (*ms.PostStar, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *tweetManageSrv) DeletePostStar(p *core.PostStar) error { +func (s *tweetManageSrv) DeletePostStar(p *ms.PostStar) error { // TODO debug.NotImplemented() return nil } -func (s *tweetSrv) GetPostByID(id int64) (*core.Post, error) { +func (s *tweetSrv) GetPostByID(id int64) (*ms.Post, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *tweetSrv) GetPosts(conditions *core.ConditionsT, offset, limit int) ([]*core.Post, error) { +func (s *tweetSrv) GetPosts(conditions *ms.ConditionsT, offset, limit int) ([]*ms.Post, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *tweetSrv) GetPostCount(conditions *core.ConditionsT) (int64, error) { +func (s *tweetSrv) GetPostCount(conditions *ms.ConditionsT) (int64, error) { // TODO debug.NotImplemented() return 0, nil } -func (s *tweetSrv) GetUserPostStar(postID, userID int64) (*core.PostStar, error) { +func (s *tweetSrv) GetUserPostStar(postID, userID int64) (*ms.PostStar, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *tweetSrv) GetUserPostStars(userID int64, offset, limit int) ([]*core.PostStar, error) { +func (s *tweetSrv) GetUserPostStars(userID int64, offset, limit int) ([]*ms.PostStar, error) { // TODO debug.NotImplemented() return nil, nil @@ -188,13 +189,13 @@ func (s *tweetSrv) GetUserPostStarCount(userID int64) (int64, error) { return 0, nil } -func (s *tweetSrv) GetUserPostCollection(postID, userID int64) (*core.PostCollection, error) { +func (s *tweetSrv) GetUserPostCollection(postID, userID int64) (*ms.PostCollection, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *tweetSrv) GetUserPostCollections(userID int64, offset, limit int) ([]*core.PostCollection, error) { +func (s *tweetSrv) GetUserPostCollections(userID int64, offset, limit int) ([]*ms.PostCollection, error) { // TODO debug.NotImplemented() return nil, nil @@ -206,7 +207,7 @@ func (s *tweetSrv) GetUserPostCollectionCount(userID int64) (int64, error) { return 0, nil } -func (s *tweetSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*core.WalletStatement, error) { +func (s *tweetSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*ms.WalletStatement, error) { // TODO debug.NotImplemented() return nil, nil @@ -218,19 +219,19 @@ func (s *tweetSrv) GetUserWalletBillCount(userID int64) (int64, error) { return 0, nil } -func (s *tweetSrv) GetPostAttatchmentBill(postID, userID int64) (*core.PostAttachmentBill, error) { +func (s *tweetSrv) GetPostAttatchmentBill(postID, userID int64) (*ms.PostAttachmentBill, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *tweetSrv) GetPostContentsByIDs(ids []int64) ([]*core.PostContent, error) { +func (s *tweetSrv) GetPostContentsByIDs(ids []int64) ([]*ms.PostContent, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *tweetSrv) GetPostContentByID(id int64) (*core.PostContent, error) { +func (s *tweetSrv) GetPostContentByID(id int64) (*ms.PostContent, error) { // TODO debug.NotImplemented() return nil, nil diff --git a/internal/dao/sakila/user.go b/internal/dao/sakila/user.go index c063fc81..9611b498 100644 --- a/internal/dao/sakila/user.go +++ b/internal/dao/sakila/user.go @@ -7,6 +7,7 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -20,43 +21,43 @@ type userManageSrv struct { q *cc.UserManage } -func (s *userManageSrv) GetUserByID(id int64) (*core.User, error) { +func (s *userManageSrv) GetUserByID(id int64) (*ms.User, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *userManageSrv) GetUserByUsername(username string) (*core.User, error) { +func (s *userManageSrv) GetUserByUsername(username string) (*ms.User, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *userManageSrv) GetUserByPhone(phone string) (*core.User, error) { +func (s *userManageSrv) GetUserByPhone(phone string) (*ms.User, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *userManageSrv) GetUsersByIDs(ids []int64) ([]*core.User, error) { +func (s *userManageSrv) GetUsersByIDs(ids []int64) ([]*ms.User, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *userManageSrv) GetUsersByKeyword(keyword string) ([]*core.User, error) { +func (s *userManageSrv) GetUsersByKeyword(keyword string) ([]*ms.User, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *userManageSrv) CreateUser(user *core.User) (*core.User, error) { +func (s *userManageSrv) CreateUser(user *ms.User) (*ms.User, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *userManageSrv) UpdateUser(user *core.User) error { +func (s *userManageSrv) UpdateUser(user *ms.User) error { // TODO debug.NotImplemented() return nil diff --git a/internal/dao/sakila/wallet.go b/internal/dao/sakila/wallet.go index c733965a..42649113 100644 --- a/internal/dao/sakila/wallet.go +++ b/internal/dao/sakila/wallet.go @@ -7,6 +7,7 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -20,18 +21,18 @@ type walletSrv struct { q *cc.Wallet } -func (s *walletSrv) GetRechargeByID(id int64) (*core.WalletRecharge, error) { +func (s *walletSrv) GetRechargeByID(id int64) (*ms.WalletRecharge, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *walletSrv) CreateRecharge(userId, amount int64) (*core.WalletRecharge, error) { +func (s *walletSrv) CreateRecharge(userId, amount int64) (*ms.WalletRecharge, error) { // TODO debug.NotImplemented() return nil, nil } -func (s *walletSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*core.WalletStatement, error) { +func (s *walletSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*ms.WalletStatement, error) { // TODO debug.NotImplemented() return nil, nil @@ -43,13 +44,13 @@ func (s *walletSrv) GetUserWalletBillCount(userID int64) (int64, error) { return 0, nil } -func (s *walletSrv) HandleRechargeSuccess(recharge *core.WalletRecharge, tradeNo string) error { +func (s *walletSrv) HandleRechargeSuccess(recharge *ms.WalletRecharge, tradeNo string) error { // TODO debug.NotImplemented() return nil } -func (s *walletSrv) HandlePostAttachmentBought(post *core.Post, user *core.User) error { +func (s *walletSrv) HandlePostAttachmentBought(post *ms.Post, user *ms.User) error { // TODO debug.NotImplemented() return nil diff --git a/internal/dao/search/bridge.go b/internal/dao/search/bridge.go index f23aaa25..bc4eb039 100644 --- a/internal/dao/search/bridge.go +++ b/internal/dao/search/bridge.go @@ -8,6 +8,7 @@ import ( "time" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/sirupsen/logrus" ) @@ -46,7 +47,7 @@ func (s *bridgeTweetSearchServant) DeleteDocuments(identifiers []string) error { return nil } -func (s *bridgeTweetSearchServant) Search(user *core.User, q *core.QueryReq, offset, limit int) (*core.QueryResp, error) { +func (s *bridgeTweetSearchServant) Search(user *ms.User, q *core.QueryReq, offset, limit int) (*core.QueryResp, error) { return s.ts.Search(user, q, offset, limit) } diff --git a/internal/dao/search/filter.go b/internal/dao/search/filter.go index 5840e189..a601c46f 100644 --- a/internal/dao/search/filter.go +++ b/internal/dao/search/filter.go @@ -6,6 +6,7 @@ package search import ( "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/pkg/types" ) @@ -13,13 +14,13 @@ type tweetSearchFilter struct { ams core.AuthorizationManageService } -func (s *tweetSearchFilter) filterResp(user *core.User, resp *core.QueryResp) { +func (s *tweetSearchFilter) filterResp(user *ms.User, resp *core.QueryResp) { // 管理员不过滤 if user != nil && user.IsAdmin { return } - var item *core.PostFormated + var item *ms.PostFormated items := resp.Items latestIndex := len(items) - 1 if user == nil { diff --git a/internal/dao/search/meili.go b/internal/dao/search/meili.go index fc19e358..74391ef3 100644 --- a/internal/dao/search/meili.go +++ b/internal/dao/search/meili.go @@ -11,6 +11,7 @@ import ( "github.com/Masterminds/semver/v3" "github.com/meilisearch/meilisearch-go" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/pkg/json" "github.com/sirupsen/logrus" ) @@ -81,7 +82,7 @@ func (s *meiliTweetSearchServant) DeleteDocuments(identifiers []string) error { return nil } -func (s *meiliTweetSearchServant) Search(user *core.User, q *core.QueryReq, offset, limit int) (resp *core.QueryResp, err error) { +func (s *meiliTweetSearchServant) Search(user *ms.User, q *core.QueryReq, offset, limit int) (resp *core.QueryResp, err error) { if q.Type == core.SearchTypeDefault && q.Query != "" { resp, err = s.queryByContent(user, q, offset, limit) } else if q.Type == core.SearchTypeTag && q.Query != "" { @@ -99,7 +100,7 @@ func (s *meiliTweetSearchServant) Search(user *core.User, q *core.QueryReq, offs return } -func (s *meiliTweetSearchServant) queryByContent(user *core.User, q *core.QueryReq, offset, limit int) (*core.QueryResp, error) { +func (s *meiliTweetSearchServant) queryByContent(user *ms.User, q *core.QueryReq, offset, limit int) (*core.QueryResp, error) { request := &meilisearch.SearchRequest{ Offset: int64(offset), Limit: int64(limit), @@ -120,7 +121,7 @@ func (s *meiliTweetSearchServant) queryByContent(user *core.User, q *core.QueryR return s.postsFrom(resp) } -func (s *meiliTweetSearchServant) queryByTag(user *core.User, q *core.QueryReq, offset, limit int) (*core.QueryResp, error) { +func (s *meiliTweetSearchServant) queryByTag(user *ms.User, q *core.QueryReq, offset, limit int) (*core.QueryResp, error) { request := &meilisearch.SearchRequest{ Offset: int64(offset), Limit: int64(limit), @@ -144,7 +145,7 @@ func (s *meiliTweetSearchServant) queryByTag(user *core.User, q *core.QueryReq, return s.postsFrom(resp) } -func (s *meiliTweetSearchServant) queryAny(user *core.User, offset, limit int) (*core.QueryResp, error) { +func (s *meiliTweetSearchServant) queryAny(user *ms.User, offset, limit int) (*core.QueryResp, error) { request := &meilisearch.SearchRequest{ Offset: int64(offset), Limit: int64(limit), @@ -164,7 +165,7 @@ func (s *meiliTweetSearchServant) queryAny(user *core.User, offset, limit int) ( return s.postsFrom(resp) } -func (s *meiliTweetSearchServant) filterList(user *core.User) string { +func (s *meiliTweetSearchServant) filterList(user *ms.User) string { if user == nil { return s.publicFilter } @@ -177,7 +178,7 @@ func (s *meiliTweetSearchServant) filterList(user *core.User) string { } func (s *meiliTweetSearchServant) postsFrom(resp *meilisearch.SearchResponse) (*core.QueryResp, error) { - posts := make([]*core.PostFormated, 0, len(resp.Hits)) + posts := make([]*ms.PostFormated, 0, len(resp.Hits)) for _, hit := range resp.Hits { raw, err := json.Marshal(hit) if err != nil { @@ -187,7 +188,7 @@ func (s *meiliTweetSearchServant) postsFrom(resp *meilisearch.SearchResponse) (* if err = json.Unmarshal(raw, p); err != nil { return nil, err } - posts = append(posts, &core.PostFormated{ + posts = append(posts, &ms.PostFormated{ ID: p.ID, UserID: p.UserID, CommentCount: p.CommentCount, diff --git a/internal/dao/search/zinc.go b/internal/dao/search/zinc.go index ea9a7fa5..91f74b42 100644 --- a/internal/dao/search/zinc.go +++ b/internal/dao/search/zinc.go @@ -9,6 +9,7 @@ import ( "github.com/Masterminds/semver/v3" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/pkg/json" "github.com/rocboss/paopao-ce/pkg/zinc" "github.com/sirupsen/logrus" @@ -76,7 +77,7 @@ func (s *zincTweetSearchServant) DeleteDocuments(identifiers []string) error { return nil } -func (s *zincTweetSearchServant) Search(user *core.User, q *core.QueryReq, offset, limit int) (resp *core.QueryResp, err error) { +func (s *zincTweetSearchServant) Search(user *ms.User, q *core.QueryReq, offset, limit int) (resp *core.QueryResp, err error) { if q.Type == core.SearchTypeDefault && q.Query != "" { resp, err = s.queryByContent(user, q, offset, limit) } else if q.Type == core.SearchTypeTag && q.Query != "" { @@ -94,7 +95,7 @@ func (s *zincTweetSearchServant) Search(user *core.User, q *core.QueryReq, offse return } -func (s *zincTweetSearchServant) queryByContent(user *core.User, q *core.QueryReq, offset, limit int) (*core.QueryResp, error) { +func (s *zincTweetSearchServant) queryByContent(user *ms.User, q *core.QueryReq, offset, limit int) (*core.QueryResp, error) { resp, err := s.client.EsQuery(s.indexName, map[string]any{ "query": map[string]any{ "match_phrase": map[string]any{ @@ -111,7 +112,7 @@ func (s *zincTweetSearchServant) queryByContent(user *core.User, q *core.QueryRe return s.postsFrom(resp) } -func (s *zincTweetSearchServant) queryByTag(user *core.User, q *core.QueryReq, offset, limit int) (*core.QueryResp, error) { +func (s *zincTweetSearchServant) queryByTag(user *ms.User, q *core.QueryReq, offset, limit int) (*core.QueryResp, error) { resp, err := s.client.ApiQuery(s.indexName, map[string]any{ "search_type": "querystring", "query": map[string]any{ @@ -127,7 +128,7 @@ func (s *zincTweetSearchServant) queryByTag(user *core.User, q *core.QueryReq, o return s.postsFrom(resp) } -func (s *zincTweetSearchServant) queryAny(user *core.User, offset, limit int) (*core.QueryResp, error) { +func (s *zincTweetSearchServant) queryAny(user *ms.User, offset, limit int) (*core.QueryResp, error) { queryMap := map[string]any{ "query": map[string]any{ "match_all": map[string]string{}, @@ -144,9 +145,9 @@ func (s *zincTweetSearchServant) queryAny(user *core.User, offset, limit int) (* } func (s *zincTweetSearchServant) postsFrom(resp *zinc.QueryResultT) (*core.QueryResp, error) { - posts := make([]*core.PostFormated, 0, len(resp.Hits.Hits)) + posts := make([]*ms.PostFormated, 0, len(resp.Hits.Hits)) for _, hit := range resp.Hits.Hits { - item := &core.PostFormated{} + item := &ms.PostFormated{} raw, err := json.Marshal(hit.Source) if err != nil { return nil, err diff --git a/internal/model/web/priv.go b/internal/model/web/priv.go index d0c57caf..665ea665 100644 --- a/internal/model/web/priv.go +++ b/internal/model/web/priv.go @@ -11,6 +11,7 @@ import ( "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" ) type TweetCommentThumbsReq struct { @@ -27,9 +28,9 @@ type TweetReplyThumbsReq struct { } type PostContentItem struct { - Content string `json:"content" binding:"required"` - Type core.PostContentT `json:"type" binding:"required"` - Sort int64 `json:"sort" binding:"required"` + Content string `json:"content" binding:"required"` + Type ms.PostContentT `json:"type" binding:"required"` + Sort int64 `json:"sort" binding:"required"` } type CreateTweetReq struct { @@ -42,7 +43,7 @@ type CreateTweetReq struct { ClientIP string `json:"-" binding:"-"` } -type CreateTweetResp core.PostFormated +type CreateTweetResp ms.PostFormated type DeleteTweetReq struct { BaseInfo `json:"-" binding:"-"` @@ -103,7 +104,7 @@ type CreateCommentReq struct { ClientIP string `json:"-" binding:"-"` } -type CreateCommentResp core.Comment +type CreateCommentResp ms.Comment type CreateCommentReplyReq struct { SimpleInfo `json:"-" binding:"-"` @@ -113,7 +114,7 @@ type CreateCommentReplyReq struct { ClientIP string `json:"-" binding:"-"` } -type CreateCommentReplyResp core.CommentReply +type CreateCommentReplyResp ms.CommentReply type DeleteCommentReq struct { BaseInfo `json:"-" binding:"-"` @@ -182,13 +183,13 @@ type UnfollowTopicReq struct { // Check 检查PostContentItem属性 func (p *PostContentItem) Check(acs core.AttachmentCheckService) error { // 检查附件是否是本站资源 - if p.Type == core.ContentTypeImage || p.Type == core.ContentTypeVideo || p.Type == core.ContentTypeAttachment { + if p.Type == ms.ContentTypeImage || p.Type == ms.ContentTypeVideo || p.Type == ms.ContentTypeAttachment { if err := acs.CheckAttachment(p.Content); err != nil { return err } } // 检查链接是否合法 - if p.Type == core.ContentTypeLink { + if p.Type == ms.ContentTypeLink { if strings.Index(p.Content, "http://") != 0 && strings.Index(p.Content, "https://") != 0 { return fmt.Errorf("链接不合法") } diff --git a/internal/model/web/pub.go b/internal/model/web/pub.go index 422249cf..058288e8 100644 --- a/internal/model/web/pub.go +++ b/internal/model/web/pub.go @@ -5,7 +5,7 @@ package web import ( - "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/pkg/version" ) @@ -13,7 +13,7 @@ type TweetDetailReq struct { TweetId int64 `form:"id"` } -type TweetDetailResp core.PostFormated +type TweetDetailResp ms.PostFormated type GetCaptchaResp struct { Id string `json:"id"` diff --git a/internal/model/web/web.go b/internal/model/web/web.go index bec917fa..a8a7c59c 100644 --- a/internal/model/web/web.go +++ b/internal/model/web/web.go @@ -7,14 +7,14 @@ package web import ( "github.com/alimy/mir/v3" "github.com/gin-gonic/gin" - "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/servants/base" "github.com/rocboss/paopao-ce/pkg/app" "github.com/rocboss/paopao-ce/pkg/xerror" ) type BaseInfo struct { - User *core.User + User *ms.User } type SimpleInfo struct { @@ -27,7 +27,7 @@ type BasePageReq struct { PageSize int } -func (b *BaseInfo) SetUser(user *core.User) { +func (b *BaseInfo) SetUser(user *ms.User) { b.User = user } diff --git a/internal/servants/base/base.go b/internal/servants/base/base.go index d17ae139..34a78589 100644 --- a/internal/servants/base/base.go +++ b/internal/servants/base/base.go @@ -17,6 +17,7 @@ import ( "github.com/gin-gonic/gin" "github.com/rocboss/paopao-ce/internal/conf" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao" "github.com/rocboss/paopao-ce/internal/dao/cache" "github.com/rocboss/paopao-ce/pkg/app" @@ -49,7 +50,7 @@ type SentryHubSetter interface { } type UserSetter interface { - SetUser(*core.User) + SetUser(*ms.User) } type UserIdSetter interface { @@ -60,9 +61,9 @@ type PageInfoSetter interface { SetPageInfo(page, pageSize int) } -func UserFrom(c *gin.Context) (*core.User, bool) { +func UserFrom(c *gin.Context) (*ms.User, bool) { if u, exists := c.Get("USER"); exists { - user, ok := u.(*core.User) + user, ok := u.(*ms.User) return user, ok } return nil, false @@ -157,7 +158,7 @@ func RenderAny(c *gin.Context, data any, err mir.Error) { } } -func (s *DaoServant) GetTweetBy(id int64) (*core.PostFormated, error) { +func (s *DaoServant) GetTweetBy(id int64) (*ms.PostFormated, error) { post, err := s.Ds.GetPostByID(id) if err != nil { return nil, err @@ -188,20 +189,20 @@ func (s *DaoServant) PushPostsToSearch(c context.Context) { defer s.Redis.DelPushToSearchJob(c) splitNum := 1000 - totalRows, _ := s.Ds.GetPostCount(&core.ConditionsT{ + totalRows, _ := s.Ds.GetPostCount(&ms.ConditionsT{ "visibility IN ?": []core.PostVisibleT{core.PostVisitPublic, core.PostVisitFriend}, }) pages := math.Ceil(float64(totalRows) / float64(splitNum)) nums := int(pages) for i := 0; i < nums; i++ { - posts, postsFormated, err := s.GetTweetList(&core.ConditionsT{}, i*splitNum, splitNum) + posts, postsFormated, err := s.GetTweetList(&ms.ConditionsT{}, i*splitNum, splitNum) if err != nil || len(posts) != len(postsFormated) { continue } for i, pf := range postsFormated { contentFormated := "" for _, content := range pf.Contents { - if content.Type == core.ContentTypeText || content.Type == core.ContentTypeTitle { + if content.Type == ms.ContentTypeText || content.Type == ms.ContentTypeTitle { contentFormated = contentFormated + content.Content + "\n" } } @@ -217,9 +218,9 @@ func (s *DaoServant) PushPostsToSearch(c context.Context) { } } -func (s *DaoServant) PushPostToSearch(post *core.Post) { +func (s *DaoServant) PushPostToSearch(post *ms.Post) { postFormated := post.Format() - postFormated.User = &core.UserFormated{ + postFormated.User = &ms.UserFormated{ ID: post.UserID, } contents, _ := s.Ds.GetPostContentsByIDs([]int64{post.ID}) @@ -229,7 +230,7 @@ func (s *DaoServant) PushPostToSearch(post *core.Post) { contentFormated := "" for _, content := range postFormated.Contents { - if content.Type == core.ContentTypeText || content.Type == core.ContentTypeTitle { + if content.Type == ms.ContentTypeText || content.Type == ms.ContentTypeTitle { contentFormated = contentFormated + content.Content + "\n" } } @@ -241,11 +242,11 @@ func (s *DaoServant) PushPostToSearch(post *core.Post) { s.Ts.AddDocuments(docs, fmt.Sprintf("%d", post.ID)) } -func (s *DaoServant) DeleteSearchPost(post *core.Post) error { +func (s *DaoServant) DeleteSearchPost(post *ms.Post) error { return s.Ts.DeleteDocuments([]string{fmt.Sprintf("%d", post.ID)}) } -func (s *DaoServant) GetTweetList(conditions *core.ConditionsT, offset, limit int) ([]*core.Post, []*core.PostFormated, error) { +func (s *DaoServant) GetTweetList(conditions *ms.ConditionsT, offset, limit int) ([]*ms.Post, []*ms.PostFormated, error) { posts, err := s.Ds.GetPosts(conditions, offset, limit) if err != nil { return nil, nil, err diff --git a/internal/servants/chain/admin.go b/internal/servants/chain/admin.go index 4660baa8..37a6e4c7 100644 --- a/internal/servants/chain/admin.go +++ b/internal/servants/chain/admin.go @@ -6,15 +6,15 @@ package chain import ( "github.com/gin-gonic/gin" - "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/pkg/app" ) func Admin() gin.HandlerFunc { return func(c *gin.Context) { if user, exist := c.Get("USER"); exist { - if userModel, ok := user.(*core.User); ok { - if userModel.Status == core.UserStatusNormal && userModel.IsAdmin { + if userModel, ok := user.(*ms.User); ok { + if userModel.Status == ms.UserStatusNormal && userModel.IsAdmin { c.Next() return } diff --git a/internal/servants/chain/priv.go b/internal/servants/chain/priv.go index c2a017ca..420c3a9c 100644 --- a/internal/servants/chain/priv.go +++ b/internal/servants/chain/priv.go @@ -7,7 +7,7 @@ package chain import ( "github.com/alimy/cfg" "github.com/gin-gonic/gin" - "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/pkg/app" ) @@ -15,8 +15,8 @@ func Priv() gin.HandlerFunc { if cfg.If("PhoneBind") { return func(c *gin.Context) { if u, exist := c.Get("USER"); exist { - if user, ok := u.(*core.User); ok { - if user.Status == core.UserStatusNormal { + if user, ok := u.(*ms.User); ok { + if user.Status == ms.UserStatusNormal { if user.Phone == "" { response := app.NewResponse(c) response.ToErrorResponse(_errAccountNoPhoneBind) @@ -35,7 +35,7 @@ func Priv() gin.HandlerFunc { } else { return func(c *gin.Context) { if u, exist := c.Get("USER"); exist { - if user, ok := u.(*core.User); ok && user.Status == core.UserStatusNormal { + if user, ok := u.(*ms.User); ok && user.Status == ms.UserStatusNormal { c.Next() return } diff --git a/internal/servants/web/core.go b/internal/servants/web/core.go index c4f60af3..52552c25 100644 --- a/internal/servants/web/core.go +++ b/internal/servants/web/core.go @@ -14,6 +14,7 @@ import ( "github.com/gin-gonic/gin" api "github.com/rocboss/paopao-ce/auto/api/v1" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/model/web" "github.com/rocboss/paopao-ce/internal/servants/base" "github.com/rocboss/paopao-ce/internal/servants/chain" @@ -159,7 +160,7 @@ func (s *coreSrv) GetUnreadMsgCount(req *web.GetUnreadMsgCountReq) (*web.GetUnre } func (s *coreSrv) GetMessages(req *web.GetMessagesReq) (*web.GetMessagesResp, mir.Error) { - conditions := &core.ConditionsT{ + conditions := &ms.ConditionsT{ "receiver_user_id": req.UserId, "ORDER": "id DESC", } @@ -172,7 +173,7 @@ func (s *coreSrv) GetMessages(req *web.GetMessagesReq) (*web.GetMessagesResp, mi } } // 好友申请消息不需要获取其他信息 - if mf.Type == core.MsgTypeRequestingFriend { + if mf.Type == ms.MsgTypeRequestingFriend { continue } if mf.PostID > 0 { @@ -231,10 +232,10 @@ func (s *coreSrv) SendUserWhisper(req *web.SendWhisperReq) mir.Error { } // 创建私信 - _, err := s.Ds.CreateMessage(&core.Message{ + _, err := s.Ds.CreateMessage(&ms.Message{ SenderUserID: req.Uid, ReceiverUserID: req.UserID, - Type: core.MsgTypeWhisper, + Type: ms.MsgTypeWhisper, Brief: "给你发送新私信了", Content: req.Content, }) @@ -261,7 +262,7 @@ func (s *coreSrv) GetCollections(req *web.GetCollectionsReq) (*web.GetCollection return nil, _errGetCollectionsFailed } - var posts []*core.Post + var posts []*ms.Post for _, collection := range collections { posts = append(posts, collection.Post) } @@ -324,7 +325,7 @@ func (s *coreSrv) GetStars(req *web.GetStarsReq) (*web.GetStarsResp, mir.Error) return nil, _errGetStarsFailed } - var posts []*core.Post + var posts []*ms.Post for _, star := range stars { posts = append(posts, star.Post) } diff --git a/internal/servants/web/loose.go b/internal/servants/web/loose.go index 3c0dda80..cb6327f0 100644 --- a/internal/servants/web/loose.go +++ b/internal/servants/web/loose.go @@ -10,6 +10,7 @@ import ( api "github.com/rocboss/paopao-ce/auto/api/v1" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/rocboss/paopao-ce/internal/model/web" "github.com/rocboss/paopao-ce/internal/servants/base" @@ -106,7 +107,7 @@ func (s *looseSrv) GetUserTweets(req *web.GetUserTweetsReq) (*web.GetUserTweetsR visibilities = append(visibilities, core.PostVisitFriend) } } - conditions := &core.ConditionsT{ + conditions := &ms.ConditionsT{ "user_id": other.ID, "visibility IN ?": visibilities, "ORDER": "latest_replied_on DESC", @@ -191,7 +192,7 @@ func (s *looseSrv) TweetComments(req *web.TweetCommentsReq) (*web.TweetCommentsR if req.SortStrategy == "newest" { sort = "id DESC" } - conditions := &core.ConditionsT{ + conditions := &ms.ConditionsT{ "post_id": req.TweetId, "ORDER": sort, } @@ -245,7 +246,7 @@ func (s *looseSrv) TweetComments(req *web.TweetCommentsReq) (*web.TweetCommentsR } } - commentsFormated := []*core.CommentFormated{} + commentsFormated := []*ms.CommentFormated{} for _, comment := range comments { commentFormated := comment.Format() if thumbs, exist := commentThumbs[comment.ID]; exist { diff --git a/internal/servants/web/priv.go b/internal/servants/web/priv.go index 8dc7a2b7..25400252 100644 --- a/internal/servants/web/priv.go +++ b/internal/servants/web/priv.go @@ -17,6 +17,7 @@ import ( "github.com/rocboss/paopao-ce/internal/conf" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/model/web" "github.com/rocboss/paopao-ce/internal/servants/base" "github.com/rocboss/paopao-ce/internal/servants/chain" @@ -252,7 +253,7 @@ func (s *privSrv) DownloadAttachmentPrecheck(req *web.DownloadAttachmentPrecheck return nil, _errInvalidDownloadReq } resp := &web.DownloadAttachmentPrecheckResp{Paid: true} - if content.Type == core.ContentTypeChargeAttachment { + if content.Type == ms.ContentTypeChargeAttachment { tweet, err := s.GetTweetBy(content.PostID) if err != nil { logrus.Errorf("get tweet err: %v", err) @@ -275,7 +276,7 @@ func (s *privSrv) DownloadAttachment(req *web.DownloadAttachmentReq) (*web.Downl return nil, _errInvalidDownloadReq } // 收费附件 - if content.Type == core.ContentTypeChargeAttachment { + if content.Type == ms.ContentTypeChargeAttachment { post, err := s.GetTweetBy(content.PostID) if err != nil { logrus.Errorf("s.GetTweetBy err: %v", err) @@ -288,8 +289,8 @@ func (s *privSrv) DownloadAttachment(req *web.DownloadAttachmentReq) (*web.Downl } // 未购买,则尝试购买 if !paidFlag { - err := s.buyPostAttachment(&core.Post{ - Model: &core.Model{ + err := s.buyPostAttachment(&ms.Post{ + Model: &ms.Model{ ID: post.ID, }, UserID: post.UserID, @@ -326,7 +327,7 @@ func (s *privSrv) CreateTweet(req *web.CreateTweetReq) (_ *web.CreateTweetResp, } mediaContents = contents tags := tagsFrom(req.Tags) - post := &core.Post{ + post := &ms.Post{ UserID: req.User.ID, Tags: strings.Join(tags, ","), IP: req.ClientIP, @@ -347,10 +348,10 @@ func (s *privSrv) CreateTweet(req *web.CreateTweetReq) (_ *web.CreateTweetResp, logrus.Infof("contents check err: %s", err) continue } - if item.Type == core.ContentTypeAttachment && req.AttachmentPrice > 0 { - item.Type = core.ContentTypeChargeAttachment + if item.Type == ms.ContentTypeAttachment && req.AttachmentPrice > 0 { + item.Type = ms.ContentTypeChargeAttachment } - postContent := &core.PostContent{ + postContent := &ms.PostContent{ PostID: post.ID, UserID: req.User.ID, Content: item.Content, @@ -377,10 +378,10 @@ func (s *privSrv) CreateTweet(req *web.CreateTweetReq) (_ *web.CreateTweetResp, // 创建消息提醒 // TODO: 优化消息提醒处理机制 - go s.Ds.CreateMessage(&core.Message{ + go s.Ds.CreateMessage(&ms.Message{ SenderUserID: req.User.ID, ReceiverUserID: user.ID, - Type: core.MsgTypePost, + Type: ms.MsgTypePost, Brief: "在新发布的泡泡动态中@了你", PostID: post.ID, }) @@ -388,7 +389,7 @@ func (s *privSrv) CreateTweet(req *web.CreateTweetReq) (_ *web.CreateTweetResp, } // 推送Search s.PushPostToSearch(post) - formatedPosts, err := s.Ds.RevampPosts([]*core.PostFormated{post.Format()}) + formatedPosts, err := s.Ds.RevampPosts([]*ms.PostFormated{post.Format()}) if err != nil { logrus.Infof("Ds.RevampPosts err: %s", err) return nil, _errCreatePostFailed @@ -444,8 +445,8 @@ func (s *privSrv) DeleteCommentReply(req *web.DeleteCommentReplyReq) mir.Error { func (s *privSrv) CreateCommentReply(req *web.CreateCommentReplyReq) (*web.CreateCommentReplyResp, mir.Error) { var ( - post *core.Post - comment *core.Comment + post *ms.Post + comment *ms.Comment atUserID int64 err error ) @@ -455,7 +456,7 @@ func (s *privSrv) CreateCommentReply(req *web.CreateCommentReplyReq) (*web.Creat } // 创建评论 - reply := &core.CommentReply{ + reply := &ms.CommentReply{ CommentID: req.CommentID, UserID: req.Uid, Content: req.Content, @@ -480,10 +481,10 @@ func (s *privSrv) CreateCommentReply(req *web.CreateCommentReplyReq) (*web.Creat // 创建用户消息提醒 commentMaster, err := s.Ds.GetUserByID(comment.UserID) if err == nil && commentMaster.ID != req.Uid { - go s.Ds.CreateMessage(&core.Message{ + go s.Ds.CreateMessage(&ms.Message{ SenderUserID: req.Uid, ReceiverUserID: commentMaster.ID, - Type: core.MsgTypeReply, + Type: ms.MsgTypeReply, Brief: "在泡泡评论下回复了你", PostID: post.ID, CommentID: comment.ID, @@ -492,10 +493,10 @@ func (s *privSrv) CreateCommentReply(req *web.CreateCommentReplyReq) (*web.Creat } postMaster, err := s.Ds.GetUserByID(post.UserID) if err == nil && postMaster.ID != req.Uid && commentMaster.ID != postMaster.ID { - go s.Ds.CreateMessage(&core.Message{ + go s.Ds.CreateMessage(&ms.Message{ SenderUserID: req.Uid, ReceiverUserID: postMaster.ID, - Type: core.MsgTypeReply, + Type: ms.MsgTypeReply, Brief: "在泡泡评论下发布了新回复", PostID: post.ID, CommentID: comment.ID, @@ -506,10 +507,10 @@ func (s *privSrv) CreateCommentReply(req *web.CreateCommentReplyReq) (*web.Creat user, err := s.Ds.GetUserByID(atUserID) if err == nil && user.ID != req.Uid && commentMaster.ID != user.ID && postMaster.ID != user.ID { // 创建消息提醒 - go s.Ds.CreateMessage(&core.Message{ + go s.Ds.CreateMessage(&ms.Message{ SenderUserID: req.Uid, ReceiverUserID: user.ID, - Type: core.MsgTypeReply, + Type: ms.MsgTypeReply, Brief: "在泡泡评论的回复中@了你", PostID: post.ID, CommentID: comment.ID, @@ -572,7 +573,7 @@ func (s *privSrv) CreateComment(req *web.CreateCommentReq) (_ *web.CreateComment if post.CommentCount >= conf.AppSetting.MaxCommentCount { return nil, _errMaxCommentCount } - comment := &core.Comment{ + comment := &ms.Comment{ PostID: post.ID, UserID: req.Uid, IP: req.ClientIP, @@ -586,12 +587,12 @@ func (s *privSrv) CreateComment(req *web.CreateCommentReq) (_ *web.CreateComment for _, item := range req.Contents { // 检查附件是否是本站资源 - if item.Type == core.ContentTypeImage || item.Type == core.ContentTypeVideo || item.Type == core.ContentTypeAttachment { + if item.Type == ms.ContentTypeImage || item.Type == ms.ContentTypeVideo || item.Type == ms.ContentTypeAttachment { if err := s.Ds.CheckAttachment(item.Content); err != nil { continue } } - postContent := &core.CommentContent{ + postContent := &ms.CommentContent{ CommentID: comment.ID, UserID: req.Uid, Content: item.Content, @@ -612,10 +613,10 @@ func (s *privSrv) CreateComment(req *web.CreateCommentReq) (_ *web.CreateComment // 创建用户消息提醒 postMaster, err := s.Ds.GetUserByID(post.UserID) if err == nil && postMaster.ID != req.Uid { - go s.Ds.CreateMessage(&core.Message{ + go s.Ds.CreateMessage(&ms.Message{ SenderUserID: req.Uid, ReceiverUserID: postMaster.ID, - Type: core.MsgtypeComment, + Type: ms.MsgtypeComment, Brief: "在泡泡中评论了你", PostID: post.ID, CommentID: comment.ID, @@ -628,10 +629,10 @@ func (s *privSrv) CreateComment(req *web.CreateCommentReq) (_ *web.CreateComment } // 创建消息提醒 - go s.Ds.CreateMessage(&core.Message{ + go s.Ds.CreateMessage(&ms.Message{ SenderUserID: req.Uid, ReceiverUserID: user.ID, - Type: core.MsgtypeComment, + Type: ms.MsgtypeComment, Brief: "在泡泡评论中@了你", PostID: post.ID, CommentID: comment.ID, @@ -741,7 +742,7 @@ func (s *privSrv) LockTweet(req *web.LockTweetReq) (*web.LockTweetResp, mir.Erro }, nil } -func (s *privSrv) deletePostCommentReply(reply *core.CommentReply) error { +func (s *privSrv) deletePostCommentReply(reply *ms.CommentReply) error { err := s.Ds.DeleteCommentReply(reply) if err != nil { return err @@ -765,7 +766,7 @@ func (s *privSrv) deletePostCommentReply(reply *core.CommentReply) error { return nil } -func (s *privSrv) createPostPreHandler(commentID int64, userID, atUserID int64) (*core.Post, *core.Comment, int64, +func (s *privSrv) createPostPreHandler(commentID int64, userID, atUserID int64) (*ms.Post, *ms.Comment, int64, error) { // 加载Comment comment, err := s.Ds.GetCommentByID(commentID) @@ -798,7 +799,7 @@ func (s *privSrv) createPostPreHandler(commentID int64, userID, atUserID int64) return post, comment, atUserID, nil } -func (s *privSrv) createPostStar(postID, userID int64) (*core.PostStar, mir.Error) { +func (s *privSrv) createPostStar(postID, userID int64) (*ms.PostStar, mir.Error) { post, err := s.Ds.GetPostByID(postID) if err != nil { return nil, xerror.ServerError @@ -824,7 +825,7 @@ func (s *privSrv) createPostStar(postID, userID int64) (*core.PostStar, mir.Erro return star, nil } -func (s *privSrv) deletePostStar(star *core.PostStar) mir.Error { +func (s *privSrv) deletePostStar(star *ms.PostStar) mir.Error { post, err := s.Ds.GetPostByID(star.PostID) if err != nil { return xerror.ServerError @@ -849,7 +850,7 @@ func (s *privSrv) deletePostStar(star *core.PostStar) mir.Error { return nil } -func (s *privSrv) createPostCollection(postID, userID int64) (*core.PostCollection, mir.Error) { +func (s *privSrv) createPostCollection(postID, userID int64) (*ms.PostCollection, mir.Error) { post, err := s.Ds.GetPostByID(postID) if err != nil { return nil, xerror.ServerError @@ -875,7 +876,7 @@ func (s *privSrv) createPostCollection(postID, userID int64) (*core.PostCollecti return collection, nil } -func (s *privSrv) deletePostCollection(collection *core.PostCollection) mir.Error { +func (s *privSrv) deletePostCollection(collection *ms.PostCollection) mir.Error { post, err := s.Ds.GetPostByID(collection.PostID) if err != nil { return xerror.ServerError @@ -904,7 +905,7 @@ func (s *privSrv) checkPostAttachmentIsPaid(postID, userID int64) bool { return err == nil && bill.Model != nil && bill.ID > 0 } -func (s *privSrv) buyPostAttachment(post *core.Post, user *core.User) mir.Error { +func (s *privSrv) buyPostAttachment(post *ms.Post, user *ms.User) mir.Error { if user.Balance < post.AttachmentPrice { return _errInsuffientDownloadMoney } diff --git a/internal/servants/web/pub.go b/internal/servants/web/pub.go index 6c58de3c..53bfe167 100644 --- a/internal/servants/web/pub.go +++ b/internal/servants/web/pub.go @@ -17,7 +17,7 @@ import ( "github.com/alimy/mir/v3" "github.com/gofrs/uuid" api "github.com/rocboss/paopao-ce/auto/api/v1" - "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/model/web" "github.com/rocboss/paopao-ce/internal/servants/base" "github.com/rocboss/paopao-ce/internal/servants/web/assets" @@ -141,13 +141,13 @@ func (s *pubSrv) Register(req *web.RegisterReq) (*web.RegisterResp, mir.Error) { return nil, _errUserRegisterFailed } password, salt := encryptPasswordAndSalt(req.Password) - user := &core.User{ + user := &ms.User{ Nickname: req.Username, Username: req.Username, Password: password, Avatar: getRandomAvatar(), Salt: salt, - Status: core.UserStatusNormal, + Status: ms.UserStatusNormal, } user, err := s.Ds.CreateUser(user) if err != nil { @@ -174,7 +174,7 @@ func (s *pubSrv) Login(req *web.LoginReq) (*web.LoginResp, mir.Error) { } // 对比密码是否正确 if validPassword(user.Password, req.Password, user.Salt) { - if user.Status == core.UserStatusClosed { + if user.Status == ms.UserStatusClosed { return nil, _errUserHasBeenBanned } // 清空登录计数 diff --git a/internal/servants/web/utils.go b/internal/servants/web/utils.go index b4dc77b8..db2f3ab7 100644 --- a/internal/servants/web/utils.go +++ b/internal/servants/web/utils.go @@ -14,6 +14,7 @@ import ( "github.com/alimy/mir/v3" "github.com/gofrs/uuid" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/model/web" "github.com/rocboss/paopao-ce/pkg/utils" "github.com/rocboss/paopao-ce/pkg/xerror" @@ -119,11 +120,11 @@ func persistMediaContents(oss core.ObjectStorageService, contents []*web.PostCon items = make([]string, 0, len(contents)) for _, item := range contents { switch item.Type { - case core.ContentTypeImage, - core.ContentTypeVideo, - core.ContentTypeAudio, - core.ContentTypeAttachment, - core.ContentTypeChargeAttachment: + case ms.ContentTypeImage, + ms.ContentTypeVideo, + ms.ContentTypeAudio, + ms.ContentTypeAttachment, + ms.ContentTypeChargeAttachment: items = append(items, item.Content) if err != nil { continue @@ -200,7 +201,7 @@ func tagsFrom(originTags []string) []string { } // checkPermision 检查是否拥有者或管理员 -func checkPermision(user *core.User, targetUserId int64) mir.Error { +func checkPermision(user *ms.User, targetUserId int64) mir.Error { if user == nil || (user.ID != targetUserId && !user.IsAdmin) { return _errNoPermission } diff --git a/pkg/app/jwt.go b/pkg/app/jwt.go index b9759e07..a861faa2 100644 --- a/pkg/app/jwt.go +++ b/pkg/app/jwt.go @@ -9,7 +9,7 @@ import ( "github.com/golang-jwt/jwt/v4" "github.com/rocboss/paopao-ce/internal/conf" - "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/ms" ) type Claims struct { @@ -22,7 +22,7 @@ func GetJWTSecret() []byte { return []byte(conf.JWTSetting.Secret) } -func GenerateToken(User *core.User) (string, error) { +func GenerateToken(User *ms.User) (string, error) { expireTime := time.Now().Add(conf.JWTSetting.Expire) claims := Claims{ UID: User.ID, From fe11dae223b221f66a972545d3066adcec42735f Mon Sep 17 00:00:00 2001 From: Michael Li Date: Tue, 11 Jul 2023 11:38:39 +0800 Subject: [PATCH 02/19] re-generate mir code" --- auto/api/v1/alipay_pub.go | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/auto/api/v1/alipay_pub.go b/auto/api/v1/alipay_pub.go index 10e067ad..b31172ad 100644 --- a/auto/api/v1/alipay_pub.go +++ b/auto/api/v1/alipay_pub.go @@ -12,19 +12,6 @@ import ( "github.com/rocboss/paopao-ce/internal/model/web" ) -type _binding_ interface { - Bind(*gin.Context) mir.Error -} - -type _render_ interface { - Render(*gin.Context) -} - -type _default_ interface { - Bind(*gin.Context, any) mir.Error - Render(*gin.Context, any, mir.Error) -} - type AlipayPub interface { _default_ From 2d0477cf65a9aafd3b8bef24030d3a6229e70ba2 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Thu, 13 Jul 2023 16:52:18 +0800 Subject: [PATCH 03/19] sqlx: add some logic implement 5% --- internal/core/cs/tweets.go | 4 +- internal/core/tweets.go | 2 +- 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/tweets.go | 6 +- internal/dao/sakila/contacts.go | 21 +- internal/dao/sakila/tweets.go | 344 ++++++++++++++------- internal/dao/sakila/user.go | 51 +-- internal/dao/sakila/yesql/cc/yesql.go | 326 +++++++++++++++---- internal/dao/sakila/yesql/yesql.sql | 196 +++++++++++- internal/model/web/priv.go | 3 +- internal/servants/web/priv.go | 14 +- 13 files changed, 747 insertions(+), 228 deletions(-) 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/tweets.go b/internal/core/tweets.go index 4ea9126d..15ec3a9f 100644 --- a/internal/core/tweets.go +++ b/internal/core/tweets.go @@ -38,7 +38,7 @@ type TweetManageService interface { CreatePostCollection(postID, userID int64) (*ms.PostCollection, error) DeletePostCollection(p *ms.PostCollection) error CreatePostContent(content *ms.PostContent) (*ms.PostContent, error) - CreateAttachment(obj *cs.Attachment) (int64, error) + CreateAttachment(obj *ms.Attachment) (int64, error) } // TweetHelpService 推文辅助服务 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/tweets.go b/internal/dao/jinzhu/tweets.go index a9dc2a27..49cc2d56 100644 --- a/internal/dao/jinzhu/tweets.go +++ b/internal/dao/jinzhu/tweets.go @@ -197,9 +197,9 @@ func (s *tweetManageSrv) CreatePostContent(content *ms.PostContent) (*ms.PostCon 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 *ms.Post) (*ms.Post, error) { diff --git a/internal/dao/sakila/contacts.go b/internal/dao/sakila/contacts.go index f37dc872..5c1d6883 100644 --- a/internal/dao/sakila/contacts.go +++ b/internal/dao/sakila/contacts.go @@ -22,32 +22,27 @@ type contactManageSrv struct { } func (s *contactManageSrv) RequestingFriend(userId int64, friendId int64, greetings string) (err error) { - // TODO - debug.NotImplemented() - return nil + _, err = s.q.RejectFriend.Query(userId, friendId, greetings) + return } func (s *contactManageSrv) AddFriend(userId int64, friendId int64) (err error) { - // TODO - debug.NotImplemented() - return nil + _, err = s.q.AddFriend.Exec(userId, friendId) + return } func (s *contactManageSrv) RejectFriend(userId int64, friendId int64) (err error) { - // TODO - debug.NotImplemented() - return nil + _, err = s.q.RejectFriend.Exec(userId, friendId) + return } func (s *contactManageSrv) DeleteFriend(userId int64, friendId int64) (err error) { - // TODO - debug.NotImplemented() - return nil + _, err = s.q.DelFriend.Exec(userId, friendId) + return } func (s *contactManageSrv) GetContacts(userId int64, offset int, limit int) (*ms.ContactList, error) { // TODO - debug.NotImplemented() return nil, nil } diff --git a/internal/dao/sakila/tweets.go b/internal/dao/sakila/tweets.go index e9272026..b2db0c76 100644 --- a/internal/dao/sakila/tweets.go +++ b/internal/dao/sakila/tweets.go @@ -58,57 +58,140 @@ type tweetHelpSrvA struct { // MergePosts post数据整合 func (s *tweetHelpSrv) MergePosts(posts []*ms.Post) ([]*ms.PostFormated, error) { - // TODO - debug.NotImplemented() - return nil, nil + postIds := make([]int64, 0, len(posts)) + userIds := make([]int64, 0, len(posts)) + for _, post := range posts { + postIds = append(postIds, post.ID) + userIds = append(userIds, post.UserID) + } + postContents, err := s.getPostContentsByIDs(postIds) + if err != nil { + return nil, err + } + users, err := s.getUsersByIDs(userIds) + if err != nil { + return nil, err + } + userMap := make(map[int64]*dbr.UserFormated, len(users)) + for _, user := range users { + userMap[user.ID] = user + } + contentMap := make(map[int64][]*dbr.PostContentFormated, len(postContents)) + for _, content := range postContents { + contentMap[content.PostID] = append(contentMap[content.PostID], content) + } + // 数据整合 + postsFormated := make([]*dbr.PostFormated, 0, len(posts)) + for _, post := range posts { + postFormated := post.Format() + postFormated.User = userMap[post.UserID] + postFormated.Contents = contentMap[post.ID] + postsFormated = append(postsFormated, postFormated) + } + return postsFormated, nil } // RevampPosts post数据整形修复 func (s *tweetHelpSrv) RevampPosts(posts []*ms.PostFormated) ([]*ms.PostFormated, error) { - // TODO - debug.NotImplemented() - return nil, nil + postIds := make([]int64, 0, len(posts)) + userIds := make([]int64, 0, len(posts)) + for _, post := range posts { + postIds = append(postIds, post.ID) + userIds = append(userIds, post.UserID) + } + postContents, err := s.getPostContentsByIDs(postIds) + if err != nil { + return nil, err + } + users, err := s.getUsersByIDs(userIds) + if err != nil { + return nil, err + } + userMap := make(map[int64]*dbr.UserFormated, len(users)) + for _, user := range users { + userMap[user.ID] = user + } + contentMap := make(map[int64][]*dbr.PostContentFormated, len(postContents)) + for _, content := range postContents { + contentMap[content.PostID] = append(contentMap[content.PostID], content) + } + // 数据整合 + for _, post := range posts { + post.User = userMap[post.UserID] + post.Contents = contentMap[post.ID] + } + return posts, nil } -func (s *tweetHelpSrv) getPostContentsByIDs(ids []int64) ([]*dbr.PostContent, error) { - // TODO - debug.NotImplemented() - return nil, nil +func (s *tweetHelpSrv) getPostContentsByIDs(ids []int64) ([]*dbr.PostContentFormated, error) { + res := []*dbr.PostContentFormated{} + err := s.inSelect(s.db, &res, s.q.GetPostContentByIds, ids) + return res, err } -func (s *tweetHelpSrv) getUsersByIDs(ids []int64) ([]*dbr.User, error) { - // TODO - debug.NotImplemented() - return nil, nil +func (s *tweetHelpSrv) getUsersByIDs(ids []int64) ([]*dbr.UserFormated, error) { + res := []*dbr.UserFormated{} + err := s.inSelect(s.db, &res, s.q.GetUsersByIds, ids) + return res, err } func (s *tweetManageSrv) CreatePostCollection(postID, userID int64) (*ms.PostCollection, error) { - // TODO - debug.NotImplemented() - return nil, nil + res, err := s.q.AddPostCollection.Exec(postID, userID) + if err != nil { + return nil, err + } + id, err := res.LastInsertId() + if err != nil { + return nil, err + } + return &ms.PostCollection{ + Model: &dbr.Model{ + ID: id, + }, + PostID: postID, + UserID: userID, + }, nil } -func (s *tweetManageSrv) DeletePostCollection(p *ms.PostCollection) error { - // TODO - debug.NotImplemented() - return nil +func (s *tweetManageSrv) DeletePostCollection(r *ms.PostCollection) error { + _, err := s.q.DelPostCollection.Exec(r.ID) + return err } -func (s *tweetManageSrv) CreatePostContent(content *ms.PostContent) (*ms.PostContent, error) { - // TODO - debug.NotImplemented() - return nil, nil +func (s *tweetManageSrv) CreatePostContent(r *ms.PostContent) (*ms.PostContent, error) { + res, err := s.q.AddPostContent.Exec(r.PostID, r.UserID, r.Content, r.Type, r.Sort) + if err != nil { + return nil, err + } + r.Model = &dbr.Model{} + r.ID, err = res.LastInsertId() + if err != nil { + return nil, err + } + return r, nil } -func (s *tweetManageSrv) CreateAttachment(obj *cs.Attachment) (int64, error) { - // TODO - return 0, debug.ErrNotImplemented +func (s *tweetManageSrv) CreateAttachment(r *ms.Attachment) (int64, error) { + res, err := s.q.AddAttachment.Exec(r.UserID, r.FileSize, r.ImgWidth, r.ImgHeight, r.Type, r.Content) + if err != nil { + return 0, err + } + return res.LastInsertId() } -func (s *tweetManageSrv) CreatePost(post *ms.Post) (*ms.Post, error) { - // TODO - debug.NotImplemented() - return nil, nil +func (s *tweetManageSrv) CreatePost(r *ms.Post) (*ms.Post, error) { + res, err := s.q.AddPost.Exec(r.UserID, r.Visibility, r.Tags, r.AttachmentPrice, r.IP, r.IPLoc) + if err != nil { + return nil, err + } + if id, err := res.LastInsertId(); err == nil { + r.Model = &dbr.Model{ + ID: id, + } + } else { + return nil, err + } + return r, nil } func (s *tweetManageSrv) DeletePost(post *ms.Post) ([]string, error) { @@ -117,164 +200,193 @@ func (s *tweetManageSrv) DeletePost(post *ms.Post) ([]string, error) { return nil, nil } -func (s *tweetManageSrv) LockPost(post *ms.Post) error { - // TODO - debug.NotImplemented() - return nil +func (s *tweetManageSrv) LockPost(r *ms.Post) error { + _, err := s.q.LockPost.Exec(r.ID) + return err } -func (s *tweetManageSrv) StickPost(post *ms.Post) error { - // TODO - debug.NotImplemented() - return nil +func (s *tweetManageSrv) StickPost(r *ms.Post) error { + _, err := s.q.StickPost.Exec(r.ID) + return err } -func (s *tweetManageSrv) VisiblePost(post *ms.Post, visibility core.PostVisibleT) error { - // TODO - debug.NotImplemented() - return nil +func (s *tweetManageSrv) VisiblePost(r *ms.Post, visibility core.PostVisibleT) error { + _, err := s.q.VisiblePost.Exec(r.ID, visibility) + return err } -func (s *tweetManageSrv) UpdatePost(post *ms.Post) error { - // TODO - debug.NotImplemented() +func (s *tweetManageSrv) UpdatePost(r *ms.Post) error { + if _, err := s.q.UpdatePost.Exec(r.CommentCount, r.UpvoteCount, r.ID); err != nil { + return err + } + s.cis.SendAction(core.IdxActUpdatePost, r) return nil } func (s *tweetManageSrv) CreatePostStar(postID, userID int64) (*ms.PostStar, error) { - // TODO - debug.NotImplemented() - return nil, nil + res, err := s.q.AddPostStar.Exec(postID, userID) + if err != nil { + return nil, err + } + id, err := res.LastInsertId() + if err != nil { + return nil, err + } + return &ms.PostStar{ + Model: &dbr.Model{ + ID: id, + }, + PostID: postID, + UserID: userID, + }, nil } -func (s *tweetManageSrv) DeletePostStar(p *ms.PostStar) error { - // TODO - debug.NotImplemented() - return nil +func (s *tweetManageSrv) DeletePostStar(r *ms.PostStar) error { + _, err := s.q.DelPostStar.Exec(r.ID) + return err } func (s *tweetSrv) GetPostByID(id int64) (*ms.Post, error) { - // TODO - debug.NotImplemented() - return nil, nil + res := &ms.Post{} + err := s.q.GetPostById.Get(res, id) + return res, err } func (s *tweetSrv) GetPosts(conditions *ms.ConditionsT, offset, limit int) ([]*ms.Post, error) { - // TODO + // TODO 需要精细化接口 debug.NotImplemented() return nil, nil } func (s *tweetSrv) GetPostCount(conditions *ms.ConditionsT) (int64, error) { - // TODO + // TODO 需要精细化接口 debug.NotImplemented() return 0, nil } func (s *tweetSrv) GetUserPostStar(postID, userID int64) (*ms.PostStar, error) { - // TODO - debug.NotImplemented() - return nil, nil + res := &ms.PostStar{} + err := s.q.GetUserPostStar.Get(res, postID, userID) + return res, err } func (s *tweetSrv) GetUserPostStars(userID int64, offset, limit int) ([]*ms.PostStar, error) { - // TODO - debug.NotImplemented() - return nil, nil + res := []*ms.PostStar{} + err := s.q.GetUserPostStar.Select(&res, userID, limit, offset) + return res, err } -func (s *tweetSrv) GetUserPostStarCount(userID int64) (int64, error) { - // TODO - debug.NotImplemented() - return 0, nil +func (s *tweetSrv) GetUserPostStarCount(userID int64) (res int64, err error) { + err = s.q.GetUserPostStarCount.Get(&res, userID) + return } func (s *tweetSrv) GetUserPostCollection(postID, userID int64) (*ms.PostCollection, error) { - // TODO - debug.NotImplemented() - return nil, nil + res := &ms.PostCollection{} + err := s.q.GetUserPostCollection.Get(res, postID, userID) + return res, err } func (s *tweetSrv) GetUserPostCollections(userID int64, offset, limit int) ([]*ms.PostCollection, error) { - // TODO - debug.NotImplemented() - return nil, nil -} - -func (s *tweetSrv) GetUserPostCollectionCount(userID int64) (int64, error) { - // TODO - debug.NotImplemented() - return 0, nil -} - -func (s *tweetSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*ms.WalletStatement, error) { - // TODO - debug.NotImplemented() - return nil, nil + res := []*ms.PostCollection{} + err := s.q.GetUserPostCollections.Select(&res, userID, limit, offset) + return res, err } -func (s *tweetSrv) GetUserWalletBillCount(userID int64) (int64, error) { - // TODO - debug.NotImplemented() - return 0, nil +func (s *tweetSrv) GetUserPostCollectionCount(userID int64) (res int64, err error) { + err = s.q.GetUserPostCollectionCount.Get(&res) + return } func (s *tweetSrv) GetPostAttatchmentBill(postID, userID int64) (*ms.PostAttachmentBill, error) { - // TODO - debug.NotImplemented() - return nil, nil + res := &ms.PostAttachmentBill{} + err := s.q.GetPostAttachmentBill.Get(res, postID, userID) + return res, err } func (s *tweetSrv) GetPostContentsByIDs(ids []int64) ([]*ms.PostContent, error) { - // TODO - debug.NotImplemented() - return nil, nil + res := []*ms.PostContent{} + err := s.inSelect(s.db, &res, s.q.GetPostContetnsByIds, ids) + return res, err } func (s *tweetSrv) GetPostContentByID(id int64) (*ms.PostContent, error) { - // TODO - debug.NotImplemented() - return nil, nil + res := &ms.PostContent{} + err := s.q.GetPostContentById.Get(res, id) + return res, err } func (s *tweetSrvA) TweetInfoById(id int64) (*cs.TweetInfo, error) { - // TODO - return nil, debug.ErrNotImplemented + res := &cs.TweetInfo{} + err := s.q.TweetInfoById.Get(res, id) + return res, err } func (s *tweetSrvA) TweetItemById(id int64) (*cs.TweetItem, error) { - // TODO - return nil, debug.ErrNotImplemented + res := &cs.TweetItem{} + err := s.q.TweetItemById.Get(res, id) + if err != nil { + return nil, err + } + // TODO need add contents info to res + return res, nil +} + +func (s *tweetSrvA) UserTweets(visitorId, userId int64) (res cs.TweetList, err error) { + res = cs.TweetList{} + switch s.checkRelationBy(visitorId, userId) { + case 0: // admin + err = s.q.UserTweetsByAdmin.Select(&res, userId) + case 1: // self + err = s.q.UserTweetsBySelf.Select(&res, userId) + case 2: // friend + err = s.q.UserTweetsByFriend.Select(&res, userId) + case 3: // follower + fallthrough + default: // guest + err = s.q.UserTweetsByGuest.Select(&res, userId) + } + if err != nil { + return nil, err + } + // TODO need add contents info to res + return res, nil } -func (s *tweetSrvA) UserTweets(visitorId, userId int64) (cs.TweetList, error) { +// checkRelationBy check the relation of visitor with user +func (s *tweetSrvA) checkRelationBy(visitorId, userId int64) uint { // TODO - return nil, debug.ErrNotImplemented + return 0 } func (s *tweetSrvA) ReactionByTweetId(userId int64, tweetId int64) (*cs.ReactionItem, error) { - // TODO - return nil, debug.ErrNotImplemented + res := &cs.ReactionItem{} + err := s.q.ReactionByTweetId.Get(res, userId, tweetId) + return res, err } func (s *tweetSrvA) UserReactions(userId int64, limit int, offset int) (cs.ReactionList, error) { - // TODO - return nil, debug.ErrNotImplemented + res := cs.ReactionList{} + err := s.q.UserReactions.Select(&res, userId) + return res, err } func (s *tweetSrvA) FavoriteByTweetId(userId int64, tweetId int64) (*cs.FavoriteItem, error) { - // TODO - return nil, debug.ErrNotImplemented + res := &cs.FavoriteItem{} + err := s.q.FavoriteByTweetId.Get(res, userId, tweetId) + return res, err } func (s *tweetSrvA) UserFavorites(userId int64, limit int, offset int) (cs.FavoriteList, error) { - // TODO - return nil, debug.ErrNotImplemented + res := cs.FavoriteList{} + err := s.q.UserFavorites.Select(&res, userId) + return res, err } func (s *tweetSrvA) AttachmentByTweetId(userId int64, tweetId int64) (*cs.AttachmentBill, error) { - // TODO - return nil, debug.ErrNotImplemented + res := &cs.AttachmentBill{} + err := s.q.AttachmentByTweetId.Get(res, userId, tweetId) + return res, err } func (s *tweetManageSrvA) CreateAttachment(obj *cs.Attachment) (int64, error) { diff --git a/internal/dao/sakila/user.go b/internal/dao/sakila/user.go index 9611b498..c877f475 100644 --- a/internal/dao/sakila/user.go +++ b/internal/dao/sakila/user.go @@ -8,8 +8,8 @@ import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/ms" + "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" - "github.com/rocboss/paopao-ce/pkg/debug" ) var ( @@ -22,45 +22,48 @@ type userManageSrv struct { } func (s *userManageSrv) GetUserByID(id int64) (*ms.User, error) { - // TODO - debug.NotImplemented() - return nil, nil + res := &ms.User{} + err := s.q.GetUserById.Get(res, id) + return res, err } func (s *userManageSrv) GetUserByUsername(username string) (*ms.User, error) { - // TODO - debug.NotImplemented() - return nil, nil + res := &ms.User{} + err := s.q.GetUserByUsername.Get(res, username) + return res, err } func (s *userManageSrv) GetUserByPhone(phone string) (*ms.User, error) { - // TODO - debug.NotImplemented() - return nil, nil + res := &ms.User{} + err := s.q.GetUserByPhone.Get(res, phone) + return res, err } func (s *userManageSrv) GetUsersByIDs(ids []int64) ([]*ms.User, error) { - // TODO - debug.NotImplemented() - return nil, nil + res := []*ms.User{} + err := s.inSelect(s.db, &res, s.q.GetUsersByIds, ids) + return res, err } func (s *userManageSrv) GetUsersByKeyword(keyword string) ([]*ms.User, error) { - // TODO - debug.NotImplemented() - return nil, nil + res := []*ms.User{} + err := s.q.GetUsersByKeyword.Select(&res, keyword) + return res, err } -func (s *userManageSrv) CreateUser(user *ms.User) (*ms.User, error) { - // TODO - debug.NotImplemented() - return nil, nil +func (s *userManageSrv) CreateUser(r *ms.User) (*ms.User, error) { + res, err := s.q.AddUser.Exec(r.Username, r.Nickname, r.Password, r.Salt, r.Avatar) + if err != nil { + return nil, err + } + r.Model = &dbr.Model{} + r.ID, err = res.LastInsertId() + return r, err } -func (s *userManageSrv) UpdateUser(user *ms.User) error { - // TODO - debug.NotImplemented() - return nil +func (s *userManageSrv) UpdateUser(r *ms.User) error { + _, err := s.q.UpdateUser.Exec(r.Nickname, r.Password, r.Salt, r.Phone, r.Status) + return err } func newUserManageService(db *sqlx.DB) core.UserManageService { diff --git a/internal/dao/sakila/yesql/cc/yesql.go b/internal/dao/sakila/yesql/cc/yesql.go index 0483dbb3..78351e25 100644 --- a/internal/dao/sakila/yesql/cc/yesql.go +++ b/internal/dao/sakila/yesql/cc/yesql.go @@ -12,38 +12,83 @@ import ( ) const ( - _UserInfo_AuthorizationManage = `SELECT * FROM @user WHERE username=?` - _UserInfo_CommentManage = `SELECT * FROM @user WHERE username=?` - _UserInfo_Comment = `SELECT * FROM @user WHERE username=?` - _UserInfo_ContactManager = `SELECT * FROM @user WHERE username=?` - _UserInfo_FollowIndexA = `SELECT * FROM @user WHERE username=?` - _UserInfo_FollowIndex = `SELECT * FROM @user WHERE username=?` - _UserInfo_FriendIndexA = `SELECT * FROM @user WHERE username=?` - _UserInfo_FriendIndex = `SELECT * FROM @user WHERE username=?` - _UserInfo_LightIndexA = `SELECT * FROM @user WHERE username=?` - _UserInfo_LightIndex = `SELECT * FROM @user WHERE username=?` - _UserInfo_Message = `SELECT * FROM @user WHERE username=?` - _UserInfo_Security = `SELECT * FROM @user WHERE username=?` - _UserInfo_SimpleIndexA = `SELECT * FROM @user WHERE username=?` - _UserInfo_SimpleIndex = `SELECT * FROM @user WHERE username=?` - _DecrTagsById_TopicA = `UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?)` - _HotTags_TopicA = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.quote_num DESC LIMIT ? OFFSET ?` - _IncrTagsById_TopicA = `UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?)` - _InsertTag_TopicA = `INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1)` - _NewestTags_TopicA = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.id DESC LIMIT ? OFFSET ?` - _TagsByIdA_TopicA = `SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0` - _TagsByIdB_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?)` - _TagsByKeywordA_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6` - _TagsByKeywordB_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6` - _TagsForIncr_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` - _UserInfo_TweetA = `SELECT * FROM @user WHERE username=?` - _UserInfo_TweetHelpA = `SELECT * FROM @user WHERE username=?` - _UserInfo_TweetHelp = `SELECT * FROM @user WHERE username=?` - _UserInfo_TweetManageA = `SELECT * FROM @user WHERE username=?` - _UserInfo_TweetManage = `SELECT * FROM @user WHERE username=?` - _UserInfo_Tweet = `SELECT * FROM @user WHERE username=?` - _UserInfo_UserManage = `SELECT * FROM @user WHERE username=?` - _UserInfo_Wallet = `SELECT * FROM @user WHERE username=?` + _UserInfo_AuthorizationManage = `SELECT * FROM @user WHERE username=?` + _UserInfo_CommentManage = `SELECT * FROM @user WHERE username=?` + _UserInfo_Comment = `SELECT * FROM @user WHERE username=?` + _AddFriend_ContactManager = `SELECT * FROM @user WHERE username=?` + _DelFriend_ContactManager = `SELECT * FROM @user WHERE username=?` + _GetContacts_ContactManager = `SELECT * FROM @user WHERE username=?` + _IsFriend_ContactManager = `SELECT * FROM @user WHERE username=?` + _RejectFriend_ContactManager = `SELECT * FROM @user WHERE username=?` + _RequestingFriend_ContactManager = `SELECT * FROM @user WHERE username=?` + _UserInfo_FollowIndexA = `SELECT * FROM @user WHERE username=?` + _UserInfo_FollowIndex = `SELECT * FROM @user WHERE username=?` + _UserInfo_FriendIndexA = `SELECT * FROM @user WHERE username=?` + _UserInfo_FriendIndex = `SELECT * FROM @user WHERE username=?` + _UserInfo_LightIndexA = `SELECT * FROM @user WHERE username=?` + _UserInfo_LightIndex = `SELECT * FROM @user WHERE username=?` + _UserInfo_Message = `SELECT * FROM @user WHERE username=?` + _UserInfo_Security = `SELECT * FROM @user WHERE username=?` + _UserInfo_SimpleIndexA = `SELECT * FROM @user WHERE username=?` + _UserInfo_SimpleIndex = `SELECT * FROM @user WHERE username=?` + _DecrTagsById_TopicA = `UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?)` + _HotTags_TopicA = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.quote_num DESC LIMIT ? OFFSET ?` + _IncrTagsById_TopicA = `UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?)` + _InsertTag_TopicA = `INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1)` + _NewestTags_TopicA = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.id DESC LIMIT ? OFFSET ?` + _TagsByIdA_TopicA = `SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0` + _TagsByIdB_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?)` + _TagsByKeywordA_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6` + _TagsByKeywordB_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6` + _TagsForIncr_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` + _AttachmentByTweetId_TweetA = `SELECT * FROM @user WHERE username=?` + _FavoriteByTweetId_TweetA = `SELECT * FROM @user WHERE username=?` + _ReactionByTweetId_TweetA = `SELECT * FROM @user WHERE username=?` + _TweetInfoById_TweetA = `SELECT * FROM @user WHERE username=?` + _TweetItemById_TweetA = `SELECT * FROM @user WHERE username=?` + _UserFavorites_TweetA = `SELECT * FROM @user WHERE username=?` + _UserInfo_TweetA = `SELECT * FROM @user WHERE username=?` + _UserReactions_TweetA = `SELECT * FROM @user WHERE username=?` + _UserTweetsByAdmin_TweetA = `SELECT * FROM @user WHERE username=?` + _UserTweetsByFriend_TweetA = `SELECT * FROM @user WHERE username=?` + _UserTweetsByGuest_TweetA = `SELECT * FROM @user WHERE username=?` + _UserTweetsBySelf_TweetA = `SELECT * FROM @user WHERE username=?` + _GetPostAttachmentBill_Tweet = `SELECT * FROM @user WHERE username=?` + _GetPostById_Tweet = `SELECT * FROM @user WHERE username=?` + _GetPostContentById_Tweet = `SELECT * FROM @user WHERE username=?` + _GetPostContetnsByIds_Tweet = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` + _GetPostCount_Tweet = `SELECT * FROM @user WHERE username=?` + _GetPosts_Tweet = `SELECT * FROM @user WHERE username=?` + _GetUserPostCollection_Tweet = `SELECT * FROM @user WHERE username=?` + _GetUserPostCollectionCount_Tweet = `SELECT * FROM @user WHERE username=?` + _GetUserPostCollections_Tweet = `SELECT * FROM @user WHERE username=?` + _GetUserPostStar_Tweet = `SELECT * FROM @user WHERE username=?` + _GetUserPostStarCount_Tweet = `SELECT * FROM @user WHERE username=?` + _GetUserPostStars_Tweet = `SELECT * FROM @user WHERE username=?` + _UserInfo_TweetHelpA = `SELECT * FROM @user WHERE username=?` + _GetPostContentByIds_TweetHelp = `SELECT * FROM @user WHERE username=?` + _GetUsersByIds_TweetHelp = `SELECT * FROM @user WHERE username=?` + _UserInfo_TweetManageA = `SELECT * FROM @user WHERE username=?` + _AddAttachment_TweetManage = `SELECT * FROM @user WHERE username=?` + _AddPost_TweetManage = `SELECT * FROM @user WHERE username=?` + _AddPostCollection_TweetManage = `SELECT * FROM @user WHERE username=?` + _AddPostContent_TweetManage = `SELECT * FROM @user WHERE username=?` + _AddPostStar_TweetManage = `SELECT * FROM @user WHERE username=?` + _DelPost_TweetManage = `SELECT * FROM @user WHERE username=?` + _DelPostCollection_TweetManage = `SELECT * FROM @user WHERE username=?` + _DelPostStar_TweetManage = `SELECT * FROM @user WHERE username=?` + _LockPost_TweetManage = `SELECT * FROM @user WHERE username=?` + _StickPost_TweetManage = `SELECT * FROM @user WHERE username=?` + _UpdatePost_TweetManage = `SELECT * FROM @user WHERE username=?` + _VisiblePost_TweetManage = `SELECT * FROM @user WHERE username=?` + _AddUser_UserManage = `SELECT * FROM @user WHERE username=?` + _GetUserById_UserManage = `SELECT * FROM @user WHERE username=?` + _GetUserByPhone_UserManage = `SELECT * FROM @user WHERE username=?` + _GetUserByUsername_UserManage = `SELECT * FROM @user WHERE username=?` + _GetUsersByIds_UserManage = `SELECT * FROM @user WHERE username=?` + _GetUsersByKeyword_UserManage = `SELECT * FROM @user WHERE username=?` + _UpdateUser_UserManage = `SELECT * FROM @user WHERE username=?` + _UserInfo_Wallet = `SELECT * FROM @user WHERE username=?` ) type AuthorizationManage struct { @@ -62,8 +107,13 @@ type CommentManage struct { } type ContactManager struct { - yesql.Namespace `yesql:"contact_manager"` - UserInfo *sqlx.Stmt `yesql:"user_info"` + yesql.Namespace `yesql:"contact_manager"` + AddFriend *sqlx.Stmt `yesql:"add_friend"` + DelFriend *sqlx.Stmt `yesql:"del_friend"` + GetContacts *sqlx.Stmt `yesql:"get_contacts"` + IsFriend *sqlx.Stmt `yesql:"is_friend"` + RejectFriend *sqlx.Stmt `yesql:"reject_friend"` + RequestingFriend *sqlx.Stmt `yesql:"requesting_friend"` } type FollowIndex struct { @@ -131,18 +181,41 @@ type TopicA struct { } type Tweet struct { - yesql.Namespace `yesql:"tweet"` - UserInfo *sqlx.Stmt `yesql:"user_info"` + yesql.Namespace `yesql:"tweet"` + GetPostContetnsByIds string `yesql:"get_post_contetns_by_ids"` + GetPostAttachmentBill *sqlx.Stmt `yesql:"get_post_attachment_bill"` + GetPostById *sqlx.Stmt `yesql:"get_post_by_id"` + GetPostContentById *sqlx.Stmt `yesql:"get_post_content_by_id"` + GetPostCount *sqlx.Stmt `yesql:"get_post_count"` + GetPosts *sqlx.Stmt `yesql:"get_posts"` + GetUserPostCollection *sqlx.Stmt `yesql:"get_user_post_collection"` + GetUserPostCollectionCount *sqlx.Stmt `yesql:"get_user_post_collection_count"` + GetUserPostCollections *sqlx.Stmt `yesql:"get_user_post_collections"` + GetUserPostStar *sqlx.Stmt `yesql:"get_user_post_star"` + GetUserPostStarCount *sqlx.Stmt `yesql:"get_user_post_star_count"` + GetUserPostStars *sqlx.Stmt `yesql:"get_user_post_stars"` } type TweetA struct { - yesql.Namespace `yesql:"tweet_a"` - UserInfo *sqlx.Stmt `yesql:"user_info"` + yesql.Namespace `yesql:"tweet_a"` + AttachmentByTweetId *sqlx.Stmt `yesql:"attachment_by_tweet_id"` + FavoriteByTweetId *sqlx.Stmt `yesql:"favorite_by_tweet_id"` + ReactionByTweetId *sqlx.Stmt `yesql:"reaction_by_tweet_id"` + TweetInfoById *sqlx.Stmt `yesql:"tweet_info_by_id"` + TweetItemById *sqlx.Stmt `yesql:"tweet_item_by_id"` + UserFavorites *sqlx.Stmt `yesql:"user_favorites"` + UserInfo *sqlx.Stmt `yesql:"user_info"` + UserReactions *sqlx.Stmt `yesql:"user_reactions"` + UserTweetsByAdmin *sqlx.Stmt `yesql:"user_tweets_by_admin"` + UserTweetsByFriend *sqlx.Stmt `yesql:"user_tweets_by_friend"` + UserTweetsByGuest *sqlx.Stmt `yesql:"user_tweets_by_guest"` + UserTweetsBySelf *sqlx.Stmt `yesql:"user_tweets_by_self"` } type TweetHelp struct { - yesql.Namespace `yesql:"tweet_help"` - UserInfo *sqlx.Stmt `yesql:"user_info"` + yesql.Namespace `yesql:"tweet_help"` + GetPostContentByIds string `yesql:"get_post_content_by_ids"` + GetUsersByIds string `yesql:"get_users_by_ids"` } type TweetHelpA struct { @@ -151,8 +224,19 @@ type TweetHelpA struct { } type TweetManage struct { - yesql.Namespace `yesql:"tweet_manage"` - UserInfo *sqlx.Stmt `yesql:"user_info"` + yesql.Namespace `yesql:"tweet_manage"` + AddAttachment *sqlx.Stmt `yesql:"add_attachment"` + AddPost *sqlx.Stmt `yesql:"add_post"` + AddPostCollection *sqlx.Stmt `yesql:"add_post_collection"` + AddPostContent *sqlx.Stmt `yesql:"add_post_content"` + AddPostStar *sqlx.Stmt `yesql:"add_post_star"` + DelPost *sqlx.Stmt `yesql:"del_post"` + DelPostCollection *sqlx.Stmt `yesql:"del_post_collection"` + DelPostStar *sqlx.Stmt `yesql:"del_post_star"` + LockPost *sqlx.Stmt `yesql:"lock_post"` + StickPost *sqlx.Stmt `yesql:"stick_post"` + UpdatePost *sqlx.Stmt `yesql:"update_post"` + VisiblePost *sqlx.Stmt `yesql:"visible_post"` } type TweetManageA struct { @@ -161,8 +245,14 @@ type TweetManageA struct { } type UserManage struct { - yesql.Namespace `yesql:"user_manage"` - UserInfo *sqlx.Stmt `yesql:"user_info"` + yesql.Namespace `yesql:"user_manage"` + GetUsersByIds string `yesql:"get_users_by_ids"` + AddUser *sqlx.Stmt `yesql:"add_user"` + GetUserById *sqlx.Stmt `yesql:"get_user_by_id"` + GetUserByPhone *sqlx.Stmt `yesql:"get_user_by_phone"` + GetUserByUsername *sqlx.Stmt `yesql:"get_user_by_username"` + GetUsersByKeyword *sqlx.Stmt `yesql:"get_users_by_keyword"` + UpdateUser *sqlx.Stmt `yesql:"update_user"` } type Wallet struct { @@ -220,7 +310,22 @@ func BuildContactManager(p yesql.PreparexBuilder, ctx ...context.Context) (obj * c = context.Background() } obj = &ContactManager{} - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_ContactManager))); err != nil { + if obj.AddFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AddFriend_ContactManager))); err != nil { + return + } + if obj.DelFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_DelFriend_ContactManager))); err != nil { + return + } + if obj.GetContacts, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetContacts_ContactManager))); err != nil { + return + } + if obj.IsFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_IsFriend_ContactManager))); err != nil { + return + } + if obj.RejectFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_RejectFriend_ContactManager))); err != nil { + return + } + if obj.RequestingFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_RequestingFriend_ContactManager))); err != nil { return } return @@ -405,8 +510,40 @@ func BuildTweet(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Tweet, er } else { c = context.Background() } - obj = &Tweet{} - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_Tweet))); err != nil { + obj = &Tweet{ + GetPostContetnsByIds: p.QueryHook(_GetPostContetnsByIds_Tweet), + } + if obj.GetPostAttachmentBill, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetPostAttachmentBill_Tweet))); err != nil { + return + } + if obj.GetPostById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetPostById_Tweet))); err != nil { + return + } + if obj.GetPostContentById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetPostContentById_Tweet))); err != nil { + return + } + if obj.GetPostCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetPostCount_Tweet))); err != nil { + return + } + if obj.GetPosts, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetPosts_Tweet))); err != nil { + return + } + if obj.GetUserPostCollection, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserPostCollection_Tweet))); err != nil { + return + } + if obj.GetUserPostCollectionCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserPostCollectionCount_Tweet))); err != nil { + return + } + if obj.GetUserPostCollections, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserPostCollections_Tweet))); err != nil { + return + } + if obj.GetUserPostStar, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserPostStar_Tweet))); err != nil { + return + } + if obj.GetUserPostStarCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserPostStarCount_Tweet))); err != nil { + return + } + if obj.GetUserPostStars, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserPostStars_Tweet))); err != nil { return } return @@ -420,9 +557,42 @@ func BuildTweetA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *TweetA, c = context.Background() } obj = &TweetA{} + if obj.AttachmentByTweetId, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AttachmentByTweetId_TweetA))); err != nil { + return + } + if obj.FavoriteByTweetId, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_FavoriteByTweetId_TweetA))); err != nil { + return + } + if obj.ReactionByTweetId, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ReactionByTweetId_TweetA))); err != nil { + return + } + if obj.TweetInfoById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetInfoById_TweetA))); err != nil { + return + } + if obj.TweetItemById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetItemById_TweetA))); err != nil { + return + } + if obj.UserFavorites, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserFavorites_TweetA))); err != nil { + return + } if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_TweetA))); err != nil { return } + if obj.UserReactions, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserReactions_TweetA))); err != nil { + return + } + if obj.UserTweetsByAdmin, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserTweetsByAdmin_TweetA))); err != nil { + return + } + if obj.UserTweetsByFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserTweetsByFriend_TweetA))); err != nil { + return + } + if obj.UserTweetsByGuest, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserTweetsByGuest_TweetA))); err != nil { + return + } + if obj.UserTweetsBySelf, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserTweetsBySelf_TweetA))); err != nil { + return + } return } @@ -433,9 +603,9 @@ func BuildTweetHelp(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Tweet } else { c = context.Background() } - obj = &TweetHelp{} - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_TweetHelp))); err != nil { - return + obj = &TweetHelp{ + GetPostContentByIds: p.QueryHook(_GetPostContentByIds_TweetHelp), + GetUsersByIds: p.QueryHook(_GetUsersByIds_TweetHelp), } return } @@ -462,7 +632,40 @@ func BuildTweetManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Twe c = context.Background() } obj = &TweetManage{} - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_TweetManage))); err != nil { + if obj.AddAttachment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AddAttachment_TweetManage))); err != nil { + return + } + if obj.AddPost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AddPost_TweetManage))); err != nil { + return + } + if obj.AddPostCollection, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AddPostCollection_TweetManage))); err != nil { + return + } + if obj.AddPostContent, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AddPostContent_TweetManage))); err != nil { + return + } + if obj.AddPostStar, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AddPostStar_TweetManage))); err != nil { + return + } + if obj.DelPost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_DelPost_TweetManage))); err != nil { + return + } + if obj.DelPostCollection, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_DelPostCollection_TweetManage))); err != nil { + return + } + if obj.DelPostStar, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_DelPostStar_TweetManage))); err != nil { + return + } + if obj.LockPost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_LockPost_TweetManage))); err != nil { + return + } + if obj.StickPost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_StickPost_TweetManage))); err != nil { + return + } + if obj.UpdatePost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UpdatePost_TweetManage))); err != nil { + return + } + if obj.VisiblePost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_VisiblePost_TweetManage))); err != nil { return } return @@ -489,8 +692,25 @@ func BuildUserManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *User } else { c = context.Background() } - obj = &UserManage{} - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_UserManage))); err != nil { + obj = &UserManage{ + GetUsersByIds: p.QueryHook(_GetUsersByIds_UserManage), + } + if obj.AddUser, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AddUser_UserManage))); err != nil { + return + } + if obj.GetUserById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserById_UserManage))); err != nil { + return + } + if obj.GetUserByPhone, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserByPhone_UserManage))); err != nil { + return + } + if obj.GetUserByUsername, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserByUsername_UserManage))); err != nil { + return + } + if obj.GetUsersByKeyword, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUsersByKeyword_UserManage))); err != nil { + return + } + if obj.UpdateUser, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UpdateUser_UserManage))); err != nil { return } return diff --git a/internal/dao/sakila/yesql/yesql.sql b/internal/dao/sakila/yesql/yesql.sql index ae78b357..559a6b03 100644 --- a/internal/dao/sakila/yesql/yesql.sql +++ b/internal/dao/sakila/yesql/yesql.sql @@ -26,7 +26,27 @@ SELECT * FROM @user WHERE username=? -- contact_manager sql dml -------------------------------------------------------------------------------- --- name: user_info@contact_manager +-- name: requesting_friend@contact_manager +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: add_friend@contact_manager +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: reject_friend@contact_manager +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: del_friend@contact_manager +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_contacts@contact_manager +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: is_friend@contact_manager -- prepare: stmt SELECT * FROM @user WHERE username=? @@ -114,7 +134,52 @@ SELECT * FROM @user WHERE username=? -- tweet sql dml -------------------------------------------------------------------------------- --- name: user_info@tweet +-- name: get_post_by_id@tweet +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_posts@tweet +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_post_count@tweet +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_user_post_star@tweet +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_user_post_stars@tweet +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_user_post_star_count@tweet +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_user_post_collection@tweet +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_user_post_collections@tweet +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_user_post_collection_count@tweet +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_post_attachment_bill@tweet +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_post_contetns_by_ids@tweet +-- prepare: raw +-- clause: in +SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?); + +-- name: get_post_content_by_id@tweet -- prepare: stmt SELECT * FROM @user WHERE username=? @@ -122,7 +187,51 @@ SELECT * FROM @user WHERE username=? -- tweet_manage sql dml -------------------------------------------------------------------------------- --- name: user_info@tweet_manage +-- name: add_post@tweet_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: del_post@tweet_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: lock_post@tweet_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: stick_post@tweet_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: visible_post@tweet_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: update_post@tweet_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: add_post_star@tweet_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: del_post_star@tweet_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: add_post_collection@tweet_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: del_post_collection@tweet_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: add_post_content@tweet_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: add_attachment@tweet_manage -- prepare: stmt SELECT * FROM @user WHERE username=? @@ -130,8 +239,14 @@ SELECT * FROM @user WHERE username=? -- tweet_help sql dml -------------------------------------------------------------------------------- --- name: user_info@tweet_help --- prepare: stmt +-- name: get_post_content_by_ids@tweet_help +-- prepare: raw +-- clause: in +SELECT * FROM @user WHERE username=? + +-- name: get_users_by_ids@tweet_help +-- prepare: raw +-- clause: in SELECT * FROM @user WHERE username=? -------------------------------------------------------------------------------- @@ -142,6 +257,50 @@ SELECT * FROM @user WHERE username=? -- prepare: stmt SELECT * FROM @user WHERE username=? +-- name: tweet_info_by_id@tweet_a +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: tweet_item_by_id@tweet_a +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: user_tweets_by_admin@tweet_a +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: user_tweets_by_self@tweet_a +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: user_tweets_by_friend@tweet_a +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: user_tweets_by_guest@tweet_a +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: reaction_by_tweet_id@tweet_a +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: user_reactions@tweet_a +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: favorite_by_tweet_id@tweet_a +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: user_favorites@tweet_a +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: attachment_by_tweet_id@tweet_a +-- prepare: stmt +SELECT * FROM @user WHERE username=? + -------------------------------------------------------------------------------- -- tweet_manage_a sql dml -------------------------------------------------------------------------------- @@ -221,7 +380,32 @@ UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?); -- user_manage sql dml -------------------------------------------------------------------------------- --- name: user_info@user_manage +-- name: get_user_by_id@user_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_user_by_username@user_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_user_by_phone@user_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_users_by_ids@user_manage +-- prepare: raw +-- clause: in +SELECT * FROM @user WHERE username=? + +-- name: get_users_by_keyword@user_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: add_user@user_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: update_user@user_manage -- prepare: stmt SELECT * FROM @user WHERE username=? diff --git a/internal/model/web/priv.go b/internal/model/web/priv.go index b11c7bfb..c35c4617 100644 --- a/internal/model/web/priv.go +++ b/internal/model/web/priv.go @@ -12,7 +12,6 @@ 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" @@ -144,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"` } diff --git a/internal/servants/web/priv.go b/internal/servants/web/priv.go index ee5c38d1..e4e04a20 100644 --- a/internal/servants/web/priv.go +++ b/internal/servants/web/priv.go @@ -29,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, @@ -120,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 From fc3659b4a23be8b030f7f9f4a87999ac52cf0056 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Thu, 13 Jul 2023 22:41:27 +0800 Subject: [PATCH 04/19] sqlx: use yesql => v1.3.0 --- go.mod | 2 +- go.sum | 4 ++-- internal/dao/sakila/sqlx.go | 9 +++++++++ internal/dao/sakila/tweets.go | 2 +- internal/dao/sakila/yesql/cc/yesql.go | 10 ++-------- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 8ed19b5e..cf285972 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/afocus/captcha v0.0.0-20191010092841-4bd1f21c8868 github.com/alimy/cfg v0.3.0 github.com/alimy/mir/v4 v4.0.0-rc.1 - github.com/alimy/yesql v1.2.0 + github.com/alimy/yesql v1.3.0 github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible github.com/allegro/bigcache/v3 v3.1.0 github.com/bytedance/sonic v1.9.2 diff --git a/go.sum b/go.sum index 329a47e5..5f1eba08 100644 --- a/go.sum +++ b/go.sum @@ -127,8 +127,8 @@ github.com/alimy/cfg v0.3.0 h1:9xgA0QWVCPSq9fFNRcYahVCAX22IL9ts2wrTQPfAStY= github.com/alimy/cfg v0.3.0/go.mod h1:rOxbasTH2srl6StAjNF5Vyi8bfrdkl3fLGmOYtSw81c= github.com/alimy/mir/v4 v4.0.0-rc.1 h1:x9rKbD6I4INqwvgmSI4Vbswff66ANDnPmCySMLzEV4w= github.com/alimy/mir/v4 v4.0.0-rc.1/go.mod h1:d58dBvw2KImcVbAUANrciEV/of0arMNsI9c/5UNCMMc= -github.com/alimy/yesql v1.2.0 h1:yWa4kYk/7E2iYtS/4xvjlKQvGsfRhAHqr58s5Sig33A= -github.com/alimy/yesql v1.2.0/go.mod h1:Y0FdRIwIbJyTv56wSX+MpaIHiAW1PyKTDYO6K/er4JY= +github.com/alimy/yesql v1.3.0 h1:4/p097ZvFMlIzm1CWYy1q+eBQH0DcqlB+/UxKTHsj30= +github.com/alimy/yesql v1.3.0/go.mod h1:Y0FdRIwIbJyTv56wSX+MpaIHiAW1PyKTDYO6K/er4JY= github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible h1:KpbJFXwhVeuxNtBJ74MCGbIoaBok2uZvkD7QXp2+Wis= github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= github.com/allegro/bigcache/v3 v3.1.0 h1:H2Vp8VOvxcrB91o86fUSVJFqeuz8kpyyB02eH3bSzwk= diff --git a/internal/dao/sakila/sqlx.go b/internal/dao/sakila/sqlx.go index 4e6b440c..32af8c1a 100644 --- a/internal/dao/sakila/sqlx.go +++ b/internal/dao/sakila/sqlx.go @@ -151,6 +151,15 @@ func mustBuild[T any](db *sqlx.DB, fn func(yesql.PreparexBuilder, ...context.Con return obj } +func mustBuildFn[T any](db *sqlx.DB, fn func(yesql.PreparexBuilder) (T, error)) T { + p := yesql.NewPreparexBuilder(db, t) + obj, err := fn(p) + if err != nil { + logrus.Fatalf("build object failure: %s", err) + } + return obj +} + func initSqlxDB() { _db = conf.MustSqlxDB() _tablePrefix = conf.DatabaseSetting.TablePrefix diff --git a/internal/dao/sakila/tweets.go b/internal/dao/sakila/tweets.go index b2db0c76..78cb37f4 100644 --- a/internal/dao/sakila/tweets.go +++ b/internal/dao/sakila/tweets.go @@ -467,7 +467,7 @@ func newTweetManageService(db *sqlx.DB, cacheIndex core.CacheIndexService) core. func newTweetHelpService(db *sqlx.DB) core.TweetHelpService { return &tweetHelpSrv{ sqlxSrv: newSqlxSrv(db), - q: mustBuild(db, cc.BuildTweetHelp), + q: mustBuildFn(db, cc.BuildTweetHelp), } } diff --git a/internal/dao/sakila/yesql/cc/yesql.go b/internal/dao/sakila/yesql/cc/yesql.go index 78351e25..f5544e76 100644 --- a/internal/dao/sakila/yesql/cc/yesql.go +++ b/internal/dao/sakila/yesql/cc/yesql.go @@ -1,6 +1,6 @@ // Code generated by Yesql. DO NOT EDIT. // versions: -// - Yesql v1.2.0 +// - Yesql v1.3.0 package cc @@ -596,13 +596,7 @@ func BuildTweetA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *TweetA, return } -func BuildTweetHelp(p yesql.PreparexBuilder, ctx ...context.Context) (obj *TweetHelp, err error) { - var c context.Context - if len(ctx) > 0 && ctx[0] != nil { - c = ctx[0] - } else { - c = context.Background() - } +func BuildTweetHelp(p yesql.PreparexBuilder) (obj *TweetHelp, err error) { obj = &TweetHelp{ GetPostContentByIds: p.QueryHook(_GetPostContentByIds_TweetHelp), GetUsersByIds: p.QueryHook(_GetUsersByIds_TweetHelp), From 7b16fbe5422779840d31168012f5a2f4a9adb0f7 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Fri, 14 Jul 2023 11:34:28 +0800 Subject: [PATCH 05/19] sqlx: add some logic implement 6% --- internal/dao/sakila/sqlx.go | 33 ++- internal/dao/sakila/topics.go | 10 +- internal/dao/sakila/tweets.go | 6 +- internal/dao/sakila/user.go | 2 +- internal/dao/sakila/yesql/cc/yesql.go | 326 ++++++++++++++++++-------- internal/dao/sakila/yesql/yesql.sql | 126 +++++++++- 6 files changed, 391 insertions(+), 112 deletions(-) diff --git a/internal/dao/sakila/sqlx.go b/internal/dao/sakila/sqlx.go index 32af8c1a..2e5819ea 100644 --- a/internal/dao/sakila/sqlx.go +++ b/internal/dao/sakila/sqlx.go @@ -57,7 +57,32 @@ func (s *sqlxSrv) in(query string, args ...any) (string, []any, error) { return s.db.Rebind(q), params, nil } -func (s *sqlxSrv) inExec(execer sqlx.Execer, query string, args ...any) (sql.Result, error) { +func (s *sqlxSrv) inExec(query string, args ...any) (sql.Result, error) { + q, params, err := sqlx.In(query, args...) + if err != nil { + return nil, err + } + return s.db.Exec(s.db.Rebind(q), params...) +} + +func (s *sqlxSrv) inSelect(dest any, query string, args ...any) error { + q, params, err := sqlx.In(query, args...) + if err != nil { + return err + } + return sqlx.Select(s.db, dest, s.db.Rebind(q), params...) +} + +func (s *sqlxSrv) inGet(dest any, query string, args ...any) error { + q, params, err := sqlx.In(query, args...) + if err != nil { + return err + } + return sqlx.Get(s.db, dest, s.db.Rebind(q), params...) +} + +// inExecx execute for in clause with Transcation +func (s *sqlxSrv) inExecx(execer sqlx.Execer, query string, args ...any) (sql.Result, error) { q, params, err := sqlx.In(query, args...) if err != nil { return nil, err @@ -65,7 +90,8 @@ func (s *sqlxSrv) inExec(execer sqlx.Execer, query string, args ...any) (sql.Res return execer.Exec(s.db.Rebind(q), params...) } -func (s *sqlxSrv) inSelect(queryer sqlx.Queryer, dest any, query string, args ...any) error { +// inSelectx select for in clause with Transcation +func (s *sqlxSrv) inSelectx(queryer sqlx.Queryer, dest any, query string, args ...any) error { q, params, err := sqlx.In(query, args...) if err != nil { return err @@ -73,7 +99,8 @@ func (s *sqlxSrv) inSelect(queryer sqlx.Queryer, dest any, query string, args .. return sqlx.Select(queryer, dest, s.db.Rebind(q), params...) } -func (s *sqlxSrv) inGet(queryer sqlx.Queryer, dest any, query string, args ...any) error { +// inGetx get for in clause with Transcation +func (s *sqlxSrv) inGetx(queryer sqlx.Queryer, dest any, query string, args ...any) error { q, params, err := sqlx.In(query, args...) if err != nil { return err diff --git a/internal/dao/sakila/topics.go b/internal/dao/sakila/topics.go index 669a87d7..883ba586 100644 --- a/internal/dao/sakila/topics.go +++ b/internal/dao/sakila/topics.go @@ -31,7 +31,7 @@ func (s *topicSrvA) UpsertTags(userId int64, tags []string) (res cs.TagInfoList, } xerr = s.with(func(tx *sqlx.Tx) error { var upTags cs.TagInfoList - if err := s.inSelect(tx, &upTags, s.q.TagsForIncr, tags); err != nil { + if err := s.inSelectx(tx, &upTags, s.q.TagsForIncr, tags); err != nil { return err } now := time.Now().Unix() @@ -51,7 +51,7 @@ func (s *topicSrvA) UpsertTags(userId int64, tags []string) (res cs.TagInfoList, } } } - if _, err := s.inExec(tx, s.q.IncrTagsById, now, ids); err != nil { + if _, err := s.inExecx(tx, s.q.IncrTagsById, now, ids); err != nil { return err } res = append(res, upTags...) @@ -73,7 +73,7 @@ func (s *topicSrvA) UpsertTags(userId int64, tags []string) (res cs.TagInfoList, ids = append(ids, id) } var newTags cs.TagInfoList - if err := s.inSelect(tx, &newTags, s.q.TagsByIdB, ids); err != nil { + if err := s.inSelectx(tx, &newTags, s.q.TagsByIdB, ids); err != nil { return err } res = append(res, newTags...) @@ -85,11 +85,11 @@ func (s *topicSrvA) UpsertTags(userId int64, tags []string) (res cs.TagInfoList, func (s *topicSrvA) DecrTagsById(ids []int64) error { return s.with(func(tx *sqlx.Tx) error { var ids []int64 - err := s.inSelect(tx, &ids, s.q.TagsByIdA, ids) + err := s.inSelectx(tx, &ids, s.q.TagsByIdA, ids) if err != nil { return err } - _, err = s.inExec(tx, s.q.DecrTagsById, time.Now().Unix(), ids) + _, err = s.inExecx(tx, s.q.DecrTagsById, time.Now().Unix(), ids) return err }) } diff --git a/internal/dao/sakila/tweets.go b/internal/dao/sakila/tweets.go index 78cb37f4..5c494dfa 100644 --- a/internal/dao/sakila/tweets.go +++ b/internal/dao/sakila/tweets.go @@ -125,13 +125,13 @@ func (s *tweetHelpSrv) RevampPosts(posts []*ms.PostFormated) ([]*ms.PostFormated func (s *tweetHelpSrv) getPostContentsByIDs(ids []int64) ([]*dbr.PostContentFormated, error) { res := []*dbr.PostContentFormated{} - err := s.inSelect(s.db, &res, s.q.GetPostContentByIds, ids) + err := s.inSelect(&res, s.q.GetPostContentByIds, ids) return res, err } func (s *tweetHelpSrv) getUsersByIDs(ids []int64) ([]*dbr.UserFormated, error) { res := []*dbr.UserFormated{} - err := s.inSelect(s.db, &res, s.q.GetUsersByIds, ids) + err := s.inSelect(&res, s.q.GetUsersByIds, ids) return res, err } @@ -306,7 +306,7 @@ func (s *tweetSrv) GetPostAttatchmentBill(postID, userID int64) (*ms.PostAttachm func (s *tweetSrv) GetPostContentsByIDs(ids []int64) ([]*ms.PostContent, error) { res := []*ms.PostContent{} - err := s.inSelect(s.db, &res, s.q.GetPostContetnsByIds, ids) + err := s.inSelect(&res, s.q.GetPostContetnsByIds, ids) return res, err } diff --git a/internal/dao/sakila/user.go b/internal/dao/sakila/user.go index c877f475..6910df62 100644 --- a/internal/dao/sakila/user.go +++ b/internal/dao/sakila/user.go @@ -41,7 +41,7 @@ func (s *userManageSrv) GetUserByPhone(phone string) (*ms.User, error) { func (s *userManageSrv) GetUsersByIDs(ids []int64) ([]*ms.User, error) { res := []*ms.User{} - err := s.inSelect(s.db, &res, s.q.GetUsersByIds, ids) + err := s.inSelect(&res, s.q.GetUsersByIds, ids) return res, err } diff --git a/internal/dao/sakila/yesql/cc/yesql.go b/internal/dao/sakila/yesql/cc/yesql.go index f5544e76..adc6081f 100644 --- a/internal/dao/sakila/yesql/cc/yesql.go +++ b/internal/dao/sakila/yesql/cc/yesql.go @@ -12,98 +12,142 @@ import ( ) const ( - _UserInfo_AuthorizationManage = `SELECT * FROM @user WHERE username=?` - _UserInfo_CommentManage = `SELECT * FROM @user WHERE username=?` - _UserInfo_Comment = `SELECT * FROM @user WHERE username=?` - _AddFriend_ContactManager = `SELECT * FROM @user WHERE username=?` - _DelFriend_ContactManager = `SELECT * FROM @user WHERE username=?` - _GetContacts_ContactManager = `SELECT * FROM @user WHERE username=?` - _IsFriend_ContactManager = `SELECT * FROM @user WHERE username=?` - _RejectFriend_ContactManager = `SELECT * FROM @user WHERE username=?` - _RequestingFriend_ContactManager = `SELECT * FROM @user WHERE username=?` - _UserInfo_FollowIndexA = `SELECT * FROM @user WHERE username=?` - _UserInfo_FollowIndex = `SELECT * FROM @user WHERE username=?` - _UserInfo_FriendIndexA = `SELECT * FROM @user WHERE username=?` - _UserInfo_FriendIndex = `SELECT * FROM @user WHERE username=?` - _UserInfo_LightIndexA = `SELECT * FROM @user WHERE username=?` - _UserInfo_LightIndex = `SELECT * FROM @user WHERE username=?` - _UserInfo_Message = `SELECT * FROM @user WHERE username=?` - _UserInfo_Security = `SELECT * FROM @user WHERE username=?` - _UserInfo_SimpleIndexA = `SELECT * FROM @user WHERE username=?` - _UserInfo_SimpleIndex = `SELECT * FROM @user WHERE username=?` - _DecrTagsById_TopicA = `UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?)` - _HotTags_TopicA = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.quote_num DESC LIMIT ? OFFSET ?` - _IncrTagsById_TopicA = `UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?)` - _InsertTag_TopicA = `INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1)` - _NewestTags_TopicA = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.id DESC LIMIT ? OFFSET ?` - _TagsByIdA_TopicA = `SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0` - _TagsByIdB_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?)` - _TagsByKeywordA_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6` - _TagsByKeywordB_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6` - _TagsForIncr_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` - _AttachmentByTweetId_TweetA = `SELECT * FROM @user WHERE username=?` - _FavoriteByTweetId_TweetA = `SELECT * FROM @user WHERE username=?` - _ReactionByTweetId_TweetA = `SELECT * FROM @user WHERE username=?` - _TweetInfoById_TweetA = `SELECT * FROM @user WHERE username=?` - _TweetItemById_TweetA = `SELECT * FROM @user WHERE username=?` - _UserFavorites_TweetA = `SELECT * FROM @user WHERE username=?` - _UserInfo_TweetA = `SELECT * FROM @user WHERE username=?` - _UserReactions_TweetA = `SELECT * FROM @user WHERE username=?` - _UserTweetsByAdmin_TweetA = `SELECT * FROM @user WHERE username=?` - _UserTweetsByFriend_TweetA = `SELECT * FROM @user WHERE username=?` - _UserTweetsByGuest_TweetA = `SELECT * FROM @user WHERE username=?` - _UserTweetsBySelf_TweetA = `SELECT * FROM @user WHERE username=?` - _GetPostAttachmentBill_Tweet = `SELECT * FROM @user WHERE username=?` - _GetPostById_Tweet = `SELECT * FROM @user WHERE username=?` - _GetPostContentById_Tweet = `SELECT * FROM @user WHERE username=?` - _GetPostContetnsByIds_Tweet = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` - _GetPostCount_Tweet = `SELECT * FROM @user WHERE username=?` - _GetPosts_Tweet = `SELECT * FROM @user WHERE username=?` - _GetUserPostCollection_Tweet = `SELECT * FROM @user WHERE username=?` - _GetUserPostCollectionCount_Tweet = `SELECT * FROM @user WHERE username=?` - _GetUserPostCollections_Tweet = `SELECT * FROM @user WHERE username=?` - _GetUserPostStar_Tweet = `SELECT * FROM @user WHERE username=?` - _GetUserPostStarCount_Tweet = `SELECT * FROM @user WHERE username=?` - _GetUserPostStars_Tweet = `SELECT * FROM @user WHERE username=?` - _UserInfo_TweetHelpA = `SELECT * FROM @user WHERE username=?` - _GetPostContentByIds_TweetHelp = `SELECT * FROM @user WHERE username=?` - _GetUsersByIds_TweetHelp = `SELECT * FROM @user WHERE username=?` - _UserInfo_TweetManageA = `SELECT * FROM @user WHERE username=?` - _AddAttachment_TweetManage = `SELECT * FROM @user WHERE username=?` - _AddPost_TweetManage = `SELECT * FROM @user WHERE username=?` - _AddPostCollection_TweetManage = `SELECT * FROM @user WHERE username=?` - _AddPostContent_TweetManage = `SELECT * FROM @user WHERE username=?` - _AddPostStar_TweetManage = `SELECT * FROM @user WHERE username=?` - _DelPost_TweetManage = `SELECT * FROM @user WHERE username=?` - _DelPostCollection_TweetManage = `SELECT * FROM @user WHERE username=?` - _DelPostStar_TweetManage = `SELECT * FROM @user WHERE username=?` - _LockPost_TweetManage = `SELECT * FROM @user WHERE username=?` - _StickPost_TweetManage = `SELECT * FROM @user WHERE username=?` - _UpdatePost_TweetManage = `SELECT * FROM @user WHERE username=?` - _VisiblePost_TweetManage = `SELECT * FROM @user WHERE username=?` - _AddUser_UserManage = `SELECT * FROM @user WHERE username=?` - _GetUserById_UserManage = `SELECT * FROM @user WHERE username=?` - _GetUserByPhone_UserManage = `SELECT * FROM @user WHERE username=?` - _GetUserByUsername_UserManage = `SELECT * FROM @user WHERE username=?` - _GetUsersByIds_UserManage = `SELECT * FROM @user WHERE username=?` - _GetUsersByKeyword_UserManage = `SELECT * FROM @user WHERE username=?` - _UpdateUser_UserManage = `SELECT * FROM @user WHERE username=?` - _UserInfo_Wallet = `SELECT * FROM @user WHERE username=?` + _BeFriendFilter_AuthorizationManage = `SELECT * FROM @user WHERE username=?` + _BeFriendIds_AuthorizationManage = `SELECT * FROM @user WHERE username=?` + _MyFriendSet_AuthorizationManage = `SELECT * FROM @user WHERE username=?` + _GetCommentById_Comment = `SELECT * FROM @user WHERE username=?` + _GetCommentContentsByIds_Comment = `SELECT * FROM @user WHERE username=?` + _GetCommentCount_Comment = `SELECT * FROM @user WHERE username=?` + _GetCommentReplayById_Comment = `SELECT * FROM @user WHERE username=?` + _GetCommentThumbsMap_Comment = `SELECT * FROM @user WHERE username=?` + _GetComments_Comment = `SELECT * FROM @user WHERE username=?` + _GetCommmentRepliesById_Comment = `SELECT * FROM @user WHERE username=?` + _CreateComment_CommentManage = `SELECT * FROM @user WHERE username=?` + _CreateCommentContent_CommentManage = `SELECT * FROM @user WHERE username=?` + _CreateCommentReply_CommentManage = `SELECT * FROM @user WHERE username=?` + _DeleteComment_CommentManage = `SELECT * FROM @user WHERE username=?` + _DeleteCommentReply_CommentManage = `SELECT * FROM @user WHERE username=?` + _ThumbsDownComment_CommentManage = `SELECT * FROM @user WHERE username=?` + _ThumbsDownReply_CommentManage = `SELECT * FROM @user WHERE username=?` + _ThumbsUpComment_CommentManage = `SELECT * FROM @user WHERE username=?` + _ThumbsUpReply_CommentManage = `SELECT * FROM @user WHERE username=?` + _AddFriend_ContactManager = `SELECT * FROM @user WHERE username=?` + _DelFriend_ContactManager = `SELECT * FROM @user WHERE username=?` + _GetContacts_ContactManager = `SELECT * FROM @user WHERE username=?` + _IsFriend_ContactManager = `SELECT * FROM @user WHERE username=?` + _RejectFriend_ContactManager = `SELECT * FROM @user WHERE username=?` + _RequestingFriend_ContactManager = `SELECT * FROM @user WHERE username=?` + _UserInfo_FollowIndexA = `SELECT * FROM @user WHERE username=?` + _UserInfo_FollowIndex = `SELECT * FROM @user WHERE username=?` + _UserInfo_FriendIndexA = `SELECT * FROM @user WHERE username=?` + _UserInfo_FriendIndex = `SELECT * FROM @user WHERE username=?` + _UserInfo_LightIndexA = `SELECT * FROM @user WHERE username=?` + _UserInfo_LightIndex = `SELECT * FROM @user WHERE username=?` + _CreateMessage_Message = `SELECT * FROM @user WHERE username=?` + _GetMessageById_Message = `SELECT * FROM @user WHERE username=?` + _GetMessageCount_Message = `SELECT * FROM @user WHERE username=?` + _GetMessages_Message = `SELECT * FROM @user WHERE username=?` + _GetUnreadCount_Message = `SELECT * FROM @user WHERE username=?` + _ReadMessage_Message = `SELECT * FROM @user WHERE username=?` + _GetLatestPhoneCaptcha_Security = `SELECT * FROM @user WHERE username=?` + _SendPhoneCaptcha_Security = `SELECT * FROM @user WHERE username=?` + _UsePhoneCaptcha_Security = `SELECT * FROM @user WHERE username=?` + _UserInfo_SimpleIndexA = `SELECT * FROM @user WHERE username=?` + _UserInfo_SimpleIndex = `SELECT * FROM @user WHERE username=?` + _DecrTagsById_TopicA = `UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?)` + _HotTags_TopicA = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.quote_num DESC LIMIT ? OFFSET ?` + _IncrTagsById_TopicA = `UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?)` + _InsertTag_TopicA = `INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1)` + _NewestTags_TopicA = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.id DESC LIMIT ? OFFSET ?` + _TagsByIdA_TopicA = `SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0` + _TagsByIdB_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?)` + _TagsByKeywordA_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6` + _TagsByKeywordB_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6` + _TagsForIncr_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` + _AttachmentByTweetId_TweetA = `SELECT * FROM @user WHERE username=?` + _FavoriteByTweetId_TweetA = `SELECT * FROM @user WHERE username=?` + _ReactionByTweetId_TweetA = `SELECT * FROM @user WHERE username=?` + _TweetInfoById_TweetA = `SELECT * FROM @user WHERE username=?` + _TweetItemById_TweetA = `SELECT * FROM @user WHERE username=?` + _UserFavorites_TweetA = `SELECT * FROM @user WHERE username=?` + _UserInfo_TweetA = `SELECT * FROM @user WHERE username=?` + _UserReactions_TweetA = `SELECT * FROM @user WHERE username=?` + _UserTweetsByAdmin_TweetA = `SELECT * FROM @user WHERE username=?` + _UserTweetsByFriend_TweetA = `SELECT * FROM @user WHERE username=?` + _UserTweetsByGuest_TweetA = `SELECT * FROM @user WHERE username=?` + _UserTweetsBySelf_TweetA = `SELECT * FROM @user WHERE username=?` + _GetPostAttachmentBill_Tweet = `SELECT * FROM @user WHERE username=?` + _GetPostById_Tweet = `SELECT * FROM @user WHERE username=?` + _GetPostContentById_Tweet = `SELECT * FROM @user WHERE username=?` + _GetPostContetnsByIds_Tweet = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` + _GetPostCount_Tweet = `SELECT * FROM @user WHERE username=?` + _GetPosts_Tweet = `SELECT * FROM @user WHERE username=?` + _GetUserPostCollection_Tweet = `SELECT * FROM @user WHERE username=?` + _GetUserPostCollectionCount_Tweet = `SELECT * FROM @user WHERE username=?` + _GetUserPostCollections_Tweet = `SELECT * FROM @user WHERE username=?` + _GetUserPostStar_Tweet = `SELECT * FROM @user WHERE username=?` + _GetUserPostStarCount_Tweet = `SELECT * FROM @user WHERE username=?` + _GetUserPostStars_Tweet = `SELECT * FROM @user WHERE username=?` + _UserInfo_TweetHelpA = `SELECT * FROM @user WHERE username=?` + _GetPostContentByIds_TweetHelp = `SELECT * FROM @user WHERE username=?` + _GetUsersByIds_TweetHelp = `SELECT * FROM @user WHERE username=?` + _UserInfo_TweetManageA = `SELECT * FROM @user WHERE username=?` + _AddAttachment_TweetManage = `SELECT * FROM @user WHERE username=?` + _AddPost_TweetManage = `SELECT * FROM @user WHERE username=?` + _AddPostCollection_TweetManage = `SELECT * FROM @user WHERE username=?` + _AddPostContent_TweetManage = `SELECT * FROM @user WHERE username=?` + _AddPostStar_TweetManage = `SELECT * FROM @user WHERE username=?` + _DelPost_TweetManage = `SELECT * FROM @user WHERE username=?` + _DelPostCollection_TweetManage = `SELECT * FROM @user WHERE username=?` + _DelPostStar_TweetManage = `SELECT * FROM @user WHERE username=?` + _LockPost_TweetManage = `SELECT * FROM @user WHERE username=?` + _StickPost_TweetManage = `SELECT * FROM @user WHERE username=?` + _UpdatePost_TweetManage = `SELECT * FROM @user WHERE username=?` + _VisiblePost_TweetManage = `SELECT * FROM @user WHERE username=?` + _AddUser_UserManage = `SELECT * FROM @user WHERE username=?` + _GetUserById_UserManage = `SELECT * FROM @user WHERE username=?` + _GetUserByPhone_UserManage = `SELECT * FROM @user WHERE username=?` + _GetUserByUsername_UserManage = `SELECT * FROM @user WHERE username=?` + _GetUsersByIds_UserManage = `SELECT * FROM @user WHERE username=?` + _GetUsersByKeyword_UserManage = `SELECT * FROM @user WHERE username=?` + _UpdateUser_UserManage = `SELECT * FROM @user WHERE username=?` + _CreateRecharge_Wallet = `SELECT * FROM @user WHERE username=?` + _GetRechargeById_Wallet = `SELECT * FROM @user WHERE username=?` + _GetUserWalletBillCount_Wallet = `SELECT * FROM @user WHERE username=?` + _GetUserWalletBills_Wallet = `SELECT * FROM @user WHERE username=?` + _HandlePostAttachementBought_Wallet = `SELECT * FROM @user WHERE username=?` + _HandleRechargeSuccess_Wallet = `SELECT * FROM @user WHERE username=?` ) type AuthorizationManage struct { yesql.Namespace `yesql:"authorization_manage"` - UserInfo *sqlx.Stmt `yesql:"user_info"` + BeFriendFilter *sqlx.Stmt `yesql:"be_friend_filter"` + BeFriendIds *sqlx.Stmt `yesql:"be_friend_ids"` + MyFriendSet *sqlx.Stmt `yesql:"my_friend_set"` } type Comment struct { - yesql.Namespace `yesql:"comment"` - UserInfo *sqlx.Stmt `yesql:"user_info"` + yesql.Namespace `yesql:"comment"` + GetCommentById *sqlx.Stmt `yesql:"get_comment_by_id"` + GetCommentContentsByIds *sqlx.Stmt `yesql:"get_comment_contents_by_ids"` + GetCommentCount *sqlx.Stmt `yesql:"get_comment_count"` + GetCommentReplayById *sqlx.Stmt `yesql:"get_comment_replay_by_id"` + GetCommentThumbsMap *sqlx.Stmt `yesql:"get_comment_thumbs_map"` + GetComments *sqlx.Stmt `yesql:"get_comments"` + GetCommmentRepliesById *sqlx.Stmt `yesql:"get_commment_replies_by_id"` } type CommentManage struct { - yesql.Namespace `yesql:"comment_manage"` - UserInfo *sqlx.Stmt `yesql:"user_info"` + yesql.Namespace `yesql:"comment_manage"` + CreateComment *sqlx.Stmt `yesql:"create_comment"` + CreateCommentContent *sqlx.Stmt `yesql:"create_comment_content"` + CreateCommentReply *sqlx.Stmt `yesql:"create_comment_reply"` + DeleteComment *sqlx.Stmt `yesql:"delete_comment"` + DeleteCommentReply *sqlx.Stmt `yesql:"delete_comment_reply"` + ThumbsDownComment *sqlx.Stmt `yesql:"thumbs_down_comment"` + ThumbsDownReply *sqlx.Stmt `yesql:"thumbs_down_reply"` + ThumbsUpComment *sqlx.Stmt `yesql:"thumbs_up_comment"` + ThumbsUpReply *sqlx.Stmt `yesql:"thumbs_up_reply"` } type ContactManager struct { @@ -148,12 +192,19 @@ type LightIndexA struct { type Message struct { yesql.Namespace `yesql:"message"` - UserInfo *sqlx.Stmt `yesql:"user_info"` + CreateMessage *sqlx.Stmt `yesql:"create_message"` + GetMessageById *sqlx.Stmt `yesql:"get_message_by_id"` + GetMessageCount *sqlx.Stmt `yesql:"get_message_count"` + GetMessages *sqlx.Stmt `yesql:"get_messages"` + GetUnreadCount *sqlx.Stmt `yesql:"get_unread_count"` + ReadMessage *sqlx.Stmt `yesql:"read_message"` } type Security struct { - yesql.Namespace `yesql:"security"` - UserInfo *sqlx.Stmt `yesql:"user_info"` + yesql.Namespace `yesql:"security"` + GetLatestPhoneCaptcha *sqlx.Stmt `yesql:"get_latest_phone_captcha"` + SendPhoneCaptcha *sqlx.Stmt `yesql:"send_phone_captcha"` + UsePhoneCaptcha *sqlx.Stmt `yesql:"use_phone_captcha"` } type SimpleIndex struct { @@ -256,8 +307,13 @@ type UserManage struct { } type Wallet struct { - yesql.Namespace `yesql:"wallet"` - UserInfo *sqlx.Stmt `yesql:"user_info"` + yesql.Namespace `yesql:"wallet"` + CreateRecharge *sqlx.Stmt `yesql:"create_recharge"` + GetRechargeById *sqlx.Stmt `yesql:"get_recharge_by_id"` + GetUserWalletBillCount *sqlx.Stmt `yesql:"get_user_wallet_bill_count"` + GetUserWalletBills *sqlx.Stmt `yesql:"get_user_wallet_bills"` + HandlePostAttachementBought *sqlx.Stmt `yesql:"handle_post_attachement_bought"` + HandleRechargeSuccess *sqlx.Stmt `yesql:"handle_recharge_success"` } func BuildAuthorizationManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *AuthorizationManage, err error) { @@ -268,7 +324,13 @@ func BuildAuthorizationManage(p yesql.PreparexBuilder, ctx ...context.Context) ( c = context.Background() } obj = &AuthorizationManage{} - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_AuthorizationManage))); err != nil { + if obj.BeFriendFilter, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_BeFriendFilter_AuthorizationManage))); err != nil { + return + } + if obj.BeFriendIds, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_BeFriendIds_AuthorizationManage))); err != nil { + return + } + if obj.MyFriendSet, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_MyFriendSet_AuthorizationManage))); err != nil { return } return @@ -282,7 +344,25 @@ func BuildComment(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Comment c = context.Background() } obj = &Comment{} - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_Comment))); err != nil { + if obj.GetCommentById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetCommentById_Comment))); err != nil { + return + } + if obj.GetCommentContentsByIds, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetCommentContentsByIds_Comment))); err != nil { + return + } + if obj.GetCommentCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetCommentCount_Comment))); err != nil { + return + } + if obj.GetCommentReplayById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetCommentReplayById_Comment))); err != nil { + return + } + if obj.GetCommentThumbsMap, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetCommentThumbsMap_Comment))); err != nil { + return + } + if obj.GetComments, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetComments_Comment))); err != nil { + return + } + if obj.GetCommmentRepliesById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetCommmentRepliesById_Comment))); err != nil { return } return @@ -296,7 +376,31 @@ func BuildCommentManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *C c = context.Background() } obj = &CommentManage{} - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_CommentManage))); err != nil { + if obj.CreateComment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CreateComment_CommentManage))); err != nil { + return + } + if obj.CreateCommentContent, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CreateCommentContent_CommentManage))); err != nil { + return + } + if obj.CreateCommentReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CreateCommentReply_CommentManage))); err != nil { + return + } + if obj.DeleteComment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_DeleteComment_CommentManage))); err != nil { + return + } + if obj.DeleteCommentReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_DeleteCommentReply_CommentManage))); err != nil { + return + } + if obj.ThumbsDownComment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ThumbsDownComment_CommentManage))); err != nil { + return + } + if obj.ThumbsDownReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ThumbsDownReply_CommentManage))); err != nil { + return + } + if obj.ThumbsUpComment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ThumbsUpComment_CommentManage))); err != nil { + return + } + if obj.ThumbsUpReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ThumbsUpReply_CommentManage))); err != nil { return } return @@ -423,7 +527,22 @@ func BuildMessage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Message c = context.Background() } obj = &Message{} - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_Message))); err != nil { + if obj.CreateMessage, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CreateMessage_Message))); err != nil { + return + } + if obj.GetMessageById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetMessageById_Message))); err != nil { + return + } + if obj.GetMessageCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetMessageCount_Message))); err != nil { + return + } + if obj.GetMessages, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetMessages_Message))); err != nil { + return + } + if obj.GetUnreadCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUnreadCount_Message))); err != nil { + return + } + if obj.ReadMessage, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ReadMessage_Message))); err != nil { return } return @@ -437,7 +556,13 @@ func BuildSecurity(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Securi c = context.Background() } obj = &Security{} - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_Security))); err != nil { + if obj.GetLatestPhoneCaptcha, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetLatestPhoneCaptcha_Security))); err != nil { + return + } + if obj.SendPhoneCaptcha, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_SendPhoneCaptcha_Security))); err != nil { + return + } + if obj.UsePhoneCaptcha, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UsePhoneCaptcha_Security))); err != nil { return } return @@ -718,7 +843,22 @@ func BuildWallet(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Wallet, c = context.Background() } obj = &Wallet{} - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_Wallet))); err != nil { + if obj.CreateRecharge, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CreateRecharge_Wallet))); err != nil { + return + } + if obj.GetRechargeById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetRechargeById_Wallet))); err != nil { + return + } + if obj.GetUserWalletBillCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserWalletBillCount_Wallet))); err != nil { + return + } + if obj.GetUserWalletBills, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserWalletBills_Wallet))); err != nil { + return + } + if obj.HandlePostAttachementBought, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_HandlePostAttachementBought_Wallet))); err != nil { + return + } + if obj.HandleRechargeSuccess, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_HandleRechargeSuccess_Wallet))); err != nil { return } return diff --git a/internal/dao/sakila/yesql/yesql.sql b/internal/dao/sakila/yesql/yesql.sql index 559a6b03..c13e9d3e 100644 --- a/internal/dao/sakila/yesql/yesql.sql +++ b/internal/dao/sakila/yesql/yesql.sql @@ -2,7 +2,15 @@ -- authorization_manage sql dml -------------------------------------------------------------------------------- --- name: user_info@authorization_manage +-- name: be_friend_filter@authorization_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: be_friend_ids@authorization_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: my_friend_set@authorization_manage -- prepare: stmt SELECT * FROM @user WHERE username=? @@ -10,7 +18,31 @@ SELECT * FROM @user WHERE username=? -- comment sql dml -------------------------------------------------------------------------------- --- name: user_info@comment +-- name: get_comments@comment +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_comment_by_id@comment +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_comment_count@comment +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_comment_replay_by_id@comment +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_comment_contents_by_ids@comment +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_commment_replies_by_id@comment +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_comment_thumbs_map@comment -- prepare: stmt SELECT * FROM @user WHERE username=? @@ -18,7 +50,39 @@ SELECT * FROM @user WHERE username=? -- comment_manage sql dml -------------------------------------------------------------------------------- --- name: user_info@comment_manage +-- name: delete_comment@comment_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: create_comment@comment_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: create_comment_reply@comment_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: delete_comment_reply@comment_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: create_comment_content@comment_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: thumbs_up_comment@comment_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: thumbs_down_comment@comment_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: thumbs_up_reply@comment_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: thumbs_down_reply@comment_manage -- prepare: stmt SELECT * FROM @user WHERE username=? @@ -54,7 +118,27 @@ SELECT * FROM @user WHERE username=? -- message sql dml -------------------------------------------------------------------------------- --- name: user_info@message +-- name: create_message@message +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_unread_count@message +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_message_by_id@message +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: read_message@message +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_messages@message +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_message_count@message -- prepare: stmt SELECT * FROM @user WHERE username=? @@ -62,7 +146,15 @@ SELECT * FROM @user WHERE username=? -- security sql dml -------------------------------------------------------------------------------- --- name: user_info@security +-- name: get_latest_phone_captcha@security +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: use_phone_captcha@security +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: send_phone_captcha@security -- prepare: stmt SELECT * FROM @user WHERE username=? @@ -413,6 +505,26 @@ SELECT * FROM @user WHERE username=? -- wallet sql dml -------------------------------------------------------------------------------- --- name: user_info@wallet +-- name: get_user_wallet_bills@wallet +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_user_wallet_bill_count@wallet +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_recharge_by_id@wallet -- prepare: stmt -SELECT * FROM @user WHERE username=? \ No newline at end of file +SELECT * FROM @user WHERE username=? + +-- name: create_recharge@wallet +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: handle_recharge_success@wallet +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: handle_post_attachement_bought@wallet +-- prepare: stmt +SELECT * FROM @user WHERE username=? From fec8330fb81fcd6d6e5d2f717f7359989fda691b Mon Sep 17 00:00:00 2001 From: Michael Li Date: Fri, 14 Jul 2023 16:28:36 +0800 Subject: [PATCH 06/19] sqlx: add some logic implement 8% --- internal/core/cs/contact.go | 24 ++ internal/dao/jinzhu/dbr/comment_reply.go | 12 +- internal/dao/sakila/comments.go | 347 +++++++++++++++++---- internal/dao/sakila/contacts.go | 32 +- internal/dao/sakila/messages.go | 43 +-- internal/dao/sakila/security.go | 46 ++- internal/dao/sakila/wallet.go | 39 ++- internal/dao/sakila/yesql/cc/yesql.go | 368 +++++++++++++---------- internal/dao/sakila/yesql/yesql.sql | 69 ++++- 9 files changed, 694 insertions(+), 286 deletions(-) create mode 100644 internal/core/cs/contact.go diff --git a/internal/core/cs/contact.go b/internal/core/cs/contact.go new file mode 100644 index 00000000..27d87cfd --- /dev/null +++ b/internal/core/cs/contact.go @@ -0,0 +1,24 @@ +// 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"` +} 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/sakila/comments.go b/internal/dao/sakila/comments.go index dc27c690..4e8f52ed 100644 --- a/internal/dao/sakila/comments.go +++ b/internal/dao/sakila/comments.go @@ -5,12 +5,15 @@ package sakila import ( + "time" + "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" "github.com/rocboss/paopao-ce/internal/core/ms" + "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" - "github.com/rocboss/paopao-ce/pkg/debug" + "github.com/rocboss/paopao-ce/pkg/types" ) var ( @@ -28,95 +31,337 @@ type commentManageSrv struct { q *cc.CommentManage } -func (s *commentSrv) GetComments(conditions *ms.ConditionsT, offset, limit int) ([]*ms.Comment, error) { - // TODO - debug.NotImplemented() - return nil, nil +func (s *commentSrv) GetComments(r *ms.ConditionsT, offset, limit int) ([]*ms.Comment, error) { + res := []*ms.Comment{} + (*r)["limit"], (*r)["offset"] = limit, offset + err := s.q.GetComments.Select(&res, r) + return res, err } func (s *commentSrv) GetCommentByID(id int64) (*ms.Comment, error) { - // TODO - debug.NotImplemented() - return nil, nil + res := &ms.Comment{} + err := s.q.GetCommentById.Get(res, id) + return res, err } func (s *commentSrv) GetCommentReplyByID(id int64) (*ms.CommentReply, error) { - // TODO - debug.NotImplemented() - return nil, nil + res := &ms.CommentReply{} + err := s.q.GetCommentById.Get(res, id) + return res, err } -func (s *commentSrv) GetCommentCount(conditions *ms.ConditionsT) (int64, error) { - // TODO - debug.NotImplemented() - return 0, nil +func (s *commentSrv) GetCommentCount(r *ms.ConditionsT) (res int64, err error) { + err = s.q.GetCommentCount.Get(&res, r) + return } func (s *commentSrv) GetCommentContentsByIDs(ids []int64) ([]*ms.CommentContent, error) { - // TODO - debug.NotImplemented() - return nil, nil + res := []*ms.CommentContent{} + err := s.inSelect(&res, s.q.GetCommentContentsByIds, ids) + return res, err } func (s *commentSrv) GetCommentThumbsMap(userId int64, tweetId int64) (cs.CommentThumbsMap, cs.CommentThumbsMap, error) { - // TODO - return nil, nil, debug.ErrNotImplemented + if userId < 0 { + return nil, nil, nil + } + commentThumbsList := cs.CommentThumbsList{} + err := s.q.GetCommentThumbs.Select(&commentThumbsList, userId, tweetId) + if err != nil { + return nil, nil, err + } + commentThumbs, replyThumbs := make(cs.CommentThumbsMap), make(cs.CommentThumbsMap) + for _, thumbs := range commentThumbsList { + if thumbs.CommentType == 0 { + commentThumbs[thumbs.CommentID] = thumbs + } else { + replyThumbs[thumbs.ReplyID] = thumbs + } + } + return commentThumbs, replyThumbs, nil } func (s *commentSrv) GetCommentRepliesByID(ids []int64) ([]*ms.CommentReplyFormated, error) { - // TODO - debug.NotImplemented() - return nil, nil + replies := []*ms.CommentReply{} + err := s.inSelect(&replies, s.q.GetCommmentRepliesByIds, ids) + if err != nil { + return nil, err + } + userIds := []int64{} + for _, reply := range replies { + userIds = append(userIds, reply.UserID, reply.AtUserID) + } + users := []*ms.UserFormated{} + if err = s.inSelect(&users, s.q.GetUsersByIds, userIds); err != nil { + return nil, err + } + repliesFormated := []*ms.CommentReplyFormated{} + for _, reply := range replies { + replyFormated := reply.Format() + for _, user := range users { + if reply.UserID == user.ID { + replyFormated.User = user + } + if reply.AtUserID == user.ID { + replyFormated.AtUser = user + } + } + repliesFormated = append(repliesFormated, replyFormated) + } + return repliesFormated, nil } -func (s *commentManageSrv) DeleteComment(comment *ms.Comment) error { - // TODO - debug.NotImplemented() - return nil +func (s *commentManageSrv) DeleteComment(r *ms.Comment) error { + return s.with(func(tx *sqlx.Tx) error { + if _, err := tx.Stmtx(s.q.DeleteComment).Exec(r.ID); err != nil { + return err + } + _, err := tx.Stmtx(s.q.DeleteCommentThumbs).Exec(r.UserID, r.PostID, r.ID) + return err + }) } -func (s *commentManageSrv) CreateComment(comment *ms.Comment) (*ms.Comment, error) { - // TODO - debug.NotImplemented() - return nil, nil +func (s *commentManageSrv) CreateComment(r *ms.Comment) (*ms.Comment, error) { + res, err := s.q.CreateComment.Exec(r) + if err != nil { + return nil, err + } + id, err := res.LastInsertId() + if err != nil { + return nil, err + } + r.Model = &dbr.Model{ + ID: id, + } + return r, nil } -func (s *commentManageSrv) CreateCommentReply(reply *ms.CommentReply) (*ms.CommentReply, error) { - // TODO - debug.NotImplemented() - return nil, nil +func (s *commentManageSrv) CreateCommentReply(r *ms.CommentReply) (*ms.CommentReply, error) { + res, err := s.q.CreateComment.Exec(r) + if err != nil { + return nil, err + } + id, err := res.LastInsertId() + if err != nil { + return nil, err + } + r.Model = &dbr.Model{ID: id} + return r, nil } -func (s *commentManageSrv) DeleteCommentReply(reply *ms.CommentReply) error { - // TODO - debug.NotImplemented() - return nil +func (s *commentManageSrv) DeleteCommentReply(r *ms.CommentReply) error { + return s.with(func(tx *sqlx.Tx) error { + if _, err := tx.Stmtx(s.q.DeleteCommentReply).Exec(r.ID); err != nil { + return err + } + _, err := tx.Stmtx(s.q.DeleteCommentThumbs).Exec(r.UserID, r.CommentID, r.ID) + return err + }) } -func (s *commentManageSrv) CreateCommentContent(content *ms.CommentContent) (*ms.CommentContent, error) { - // TODO - debug.NotImplemented() - return nil, nil +func (s *commentManageSrv) CreateCommentContent(r *ms.CommentContent) (*ms.CommentContent, error) { + res, err := s.q.CreateCommentContent.Exec(r) + if err != nil { + return nil, err + } + id, err := res.LastInsertId() + if err != nil { + return nil, err + } + r.Model = &dbr.Model{ID: id} + return r, nil } func (s *commentManageSrv) ThumbsUpComment(userId int64, tweetId, commentId int64) error { - // TODO - return debug.ErrNotImplemented + return s.with(func(tx *sqlx.Tx) error { + var ( + thumbsUpCount int32 = 0 + thumbsDownCount int32 = 0 + ) + commentThumbs := &dbr.TweetCommentThumbs{} + // 检查thumbs状态 + err := tx.Stmtx(s.q.GetTweetCommentThumb).Get(commentThumbs, userId, tweetId, commentId) + if err == nil { + switch { + case commentThumbs.IsThumbsUp == types.Yes && commentThumbs.IsThumbsDown == types.No: + thumbsUpCount, thumbsDownCount = -1, 0 + case commentThumbs.IsThumbsUp == types.No && commentThumbs.IsThumbsDown == types.No: + thumbsUpCount, thumbsDownCount = 1, 0 + default: + thumbsUpCount, thumbsDownCount = 1, -1 + commentThumbs.IsThumbsDown = types.No + } + commentThumbs.IsThumbsUp = 1 - commentThumbs.IsThumbsUp + commentThumbs.ModifiedOn = time.Now().Unix() + if _, err := tx.NamedStmt(s.q.UpdateThumbsUpComment).Exec(commentThumbs); err != nil { + return err + } + } else { + commentThumbs = &dbr.TweetCommentThumbs{ + UserID: userId, + TweetID: tweetId, + CommentID: commentId, + IsThumbsUp: types.Yes, + IsThumbsDown: types.No, + CommentType: 0, + Model: &dbr.Model{ + CreatedOn: time.Now().Unix(), + }, + } + thumbsUpCount, thumbsDownCount = 1, 0 + if _, err := tx.NamedStmt(s.q.CreateThumbsUpComment).Exec(commentThumbs); err != nil { + return err + } + } + // 更新thumbsUpCount + _, err = tx.Stmtx(s.q.UpdateCommentThumbsCount).Exec(commentId, thumbsUpCount, thumbsDownCount) + return err + }) } func (s *commentManageSrv) ThumbsDownComment(userId int64, tweetId, commentId int64) error { - // TODO - return debug.ErrNotImplemented + return s.with(func(tx *sqlx.Tx) error { + var ( + thumbsUpCount int32 = 0 + thumbsDownCount int32 = 0 + ) + commentThumbs := &dbr.TweetCommentThumbs{} + // 检查thumbs状态 + err := tx.Stmtx(s.q.GetTweetCommentThumb).Get(commentThumbs, userId, tweetId, commentId) + if err == nil { + switch { + case commentThumbs.IsThumbsDown == types.Yes: + thumbsUpCount, thumbsDownCount = 0, -1 + case commentThumbs.IsThumbsDown == types.No && commentThumbs.IsThumbsUp == types.No: + thumbsUpCount, thumbsDownCount = 0, 1 + default: + thumbsUpCount, thumbsDownCount = -1, 1 + commentThumbs.IsThumbsUp = types.No + + } + commentThumbs.IsThumbsDown = 1 - commentThumbs.IsThumbsDown + commentThumbs.ModifiedOn = time.Now().Unix() + if _, err := tx.NamedStmt(s.q.UpdateThumbsUpComment).Exec(commentThumbs); err != nil { + return err + } + } else { + commentThumbs = &dbr.TweetCommentThumbs{ + UserID: userId, + TweetID: tweetId, + CommentID: commentId, + IsThumbsUp: types.No, + IsThumbsDown: types.Yes, + CommentType: 0, + Model: &dbr.Model{ + CreatedOn: time.Now().Unix(), + }, + } + thumbsUpCount, thumbsDownCount = 0, 1 + if _, err := tx.NamedStmt(s.q.CreateThumbsUpComment).Exec(commentThumbs); err != nil { + return err + } + } + // 更新thumbsUpCount + _, err = tx.Stmtx(s.q.UpdateCommentThumbsCount).Exec(commentId, thumbsUpCount, thumbsDownCount) + return err + }) } func (s *commentManageSrv) ThumbsUpReply(userId int64, tweetId, commentId, replyId int64) error { - // TODO - return debug.ErrNotImplemented + return s.with(func(tx *sqlx.Tx) error { + + var ( + thumbsUpCount int32 = 0 + thumbsDownCount int32 = 0 + ) + commentThumbs := &dbr.TweetCommentThumbs{} + // 检查thumbs状态 + err := tx.Stmtx(s.q.GetCommentReplyThumb).Get(commentThumbs, userId, tweetId, commentId, replyId) + if err == nil { + switch { + case commentThumbs.IsThumbsUp == types.Yes: + thumbsUpCount, thumbsDownCount = -1, 0 + case commentThumbs.IsThumbsUp == types.No && commentThumbs.IsThumbsDown == types.No: + thumbsUpCount, thumbsDownCount = 1, 0 + default: + thumbsUpCount, thumbsDownCount = 1, -1 + commentThumbs.IsThumbsDown = types.No + } + commentThumbs.IsThumbsUp = 1 - commentThumbs.IsThumbsUp + commentThumbs.ModifiedOn = time.Now().Unix() + if _, err := tx.NamedStmt(s.q.UpdateThumbsUpComment).Exec(commentThumbs); err != nil { + return err + } + } else { + commentThumbs = &dbr.TweetCommentThumbs{ + UserID: userId, + TweetID: tweetId, + CommentID: commentId, + ReplyID: replyId, + IsThumbsUp: types.Yes, + IsThumbsDown: types.No, + CommentType: 1, + Model: &dbr.Model{ + CreatedOn: time.Now().Unix(), + }, + } + thumbsUpCount, thumbsDownCount = 1, 0 + if _, err := tx.NamedStmt(s.q.CreateThumbsUpComment).Exec(commentThumbs); err != nil { + return err + } + } + // 更新thumbsUpCount + _, err = tx.Stmtx(s.q.UpdateCommentThumbsCount).Exec(commentId, thumbsUpCount, thumbsDownCount) + return err + }) } func (s *commentManageSrv) ThumbsDownReply(userId int64, tweetId, commentId, replyId int64) error { - // TODO - return debug.ErrNotImplemented + return s.with(func(tx *sqlx.Tx) error { + var ( + thumbsUpCount int32 = 0 + thumbsDownCount int32 = 0 + ) + commentThumbs := &dbr.TweetCommentThumbs{} + // 检查thumbs状态 + err := tx.Stmtx(s.q.GetCommentReplyThumb).Get(commentThumbs, userId, tweetId, commentId, replyId) + if err == nil { + switch { + case commentThumbs.IsThumbsDown == types.Yes: + thumbsUpCount, thumbsDownCount = 0, -1 + case commentThumbs.IsThumbsUp == types.No && commentThumbs.IsThumbsDown == types.No: + thumbsUpCount, thumbsDownCount = 0, 1 + default: + thumbsUpCount, thumbsDownCount = -1, 1 + commentThumbs.IsThumbsUp = types.No + } + commentThumbs.IsThumbsDown = 1 - commentThumbs.IsThumbsDown + commentThumbs.ModifiedOn = time.Now().Unix() + if _, err := tx.NamedStmt(s.q.UpdateThumbsUpComment).Exec(commentThumbs); err != nil { + return err + } + } else { + commentThumbs = &dbr.TweetCommentThumbs{ + UserID: userId, + TweetID: tweetId, + CommentID: commentId, + ReplyID: replyId, + IsThumbsUp: types.No, + IsThumbsDown: types.Yes, + CommentType: 1, + Model: &dbr.Model{ + CreatedOn: time.Now().Unix(), + }, + } + thumbsUpCount, thumbsDownCount = 0, 1 + if _, err := tx.NamedStmt(s.q.CreateThumbsUpComment).Exec(commentThumbs); err != nil { + return err + } + } + // 更新thumbsUpCount + _, err = tx.Stmtx(s.q.UpdateCommentThumbsCount).Exec(commentId, thumbsUpCount, thumbsDownCount) + return err + }) } func newCommentService(db *sqlx.DB) core.CommentService { diff --git a/internal/dao/sakila/contacts.go b/internal/dao/sakila/contacts.go index 5c1d6883..32d03047 100644 --- a/internal/dao/sakila/contacts.go +++ b/internal/dao/sakila/contacts.go @@ -7,15 +7,23 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/cs" "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" - "github.com/rocboss/paopao-ce/pkg/debug" ) var ( _ core.ContactManageService = (*contactManageSrv)(nil) ) +type contact struct { + UserId int64 `db:"user_id" json:"user_id"` + FriendId int64 `db:"friend_id" json:"friend_id"` + Status int8 `json:"status"` // 1请求好友, 2已同意好友, 3已拒绝好友, 4已删除好友 + IsBlack int8 `json:"is_black"` + NoticeEnable int8 `json:"notice_enable"` +} + type contactManageSrv struct { *sqlxSrv q *cc.ContactManager @@ -42,13 +50,27 @@ func (s *contactManageSrv) DeleteFriend(userId int64, friendId int64) (err error } func (s *contactManageSrv) GetContacts(userId int64, offset int, limit int) (*ms.ContactList, error) { - // TODO - return nil, nil + res := &ms.ContactList{ + Contacts: []ms.ContactItem{}, + } + if err := s.q.GetContacts.Select(&res.Contacts, userId, limit, offset); err != nil { + return nil, err + } + if err := s.q.TotalContactsById.Get(&res.Total, userId); err != nil { + return nil, err + } + return res, nil } func (s *contactManageSrv) IsFriend(userId int64, friendId int64) bool { - // TODO - debug.NotImplemented() + ct := &contact{ + UserId: friendId, + FriendId: userId, + } + err := s.q.GetUserFriend.Get(ct, userId, friendId) + if err == nil && ct.Status == cs.ContactStatusAgree { + return true + } return false } diff --git a/internal/dao/sakila/messages.go b/internal/dao/sakila/messages.go index 5f62b6a3..1856c496 100644 --- a/internal/dao/sakila/messages.go +++ b/internal/dao/sakila/messages.go @@ -8,6 +8,7 @@ import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/ms" + "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -22,21 +23,27 @@ type messageSrv struct { } func (s *messageSrv) CreateMessage(msg *ms.Message) (*ms.Message, error) { - // TODO - debug.NotImplemented() - return nil, nil + res, err := s.q.CreateMessage.Exec(msg) + if err != nil { + return nil, err + } + id, err := res.LastInsertId() + if err != nil { + return nil, err + } + msg.Model = &dbr.Model{ID: id} + return msg, nil } -func (s *messageSrv) GetUnreadCount(userID int64) (int64, error) { - // TODO - debug.NotImplemented() - return 0, nil +func (s *messageSrv) GetUnreadCount(userID int64) (res int64, err error) { + err = s.q.GetUnreadCount.Get(&res) + return } func (s *messageSrv) GetMessageByID(id int64) (*ms.Message, error) { - // TODO - debug.NotImplemented() - return nil, nil + res := &ms.Message{} + err := s.q.GetMessageById.Get(res, id) + return res, err } func (s *messageSrv) ReadMessage(message *ms.Message) error { @@ -45,16 +52,16 @@ func (s *messageSrv) ReadMessage(message *ms.Message) error { return nil } -func (s *messageSrv) GetMessages(conditions *ms.ConditionsT, offset, limit int) ([]*ms.MessageFormated, error) { - // TODO - debug.NotImplemented() - return nil, nil +func (s *messageSrv) GetMessages(r *ms.ConditionsT, offset, limit int) ([]*ms.MessageFormated, error) { + res := []*ms.MessageFormated{} + (*r)["limit"], (*r)["offset"] = limit, offset + err := s.q.GetMessages.Select(&res, r) + return res, err } -func (s *messageSrv) GetMessageCount(conditions *ms.ConditionsT) (int64, error) { - // TODO - debug.NotImplemented() - return 0, nil +func (s *messageSrv) GetMessageCount(r *ms.ConditionsT) (res int64, err error) { + err = s.q.GetMessageCount.Get(&res, r) + return } func newMessageService(db *sqlx.DB) core.MessageService { diff --git a/internal/dao/sakila/security.go b/internal/dao/sakila/security.go index 02154ee5..49707281 100644 --- a/internal/dao/sakila/security.go +++ b/internal/dao/sakila/security.go @@ -5,11 +5,15 @@ package sakila import ( + "math/rand" + "strconv" + "time" + "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/ms" + "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" - "github.com/rocboss/paopao-ce/pkg/debug" ) var ( @@ -18,33 +22,47 @@ var ( type securitySrv struct { *sqlxSrv - q *cc.Security + q *cc.Security + phoneVerify core.PhoneVerifyService } // GetLatestPhoneCaptcha 获取最新短信验证码 func (s *securitySrv) GetLatestPhoneCaptcha(phone string) (*ms.Captcha, error) { - // TODO - debug.NotImplemented() - return nil, nil + res := &ms.Captcha{} + err := s.q.GetLatestPhoneCaptcha.Get(res, phone) + return res, err } // UsePhoneCaptcha 更新短信验证码 -func (s *securitySrv) UsePhoneCaptcha(captcha *ms.Captcha) error { - // TODO - debug.NotImplemented() - return nil +func (s *securitySrv) UsePhoneCaptcha(r *ms.Captcha) error { + r.UseTimes++ + _, err := s.q.UsePhoneCaptcha.Exec(r) + return err } // SendPhoneCaptcha 发送短信验证码 func (s *securitySrv) SendPhoneCaptcha(phone string) error { - // TODO - debug.NotImplemented() - return nil + expire := time.Duration(5) + // 发送验证码 + rand.Seed(time.Now().UnixNano()) + captcha := strconv.Itoa(rand.Intn(900000) + 100000) + if err := s.phoneVerify.SendPhoneCaptcha(phone, captcha, expire); err != nil { + return err + } + // 写入表 + phoneCaptcha := &dbr.Captcha{ + Phone: phone, + Captcha: captcha, + ExpiredOn: time.Now().Add(expire * time.Minute).Unix(), + } + _, err := s.q.CreatePhoneCaptcha.Exec(phoneCaptcha) + return err } func newSecurityService(db *sqlx.DB, phoneVerify core.PhoneVerifyService) core.SecurityService { return &securitySrv{ - sqlxSrv: newSqlxSrv(db), - q: mustBuild(db, cc.BuildSecurity), + sqlxSrv: newSqlxSrv(db), + q: mustBuild(db, cc.BuildSecurity), + phoneVerify: phoneVerify, } } diff --git a/internal/dao/sakila/wallet.go b/internal/dao/sakila/wallet.go index 42649113..3fff19fe 100644 --- a/internal/dao/sakila/wallet.go +++ b/internal/dao/sakila/wallet.go @@ -8,6 +8,7 @@ import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/ms" + "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/rocboss/paopao-ce/pkg/debug" ) @@ -22,26 +23,38 @@ type walletSrv struct { } func (s *walletSrv) GetRechargeByID(id int64) (*ms.WalletRecharge, error) { - // TODO - debug.NotImplemented() - return nil, nil + res := &ms.WalletRecharge{} + err := s.q.GetRechargeById.Get(res, id) + return res, err } + func (s *walletSrv) CreateRecharge(userId, amount int64) (*ms.WalletRecharge, error) { - // TODO - debug.NotImplemented() - return nil, nil + res, err := s.q.CreateRecharge.Exec(userId, amount) + if err != nil { + return nil, err + } + id, err := res.LastInsertId() + if err != nil { + return nil, err + } + return &ms.WalletRecharge{ + Model: &dbr.Model{ + ID: id, + }, + UserID: userId, + Amount: amount, + }, nil } func (s *walletSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*ms.WalletStatement, error) { - // TODO - debug.NotImplemented() - return nil, nil + res := []*ms.WalletStatement{} + err := s.q.GetUserWalletBills.Select(&res, userID, limit, offset) + return res, err } -func (s *walletSrv) GetUserWalletBillCount(userID int64) (int64, error) { - // TODO - debug.NotImplemented() - return 0, nil +func (s *walletSrv) GetUserWalletBillCount(userID int64) (res int64, err error) { + err = s.q.GetUserWalletBillCount.Get(&res, userID) + return } func (s *walletSrv) HandleRechargeSuccess(recharge *ms.WalletRecharge, tradeNo string) error { diff --git a/internal/dao/sakila/yesql/cc/yesql.go b/internal/dao/sakila/yesql/cc/yesql.go index adc6081f..2fe296d0 100644 --- a/internal/dao/sakila/yesql/cc/yesql.go +++ b/internal/dao/sakila/yesql/cc/yesql.go @@ -12,111 +12,120 @@ import ( ) const ( - _BeFriendFilter_AuthorizationManage = `SELECT * FROM @user WHERE username=?` - _BeFriendIds_AuthorizationManage = `SELECT * FROM @user WHERE username=?` - _MyFriendSet_AuthorizationManage = `SELECT * FROM @user WHERE username=?` - _GetCommentById_Comment = `SELECT * FROM @user WHERE username=?` - _GetCommentContentsByIds_Comment = `SELECT * FROM @user WHERE username=?` - _GetCommentCount_Comment = `SELECT * FROM @user WHERE username=?` - _GetCommentReplayById_Comment = `SELECT * FROM @user WHERE username=?` - _GetCommentThumbsMap_Comment = `SELECT * FROM @user WHERE username=?` - _GetComments_Comment = `SELECT * FROM @user WHERE username=?` - _GetCommmentRepliesById_Comment = `SELECT * FROM @user WHERE username=?` - _CreateComment_CommentManage = `SELECT * FROM @user WHERE username=?` - _CreateCommentContent_CommentManage = `SELECT * FROM @user WHERE username=?` - _CreateCommentReply_CommentManage = `SELECT * FROM @user WHERE username=?` - _DeleteComment_CommentManage = `SELECT * FROM @user WHERE username=?` - _DeleteCommentReply_CommentManage = `SELECT * FROM @user WHERE username=?` - _ThumbsDownComment_CommentManage = `SELECT * FROM @user WHERE username=?` - _ThumbsDownReply_CommentManage = `SELECT * FROM @user WHERE username=?` - _ThumbsUpComment_CommentManage = `SELECT * FROM @user WHERE username=?` - _ThumbsUpReply_CommentManage = `SELECT * FROM @user WHERE username=?` - _AddFriend_ContactManager = `SELECT * FROM @user WHERE username=?` - _DelFriend_ContactManager = `SELECT * FROM @user WHERE username=?` - _GetContacts_ContactManager = `SELECT * FROM @user WHERE username=?` - _IsFriend_ContactManager = `SELECT * FROM @user WHERE username=?` - _RejectFriend_ContactManager = `SELECT * FROM @user WHERE username=?` - _RequestingFriend_ContactManager = `SELECT * FROM @user WHERE username=?` - _UserInfo_FollowIndexA = `SELECT * FROM @user WHERE username=?` - _UserInfo_FollowIndex = `SELECT * FROM @user WHERE username=?` - _UserInfo_FriendIndexA = `SELECT * FROM @user WHERE username=?` - _UserInfo_FriendIndex = `SELECT * FROM @user WHERE username=?` - _UserInfo_LightIndexA = `SELECT * FROM @user WHERE username=?` - _UserInfo_LightIndex = `SELECT * FROM @user WHERE username=?` - _CreateMessage_Message = `SELECT * FROM @user WHERE username=?` - _GetMessageById_Message = `SELECT * FROM @user WHERE username=?` - _GetMessageCount_Message = `SELECT * FROM @user WHERE username=?` - _GetMessages_Message = `SELECT * FROM @user WHERE username=?` - _GetUnreadCount_Message = `SELECT * FROM @user WHERE username=?` - _ReadMessage_Message = `SELECT * FROM @user WHERE username=?` - _GetLatestPhoneCaptcha_Security = `SELECT * FROM @user WHERE username=?` - _SendPhoneCaptcha_Security = `SELECT * FROM @user WHERE username=?` - _UsePhoneCaptcha_Security = `SELECT * FROM @user WHERE username=?` - _UserInfo_SimpleIndexA = `SELECT * FROM @user WHERE username=?` - _UserInfo_SimpleIndex = `SELECT * FROM @user WHERE username=?` - _DecrTagsById_TopicA = `UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?)` - _HotTags_TopicA = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.quote_num DESC LIMIT ? OFFSET ?` - _IncrTagsById_TopicA = `UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?)` - _InsertTag_TopicA = `INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1)` - _NewestTags_TopicA = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.id DESC LIMIT ? OFFSET ?` - _TagsByIdA_TopicA = `SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0` - _TagsByIdB_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?)` - _TagsByKeywordA_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6` - _TagsByKeywordB_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6` - _TagsForIncr_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` - _AttachmentByTweetId_TweetA = `SELECT * FROM @user WHERE username=?` - _FavoriteByTweetId_TweetA = `SELECT * FROM @user WHERE username=?` - _ReactionByTweetId_TweetA = `SELECT * FROM @user WHERE username=?` - _TweetInfoById_TweetA = `SELECT * FROM @user WHERE username=?` - _TweetItemById_TweetA = `SELECT * FROM @user WHERE username=?` - _UserFavorites_TweetA = `SELECT * FROM @user WHERE username=?` - _UserInfo_TweetA = `SELECT * FROM @user WHERE username=?` - _UserReactions_TweetA = `SELECT * FROM @user WHERE username=?` - _UserTweetsByAdmin_TweetA = `SELECT * FROM @user WHERE username=?` - _UserTweetsByFriend_TweetA = `SELECT * FROM @user WHERE username=?` - _UserTweetsByGuest_TweetA = `SELECT * FROM @user WHERE username=?` - _UserTweetsBySelf_TweetA = `SELECT * FROM @user WHERE username=?` - _GetPostAttachmentBill_Tweet = `SELECT * FROM @user WHERE username=?` - _GetPostById_Tweet = `SELECT * FROM @user WHERE username=?` - _GetPostContentById_Tweet = `SELECT * FROM @user WHERE username=?` - _GetPostContetnsByIds_Tweet = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` - _GetPostCount_Tweet = `SELECT * FROM @user WHERE username=?` - _GetPosts_Tweet = `SELECT * FROM @user WHERE username=?` - _GetUserPostCollection_Tweet = `SELECT * FROM @user WHERE username=?` - _GetUserPostCollectionCount_Tweet = `SELECT * FROM @user WHERE username=?` - _GetUserPostCollections_Tweet = `SELECT * FROM @user WHERE username=?` - _GetUserPostStar_Tweet = `SELECT * FROM @user WHERE username=?` - _GetUserPostStarCount_Tweet = `SELECT * FROM @user WHERE username=?` - _GetUserPostStars_Tweet = `SELECT * FROM @user WHERE username=?` - _UserInfo_TweetHelpA = `SELECT * FROM @user WHERE username=?` - _GetPostContentByIds_TweetHelp = `SELECT * FROM @user WHERE username=?` - _GetUsersByIds_TweetHelp = `SELECT * FROM @user WHERE username=?` - _UserInfo_TweetManageA = `SELECT * FROM @user WHERE username=?` - _AddAttachment_TweetManage = `SELECT * FROM @user WHERE username=?` - _AddPost_TweetManage = `SELECT * FROM @user WHERE username=?` - _AddPostCollection_TweetManage = `SELECT * FROM @user WHERE username=?` - _AddPostContent_TweetManage = `SELECT * FROM @user WHERE username=?` - _AddPostStar_TweetManage = `SELECT * FROM @user WHERE username=?` - _DelPost_TweetManage = `SELECT * FROM @user WHERE username=?` - _DelPostCollection_TweetManage = `SELECT * FROM @user WHERE username=?` - _DelPostStar_TweetManage = `SELECT * FROM @user WHERE username=?` - _LockPost_TweetManage = `SELECT * FROM @user WHERE username=?` - _StickPost_TweetManage = `SELECT * FROM @user WHERE username=?` - _UpdatePost_TweetManage = `SELECT * FROM @user WHERE username=?` - _VisiblePost_TweetManage = `SELECT * FROM @user WHERE username=?` - _AddUser_UserManage = `SELECT * FROM @user WHERE username=?` - _GetUserById_UserManage = `SELECT * FROM @user WHERE username=?` - _GetUserByPhone_UserManage = `SELECT * FROM @user WHERE username=?` - _GetUserByUsername_UserManage = `SELECT * FROM @user WHERE username=?` - _GetUsersByIds_UserManage = `SELECT * FROM @user WHERE username=?` - _GetUsersByKeyword_UserManage = `SELECT * FROM @user WHERE username=?` - _UpdateUser_UserManage = `SELECT * FROM @user WHERE username=?` - _CreateRecharge_Wallet = `SELECT * FROM @user WHERE username=?` - _GetRechargeById_Wallet = `SELECT * FROM @user WHERE username=?` - _GetUserWalletBillCount_Wallet = `SELECT * FROM @user WHERE username=?` - _GetUserWalletBills_Wallet = `SELECT * FROM @user WHERE username=?` - _HandlePostAttachementBought_Wallet = `SELECT * FROM @user WHERE username=?` - _HandleRechargeSuccess_Wallet = `SELECT * FROM @user WHERE username=?` + _BeFriendFilter_AuthorizationManage = `SELECT * FROM @user WHERE username=?` + _BeFriendIds_AuthorizationManage = `SELECT * FROM @user WHERE username=?` + _MyFriendSet_AuthorizationManage = `SELECT * FROM @user WHERE username=?` + _GetCommentById_Comment = `SELECT * FROM @user WHERE username=?` + _GetCommentContentsByIds_Comment = `SELECT * FROM @user WHERE username=?` + _GetCommentCount_Comment = `SELECT * FROM @user WHERE username=?` + _GetCommentReplyById_Comment = `SELECT * FROM @user WHERE username=?` + _GetCommentThumbs_Comment = `SELECT * FROM @user WHERE username=?` + _GetComments_Comment = `SELECT * FROM @user WHERE username=?` + _GetCommmentRepliesByIds_Comment = `SELECT * FROM @user WHERE username=?` + _GetUsersByIds_Comment = `SELECT * FROM @user WHERE username=?` + _CreateComment_CommentManage = `SELECT * FROM @user WHERE username=?` + _CreateCommentContent_CommentManage = `SELECT * FROM @user WHERE username=?` + _CreateCommentReply_CommentManage = `SELECT * FROM @user WHERE username=?` + _CreateThumbsUpComment_CommentManage = `SELECT * FROM @user WHERE username=?` + _DeleteComment_CommentManage = `SELECT * FROM @user WHERE username=?` + _DeleteCommentReply_CommentManage = `SELECT * FROM @user WHERE username=?` + _DeleteCommentThumbs_CommentManage = `SELECT * FROM @user WHERE username=?` + _DeleteReplyThumbs_CommentManage = `SELECT * FROM @user WHERE username=?` + _GetCommentReplyThumb_CommentManage = `SELECT * FROM @user WHERE username=?` + _GetTweetCommentThumb_CommentManage = `SELECT * FROM @user WHERE username=?` + _ThumbsDownComment_CommentManage = `SELECT * FROM @user WHERE username=?` + _ThumbsDownReply_CommentManage = `SELECT * FROM @user WHERE username=?` + _ThumbsUpReply_CommentManage = `SELECT * FROM @user WHERE username=?` + _UpdateCommentThumbsCount_CommentManage = `SELECT * FROM @user WHERE username=?` + _UpdateThumbsUpComment_CommentManage = `SELECT * FROM @user WHERE username=?` + _AddFriend_ContactManager = `SELECT * FROM @user WHERE username=?` + _DelFriend_ContactManager = `SELECT * FROM @user WHERE username=?` + _GetContacts_ContactManager = `SELECT * FROM @user WHERE username=?` + _GetUserFriend_ContactManager = `SELECT * FROM @user WHERE username=?` + _RejectFriend_ContactManager = `SELECT * FROM @user WHERE username=?` + _RequestingFriend_ContactManager = `SELECT * FROM @user WHERE username=?` + _TotalContactsById_ContactManager = `SELECT * FROM @user WHERE username=?` + _UserInfo_FollowIndexA = `SELECT * FROM @user WHERE username=?` + _UserInfo_FollowIndex = `SELECT * FROM @user WHERE username=?` + _UserInfo_FriendIndexA = `SELECT * FROM @user WHERE username=?` + _UserInfo_FriendIndex = `SELECT * FROM @user WHERE username=?` + _UserInfo_LightIndexA = `SELECT * FROM @user WHERE username=?` + _UserInfo_LightIndex = `SELECT * FROM @user WHERE username=?` + _CreateMessage_Message = `SELECT * FROM @user WHERE username=?` + _GetMessageById_Message = `SELECT * FROM @user WHERE username=?` + _GetMessageCount_Message = `SELECT * FROM @user WHERE username=?` + _GetMessages_Message = `SELECT * FROM @user WHERE username=?` + _GetUnreadCount_Message = `SELECT * FROM @user WHERE username=?` + _ReadMessage_Message = `SELECT * FROM @user WHERE username=?` + _CreatePhoneCaptcha_Security = `SELECT * FROM @user WHERE username=?` + _GetLatestPhoneCaptcha_Security = `SELECT * FROM @user WHERE username=?` + _SendPhoneCaptcha_Security = `SELECT * FROM @user WHERE username=?` + _UsePhoneCaptcha_Security = `SELECT * FROM @user WHERE username=?` + _UserInfo_SimpleIndexA = `SELECT * FROM @user WHERE username=?` + _UserInfo_SimpleIndex = `SELECT * FROM @user WHERE username=?` + _DecrTagsById_TopicA = `UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?)` + _HotTags_TopicA = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.quote_num DESC LIMIT ? OFFSET ?` + _IncrTagsById_TopicA = `UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?)` + _InsertTag_TopicA = `INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1)` + _NewestTags_TopicA = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.id DESC LIMIT ? OFFSET ?` + _TagsByIdA_TopicA = `SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0` + _TagsByIdB_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?)` + _TagsByKeywordA_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6` + _TagsByKeywordB_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6` + _TagsForIncr_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` + _AttachmentByTweetId_TweetA = `SELECT * FROM @user WHERE username=?` + _FavoriteByTweetId_TweetA = `SELECT * FROM @user WHERE username=?` + _ReactionByTweetId_TweetA = `SELECT * FROM @user WHERE username=?` + _TweetInfoById_TweetA = `SELECT * FROM @user WHERE username=?` + _TweetItemById_TweetA = `SELECT * FROM @user WHERE username=?` + _UserFavorites_TweetA = `SELECT * FROM @user WHERE username=?` + _UserInfo_TweetA = `SELECT * FROM @user WHERE username=?` + _UserReactions_TweetA = `SELECT * FROM @user WHERE username=?` + _UserTweetsByAdmin_TweetA = `SELECT * FROM @user WHERE username=?` + _UserTweetsByFriend_TweetA = `SELECT * FROM @user WHERE username=?` + _UserTweetsByGuest_TweetA = `SELECT * FROM @user WHERE username=?` + _UserTweetsBySelf_TweetA = `SELECT * FROM @user WHERE username=?` + _GetPostAttachmentBill_Tweet = `SELECT * FROM @user WHERE username=?` + _GetPostById_Tweet = `SELECT * FROM @user WHERE username=?` + _GetPostContentById_Tweet = `SELECT * FROM @user WHERE username=?` + _GetPostContetnsByIds_Tweet = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` + _GetPostCount_Tweet = `SELECT * FROM @user WHERE username=?` + _GetPosts_Tweet = `SELECT * FROM @user WHERE username=?` + _GetUserPostCollection_Tweet = `SELECT * FROM @user WHERE username=?` + _GetUserPostCollectionCount_Tweet = `SELECT * FROM @user WHERE username=?` + _GetUserPostCollections_Tweet = `SELECT * FROM @user WHERE username=?` + _GetUserPostStar_Tweet = `SELECT * FROM @user WHERE username=?` + _GetUserPostStarCount_Tweet = `SELECT * FROM @user WHERE username=?` + _GetUserPostStars_Tweet = `SELECT * FROM @user WHERE username=?` + _UserInfo_TweetHelpA = `SELECT * FROM @user WHERE username=?` + _GetPostContentByIds_TweetHelp = `SELECT * FROM @user WHERE username=?` + _GetUsersByIds_TweetHelp = `SELECT * FROM @user WHERE username=?` + _UserInfo_TweetManageA = `SELECT * FROM @user WHERE username=?` + _AddAttachment_TweetManage = `SELECT * FROM @user WHERE username=?` + _AddPost_TweetManage = `SELECT * FROM @user WHERE username=?` + _AddPostCollection_TweetManage = `SELECT * FROM @user WHERE username=?` + _AddPostContent_TweetManage = `SELECT * FROM @user WHERE username=?` + _AddPostStar_TweetManage = `SELECT * FROM @user WHERE username=?` + _DelPost_TweetManage = `SELECT * FROM @user WHERE username=?` + _DelPostCollection_TweetManage = `SELECT * FROM @user WHERE username=?` + _DelPostStar_TweetManage = `SELECT * FROM @user WHERE username=?` + _LockPost_TweetManage = `SELECT * FROM @user WHERE username=?` + _StickPost_TweetManage = `SELECT * FROM @user WHERE username=?` + _UpdatePost_TweetManage = `SELECT * FROM @user WHERE username=?` + _VisiblePost_TweetManage = `SELECT * FROM @user WHERE username=?` + _AddUser_UserManage = `SELECT * FROM @user WHERE username=?` + _GetUserById_UserManage = `SELECT * FROM @user WHERE username=?` + _GetUserByPhone_UserManage = `SELECT * FROM @user WHERE username=?` + _GetUserByUsername_UserManage = `SELECT * FROM @user WHERE username=?` + _GetUsersByIds_UserManage = `SELECT * FROM @user WHERE username=?` + _GetUsersByKeyword_UserManage = `SELECT * FROM @user WHERE username=?` + _UpdateUser_UserManage = `SELECT * FROM @user WHERE username=?` + _CreateRecharge_Wallet = `SELECT * FROM @user WHERE username=?` + _GetRechargeById_Wallet = `SELECT * FROM @user WHERE username=?` + _GetUserWalletBillCount_Wallet = `SELECT * FROM @user WHERE username=?` + _GetUserWalletBills_Wallet = `SELECT * FROM @user WHERE username=?` + _HandlePostAttachementBought_Wallet = `SELECT * FROM @user WHERE username=?` + _HandleRechargeSuccess_Wallet = `SELECT * FROM @user WHERE username=?` ) type AuthorizationManage struct { @@ -128,36 +137,44 @@ type AuthorizationManage struct { type Comment struct { yesql.Namespace `yesql:"comment"` - GetCommentById *sqlx.Stmt `yesql:"get_comment_by_id"` - GetCommentContentsByIds *sqlx.Stmt `yesql:"get_comment_contents_by_ids"` - GetCommentCount *sqlx.Stmt `yesql:"get_comment_count"` - GetCommentReplayById *sqlx.Stmt `yesql:"get_comment_replay_by_id"` - GetCommentThumbsMap *sqlx.Stmt `yesql:"get_comment_thumbs_map"` - GetComments *sqlx.Stmt `yesql:"get_comments"` - GetCommmentRepliesById *sqlx.Stmt `yesql:"get_commment_replies_by_id"` + GetCommentContentsByIds string `yesql:"get_comment_contents_by_ids"` + GetCommmentRepliesByIds string `yesql:"get_commment_replies_by_ids"` + GetUsersByIds string `yesql:"get_users_by_ids"` + GetCommentById *sqlx.Stmt `yesql:"get_comment_by_id"` + GetCommentReplyById *sqlx.Stmt `yesql:"get_comment_reply_by_id"` + GetCommentThumbs *sqlx.Stmt `yesql:"get_comment_thumbs"` + GetCommentCount *sqlx.NamedStmt `yesql:"get_comment_count"` + GetComments *sqlx.NamedStmt `yesql:"get_comments"` } type CommentManage struct { - yesql.Namespace `yesql:"comment_manage"` - CreateComment *sqlx.Stmt `yesql:"create_comment"` - CreateCommentContent *sqlx.Stmt `yesql:"create_comment_content"` - CreateCommentReply *sqlx.Stmt `yesql:"create_comment_reply"` - DeleteComment *sqlx.Stmt `yesql:"delete_comment"` - DeleteCommentReply *sqlx.Stmt `yesql:"delete_comment_reply"` - ThumbsDownComment *sqlx.Stmt `yesql:"thumbs_down_comment"` - ThumbsDownReply *sqlx.Stmt `yesql:"thumbs_down_reply"` - ThumbsUpComment *sqlx.Stmt `yesql:"thumbs_up_comment"` - ThumbsUpReply *sqlx.Stmt `yesql:"thumbs_up_reply"` + yesql.Namespace `yesql:"comment_manage"` + DeleteComment *sqlx.Stmt `yesql:"delete_comment"` + DeleteCommentReply *sqlx.Stmt `yesql:"delete_comment_reply"` + DeleteCommentThumbs *sqlx.Stmt `yesql:"delete_comment_thumbs"` + DeleteReplyThumbs *sqlx.Stmt `yesql:"delete_reply_thumbs"` + GetCommentReplyThumb *sqlx.Stmt `yesql:"get_comment_reply_thumb"` + GetTweetCommentThumb *sqlx.Stmt `yesql:"get_tweet_comment_thumb"` + ThumbsDownComment *sqlx.Stmt `yesql:"thumbs_down_comment"` + ThumbsDownReply *sqlx.Stmt `yesql:"thumbs_down_reply"` + ThumbsUpReply *sqlx.Stmt `yesql:"thumbs_up_reply"` + UpdateCommentThumbsCount *sqlx.Stmt `yesql:"update_comment_thumbs_count"` + CreateComment *sqlx.NamedStmt `yesql:"create_comment"` + CreateCommentContent *sqlx.NamedStmt `yesql:"create_comment_content"` + CreateCommentReply *sqlx.NamedStmt `yesql:"create_comment_reply"` + CreateThumbsUpComment *sqlx.NamedStmt `yesql:"create_thumbs_up_comment"` + UpdateThumbsUpComment *sqlx.NamedStmt `yesql:"update_thumbs_up_comment"` } type ContactManager struct { - yesql.Namespace `yesql:"contact_manager"` - AddFriend *sqlx.Stmt `yesql:"add_friend"` - DelFriend *sqlx.Stmt `yesql:"del_friend"` - GetContacts *sqlx.Stmt `yesql:"get_contacts"` - IsFriend *sqlx.Stmt `yesql:"is_friend"` - RejectFriend *sqlx.Stmt `yesql:"reject_friend"` - RequestingFriend *sqlx.Stmt `yesql:"requesting_friend"` + yesql.Namespace `yesql:"contact_manager"` + AddFriend *sqlx.Stmt `yesql:"add_friend"` + DelFriend *sqlx.Stmt `yesql:"del_friend"` + GetContacts *sqlx.Stmt `yesql:"get_contacts"` + GetUserFriend *sqlx.Stmt `yesql:"get_user_friend"` + RejectFriend *sqlx.Stmt `yesql:"reject_friend"` + RequestingFriend *sqlx.Stmt `yesql:"requesting_friend"` + TotalContactsById *sqlx.Stmt `yesql:"total_contacts_by_id"` } type FollowIndex struct { @@ -192,19 +209,20 @@ type LightIndexA struct { type Message struct { yesql.Namespace `yesql:"message"` - CreateMessage *sqlx.Stmt `yesql:"create_message"` - GetMessageById *sqlx.Stmt `yesql:"get_message_by_id"` - GetMessageCount *sqlx.Stmt `yesql:"get_message_count"` - GetMessages *sqlx.Stmt `yesql:"get_messages"` - GetUnreadCount *sqlx.Stmt `yesql:"get_unread_count"` - ReadMessage *sqlx.Stmt `yesql:"read_message"` + GetMessageById *sqlx.Stmt `yesql:"get_message_by_id"` + GetUnreadCount *sqlx.Stmt `yesql:"get_unread_count"` + ReadMessage *sqlx.Stmt `yesql:"read_message"` + CreateMessage *sqlx.NamedStmt `yesql:"create_message"` + GetMessageCount *sqlx.NamedStmt `yesql:"get_message_count"` + GetMessages *sqlx.NamedStmt `yesql:"get_messages"` } type Security struct { yesql.Namespace `yesql:"security"` - GetLatestPhoneCaptcha *sqlx.Stmt `yesql:"get_latest_phone_captcha"` - SendPhoneCaptcha *sqlx.Stmt `yesql:"send_phone_captcha"` - UsePhoneCaptcha *sqlx.Stmt `yesql:"use_phone_captcha"` + GetLatestPhoneCaptcha *sqlx.Stmt `yesql:"get_latest_phone_captcha"` + SendPhoneCaptcha *sqlx.Stmt `yesql:"send_phone_captcha"` + CreatePhoneCaptcha *sqlx.NamedStmt `yesql:"create_phone_captcha"` + UsePhoneCaptcha *sqlx.NamedStmt `yesql:"use_phone_captcha"` } type SimpleIndex struct { @@ -343,26 +361,24 @@ func BuildComment(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Comment } else { c = context.Background() } - obj = &Comment{} - if obj.GetCommentById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetCommentById_Comment))); err != nil { - return + obj = &Comment{ + GetCommentContentsByIds: p.QueryHook(_GetCommentContentsByIds_Comment), + GetCommmentRepliesByIds: p.QueryHook(_GetCommmentRepliesByIds_Comment), + GetUsersByIds: p.QueryHook(_GetUsersByIds_Comment), } - if obj.GetCommentContentsByIds, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetCommentContentsByIds_Comment))); err != nil { - return - } - if obj.GetCommentCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetCommentCount_Comment))); err != nil { + if obj.GetCommentById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetCommentById_Comment))); err != nil { return } - if obj.GetCommentReplayById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetCommentReplayById_Comment))); err != nil { + if obj.GetCommentReplyById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetCommentReplyById_Comment))); err != nil { return } - if obj.GetCommentThumbsMap, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetCommentThumbsMap_Comment))); err != nil { + if obj.GetCommentThumbs, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetCommentThumbs_Comment))); err != nil { return } - if obj.GetComments, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetComments_Comment))); err != nil { + if obj.GetCommentCount, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_GetCommentCount_Comment))); err != nil { return } - if obj.GetCommmentRepliesById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetCommmentRepliesById_Comment))); err != nil { + if obj.GetComments, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_GetComments_Comment))); err != nil { return } return @@ -376,19 +392,22 @@ func BuildCommentManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *C c = context.Background() } obj = &CommentManage{} - if obj.CreateComment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CreateComment_CommentManage))); err != nil { + if obj.DeleteComment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_DeleteComment_CommentManage))); err != nil { return } - if obj.CreateCommentContent, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CreateCommentContent_CommentManage))); err != nil { + if obj.DeleteCommentReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_DeleteCommentReply_CommentManage))); err != nil { return } - if obj.CreateCommentReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CreateCommentReply_CommentManage))); err != nil { + if obj.DeleteCommentThumbs, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_DeleteCommentThumbs_CommentManage))); err != nil { return } - if obj.DeleteComment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_DeleteComment_CommentManage))); err != nil { + if obj.DeleteReplyThumbs, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_DeleteReplyThumbs_CommentManage))); err != nil { return } - if obj.DeleteCommentReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_DeleteCommentReply_CommentManage))); err != nil { + if obj.GetCommentReplyThumb, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetCommentReplyThumb_CommentManage))); err != nil { + return + } + if obj.GetTweetCommentThumb, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetTweetCommentThumb_CommentManage))); err != nil { return } if obj.ThumbsDownComment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ThumbsDownComment_CommentManage))); err != nil { @@ -397,10 +416,25 @@ func BuildCommentManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *C if obj.ThumbsDownReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ThumbsDownReply_CommentManage))); err != nil { return } - if obj.ThumbsUpComment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ThumbsUpComment_CommentManage))); err != nil { + if obj.ThumbsUpReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ThumbsUpReply_CommentManage))); err != nil { return } - if obj.ThumbsUpReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ThumbsUpReply_CommentManage))); err != nil { + if obj.UpdateCommentThumbsCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UpdateCommentThumbsCount_CommentManage))); err != nil { + return + } + if obj.CreateComment, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CreateComment_CommentManage))); err != nil { + return + } + if obj.CreateCommentContent, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CreateCommentContent_CommentManage))); err != nil { + return + } + if obj.CreateCommentReply, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CreateCommentReply_CommentManage))); err != nil { + return + } + if obj.CreateThumbsUpComment, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CreateThumbsUpComment_CommentManage))); err != nil { + return + } + if obj.UpdateThumbsUpComment, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_UpdateThumbsUpComment_CommentManage))); err != nil { return } return @@ -423,7 +457,7 @@ func BuildContactManager(p yesql.PreparexBuilder, ctx ...context.Context) (obj * if obj.GetContacts, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetContacts_ContactManager))); err != nil { return } - if obj.IsFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_IsFriend_ContactManager))); err != nil { + if obj.GetUserFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserFriend_ContactManager))); err != nil { return } if obj.RejectFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_RejectFriend_ContactManager))); err != nil { @@ -432,6 +466,9 @@ func BuildContactManager(p yesql.PreparexBuilder, ctx ...context.Context) (obj * if obj.RequestingFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_RequestingFriend_ContactManager))); err != nil { return } + if obj.TotalContactsById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TotalContactsById_ContactManager))); err != nil { + return + } return } @@ -527,22 +564,22 @@ func BuildMessage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Message c = context.Background() } obj = &Message{} - if obj.CreateMessage, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CreateMessage_Message))); err != nil { + if obj.GetMessageById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetMessageById_Message))); err != nil { return } - if obj.GetMessageById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetMessageById_Message))); err != nil { + if obj.GetUnreadCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUnreadCount_Message))); err != nil { return } - if obj.GetMessageCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetMessageCount_Message))); err != nil { + if obj.ReadMessage, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ReadMessage_Message))); err != nil { return } - if obj.GetMessages, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetMessages_Message))); err != nil { + if obj.CreateMessage, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CreateMessage_Message))); err != nil { return } - if obj.GetUnreadCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUnreadCount_Message))); err != nil { + if obj.GetMessageCount, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_GetMessageCount_Message))); err != nil { return } - if obj.ReadMessage, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ReadMessage_Message))); err != nil { + if obj.GetMessages, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_GetMessages_Message))); err != nil { return } return @@ -562,7 +599,10 @@ func BuildSecurity(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Securi if obj.SendPhoneCaptcha, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_SendPhoneCaptcha_Security))); err != nil { return } - if obj.UsePhoneCaptcha, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UsePhoneCaptcha_Security))); err != nil { + if obj.CreatePhoneCaptcha, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CreatePhoneCaptcha_Security))); err != nil { + return + } + if obj.UsePhoneCaptcha, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_UsePhoneCaptcha_Security))); err != nil { return } return diff --git a/internal/dao/sakila/yesql/yesql.sql b/internal/dao/sakila/yesql/yesql.sql index c13e9d3e..3d177a97 100644 --- a/internal/dao/sakila/yesql/yesql.sql +++ b/internal/dao/sakila/yesql/yesql.sql @@ -19,7 +19,7 @@ SELECT * FROM @user WHERE username=? -------------------------------------------------------------------------------- -- name: get_comments@comment --- prepare: stmt +-- prepare: named_stmt SELECT * FROM @user WHERE username=? -- name: get_comment_by_id@comment @@ -27,22 +27,29 @@ SELECT * FROM @user WHERE username=? SELECT * FROM @user WHERE username=? -- name: get_comment_count@comment --- prepare: stmt +-- prepare: named_stmt SELECT * FROM @user WHERE username=? --- name: get_comment_replay_by_id@comment +-- name: get_comment_reply_by_id@comment -- prepare: stmt SELECT * FROM @user WHERE username=? -- name: get_comment_contents_by_ids@comment --- prepare: stmt +-- prepare: raw +-- clause: in SELECT * FROM @user WHERE username=? --- name: get_commment_replies_by_id@comment --- prepare: stmt +-- name: get_commment_replies_by_ids@comment +-- prepare: raw +-- clause: in SELECT * FROM @user WHERE username=? --- name: get_comment_thumbs_map@comment +-- name: get_users_by_ids@comment +-- prepare: raw +-- clause: in +SELECT * FROM @user WHERE username=? + +-- name: get_comment_thumbs@comment -- prepare: stmt SELECT * FROM @user WHERE username=? @@ -54,23 +61,47 @@ SELECT * FROM @user WHERE username=? -- prepare: stmt SELECT * FROM @user WHERE username=? --- name: create_comment@comment_manage +-- name: delete_comment_thumbs@comment_manage -- prepare: stmt SELECT * FROM @user WHERE username=? +-- name: create_comment@comment_manage +-- prepare: named_stmt +SELECT * FROM @user WHERE username=? + -- name: create_comment_reply@comment_manage --- prepare: stmt +-- prepare: named_stmt SELECT * FROM @user WHERE username=? -- name: delete_comment_reply@comment_manage -- prepare: stmt SELECT * FROM @user WHERE username=? +-- name: delete_reply_thumbs@comment_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + -- name: create_comment_content@comment_manage +-- prepare: named_stmt +SELECT * FROM @user WHERE username=? + +-- name: update_thumbs_up_comment@comment_manage +-- prepare: named_stmt +SELECT * FROM @user WHERE username=? + +-- name: create_thumbs_up_comment@comment_manage +-- prepare: named_stmt +SELECT * FROM @user WHERE username=? + +-- name: update_comment_thumbs_count@comment_manage +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_tweet_comment_thumb@comment_manage -- prepare: stmt SELECT * FROM @user WHERE username=? --- name: thumbs_up_comment@comment_manage +-- name: get_comment_reply_thumb@comment_manage -- prepare: stmt SELECT * FROM @user WHERE username=? @@ -110,7 +141,11 @@ SELECT * FROM @user WHERE username=? -- prepare: stmt SELECT * FROM @user WHERE username=? --- name: is_friend@contact_manager +-- name: total_contacts_by_id@contact_manager +-- prepare: stmt +SELECT * FROM @user WHERE username=? + +-- name: get_user_friend@contact_manager -- prepare: stmt SELECT * FROM @user WHERE username=? @@ -119,7 +154,7 @@ SELECT * FROM @user WHERE username=? -------------------------------------------------------------------------------- -- name: create_message@message --- prepare: stmt +-- prepare: named_stmt SELECT * FROM @user WHERE username=? -- name: get_unread_count@message @@ -135,11 +170,11 @@ SELECT * FROM @user WHERE username=? SELECT * FROM @user WHERE username=? -- name: get_messages@message --- prepare: stmt +-- prepare: named_stmt SELECT * FROM @user WHERE username=? -- name: get_message_count@message --- prepare: stmt +-- prepare: named_stmt SELECT * FROM @user WHERE username=? -------------------------------------------------------------------------------- @@ -151,13 +186,17 @@ SELECT * FROM @user WHERE username=? SELECT * FROM @user WHERE username=? -- name: use_phone_captcha@security --- prepare: stmt +-- prepare: named_stmt SELECT * FROM @user WHERE username=? -- name: send_phone_captcha@security -- prepare: stmt SELECT * FROM @user WHERE username=? +-- name: create_phone_captcha@security +-- prepare: named_stmt +SELECT * FROM @user WHERE username=? + -------------------------------------------------------------------------------- -- friend_index sql dml -------------------------------------------------------------------------------- From 33262c3ccfeba73fac3a1b18ffa38b21b805543d Mon Sep 17 00:00:00 2001 From: Michael Li Date: Thu, 27 Jul 2023 19:45:21 +0800 Subject: [PATCH 07/19] fixed type error in web service --- internal/servants/web/loose.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/servants/web/loose.go b/internal/servants/web/loose.go index f2378fa9..3e5ca1d4 100644 --- a/internal/servants/web/loose.go +++ b/internal/servants/web/loose.go @@ -122,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) } From a68d3816ed91f0814614fef40702a2a184c3ae6d Mon Sep 17 00:00:00 2001 From: Michael Li Date: Tue, 1 Aug 2023 08:21:27 +0800 Subject: [PATCH 08/19] sqlx: implement some logic WIP %20 --- go.mod | 2 +- go.sum | 4 +- internal/dao/jinzhu/dbr/comment.go | 2 +- internal/dao/sakila/authority.go | 52 ++- internal/dao/sakila/comments.go | 31 +- internal/dao/sakila/messages.go | 8 +- internal/dao/sakila/yesql/cc/yesql.go | 466 +++++++++++++------------- internal/dao/sakila/yesql/yesql.sql | 32 +- 8 files changed, 306 insertions(+), 291 deletions(-) diff --git a/go.mod b/go.mod index d1c0e65f..1a548302 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/afocus/captcha v0.0.0-20191010092841-4bd1f21c8868 github.com/alimy/cfg v0.4.0 github.com/alimy/mir/v4 v4.0.0 - github.com/alimy/yesql v1.3.0 + github.com/alimy/yesql v1.4.0 github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible github.com/allegro/bigcache/v3 v3.1.0 github.com/bufbuild/connect-go v1.9.0 diff --git a/go.sum b/go.sum index da9c4ca7..db207893 100644 --- a/go.sum +++ b/go.sum @@ -127,8 +127,8 @@ github.com/alimy/cfg v0.4.0 h1:SslKPndmxRViT1ePWLmNsEq7okYP0GVeuowQlRWZPkw= github.com/alimy/cfg v0.4.0/go.mod h1:rOxbasTH2srl6StAjNF5Vyi8bfrdkl3fLGmOYtSw81c= github.com/alimy/mir/v4 v4.0.0 h1:MzGfmoLjjvR69jbZEmpKJO3tUuqB0RGRv1UWPbtukBg= github.com/alimy/mir/v4 v4.0.0/go.mod h1:d58dBvw2KImcVbAUANrciEV/of0arMNsI9c/5UNCMMc= -github.com/alimy/yesql v1.3.0 h1:4/p097ZvFMlIzm1CWYy1q+eBQH0DcqlB+/UxKTHsj30= -github.com/alimy/yesql v1.3.0/go.mod h1:Y0FdRIwIbJyTv56wSX+MpaIHiAW1PyKTDYO6K/er4JY= +github.com/alimy/yesql v1.4.0 h1:8q5PgUnLR1u9vi5Y9cLj1/cuie2I/4ShpCOp2jE1V6A= +github.com/alimy/yesql v1.4.0/go.mod h1:Y0FdRIwIbJyTv56wSX+MpaIHiAW1PyKTDYO6K/er4JY= github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible h1:KpbJFXwhVeuxNtBJ74MCGbIoaBok2uZvkD7QXp2+Wis= github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= github.com/allegro/bigcache/v3 v3.1.0 h1:H2Vp8VOvxcrB91o86fUSVJFqeuz8kpyyB02eH3bSzwk= 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/sakila/authority.go b/internal/dao/sakila/authority.go index 688068cc..4d4a2168 100644 --- a/internal/dao/sakila/authority.go +++ b/internal/dao/sakila/authority.go @@ -7,9 +7,11 @@ package sakila import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" + "github.com/rocboss/paopao-ce/internal/core/cs" "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" - "github.com/rocboss/paopao-ce/pkg/debug" + "github.com/rocboss/paopao-ce/pkg/types" + "github.com/sirupsen/logrus" ) var ( @@ -22,32 +24,50 @@ type authorizationManageSrv struct { } func (s *authorizationManageSrv) IsAllow(user *ms.User, action *ms.Action) bool { - // TODO - debug.NotImplemented() - return false + // user is activation if had bind phone + isActivation := (len(user.Phone) != 0) + isFriend := s.isFriend(user.ID, action.UserId) + // TODO: just use defaut act authorization chek rule now + return action.Act.IsAllow(user, action.UserId, isFriend, isActivation) } func (s *authorizationManageSrv) MyFriendSet(userId int64) ms.FriendSet { - // TODO - debug.NotImplemented() - return nil + var ids []string + if err := s.q.MyFriendSet.Get(&ids, userId); err != nil { + logrus.Warnf("get my FriendSet error: %s", err) + return ms.FriendSet{} + } + resp := make(ms.FriendSet, len(ids)) + for _, id := range ids { + resp[id] = types.Empty{} + } + return resp } func (s *authorizationManageSrv) BeFriendFilter(userId int64) ms.FriendFilter { - // TODO - debug.NotImplemented() - return nil + var ids []int64 + if err := s.q.BeFriendIds.Get(&ids, userId); err != nil { + logrus.Warnf("get my BeFriendFilter error: %s", err) + return ms.FriendFilter{} + } + resp := make(ms.FriendFilter, len(ids)) + for _, id := range ids { + resp[id] = types.Empty{} + } + return resp } -func (s *authorizationManageSrv) BeFriendIds(userId int64) ([]int64, error) { - // TODO - debug.NotImplemented() - return nil, nil +func (s *authorizationManageSrv) BeFriendIds(userId int64) (res []int64, err error) { + err = s.q.BeFriendIds.Get(&res, userId) + return } func (s *authorizationManageSrv) isFriend(userId int64, friendId int64) bool { - // TODO - debug.NotImplemented() + var status int8 + err := s.q.IsFriend.Get(&status, userId, friendId) + if err == nil || status == cs.ContactStatusAgree { + return true + } return false } diff --git a/internal/dao/sakila/comments.go b/internal/dao/sakila/comments.go index 4e8f52ed..9efdcb27 100644 --- a/internal/dao/sakila/comments.go +++ b/internal/dao/sakila/comments.go @@ -5,6 +5,7 @@ package sakila import ( + "strings" "time" "github.com/jmoiron/sqlx" @@ -31,23 +32,22 @@ type commentManageSrv struct { q *cc.CommentManage } -func (s *commentSrv) GetComments(r *ms.ConditionsT, offset, limit int) ([]*ms.Comment, error) { - res := []*ms.Comment{} - (*r)["limit"], (*r)["offset"] = limit, offset - err := s.q.GetComments.Select(&res, r) - return res, err +func (s *commentSrv) GetComments(r *ms.ConditionsT, offset, limit int) (res []*ms.Comment, err error) { + order := (*r)["ORDER"].(string) + postId := (*r)["post_id"] + stmt := strings.Replace(s.q.GetComments, "%order%", order, 1) + err = s.db.Select(&res, stmt, postId, limit, offset) + return } -func (s *commentSrv) GetCommentByID(id int64) (*ms.Comment, error) { - res := &ms.Comment{} - err := s.q.GetCommentById.Get(res, id) - return res, err +func (s *commentSrv) GetCommentByID(id int64) (res *ms.Comment, err error) { + err = s.q.GetCommentById.Get(res, id) + return } -func (s *commentSrv) GetCommentReplyByID(id int64) (*ms.CommentReply, error) { - res := &ms.CommentReply{} - err := s.q.GetCommentById.Get(res, id) - return res, err +func (s *commentSrv) GetCommentReplyByID(id int64) (res *ms.CommentReply, err error) { + err = s.q.GetCommentReplyById.Get(res, id) + return } func (s *commentSrv) GetCommentCount(r *ms.ConditionsT) (res int64, err error) { @@ -55,9 +55,8 @@ func (s *commentSrv) GetCommentCount(r *ms.ConditionsT) (res int64, err error) { return } -func (s *commentSrv) GetCommentContentsByIDs(ids []int64) ([]*ms.CommentContent, error) { - res := []*ms.CommentContent{} - err := s.inSelect(&res, s.q.GetCommentContentsByIds, ids) +func (s *commentSrv) GetCommentContentsByIDs(ids []int64) (res []*ms.CommentContent, err error) { + err = s.inSelect(&res, s.q.GetCommentContentsByIds, ids) return res, err } diff --git a/internal/dao/sakila/messages.go b/internal/dao/sakila/messages.go index 1856c496..767e949f 100644 --- a/internal/dao/sakila/messages.go +++ b/internal/dao/sakila/messages.go @@ -10,7 +10,6 @@ import ( "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" - "github.com/rocboss/paopao-ce/pkg/debug" ) var ( @@ -46,10 +45,9 @@ func (s *messageSrv) GetMessageByID(id int64) (*ms.Message, error) { return res, err } -func (s *messageSrv) ReadMessage(message *ms.Message) error { - // TODO - debug.NotImplemented() - return nil +func (s *messageSrv) ReadMessage(message *ms.Message) (err error) { + _, err = s.q.ReadMessage.Exec(message) + return } func (s *messageSrv) GetMessages(r *ms.ConditionsT, offset, limit int) ([]*ms.MessageFormated, error) { diff --git a/internal/dao/sakila/yesql/cc/yesql.go b/internal/dao/sakila/yesql/cc/yesql.go index 2fe296d0..c9da169d 100644 --- a/internal/dao/sakila/yesql/cc/yesql.go +++ b/internal/dao/sakila/yesql/cc/yesql.go @@ -1,6 +1,6 @@ // Code generated by Yesql. DO NOT EDIT. // versions: -// - Yesql v1.3.0 +// - Yesql v1.4.0 package cc @@ -12,139 +12,139 @@ import ( ) const ( - _BeFriendFilter_AuthorizationManage = `SELECT * FROM @user WHERE username=?` - _BeFriendIds_AuthorizationManage = `SELECT * FROM @user WHERE username=?` - _MyFriendSet_AuthorizationManage = `SELECT * FROM @user WHERE username=?` - _GetCommentById_Comment = `SELECT * FROM @user WHERE username=?` - _GetCommentContentsByIds_Comment = `SELECT * FROM @user WHERE username=?` - _GetCommentCount_Comment = `SELECT * FROM @user WHERE username=?` - _GetCommentReplyById_Comment = `SELECT * FROM @user WHERE username=?` - _GetCommentThumbs_Comment = `SELECT * FROM @user WHERE username=?` - _GetComments_Comment = `SELECT * FROM @user WHERE username=?` - _GetCommmentRepliesByIds_Comment = `SELECT * FROM @user WHERE username=?` - _GetUsersByIds_Comment = `SELECT * FROM @user WHERE username=?` - _CreateComment_CommentManage = `SELECT * FROM @user WHERE username=?` - _CreateCommentContent_CommentManage = `SELECT * FROM @user WHERE username=?` - _CreateCommentReply_CommentManage = `SELECT * FROM @user WHERE username=?` - _CreateThumbsUpComment_CommentManage = `SELECT * FROM @user WHERE username=?` - _DeleteComment_CommentManage = `SELECT * FROM @user WHERE username=?` - _DeleteCommentReply_CommentManage = `SELECT * FROM @user WHERE username=?` - _DeleteCommentThumbs_CommentManage = `SELECT * FROM @user WHERE username=?` - _DeleteReplyThumbs_CommentManage = `SELECT * FROM @user WHERE username=?` - _GetCommentReplyThumb_CommentManage = `SELECT * FROM @user WHERE username=?` - _GetTweetCommentThumb_CommentManage = `SELECT * FROM @user WHERE username=?` - _ThumbsDownComment_CommentManage = `SELECT * FROM @user WHERE username=?` - _ThumbsDownReply_CommentManage = `SELECT * FROM @user WHERE username=?` - _ThumbsUpReply_CommentManage = `SELECT * FROM @user WHERE username=?` - _UpdateCommentThumbsCount_CommentManage = `SELECT * FROM @user WHERE username=?` - _UpdateThumbsUpComment_CommentManage = `SELECT * FROM @user WHERE username=?` - _AddFriend_ContactManager = `SELECT * FROM @user WHERE username=?` - _DelFriend_ContactManager = `SELECT * FROM @user WHERE username=?` - _GetContacts_ContactManager = `SELECT * FROM @user WHERE username=?` - _GetUserFriend_ContactManager = `SELECT * FROM @user WHERE username=?` - _RejectFriend_ContactManager = `SELECT * FROM @user WHERE username=?` - _RequestingFriend_ContactManager = `SELECT * FROM @user WHERE username=?` - _TotalContactsById_ContactManager = `SELECT * FROM @user WHERE username=?` - _UserInfo_FollowIndexA = `SELECT * FROM @user WHERE username=?` - _UserInfo_FollowIndex = `SELECT * FROM @user WHERE username=?` - _UserInfo_FriendIndexA = `SELECT * FROM @user WHERE username=?` - _UserInfo_FriendIndex = `SELECT * FROM @user WHERE username=?` - _UserInfo_LightIndexA = `SELECT * FROM @user WHERE username=?` - _UserInfo_LightIndex = `SELECT * FROM @user WHERE username=?` - _CreateMessage_Message = `SELECT * FROM @user WHERE username=?` - _GetMessageById_Message = `SELECT * FROM @user WHERE username=?` - _GetMessageCount_Message = `SELECT * FROM @user WHERE username=?` - _GetMessages_Message = `SELECT * FROM @user WHERE username=?` - _GetUnreadCount_Message = `SELECT * FROM @user WHERE username=?` - _ReadMessage_Message = `SELECT * FROM @user WHERE username=?` - _CreatePhoneCaptcha_Security = `SELECT * FROM @user WHERE username=?` - _GetLatestPhoneCaptcha_Security = `SELECT * FROM @user WHERE username=?` - _SendPhoneCaptcha_Security = `SELECT * FROM @user WHERE username=?` - _UsePhoneCaptcha_Security = `SELECT * FROM @user WHERE username=?` - _UserInfo_SimpleIndexA = `SELECT * FROM @user WHERE username=?` - _UserInfo_SimpleIndex = `SELECT * FROM @user WHERE username=?` - _DecrTagsById_TopicA = `UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?)` - _HotTags_TopicA = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.quote_num DESC LIMIT ? OFFSET ?` - _IncrTagsById_TopicA = `UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?)` - _InsertTag_TopicA = `INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1)` - _NewestTags_TopicA = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.id DESC LIMIT ? OFFSET ?` - _TagsByIdA_TopicA = `SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0` - _TagsByIdB_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?)` - _TagsByKeywordA_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6` - _TagsByKeywordB_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6` - _TagsForIncr_TopicA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` - _AttachmentByTweetId_TweetA = `SELECT * FROM @user WHERE username=?` - _FavoriteByTweetId_TweetA = `SELECT * FROM @user WHERE username=?` - _ReactionByTweetId_TweetA = `SELECT * FROM @user WHERE username=?` - _TweetInfoById_TweetA = `SELECT * FROM @user WHERE username=?` - _TweetItemById_TweetA = `SELECT * FROM @user WHERE username=?` - _UserFavorites_TweetA = `SELECT * FROM @user WHERE username=?` - _UserInfo_TweetA = `SELECT * FROM @user WHERE username=?` - _UserReactions_TweetA = `SELECT * FROM @user WHERE username=?` - _UserTweetsByAdmin_TweetA = `SELECT * FROM @user WHERE username=?` - _UserTweetsByFriend_TweetA = `SELECT * FROM @user WHERE username=?` - _UserTweetsByGuest_TweetA = `SELECT * FROM @user WHERE username=?` - _UserTweetsBySelf_TweetA = `SELECT * FROM @user WHERE username=?` - _GetPostAttachmentBill_Tweet = `SELECT * FROM @user WHERE username=?` - _GetPostById_Tweet = `SELECT * FROM @user WHERE username=?` - _GetPostContentById_Tweet = `SELECT * FROM @user WHERE username=?` - _GetPostContetnsByIds_Tweet = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` - _GetPostCount_Tweet = `SELECT * FROM @user WHERE username=?` - _GetPosts_Tweet = `SELECT * FROM @user WHERE username=?` - _GetUserPostCollection_Tweet = `SELECT * FROM @user WHERE username=?` - _GetUserPostCollectionCount_Tweet = `SELECT * FROM @user WHERE username=?` - _GetUserPostCollections_Tweet = `SELECT * FROM @user WHERE username=?` - _GetUserPostStar_Tweet = `SELECT * FROM @user WHERE username=?` - _GetUserPostStarCount_Tweet = `SELECT * FROM @user WHERE username=?` - _GetUserPostStars_Tweet = `SELECT * FROM @user WHERE username=?` - _UserInfo_TweetHelpA = `SELECT * FROM @user WHERE username=?` - _GetPostContentByIds_TweetHelp = `SELECT * FROM @user WHERE username=?` - _GetUsersByIds_TweetHelp = `SELECT * FROM @user WHERE username=?` - _UserInfo_TweetManageA = `SELECT * FROM @user WHERE username=?` - _AddAttachment_TweetManage = `SELECT * FROM @user WHERE username=?` - _AddPost_TweetManage = `SELECT * FROM @user WHERE username=?` - _AddPostCollection_TweetManage = `SELECT * FROM @user WHERE username=?` - _AddPostContent_TweetManage = `SELECT * FROM @user WHERE username=?` - _AddPostStar_TweetManage = `SELECT * FROM @user WHERE username=?` - _DelPost_TweetManage = `SELECT * FROM @user WHERE username=?` - _DelPostCollection_TweetManage = `SELECT * FROM @user WHERE username=?` - _DelPostStar_TweetManage = `SELECT * FROM @user WHERE username=?` - _LockPost_TweetManage = `SELECT * FROM @user WHERE username=?` - _StickPost_TweetManage = `SELECT * FROM @user WHERE username=?` - _UpdatePost_TweetManage = `SELECT * FROM @user WHERE username=?` - _VisiblePost_TweetManage = `SELECT * FROM @user WHERE username=?` - _AddUser_UserManage = `SELECT * FROM @user WHERE username=?` - _GetUserById_UserManage = `SELECT * FROM @user WHERE username=?` - _GetUserByPhone_UserManage = `SELECT * FROM @user WHERE username=?` - _GetUserByUsername_UserManage = `SELECT * FROM @user WHERE username=?` - _GetUsersByIds_UserManage = `SELECT * FROM @user WHERE username=?` - _GetUsersByKeyword_UserManage = `SELECT * FROM @user WHERE username=?` - _UpdateUser_UserManage = `SELECT * FROM @user WHERE username=?` - _CreateRecharge_Wallet = `SELECT * FROM @user WHERE username=?` - _GetRechargeById_Wallet = `SELECT * FROM @user WHERE username=?` - _GetUserWalletBillCount_Wallet = `SELECT * FROM @user WHERE username=?` - _GetUserWalletBills_Wallet = `SELECT * FROM @user WHERE username=?` - _HandlePostAttachementBought_Wallet = `SELECT * FROM @user WHERE username=?` - _HandleRechargeSuccess_Wallet = `SELECT * FROM @user WHERE username=?` + _AuthorizationManage_BeFriendIds = `SELECT user_id FROM @contact WHERE friend_id=? AND status=2 AND is_del=0` + _AuthorizationManage_IsFriend = `SELECT status FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0` + _AuthorizationManage_MyFriendSet = `SELECT friend_id FROM @contact WHERE user_id=? AND status=2 AND is_del=0` + _Comment_GetCommentById = `SELECT * FROM @comment WHERE id=? AND is_del=0` + _Comment_GetCommentContentsByIds = `SELECT * FROM @comment_content WHERE comment_id IN ?` + _Comment_GetCommentCount = `SELECT count(*) FROM @comment WHERE post_id=:post_id AND is_del=0` + _Comment_GetCommentReplyById = `SELECT * FROM @comment_reply WHERE id=? AND is_del=0` + _Comment_GetCommentThumbs = `SELECT * FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=?` + _Comment_GetComments = `SELECT * FROM @comment WHERE post_id=? AND is_del=0 ORDER BY %order% LIMIT ? OFFSET ?` + _Comment_GetCommmentRepliesByIds = `SELECT * FROM @comment_reply WHERE comment_id IN ? ORDER BY id ASC` + _Comment_GetUsersByIds = `SELECT id, nickname, username, status, avatar, is_admin FROM @user WHERE id IN ?` + _CommentManage_CreateComment = `SELECT * FROM @user WHERE username=?` + _CommentManage_CreateCommentContent = `SELECT * FROM @user WHERE username=?` + _CommentManage_CreateCommentReply = `SELECT * FROM @user WHERE username=?` + _CommentManage_CreateThumbsUpComment = `SELECT * FROM @user WHERE username=?` + _CommentManage_DeleteComment = `SELECT * FROM @user WHERE username=?` + _CommentManage_DeleteCommentReply = `SELECT * FROM @user WHERE username=?` + _CommentManage_DeleteCommentThumbs = `SELECT * FROM @user WHERE username=?` + _CommentManage_DeleteReplyThumbs = `SELECT * FROM @user WHERE username=?` + _CommentManage_GetCommentReplyThumb = `SELECT * FROM @user WHERE username=?` + _CommentManage_GetTweetCommentThumb = `SELECT * FROM @user WHERE username=?` + _CommentManage_ThumbsDownComment = `SELECT * FROM @user WHERE username=?` + _CommentManage_ThumbsDownReply = `SELECT * FROM @user WHERE username=?` + _CommentManage_ThumbsUpReply = `SELECT * FROM @user WHERE username=?` + _CommentManage_UpdateCommentThumbsCount = `SELECT * FROM @user WHERE username=?` + _CommentManage_UpdateThumbsUpComment = `SELECT * FROM @user WHERE username=?` + _ContactManager_AddFriend = `SELECT * FROM @user WHERE username=?` + _ContactManager_DelFriend = `SELECT * FROM @user WHERE username=?` + _ContactManager_GetContacts = `SELECT * FROM @user WHERE username=?` + _ContactManager_GetUserFriend = `SELECT * FROM @user WHERE username=?` + _ContactManager_RejectFriend = `SELECT * FROM @user WHERE username=?` + _ContactManager_RequestingFriend = `SELECT * FROM @user WHERE username=?` + _ContactManager_TotalContactsById = `SELECT * FROM @user WHERE username=?` + _FollowIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` + _FollowIndex_UserInfo = `SELECT * FROM @user WHERE username=?` + _FriendIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` + _FriendIndex_UserInfo = `SELECT * FROM @user WHERE username=?` + _LightIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` + _LightIndex_UserInfo = `SELECT * FROM @user WHERE username=?` + _Message_CreateMessage = `SELECT * FROM @user WHERE username=?` + _Message_GetMessageById = `SELECT * FROM @user WHERE username=?` + _Message_GetMessageCount = `SELECT * FROM @user WHERE username=?` + _Message_GetMessages = `SELECT * FROM @user WHERE username=?` + _Message_GetUnreadCount = `SELECT * FROM @user WHERE username=?` + _Message_ReadMessage = `SELECT * FROM @user WHERE username=?` + _Security_CreatePhoneCaptcha = `SELECT * FROM @user WHERE username=?` + _Security_GetLatestPhoneCaptcha = `SELECT * FROM @user WHERE username=?` + _Security_SendPhoneCaptcha = `SELECT * FROM @user WHERE username=?` + _Security_UsePhoneCaptcha = `SELECT * FROM @user WHERE username=?` + _SimpleIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` + _SimpleIndex_UserInfo = `SELECT * FROM @user WHERE username=?` + _TopicA_DecrTagsById = `UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?)` + _TopicA_HotTags = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.quote_num DESC LIMIT ? OFFSET ?` + _TopicA_IncrTagsById = `UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?)` + _TopicA_InsertTag = `INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1)` + _TopicA_NewestTags = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.id DESC LIMIT ? OFFSET ?` + _TopicA_TagsByIdA = `SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0` + _TopicA_TagsByIdB = `SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?)` + _TopicA_TagsByKeywordA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6` + _TopicA_TagsByKeywordB = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6` + _TopicA_TagsForIncr = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` + _TweetA_AttachmentByTweetId = `SELECT * FROM @user WHERE username=?` + _TweetA_FavoriteByTweetId = `SELECT * FROM @user WHERE username=?` + _TweetA_ReactionByTweetId = `SELECT * FROM @user WHERE username=?` + _TweetA_TweetInfoById = `SELECT * FROM @user WHERE username=?` + _TweetA_TweetItemById = `SELECT * FROM @user WHERE username=?` + _TweetA_UserFavorites = `SELECT * FROM @user WHERE username=?` + _TweetA_UserInfo = `SELECT * FROM @user WHERE username=?` + _TweetA_UserReactions = `SELECT * FROM @user WHERE username=?` + _TweetA_UserTweetsByAdmin = `SELECT * FROM @user WHERE username=?` + _TweetA_UserTweetsByFriend = `SELECT * FROM @user WHERE username=?` + _TweetA_UserTweetsByGuest = `SELECT * FROM @user WHERE username=?` + _TweetA_UserTweetsBySelf = `SELECT * FROM @user WHERE username=?` + _Tweet_GetPostAttachmentBill = `SELECT * FROM @user WHERE username=?` + _Tweet_GetPostById = `SELECT * FROM @user WHERE username=?` + _Tweet_GetPostContentById = `SELECT * FROM @user WHERE username=?` + _Tweet_GetPostContetnsByIds = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` + _Tweet_GetPostCount = `SELECT * FROM @user WHERE username=?` + _Tweet_GetPosts = `SELECT * FROM @user WHERE username=?` + _Tweet_GetUserPostCollection = `SELECT * FROM @user WHERE username=?` + _Tweet_GetUserPostCollectionCount = `SELECT * FROM @user WHERE username=?` + _Tweet_GetUserPostCollections = `SELECT * FROM @user WHERE username=?` + _Tweet_GetUserPostStar = `SELECT * FROM @user WHERE username=?` + _Tweet_GetUserPostStarCount = `SELECT * FROM @user WHERE username=?` + _Tweet_GetUserPostStars = `SELECT * FROM @user WHERE username=?` + _TweetHelpA_UserInfo = `SELECT * FROM @user WHERE username=?` + _TweetHelp_GetPostContentByIds = `SELECT * FROM @user WHERE username=?` + _TweetHelp_GetUsersByIds = `SELECT * FROM @user WHERE username=?` + _TweetManageA_UserInfo = `SELECT * FROM @user WHERE username=?` + _TweetManage_AddAttachment = `SELECT * FROM @user WHERE username=?` + _TweetManage_AddPost = `SELECT * FROM @user WHERE username=?` + _TweetManage_AddPostCollection = `SELECT * FROM @user WHERE username=?` + _TweetManage_AddPostContent = `SELECT * FROM @user WHERE username=?` + _TweetManage_AddPostStar = `SELECT * FROM @user WHERE username=?` + _TweetManage_DelPost = `SELECT * FROM @user WHERE username=?` + _TweetManage_DelPostCollection = `SELECT * FROM @user WHERE username=?` + _TweetManage_DelPostStar = `SELECT * FROM @user WHERE username=?` + _TweetManage_LockPost = `SELECT * FROM @user WHERE username=?` + _TweetManage_StickPost = `SELECT * FROM @user WHERE username=?` + _TweetManage_UpdatePost = `SELECT * FROM @user WHERE username=?` + _TweetManage_VisiblePost = `SELECT * FROM @user WHERE username=?` + _UserManage_AddUser = `SELECT * FROM @user WHERE username=?` + _UserManage_GetUserById = `SELECT * FROM @user WHERE username=?` + _UserManage_GetUserByPhone = `SELECT * FROM @user WHERE username=?` + _UserManage_GetUserByUsername = `SELECT * FROM @user WHERE username=?` + _UserManage_GetUsersByIds = `SELECT * FROM @user WHERE username=?` + _UserManage_GetUsersByKeyword = `SELECT * FROM @user WHERE username=?` + _UserManage_UpdateUser = `SELECT * FROM @user WHERE username=?` + _Wallet_CreateRecharge = `SELECT * FROM @user WHERE username=?` + _Wallet_GetRechargeById = `SELECT * FROM @user WHERE username=?` + _Wallet_GetUserWalletBillCount = `SELECT * FROM @user WHERE username=?` + _Wallet_GetUserWalletBills = `SELECT * FROM @user WHERE username=?` + _Wallet_HandlePostAttachementBought = `SELECT * FROM @user WHERE username=?` + _Wallet_HandleRechargeSuccess = `SELECT * FROM @user WHERE username=?` ) type AuthorizationManage struct { yesql.Namespace `yesql:"authorization_manage"` - BeFriendFilter *sqlx.Stmt `yesql:"be_friend_filter"` BeFriendIds *sqlx.Stmt `yesql:"be_friend_ids"` + IsFriend *sqlx.Stmt `yesql:"is_friend"` MyFriendSet *sqlx.Stmt `yesql:"my_friend_set"` } type Comment struct { yesql.Namespace `yesql:"comment"` GetCommentContentsByIds string `yesql:"get_comment_contents_by_ids"` + GetComments string `yesql:"get_comments"` GetCommmentRepliesByIds string `yesql:"get_commment_replies_by_ids"` GetUsersByIds string `yesql:"get_users_by_ids"` GetCommentById *sqlx.Stmt `yesql:"get_comment_by_id"` GetCommentReplyById *sqlx.Stmt `yesql:"get_comment_reply_by_id"` GetCommentThumbs *sqlx.Stmt `yesql:"get_comment_thumbs"` GetCommentCount *sqlx.NamedStmt `yesql:"get_comment_count"` - GetComments *sqlx.NamedStmt `yesql:"get_comments"` } type CommentManage struct { @@ -211,10 +211,10 @@ type Message struct { yesql.Namespace `yesql:"message"` GetMessageById *sqlx.Stmt `yesql:"get_message_by_id"` GetUnreadCount *sqlx.Stmt `yesql:"get_unread_count"` - ReadMessage *sqlx.Stmt `yesql:"read_message"` CreateMessage *sqlx.NamedStmt `yesql:"create_message"` GetMessageCount *sqlx.NamedStmt `yesql:"get_message_count"` GetMessages *sqlx.NamedStmt `yesql:"get_messages"` + ReadMessage *sqlx.NamedStmt `yesql:"read_message"` } type Security struct { @@ -342,13 +342,13 @@ func BuildAuthorizationManage(p yesql.PreparexBuilder, ctx ...context.Context) ( c = context.Background() } obj = &AuthorizationManage{} - if obj.BeFriendFilter, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_BeFriendFilter_AuthorizationManage))); err != nil { + if obj.BeFriendIds, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AuthorizationManage_BeFriendIds))); err != nil { return } - if obj.BeFriendIds, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_BeFriendIds_AuthorizationManage))); err != nil { + if obj.IsFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AuthorizationManage_IsFriend))); err != nil { return } - if obj.MyFriendSet, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_MyFriendSet_AuthorizationManage))); err != nil { + if obj.MyFriendSet, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AuthorizationManage_MyFriendSet))); err != nil { return } return @@ -362,23 +362,21 @@ func BuildComment(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Comment c = context.Background() } obj = &Comment{ - GetCommentContentsByIds: p.QueryHook(_GetCommentContentsByIds_Comment), - GetCommmentRepliesByIds: p.QueryHook(_GetCommmentRepliesByIds_Comment), - GetUsersByIds: p.QueryHook(_GetUsersByIds_Comment), + GetCommentContentsByIds: p.QueryHook(_Comment_GetCommentContentsByIds), + GetComments: p.QueryHook(_Comment_GetComments), + GetCommmentRepliesByIds: p.QueryHook(_Comment_GetCommmentRepliesByIds), + GetUsersByIds: p.QueryHook(_Comment_GetUsersByIds), } - if obj.GetCommentById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetCommentById_Comment))); err != nil { + if obj.GetCommentById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Comment_GetCommentById))); err != nil { return } - if obj.GetCommentReplyById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetCommentReplyById_Comment))); err != nil { + if obj.GetCommentReplyById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Comment_GetCommentReplyById))); err != nil { return } - if obj.GetCommentThumbs, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetCommentThumbs_Comment))); err != nil { + if obj.GetCommentThumbs, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Comment_GetCommentThumbs))); err != nil { return } - if obj.GetCommentCount, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_GetCommentCount_Comment))); err != nil { - return - } - if obj.GetComments, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_GetComments_Comment))); err != nil { + if obj.GetCommentCount, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_Comment_GetCommentCount))); err != nil { return } return @@ -392,49 +390,49 @@ func BuildCommentManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *C c = context.Background() } obj = &CommentManage{} - if obj.DeleteComment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_DeleteComment_CommentManage))); err != nil { + if obj.DeleteComment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_DeleteComment))); err != nil { return } - if obj.DeleteCommentReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_DeleteCommentReply_CommentManage))); err != nil { + if obj.DeleteCommentReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_DeleteCommentReply))); err != nil { return } - if obj.DeleteCommentThumbs, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_DeleteCommentThumbs_CommentManage))); err != nil { + if obj.DeleteCommentThumbs, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_DeleteCommentThumbs))); err != nil { return } - if obj.DeleteReplyThumbs, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_DeleteReplyThumbs_CommentManage))); err != nil { + if obj.DeleteReplyThumbs, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_DeleteReplyThumbs))); err != nil { return } - if obj.GetCommentReplyThumb, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetCommentReplyThumb_CommentManage))); err != nil { + if obj.GetCommentReplyThumb, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_GetCommentReplyThumb))); err != nil { return } - if obj.GetTweetCommentThumb, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetTweetCommentThumb_CommentManage))); err != nil { + if obj.GetTweetCommentThumb, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_GetTweetCommentThumb))); err != nil { return } - if obj.ThumbsDownComment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ThumbsDownComment_CommentManage))); err != nil { + if obj.ThumbsDownComment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_ThumbsDownComment))); err != nil { return } - if obj.ThumbsDownReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ThumbsDownReply_CommentManage))); err != nil { + if obj.ThumbsDownReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_ThumbsDownReply))); err != nil { return } - if obj.ThumbsUpReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ThumbsUpReply_CommentManage))); err != nil { + if obj.ThumbsUpReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_ThumbsUpReply))); err != nil { return } - if obj.UpdateCommentThumbsCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UpdateCommentThumbsCount_CommentManage))); err != nil { + if obj.UpdateCommentThumbsCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_UpdateCommentThumbsCount))); err != nil { return } - if obj.CreateComment, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CreateComment_CommentManage))); err != nil { + if obj.CreateComment, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CommentManage_CreateComment))); err != nil { return } - if obj.CreateCommentContent, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CreateCommentContent_CommentManage))); err != nil { + if obj.CreateCommentContent, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CommentManage_CreateCommentContent))); err != nil { return } - if obj.CreateCommentReply, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CreateCommentReply_CommentManage))); err != nil { + if obj.CreateCommentReply, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CommentManage_CreateCommentReply))); err != nil { return } - if obj.CreateThumbsUpComment, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CreateThumbsUpComment_CommentManage))); err != nil { + if obj.CreateThumbsUpComment, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CommentManage_CreateThumbsUpComment))); err != nil { return } - if obj.UpdateThumbsUpComment, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_UpdateThumbsUpComment_CommentManage))); err != nil { + if obj.UpdateThumbsUpComment, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CommentManage_UpdateThumbsUpComment))); err != nil { return } return @@ -448,25 +446,25 @@ func BuildContactManager(p yesql.PreparexBuilder, ctx ...context.Context) (obj * c = context.Background() } obj = &ContactManager{} - if obj.AddFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AddFriend_ContactManager))); err != nil { + if obj.AddFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_AddFriend))); err != nil { return } - if obj.DelFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_DelFriend_ContactManager))); err != nil { + if obj.DelFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_DelFriend))); err != nil { return } - if obj.GetContacts, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetContacts_ContactManager))); err != nil { + if obj.GetContacts, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_GetContacts))); err != nil { return } - if obj.GetUserFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserFriend_ContactManager))); err != nil { + if obj.GetUserFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_GetUserFriend))); err != nil { return } - if obj.RejectFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_RejectFriend_ContactManager))); err != nil { + if obj.RejectFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_RejectFriend))); err != nil { return } - if obj.RequestingFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_RequestingFriend_ContactManager))); err != nil { + if obj.RequestingFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_RequestingFriend))); err != nil { return } - if obj.TotalContactsById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TotalContactsById_ContactManager))); err != nil { + if obj.TotalContactsById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_TotalContactsById))); err != nil { return } return @@ -480,7 +478,7 @@ func BuildFollowIndex(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Fol c = context.Background() } obj = &FollowIndex{} - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_FollowIndex))); err != nil { + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_FollowIndex_UserInfo))); err != nil { return } return @@ -494,7 +492,7 @@ func BuildFollowIndexA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Fo c = context.Background() } obj = &FollowIndexA{} - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_FollowIndexA))); err != nil { + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_FollowIndexA_UserInfo))); err != nil { return } return @@ -508,7 +506,7 @@ func BuildFriendIndex(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Fri c = context.Background() } obj = &FriendIndex{} - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_FriendIndex))); err != nil { + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_FriendIndex_UserInfo))); err != nil { return } return @@ -522,7 +520,7 @@ func BuildFriendIndexA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Fr c = context.Background() } obj = &FriendIndexA{} - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_FriendIndexA))); err != nil { + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_FriendIndexA_UserInfo))); err != nil { return } return @@ -536,7 +534,7 @@ func BuildLightIndex(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Ligh c = context.Background() } obj = &LightIndex{} - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_LightIndex))); err != nil { + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_LightIndex_UserInfo))); err != nil { return } return @@ -550,7 +548,7 @@ func BuildLightIndexA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Lig c = context.Background() } obj = &LightIndexA{} - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_LightIndexA))); err != nil { + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_LightIndexA_UserInfo))); err != nil { return } return @@ -564,22 +562,22 @@ func BuildMessage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Message c = context.Background() } obj = &Message{} - if obj.GetMessageById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetMessageById_Message))); err != nil { + if obj.GetMessageById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_GetMessageById))); err != nil { return } - if obj.GetUnreadCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUnreadCount_Message))); err != nil { + if obj.GetUnreadCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_GetUnreadCount))); err != nil { return } - if obj.ReadMessage, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ReadMessage_Message))); err != nil { + if obj.CreateMessage, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_Message_CreateMessage))); err != nil { return } - if obj.CreateMessage, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CreateMessage_Message))); err != nil { + if obj.GetMessageCount, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_Message_GetMessageCount))); err != nil { return } - if obj.GetMessageCount, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_GetMessageCount_Message))); err != nil { + if obj.GetMessages, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_Message_GetMessages))); err != nil { return } - if obj.GetMessages, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_GetMessages_Message))); err != nil { + if obj.ReadMessage, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_Message_ReadMessage))); err != nil { return } return @@ -593,16 +591,16 @@ func BuildSecurity(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Securi c = context.Background() } obj = &Security{} - if obj.GetLatestPhoneCaptcha, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetLatestPhoneCaptcha_Security))); err != nil { + if obj.GetLatestPhoneCaptcha, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Security_GetLatestPhoneCaptcha))); err != nil { return } - if obj.SendPhoneCaptcha, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_SendPhoneCaptcha_Security))); err != nil { + if obj.SendPhoneCaptcha, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Security_SendPhoneCaptcha))); err != nil { return } - if obj.CreatePhoneCaptcha, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CreatePhoneCaptcha_Security))); err != nil { + if obj.CreatePhoneCaptcha, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_Security_CreatePhoneCaptcha))); err != nil { return } - if obj.UsePhoneCaptcha, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_UsePhoneCaptcha_Security))); err != nil { + if obj.UsePhoneCaptcha, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_Security_UsePhoneCaptcha))); err != nil { return } return @@ -616,7 +614,7 @@ func BuildSimpleIndex(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Sim c = context.Background() } obj = &SimpleIndex{} - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_SimpleIndex))); err != nil { + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_SimpleIndex_UserInfo))); err != nil { return } return @@ -630,7 +628,7 @@ func BuildSimpleIndexA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Si c = context.Background() } obj = &SimpleIndexA{} - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_SimpleIndexA))); err != nil { + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_SimpleIndexA_UserInfo))); err != nil { return } return @@ -644,25 +642,25 @@ func BuildTopicA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *TopicA, c = context.Background() } obj = &TopicA{ - DecrTagsById: p.QueryHook(_DecrTagsById_TopicA), - IncrTagsById: p.QueryHook(_IncrTagsById_TopicA), - TagsByIdA: p.QueryHook(_TagsByIdA_TopicA), - TagsByIdB: p.QueryHook(_TagsByIdB_TopicA), - TagsForIncr: p.QueryHook(_TagsForIncr_TopicA), + DecrTagsById: p.QueryHook(_TopicA_DecrTagsById), + IncrTagsById: p.QueryHook(_TopicA_IncrTagsById), + TagsByIdA: p.QueryHook(_TopicA_TagsByIdA), + TagsByIdB: p.QueryHook(_TopicA_TagsByIdB), + TagsForIncr: p.QueryHook(_TopicA_TagsForIncr), } - if obj.HotTags, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_HotTags_TopicA))); err != nil { + if obj.HotTags, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_HotTags))); err != nil { return } - if obj.InsertTag, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_InsertTag_TopicA))); err != nil { + if obj.InsertTag, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_InsertTag))); err != nil { return } - if obj.NewestTags, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_NewestTags_TopicA))); err != nil { + if obj.NewestTags, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_NewestTags))); err != nil { return } - if obj.TagsByKeywordA, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TagsByKeywordA_TopicA))); err != nil { + if obj.TagsByKeywordA, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_TagsByKeywordA))); err != nil { return } - if obj.TagsByKeywordB, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TagsByKeywordB_TopicA))); err != nil { + if obj.TagsByKeywordB, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TopicA_TagsByKeywordB))); err != nil { return } return @@ -676,39 +674,39 @@ func BuildTweet(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Tweet, er c = context.Background() } obj = &Tweet{ - GetPostContetnsByIds: p.QueryHook(_GetPostContetnsByIds_Tweet), + GetPostContetnsByIds: p.QueryHook(_Tweet_GetPostContetnsByIds), } - if obj.GetPostAttachmentBill, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetPostAttachmentBill_Tweet))); err != nil { + if obj.GetPostAttachmentBill, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetPostAttachmentBill))); err != nil { return } - if obj.GetPostById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetPostById_Tweet))); err != nil { + if obj.GetPostById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetPostById))); err != nil { return } - if obj.GetPostContentById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetPostContentById_Tweet))); err != nil { + if obj.GetPostContentById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetPostContentById))); err != nil { return } - if obj.GetPostCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetPostCount_Tweet))); err != nil { + if obj.GetPostCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetPostCount))); err != nil { return } - if obj.GetPosts, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetPosts_Tweet))); err != nil { + if obj.GetPosts, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetPosts))); err != nil { return } - if obj.GetUserPostCollection, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserPostCollection_Tweet))); err != nil { + if obj.GetUserPostCollection, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetUserPostCollection))); err != nil { return } - if obj.GetUserPostCollectionCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserPostCollectionCount_Tweet))); err != nil { + if obj.GetUserPostCollectionCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetUserPostCollectionCount))); err != nil { return } - if obj.GetUserPostCollections, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserPostCollections_Tweet))); err != nil { + if obj.GetUserPostCollections, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetUserPostCollections))); err != nil { return } - if obj.GetUserPostStar, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserPostStar_Tweet))); err != nil { + if obj.GetUserPostStar, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetUserPostStar))); err != nil { return } - if obj.GetUserPostStarCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserPostStarCount_Tweet))); err != nil { + if obj.GetUserPostStarCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetUserPostStarCount))); err != nil { return } - if obj.GetUserPostStars, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserPostStars_Tweet))); err != nil { + if obj.GetUserPostStars, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetUserPostStars))); err != nil { return } return @@ -722,40 +720,40 @@ func BuildTweetA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *TweetA, c = context.Background() } obj = &TweetA{} - if obj.AttachmentByTweetId, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AttachmentByTweetId_TweetA))); err != nil { + if obj.AttachmentByTweetId, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_AttachmentByTweetId))); err != nil { return } - if obj.FavoriteByTweetId, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_FavoriteByTweetId_TweetA))); err != nil { + if obj.FavoriteByTweetId, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_FavoriteByTweetId))); err != nil { return } - if obj.ReactionByTweetId, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ReactionByTweetId_TweetA))); err != nil { + if obj.ReactionByTweetId, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_ReactionByTweetId))); err != nil { return } - if obj.TweetInfoById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetInfoById_TweetA))); err != nil { + if obj.TweetInfoById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_TweetInfoById))); err != nil { return } - if obj.TweetItemById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetItemById_TweetA))); err != nil { + if obj.TweetItemById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_TweetItemById))); err != nil { return } - if obj.UserFavorites, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserFavorites_TweetA))); err != nil { + if obj.UserFavorites, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_UserFavorites))); err != nil { return } - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_TweetA))); err != nil { + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_UserInfo))); err != nil { return } - if obj.UserReactions, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserReactions_TweetA))); err != nil { + if obj.UserReactions, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_UserReactions))); err != nil { return } - if obj.UserTweetsByAdmin, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserTweetsByAdmin_TweetA))); err != nil { + if obj.UserTweetsByAdmin, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_UserTweetsByAdmin))); err != nil { return } - if obj.UserTweetsByFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserTweetsByFriend_TweetA))); err != nil { + if obj.UserTweetsByFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_UserTweetsByFriend))); err != nil { return } - if obj.UserTweetsByGuest, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserTweetsByGuest_TweetA))); err != nil { + if obj.UserTweetsByGuest, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_UserTweetsByGuest))); err != nil { return } - if obj.UserTweetsBySelf, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserTweetsBySelf_TweetA))); err != nil { + if obj.UserTweetsBySelf, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetA_UserTweetsBySelf))); err != nil { return } return @@ -763,8 +761,8 @@ func BuildTweetA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *TweetA, func BuildTweetHelp(p yesql.PreparexBuilder) (obj *TweetHelp, err error) { obj = &TweetHelp{ - GetPostContentByIds: p.QueryHook(_GetPostContentByIds_TweetHelp), - GetUsersByIds: p.QueryHook(_GetUsersByIds_TweetHelp), + GetPostContentByIds: p.QueryHook(_TweetHelp_GetPostContentByIds), + GetUsersByIds: p.QueryHook(_TweetHelp_GetUsersByIds), } return } @@ -777,7 +775,7 @@ func BuildTweetHelpA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Twee c = context.Background() } obj = &TweetHelpA{} - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_TweetHelpA))); err != nil { + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetHelpA_UserInfo))); err != nil { return } return @@ -791,40 +789,40 @@ func BuildTweetManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Twe c = context.Background() } obj = &TweetManage{} - if obj.AddAttachment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AddAttachment_TweetManage))); err != nil { + if obj.AddAttachment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_AddAttachment))); err != nil { return } - if obj.AddPost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AddPost_TweetManage))); err != nil { + if obj.AddPost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_AddPost))); err != nil { return } - if obj.AddPostCollection, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AddPostCollection_TweetManage))); err != nil { + if obj.AddPostCollection, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_AddPostCollection))); err != nil { return } - if obj.AddPostContent, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AddPostContent_TweetManage))); err != nil { + if obj.AddPostContent, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_AddPostContent))); err != nil { return } - if obj.AddPostStar, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AddPostStar_TweetManage))); err != nil { + if obj.AddPostStar, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_AddPostStar))); err != nil { return } - if obj.DelPost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_DelPost_TweetManage))); err != nil { + if obj.DelPost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_DelPost))); err != nil { return } - if obj.DelPostCollection, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_DelPostCollection_TweetManage))); err != nil { + if obj.DelPostCollection, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_DelPostCollection))); err != nil { return } - if obj.DelPostStar, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_DelPostStar_TweetManage))); err != nil { + if obj.DelPostStar, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_DelPostStar))); err != nil { return } - if obj.LockPost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_LockPost_TweetManage))); err != nil { + if obj.LockPost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_LockPost))); err != nil { return } - if obj.StickPost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_StickPost_TweetManage))); err != nil { + if obj.StickPost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_StickPost))); err != nil { return } - if obj.UpdatePost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UpdatePost_TweetManage))); err != nil { + if obj.UpdatePost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_UpdatePost))); err != nil { return } - if obj.VisiblePost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_VisiblePost_TweetManage))); err != nil { + if obj.VisiblePost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_VisiblePost))); err != nil { return } return @@ -838,7 +836,7 @@ func BuildTweetManageA(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Tw c = context.Background() } obj = &TweetManageA{} - if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserInfo_TweetManageA))); err != nil { + if obj.UserInfo, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManageA_UserInfo))); err != nil { return } return @@ -852,24 +850,24 @@ func BuildUserManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *User c = context.Background() } obj = &UserManage{ - GetUsersByIds: p.QueryHook(_GetUsersByIds_UserManage), + GetUsersByIds: p.QueryHook(_UserManage_GetUsersByIds), } - if obj.AddUser, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_AddUser_UserManage))); err != nil { + if obj.AddUser, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserManage_AddUser))); err != nil { return } - if obj.GetUserById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserById_UserManage))); err != nil { + if obj.GetUserById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserManage_GetUserById))); err != nil { return } - if obj.GetUserByPhone, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserByPhone_UserManage))); err != nil { + if obj.GetUserByPhone, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserManage_GetUserByPhone))); err != nil { return } - if obj.GetUserByUsername, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserByUsername_UserManage))); err != nil { + if obj.GetUserByUsername, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserManage_GetUserByUsername))); err != nil { return } - if obj.GetUsersByKeyword, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUsersByKeyword_UserManage))); err != nil { + if obj.GetUsersByKeyword, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserManage_GetUsersByKeyword))); err != nil { return } - if obj.UpdateUser, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UpdateUser_UserManage))); err != nil { + if obj.UpdateUser, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserManage_UpdateUser))); err != nil { return } return @@ -883,22 +881,22 @@ func BuildWallet(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Wallet, c = context.Background() } obj = &Wallet{} - if obj.CreateRecharge, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CreateRecharge_Wallet))); err != nil { + if obj.CreateRecharge, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_CreateRecharge))); err != nil { return } - if obj.GetRechargeById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetRechargeById_Wallet))); err != nil { + if obj.GetRechargeById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_GetRechargeById))); err != nil { return } - if obj.GetUserWalletBillCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserWalletBillCount_Wallet))); err != nil { + if obj.GetUserWalletBillCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_GetUserWalletBillCount))); err != nil { return } - if obj.GetUserWalletBills, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_GetUserWalletBills_Wallet))); err != nil { + if obj.GetUserWalletBills, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_GetUserWalletBills))); err != nil { return } - if obj.HandlePostAttachementBought, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_HandlePostAttachementBought_Wallet))); err != nil { + if obj.HandlePostAttachementBought, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_HandlePostAttachementBought))); err != nil { return } - if obj.HandleRechargeSuccess, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_HandleRechargeSuccess_Wallet))); err != nil { + if obj.HandleRechargeSuccess, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_HandleRechargeSuccess))); err != nil { return } return diff --git a/internal/dao/sakila/yesql/yesql.sql b/internal/dao/sakila/yesql/yesql.sql index 3d177a97..5603e3ab 100644 --- a/internal/dao/sakila/yesql/yesql.sql +++ b/internal/dao/sakila/yesql/yesql.sql @@ -2,56 +2,56 @@ -- authorization_manage sql dml -------------------------------------------------------------------------------- --- name: be_friend_filter@authorization_manage --- prepare: stmt -SELECT * FROM @user WHERE username=? - -- name: be_friend_ids@authorization_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT user_id FROM @contact WHERE friend_id=? AND status=2 AND is_del=0; -- name: my_friend_set@authorization_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT friend_id FROM @contact WHERE user_id=? AND status=2 AND is_del=0; + +-- name: is_friend@authorization_manage +-- prepare: stmt +SELECT status FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0; -------------------------------------------------------------------------------- -- comment sql dml -------------------------------------------------------------------------------- -- name: get_comments@comment --- prepare: named_stmt -SELECT * FROM @user WHERE username=? +-- prepare: raw +SELECT * FROM @comment WHERE post_id=? AND is_del=0 ORDER BY %order% LIMIT ? OFFSET ?; -- name: get_comment_by_id@comment -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT * FROM @comment WHERE id=? AND is_del=0; -- name: get_comment_count@comment -- prepare: named_stmt -SELECT * FROM @user WHERE username=? +SELECT count(*) FROM @comment WHERE post_id=:post_id AND is_del=0; -- name: get_comment_reply_by_id@comment -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT * FROM @comment_reply WHERE id=? AND is_del=0; -- name: get_comment_contents_by_ids@comment -- prepare: raw -- clause: in -SELECT * FROM @user WHERE username=? +SELECT * FROM @comment_content WHERE comment_id IN ?; -- name: get_commment_replies_by_ids@comment -- prepare: raw -- clause: in -SELECT * FROM @user WHERE username=? +SELECT * FROM @comment_reply WHERE comment_id IN ? ORDER BY id ASC; -- name: get_users_by_ids@comment -- prepare: raw -- clause: in -SELECT * FROM @user WHERE username=? +SELECT id, nickname, username, status, avatar, is_admin FROM @user WHERE id IN ?; -- name: get_comment_thumbs@comment -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT * FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=?; -------------------------------------------------------------------------------- -- comment_manage sql dml @@ -166,7 +166,7 @@ SELECT * FROM @user WHERE username=? SELECT * FROM @user WHERE username=? -- name: read_message@message --- prepare: stmt +-- prepare: named_stmt SELECT * FROM @user WHERE username=? -- name: get_messages@message From 86ebc3b8e638c014f780dd183824ac9032aad893 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Tue, 1 Aug 2023 08:54:35 +0800 Subject: [PATCH 09/19] upgrade github.com/alimy/yesql => v1.5.0 --- go.mod | 2 +- go.sum | 4 ++-- internal/dao/sakila/yesql/cc/yesql.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 1a548302..390155d2 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/afocus/captcha v0.0.0-20191010092841-4bd1f21c8868 github.com/alimy/cfg v0.4.0 github.com/alimy/mir/v4 v4.0.0 - github.com/alimy/yesql v1.4.0 + github.com/alimy/yesql v1.5.0 github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible github.com/allegro/bigcache/v3 v3.1.0 github.com/bufbuild/connect-go v1.9.0 diff --git a/go.sum b/go.sum index db207893..36a41f70 100644 --- a/go.sum +++ b/go.sum @@ -127,8 +127,8 @@ github.com/alimy/cfg v0.4.0 h1:SslKPndmxRViT1ePWLmNsEq7okYP0GVeuowQlRWZPkw= github.com/alimy/cfg v0.4.0/go.mod h1:rOxbasTH2srl6StAjNF5Vyi8bfrdkl3fLGmOYtSw81c= github.com/alimy/mir/v4 v4.0.0 h1:MzGfmoLjjvR69jbZEmpKJO3tUuqB0RGRv1UWPbtukBg= github.com/alimy/mir/v4 v4.0.0/go.mod h1:d58dBvw2KImcVbAUANrciEV/of0arMNsI9c/5UNCMMc= -github.com/alimy/yesql v1.4.0 h1:8q5PgUnLR1u9vi5Y9cLj1/cuie2I/4ShpCOp2jE1V6A= -github.com/alimy/yesql v1.4.0/go.mod h1:Y0FdRIwIbJyTv56wSX+MpaIHiAW1PyKTDYO6K/er4JY= +github.com/alimy/yesql v1.5.0 h1:Xmx+yBQCWA4f5xsraypbMnY7id8bckjUr8zxynteDBE= +github.com/alimy/yesql v1.5.0/go.mod h1:Y0FdRIwIbJyTv56wSX+MpaIHiAW1PyKTDYO6K/er4JY= github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible h1:KpbJFXwhVeuxNtBJ74MCGbIoaBok2uZvkD7QXp2+Wis= github.com/aliyun/aliyun-oss-go-sdk v2.2.7+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= github.com/allegro/bigcache/v3 v3.1.0 h1:H2Vp8VOvxcrB91o86fUSVJFqeuz8kpyyB02eH3bSzwk= diff --git a/internal/dao/sakila/yesql/cc/yesql.go b/internal/dao/sakila/yesql/cc/yesql.go index c9da169d..efc2ce59 100644 --- a/internal/dao/sakila/yesql/cc/yesql.go +++ b/internal/dao/sakila/yesql/cc/yesql.go @@ -1,6 +1,6 @@ // Code generated by Yesql. DO NOT EDIT. // versions: -// - Yesql v1.4.0 +// - Yesql v1.5.0 package cc From 0bb4810690b16b44c038a27102991a2261a7da39 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Wed, 2 Aug 2023 18:44:50 +0800 Subject: [PATCH 10/19] sqlx: comment logic is implemented complete. WIP %25 --- internal/dao/sakila/comments.go | 72 ++++--- internal/dao/sakila/yesql/cc/yesql.go | 286 +++++++++++++------------- internal/dao/sakila/yesql/yesql.sql | 46 ++--- pkg/naming/naming_test.go | 4 + 4 files changed, 201 insertions(+), 207 deletions(-) diff --git a/internal/dao/sakila/comments.go b/internal/dao/sakila/comments.go index 9efdcb27..c62108b0 100644 --- a/internal/dao/sakila/comments.go +++ b/internal/dao/sakila/comments.go @@ -110,18 +110,21 @@ func (s *commentSrv) GetCommentRepliesByID(ids []int64) ([]*ms.CommentReplyForma return repliesFormated, nil } +// DeleteComment delete comment +// TODO: need delete related replies and update tweet comment count and comment content? func (s *commentManageSrv) DeleteComment(r *ms.Comment) error { return s.with(func(tx *sqlx.Tx) error { - if _, err := tx.Stmtx(s.q.DeleteComment).Exec(r.ID); err != nil { + now := time.Now().Unix() + if _, err := tx.Stmtx(s.q.DeleteComment).Exec(now, r.ID); err != nil { return err } - _, err := tx.Stmtx(s.q.DeleteCommentThumbs).Exec(r.UserID, r.PostID, r.ID) + _, err := tx.Stmtx(s.q.DeleteCommentThumbs).Exec(now, r.UserID, r.PostID, r.ID) return err }) } func (s *commentManageSrv) CreateComment(r *ms.Comment) (*ms.Comment, error) { - res, err := s.q.CreateComment.Exec(r) + res, err := s.q.CreateComment.Exec(r.PostID, r.UserID, r.IP, r.IPLoc, time.Now().Unix()) if err != nil { return nil, err } @@ -136,7 +139,8 @@ func (s *commentManageSrv) CreateComment(r *ms.Comment) (*ms.Comment, error) { } func (s *commentManageSrv) CreateCommentReply(r *ms.CommentReply) (*ms.CommentReply, error) { - res, err := s.q.CreateComment.Exec(r) + res, err := s.q.CreateCommentReply.Exec(r.CommentID, r.UserID, r.Content, + r.AtUserID, r.IP, r.IPLoc, time.Now().Unix()) if err != nil { return nil, err } @@ -150,16 +154,17 @@ func (s *commentManageSrv) CreateCommentReply(r *ms.CommentReply) (*ms.CommentRe func (s *commentManageSrv) DeleteCommentReply(r *ms.CommentReply) error { return s.with(func(tx *sqlx.Tx) error { - if _, err := tx.Stmtx(s.q.DeleteCommentReply).Exec(r.ID); err != nil { + now := time.Now().Unix() + if _, err := tx.Stmtx(s.q.DeleteCommentReply).Exec(now, r.ID); err != nil { return err } - _, err := tx.Stmtx(s.q.DeleteCommentThumbs).Exec(r.UserID, r.CommentID, r.ID) + _, err := tx.Stmtx(s.q.DeleteCommentThumbs).Exec(now, r.UserID, r.CommentID, r.ID) return err }) } func (s *commentManageSrv) CreateCommentContent(r *ms.CommentContent) (*ms.CommentContent, error) { - res, err := s.q.CreateCommentContent.Exec(r) + res, err := s.q.CreateCommentContent.Exec(r.CommentID, r.UserID, r.Content, r.Type, r.Sort, time.Now().Unix()) if err != nil { return nil, err } @@ -177,6 +182,7 @@ func (s *commentManageSrv) ThumbsUpComment(userId int64, tweetId, commentId int6 thumbsUpCount int32 = 0 thumbsDownCount int32 = 0 ) + now := time.Now().Unix() commentThumbs := &dbr.TweetCommentThumbs{} // 检查thumbs状态 err := tx.Stmtx(s.q.GetTweetCommentThumb).Get(commentThumbs, userId, tweetId, commentId) @@ -191,8 +197,8 @@ func (s *commentManageSrv) ThumbsUpComment(userId int64, tweetId, commentId int6 commentThumbs.IsThumbsDown = types.No } commentThumbs.IsThumbsUp = 1 - commentThumbs.IsThumbsUp - commentThumbs.ModifiedOn = time.Now().Unix() - if _, err := tx.NamedStmt(s.q.UpdateThumbsUpComment).Exec(commentThumbs); err != nil { + commentThumbs.ModifiedOn = now + if _, err := tx.Stmtx(s.q.UpdateThumbsUpdownComment).Exec(commentThumbs); err != nil { return err } } else { @@ -204,16 +210,16 @@ func (s *commentManageSrv) ThumbsUpComment(userId int64, tweetId, commentId int6 IsThumbsDown: types.No, CommentType: 0, Model: &dbr.Model{ - CreatedOn: time.Now().Unix(), + CreatedOn: now, }, } thumbsUpCount, thumbsDownCount = 1, 0 - if _, err := tx.NamedStmt(s.q.CreateThumbsUpComment).Exec(commentThumbs); err != nil { + if _, err := tx.NamedStmt(s.q.CreateThumbsUpdownComment).Exec(commentThumbs); err != nil { return err } } - // 更新thumbsUpCount - _, err = tx.Stmtx(s.q.UpdateCommentThumbsCount).Exec(commentId, thumbsUpCount, thumbsDownCount) + // 更新comment thumbsUpCount + _, err = tx.Stmtx(s.q.UpdateCommentThumbsCount).Exec(thumbsUpCount, thumbsDownCount, now, commentId) return err }) } @@ -224,6 +230,7 @@ func (s *commentManageSrv) ThumbsDownComment(userId int64, tweetId, commentId in thumbsUpCount int32 = 0 thumbsDownCount int32 = 0 ) + now := time.Now().Unix() commentThumbs := &dbr.TweetCommentThumbs{} // 检查thumbs状态 err := tx.Stmtx(s.q.GetTweetCommentThumb).Get(commentThumbs, userId, tweetId, commentId) @@ -239,8 +246,8 @@ func (s *commentManageSrv) ThumbsDownComment(userId int64, tweetId, commentId in } commentThumbs.IsThumbsDown = 1 - commentThumbs.IsThumbsDown - commentThumbs.ModifiedOn = time.Now().Unix() - if _, err := tx.NamedStmt(s.q.UpdateThumbsUpComment).Exec(commentThumbs); err != nil { + commentThumbs.ModifiedOn = now + if _, err := tx.NamedStmt(s.q.UpdateThumbsUpdownComment).Exec(commentThumbs); err != nil { return err } } else { @@ -252,27 +259,27 @@ func (s *commentManageSrv) ThumbsDownComment(userId int64, tweetId, commentId in IsThumbsDown: types.Yes, CommentType: 0, Model: &dbr.Model{ - CreatedOn: time.Now().Unix(), + CreatedOn: now, }, } thumbsUpCount, thumbsDownCount = 0, 1 - if _, err := tx.NamedStmt(s.q.CreateThumbsUpComment).Exec(commentThumbs); err != nil { + if _, err := tx.NamedStmt(s.q.CreateThumbsUpdownComment).Exec(commentThumbs); err != nil { return err } } - // 更新thumbsUpCount - _, err = tx.Stmtx(s.q.UpdateCommentThumbsCount).Exec(commentId, thumbsUpCount, thumbsDownCount) + // 更新comment thumbsUpCount + _, err = tx.Stmtx(s.q.UpdateCommentThumbsCount).Exec(thumbsUpCount, thumbsDownCount, now, commentId) return err }) } func (s *commentManageSrv) ThumbsUpReply(userId int64, tweetId, commentId, replyId int64) error { return s.with(func(tx *sqlx.Tx) error { - var ( thumbsUpCount int32 = 0 thumbsDownCount int32 = 0 ) + now := time.Now().Unix() commentThumbs := &dbr.TweetCommentThumbs{} // 检查thumbs状态 err := tx.Stmtx(s.q.GetCommentReplyThumb).Get(commentThumbs, userId, tweetId, commentId, replyId) @@ -287,8 +294,8 @@ func (s *commentManageSrv) ThumbsUpReply(userId int64, tweetId, commentId, reply commentThumbs.IsThumbsDown = types.No } commentThumbs.IsThumbsUp = 1 - commentThumbs.IsThumbsUp - commentThumbs.ModifiedOn = time.Now().Unix() - if _, err := tx.NamedStmt(s.q.UpdateThumbsUpComment).Exec(commentThumbs); err != nil { + commentThumbs.ModifiedOn = now + if _, err := tx.NamedStmt(s.q.UpdateThumbsUpdownComment).Exec(commentThumbs); err != nil { return err } } else { @@ -301,16 +308,16 @@ func (s *commentManageSrv) ThumbsUpReply(userId int64, tweetId, commentId, reply IsThumbsDown: types.No, CommentType: 1, Model: &dbr.Model{ - CreatedOn: time.Now().Unix(), + CreatedOn: now, }, } thumbsUpCount, thumbsDownCount = 1, 0 - if _, err := tx.NamedStmt(s.q.CreateThumbsUpComment).Exec(commentThumbs); err != nil { + if _, err := tx.NamedStmt(s.q.CreateThumbsUpdownComment).Exec(commentThumbs); err != nil { return err } } - // 更新thumbsUpCount - _, err = tx.Stmtx(s.q.UpdateCommentThumbsCount).Exec(commentId, thumbsUpCount, thumbsDownCount) + // 更新comment_reply thumbsUpCount + _, err = tx.Stmtx(s.q.UpdateReplyThumbsCount).Exec(thumbsUpCount, thumbsDownCount, now, replyId) return err }) } @@ -321,6 +328,7 @@ func (s *commentManageSrv) ThumbsDownReply(userId int64, tweetId, commentId, rep thumbsUpCount int32 = 0 thumbsDownCount int32 = 0 ) + now := time.Now().Unix() commentThumbs := &dbr.TweetCommentThumbs{} // 检查thumbs状态 err := tx.Stmtx(s.q.GetCommentReplyThumb).Get(commentThumbs, userId, tweetId, commentId, replyId) @@ -335,8 +343,8 @@ func (s *commentManageSrv) ThumbsDownReply(userId int64, tweetId, commentId, rep commentThumbs.IsThumbsUp = types.No } commentThumbs.IsThumbsDown = 1 - commentThumbs.IsThumbsDown - commentThumbs.ModifiedOn = time.Now().Unix() - if _, err := tx.NamedStmt(s.q.UpdateThumbsUpComment).Exec(commentThumbs); err != nil { + commentThumbs.ModifiedOn = now + if _, err := tx.NamedStmt(s.q.UpdateThumbsUpdownComment).Exec(commentThumbs); err != nil { return err } } else { @@ -349,16 +357,16 @@ func (s *commentManageSrv) ThumbsDownReply(userId int64, tweetId, commentId, rep IsThumbsDown: types.Yes, CommentType: 1, Model: &dbr.Model{ - CreatedOn: time.Now().Unix(), + CreatedOn: now, }, } thumbsUpCount, thumbsDownCount = 0, 1 - if _, err := tx.NamedStmt(s.q.CreateThumbsUpComment).Exec(commentThumbs); err != nil { + if _, err := tx.NamedStmt(s.q.CreateThumbsUpdownComment).Exec(commentThumbs); err != nil { return err } } - // 更新thumbsUpCount - _, err = tx.Stmtx(s.q.UpdateCommentThumbsCount).Exec(commentId, thumbsUpCount, thumbsDownCount) + // 更新comment_reply thumbsUpCount + _, err = tx.Stmtx(s.q.UpdateReplyThumbsCount).Exec(thumbsUpCount, thumbsDownCount, now, replyId) return err }) } diff --git a/internal/dao/sakila/yesql/cc/yesql.go b/internal/dao/sakila/yesql/cc/yesql.go index efc2ce59..1a937406 100644 --- a/internal/dao/sakila/yesql/cc/yesql.go +++ b/internal/dao/sakila/yesql/cc/yesql.go @@ -12,120 +12,118 @@ import ( ) const ( - _AuthorizationManage_BeFriendIds = `SELECT user_id FROM @contact WHERE friend_id=? AND status=2 AND is_del=0` - _AuthorizationManage_IsFriend = `SELECT status FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0` - _AuthorizationManage_MyFriendSet = `SELECT friend_id FROM @contact WHERE user_id=? AND status=2 AND is_del=0` - _Comment_GetCommentById = `SELECT * FROM @comment WHERE id=? AND is_del=0` - _Comment_GetCommentContentsByIds = `SELECT * FROM @comment_content WHERE comment_id IN ?` - _Comment_GetCommentCount = `SELECT count(*) FROM @comment WHERE post_id=:post_id AND is_del=0` - _Comment_GetCommentReplyById = `SELECT * FROM @comment_reply WHERE id=? AND is_del=0` - _Comment_GetCommentThumbs = `SELECT * FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=?` - _Comment_GetComments = `SELECT * FROM @comment WHERE post_id=? AND is_del=0 ORDER BY %order% LIMIT ? OFFSET ?` - _Comment_GetCommmentRepliesByIds = `SELECT * FROM @comment_reply WHERE comment_id IN ? ORDER BY id ASC` - _Comment_GetUsersByIds = `SELECT id, nickname, username, status, avatar, is_admin FROM @user WHERE id IN ?` - _CommentManage_CreateComment = `SELECT * FROM @user WHERE username=?` - _CommentManage_CreateCommentContent = `SELECT * FROM @user WHERE username=?` - _CommentManage_CreateCommentReply = `SELECT * FROM @user WHERE username=?` - _CommentManage_CreateThumbsUpComment = `SELECT * FROM @user WHERE username=?` - _CommentManage_DeleteComment = `SELECT * FROM @user WHERE username=?` - _CommentManage_DeleteCommentReply = `SELECT * FROM @user WHERE username=?` - _CommentManage_DeleteCommentThumbs = `SELECT * FROM @user WHERE username=?` - _CommentManage_DeleteReplyThumbs = `SELECT * FROM @user WHERE username=?` - _CommentManage_GetCommentReplyThumb = `SELECT * FROM @user WHERE username=?` - _CommentManage_GetTweetCommentThumb = `SELECT * FROM @user WHERE username=?` - _CommentManage_ThumbsDownComment = `SELECT * FROM @user WHERE username=?` - _CommentManage_ThumbsDownReply = `SELECT * FROM @user WHERE username=?` - _CommentManage_ThumbsUpReply = `SELECT * FROM @user WHERE username=?` - _CommentManage_UpdateCommentThumbsCount = `SELECT * FROM @user WHERE username=?` - _CommentManage_UpdateThumbsUpComment = `SELECT * FROM @user WHERE username=?` - _ContactManager_AddFriend = `SELECT * FROM @user WHERE username=?` - _ContactManager_DelFriend = `SELECT * FROM @user WHERE username=?` - _ContactManager_GetContacts = `SELECT * FROM @user WHERE username=?` - _ContactManager_GetUserFriend = `SELECT * FROM @user WHERE username=?` - _ContactManager_RejectFriend = `SELECT * FROM @user WHERE username=?` - _ContactManager_RequestingFriend = `SELECT * FROM @user WHERE username=?` - _ContactManager_TotalContactsById = `SELECT * FROM @user WHERE username=?` - _FollowIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` - _FollowIndex_UserInfo = `SELECT * FROM @user WHERE username=?` - _FriendIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` - _FriendIndex_UserInfo = `SELECT * FROM @user WHERE username=?` - _LightIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` - _LightIndex_UserInfo = `SELECT * FROM @user WHERE username=?` - _Message_CreateMessage = `SELECT * FROM @user WHERE username=?` - _Message_GetMessageById = `SELECT * FROM @user WHERE username=?` - _Message_GetMessageCount = `SELECT * FROM @user WHERE username=?` - _Message_GetMessages = `SELECT * FROM @user WHERE username=?` - _Message_GetUnreadCount = `SELECT * FROM @user WHERE username=?` - _Message_ReadMessage = `SELECT * FROM @user WHERE username=?` - _Security_CreatePhoneCaptcha = `SELECT * FROM @user WHERE username=?` - _Security_GetLatestPhoneCaptcha = `SELECT * FROM @user WHERE username=?` - _Security_SendPhoneCaptcha = `SELECT * FROM @user WHERE username=?` - _Security_UsePhoneCaptcha = `SELECT * FROM @user WHERE username=?` - _SimpleIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` - _SimpleIndex_UserInfo = `SELECT * FROM @user WHERE username=?` - _TopicA_DecrTagsById = `UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?)` - _TopicA_HotTags = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.quote_num DESC LIMIT ? OFFSET ?` - _TopicA_IncrTagsById = `UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?)` - _TopicA_InsertTag = `INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1)` - _TopicA_NewestTags = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.id DESC LIMIT ? OFFSET ?` - _TopicA_TagsByIdA = `SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0` - _TopicA_TagsByIdB = `SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?)` - _TopicA_TagsByKeywordA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6` - _TopicA_TagsByKeywordB = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6` - _TopicA_TagsForIncr = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` - _TweetA_AttachmentByTweetId = `SELECT * FROM @user WHERE username=?` - _TweetA_FavoriteByTweetId = `SELECT * FROM @user WHERE username=?` - _TweetA_ReactionByTweetId = `SELECT * FROM @user WHERE username=?` - _TweetA_TweetInfoById = `SELECT * FROM @user WHERE username=?` - _TweetA_TweetItemById = `SELECT * FROM @user WHERE username=?` - _TweetA_UserFavorites = `SELECT * FROM @user WHERE username=?` - _TweetA_UserInfo = `SELECT * FROM @user WHERE username=?` - _TweetA_UserReactions = `SELECT * FROM @user WHERE username=?` - _TweetA_UserTweetsByAdmin = `SELECT * FROM @user WHERE username=?` - _TweetA_UserTweetsByFriend = `SELECT * FROM @user WHERE username=?` - _TweetA_UserTweetsByGuest = `SELECT * FROM @user WHERE username=?` - _TweetA_UserTweetsBySelf = `SELECT * FROM @user WHERE username=?` - _Tweet_GetPostAttachmentBill = `SELECT * FROM @user WHERE username=?` - _Tweet_GetPostById = `SELECT * FROM @user WHERE username=?` - _Tweet_GetPostContentById = `SELECT * FROM @user WHERE username=?` - _Tweet_GetPostContetnsByIds = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` - _Tweet_GetPostCount = `SELECT * FROM @user WHERE username=?` - _Tweet_GetPosts = `SELECT * FROM @user WHERE username=?` - _Tweet_GetUserPostCollection = `SELECT * FROM @user WHERE username=?` - _Tweet_GetUserPostCollectionCount = `SELECT * FROM @user WHERE username=?` - _Tweet_GetUserPostCollections = `SELECT * FROM @user WHERE username=?` - _Tweet_GetUserPostStar = `SELECT * FROM @user WHERE username=?` - _Tweet_GetUserPostStarCount = `SELECT * FROM @user WHERE username=?` - _Tweet_GetUserPostStars = `SELECT * FROM @user WHERE username=?` - _TweetHelpA_UserInfo = `SELECT * FROM @user WHERE username=?` - _TweetHelp_GetPostContentByIds = `SELECT * FROM @user WHERE username=?` - _TweetHelp_GetUsersByIds = `SELECT * FROM @user WHERE username=?` - _TweetManageA_UserInfo = `SELECT * FROM @user WHERE username=?` - _TweetManage_AddAttachment = `SELECT * FROM @user WHERE username=?` - _TweetManage_AddPost = `SELECT * FROM @user WHERE username=?` - _TweetManage_AddPostCollection = `SELECT * FROM @user WHERE username=?` - _TweetManage_AddPostContent = `SELECT * FROM @user WHERE username=?` - _TweetManage_AddPostStar = `SELECT * FROM @user WHERE username=?` - _TweetManage_DelPost = `SELECT * FROM @user WHERE username=?` - _TweetManage_DelPostCollection = `SELECT * FROM @user WHERE username=?` - _TweetManage_DelPostStar = `SELECT * FROM @user WHERE username=?` - _TweetManage_LockPost = `SELECT * FROM @user WHERE username=?` - _TweetManage_StickPost = `SELECT * FROM @user WHERE username=?` - _TweetManage_UpdatePost = `SELECT * FROM @user WHERE username=?` - _TweetManage_VisiblePost = `SELECT * FROM @user WHERE username=?` - _UserManage_AddUser = `SELECT * FROM @user WHERE username=?` - _UserManage_GetUserById = `SELECT * FROM @user WHERE username=?` - _UserManage_GetUserByPhone = `SELECT * FROM @user WHERE username=?` - _UserManage_GetUserByUsername = `SELECT * FROM @user WHERE username=?` - _UserManage_GetUsersByIds = `SELECT * FROM @user WHERE username=?` - _UserManage_GetUsersByKeyword = `SELECT * FROM @user WHERE username=?` - _UserManage_UpdateUser = `SELECT * FROM @user WHERE username=?` - _Wallet_CreateRecharge = `SELECT * FROM @user WHERE username=?` - _Wallet_GetRechargeById = `SELECT * FROM @user WHERE username=?` - _Wallet_GetUserWalletBillCount = `SELECT * FROM @user WHERE username=?` - _Wallet_GetUserWalletBills = `SELECT * FROM @user WHERE username=?` - _Wallet_HandlePostAttachementBought = `SELECT * FROM @user WHERE username=?` - _Wallet_HandleRechargeSuccess = `SELECT * FROM @user WHERE username=?` + _AuthorizationManage_BeFriendIds = `SELECT user_id FROM @contact WHERE friend_id=? AND status=2 AND is_del=0` + _AuthorizationManage_IsFriend = `SELECT status FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0` + _AuthorizationManage_MyFriendSet = `SELECT friend_id FROM @contact WHERE user_id=? AND status=2 AND is_del=0` + _Comment_GetCommentById = `SELECT * FROM @comment WHERE id=? AND is_del=0` + _Comment_GetCommentContentsByIds = `SELECT * FROM @comment_content WHERE comment_id IN ?` + _Comment_GetCommentCount = `SELECT count(*) FROM @comment WHERE post_id=:post_id AND is_del=0` + _Comment_GetCommentReplyById = `SELECT * FROM @comment_reply WHERE id=? AND is_del=0` + _Comment_GetCommentThumbs = `SELECT * FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=?` + _Comment_GetComments = `SELECT * FROM @comment WHERE post_id=? AND is_del=0 ORDER BY %order% LIMIT ? OFFSET ?` + _Comment_GetCommmentRepliesByIds = `SELECT * FROM @comment_reply WHERE comment_id IN ? ORDER BY id ASC` + _Comment_GetUsersByIds = `SELECT id, nickname, username, status, avatar, is_admin FROM @user WHERE id IN ?` + _CommentManage_CreateComment = `INSERT INTO @comment (post_id, user_id, ip, ip_loc, created_on) VALUES (?, ?, ?, ?, ?)` + _CommentManage_CreateCommentContent = `INSERT INTO @comment_content (comment_id, user_id, content, type, sort, created_on) VALUES (?, ?, ?, ?, ?, ?)` + _CommentManage_CreateCommentReply = `INSERT INTO @comment_reply (comment_id, user_id, content, at_user_id, ip, ip_loc, created_on) VALUES (?, ?, ?, ?, ?, ?, ?)` + _CommentManage_CreateThumbsUpdownComment = `INSERT INTO @tweet_comment_thumbs (user_id, tweet_id, comment_id, reply_id, is_thumbs_up, is_thumbs_down, comment_type, created_on) VALUES (:user_id, :tweet_id, :comment_id, :reply_id, :is_thumbs_up, :is_thumbs_down, :comment_type, :created_on)` + _CommentManage_DeleteComment = `UPDATE @comment SET deleted_on=?, is_del=1 WHERE id=? AND is_del=0` + _CommentManage_DeleteCommentReply = `UPDATE @comment_reply SET deleted_on=?, is_del=1 WHERE id=? AND is_del=0` + _CommentManage_DeleteCommentThumbs = `UPDATE @tweet_comment_thumbs SET deleted_on=?, is_del=1 WHERE user_id=? AND tweet_id=? AND comment_id=? AND is_del=0` + _CommentManage_DeleteReplyThumbs = `UPDATE @tweet_comment_thumbs SET deleted_on=?, is_del=1 WHERE user_id=? AND comment_id=? AND reply_id=? AND is_del=0` + _CommentManage_GetCommentReplyThumb = `SELECT * FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=? AND comment_id=? AND reply_id=? AND comment_type=1 AND is_del=0` + _CommentManage_GetTweetCommentThumb = `SELECT * FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=? AND comment_id=? AND comment_type=0 AND is_del=0` + _CommentManage_UpdateCommentThumbsCount = `UPDATE @comment SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? WHERE id=? AND is_del=0` + _CommentManage_UpdateReplyThumbsCount = `UPDATE @comment_reply SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? WHERE id=? AND is_del=0` + _CommentManage_UpdateThumbsUpdownComment = `UPDATE @tweet_comment_thumbs SET is_thumbs_up=:is_thumbs_up, is_thumbs_down=:is_thumbs_down, modified_on=:modified_on WHERE id=:id AND is_del=0` + _ContactManager_AddFriend = `SELECT * FROM @user WHERE username=?` + _ContactManager_DelFriend = `SELECT * FROM @user WHERE username=?` + _ContactManager_GetContacts = `SELECT * FROM @user WHERE username=?` + _ContactManager_GetUserFriend = `SELECT * FROM @user WHERE username=?` + _ContactManager_RejectFriend = `SELECT * FROM @user WHERE username=?` + _ContactManager_RequestingFriend = `SELECT * FROM @user WHERE username=?` + _ContactManager_TotalContactsById = `SELECT * FROM @user WHERE username=?` + _FollowIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` + _FollowIndex_UserInfo = `SELECT * FROM @user WHERE username=?` + _FriendIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` + _FriendIndex_UserInfo = `SELECT * FROM @user WHERE username=?` + _LightIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` + _LightIndex_UserInfo = `SELECT * FROM @user WHERE username=?` + _Message_CreateMessage = `SELECT * FROM @user WHERE username=?` + _Message_GetMessageById = `SELECT * FROM @user WHERE username=?` + _Message_GetMessageCount = `SELECT * FROM @user WHERE username=?` + _Message_GetMessages = `SELECT * FROM @user WHERE username=?` + _Message_GetUnreadCount = `SELECT * FROM @user WHERE username=?` + _Message_ReadMessage = `SELECT * FROM @user WHERE username=?` + _Security_CreatePhoneCaptcha = `SELECT * FROM @user WHERE username=?` + _Security_GetLatestPhoneCaptcha = `SELECT * FROM @user WHERE username=?` + _Security_SendPhoneCaptcha = `SELECT * FROM @user WHERE username=?` + _Security_UsePhoneCaptcha = `SELECT * FROM @user WHERE username=?` + _SimpleIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` + _SimpleIndex_UserInfo = `SELECT * FROM @user WHERE username=?` + _TopicA_DecrTagsById = `UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?)` + _TopicA_HotTags = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.quote_num DESC LIMIT ? OFFSET ?` + _TopicA_IncrTagsById = `UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?)` + _TopicA_InsertTag = `INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1)` + _TopicA_NewestTags = `SELECT t.id id, t.user_id user_id, t.tag tag, t.quote_num quote_num, u.id, u.nickname, u.username, u.status, u.avatar, u.is_admin FROM @tag t JOIN @user u ON t.user_id = u.id WHERE t.is_del = 0 AND t.quote_num > 0 ORDER BY t.id DESC LIMIT ? OFFSET ?` + _TopicA_TagsByIdA = `SELECT id FROM @tag WHERE id IN (?) AND is_del = 0 AND quote_num > 0` + _TopicA_TagsByIdB = `SELECT id, user_id, tag, quote_num FROM @tag WHERE id IN (?)` + _TopicA_TagsByKeywordA = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6` + _TopicA_TagsByKeywordB = `SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6` + _TopicA_TagsForIncr = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` + _TweetA_AttachmentByTweetId = `SELECT * FROM @user WHERE username=?` + _TweetA_FavoriteByTweetId = `SELECT * FROM @user WHERE username=?` + _TweetA_ReactionByTweetId = `SELECT * FROM @user WHERE username=?` + _TweetA_TweetInfoById = `SELECT * FROM @user WHERE username=?` + _TweetA_TweetItemById = `SELECT * FROM @user WHERE username=?` + _TweetA_UserFavorites = `SELECT * FROM @user WHERE username=?` + _TweetA_UserInfo = `SELECT * FROM @user WHERE username=?` + _TweetA_UserReactions = `SELECT * FROM @user WHERE username=?` + _TweetA_UserTweetsByAdmin = `SELECT * FROM @user WHERE username=?` + _TweetA_UserTweetsByFriend = `SELECT * FROM @user WHERE username=?` + _TweetA_UserTweetsByGuest = `SELECT * FROM @user WHERE username=?` + _TweetA_UserTweetsBySelf = `SELECT * FROM @user WHERE username=?` + _Tweet_GetPostAttachmentBill = `SELECT * FROM @user WHERE username=?` + _Tweet_GetPostById = `SELECT * FROM @user WHERE username=?` + _Tweet_GetPostContentById = `SELECT * FROM @user WHERE username=?` + _Tweet_GetPostContetnsByIds = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` + _Tweet_GetPostCount = `SELECT * FROM @user WHERE username=?` + _Tweet_GetPosts = `SELECT * FROM @user WHERE username=?` + _Tweet_GetUserPostCollection = `SELECT * FROM @user WHERE username=?` + _Tweet_GetUserPostCollectionCount = `SELECT * FROM @user WHERE username=?` + _Tweet_GetUserPostCollections = `SELECT * FROM @user WHERE username=?` + _Tweet_GetUserPostStar = `SELECT * FROM @user WHERE username=?` + _Tweet_GetUserPostStarCount = `SELECT * FROM @user WHERE username=?` + _Tweet_GetUserPostStars = `SELECT * FROM @user WHERE username=?` + _TweetHelpA_UserInfo = `SELECT * FROM @user WHERE username=?` + _TweetHelp_GetPostContentByIds = `SELECT * FROM @user WHERE username=?` + _TweetHelp_GetUsersByIds = `SELECT * FROM @user WHERE username=?` + _TweetManageA_UserInfo = `SELECT * FROM @user WHERE username=?` + _TweetManage_AddAttachment = `SELECT * FROM @user WHERE username=?` + _TweetManage_AddPost = `SELECT * FROM @user WHERE username=?` + _TweetManage_AddPostCollection = `SELECT * FROM @user WHERE username=?` + _TweetManage_AddPostContent = `SELECT * FROM @user WHERE username=?` + _TweetManage_AddPostStar = `SELECT * FROM @user WHERE username=?` + _TweetManage_DelPost = `SELECT * FROM @user WHERE username=?` + _TweetManage_DelPostCollection = `SELECT * FROM @user WHERE username=?` + _TweetManage_DelPostStar = `SELECT * FROM @user WHERE username=?` + _TweetManage_LockPost = `SELECT * FROM @user WHERE username=?` + _TweetManage_StickPost = `SELECT * FROM @user WHERE username=?` + _TweetManage_UpdatePost = `SELECT * FROM @user WHERE username=?` + _TweetManage_VisiblePost = `SELECT * FROM @user WHERE username=?` + _UserManage_AddUser = `SELECT * FROM @user WHERE username=?` + _UserManage_GetUserById = `SELECT * FROM @user WHERE username=?` + _UserManage_GetUserByPhone = `SELECT * FROM @user WHERE username=?` + _UserManage_GetUserByUsername = `SELECT * FROM @user WHERE username=?` + _UserManage_GetUsersByIds = `SELECT * FROM @user WHERE username=?` + _UserManage_GetUsersByKeyword = `SELECT * FROM @user WHERE username=?` + _UserManage_UpdateUser = `SELECT * FROM @user WHERE username=?` + _Wallet_CreateRecharge = `SELECT * FROM @user WHERE username=?` + _Wallet_GetRechargeById = `SELECT * FROM @user WHERE username=?` + _Wallet_GetUserWalletBillCount = `SELECT * FROM @user WHERE username=?` + _Wallet_GetUserWalletBills = `SELECT * FROM @user WHERE username=?` + _Wallet_HandlePostAttachementBought = `SELECT * FROM @user WHERE username=?` + _Wallet_HandleRechargeSuccess = `SELECT * FROM @user WHERE username=?` ) type AuthorizationManage struct { @@ -148,22 +146,20 @@ type Comment struct { } type CommentManage struct { - yesql.Namespace `yesql:"comment_manage"` - DeleteComment *sqlx.Stmt `yesql:"delete_comment"` - DeleteCommentReply *sqlx.Stmt `yesql:"delete_comment_reply"` - DeleteCommentThumbs *sqlx.Stmt `yesql:"delete_comment_thumbs"` - DeleteReplyThumbs *sqlx.Stmt `yesql:"delete_reply_thumbs"` - GetCommentReplyThumb *sqlx.Stmt `yesql:"get_comment_reply_thumb"` - GetTweetCommentThumb *sqlx.Stmt `yesql:"get_tweet_comment_thumb"` - ThumbsDownComment *sqlx.Stmt `yesql:"thumbs_down_comment"` - ThumbsDownReply *sqlx.Stmt `yesql:"thumbs_down_reply"` - ThumbsUpReply *sqlx.Stmt `yesql:"thumbs_up_reply"` - UpdateCommentThumbsCount *sqlx.Stmt `yesql:"update_comment_thumbs_count"` - CreateComment *sqlx.NamedStmt `yesql:"create_comment"` - CreateCommentContent *sqlx.NamedStmt `yesql:"create_comment_content"` - CreateCommentReply *sqlx.NamedStmt `yesql:"create_comment_reply"` - CreateThumbsUpComment *sqlx.NamedStmt `yesql:"create_thumbs_up_comment"` - UpdateThumbsUpComment *sqlx.NamedStmt `yesql:"update_thumbs_up_comment"` + yesql.Namespace `yesql:"comment_manage"` + CreateComment *sqlx.Stmt `yesql:"create_comment"` + CreateCommentContent *sqlx.Stmt `yesql:"create_comment_content"` + CreateCommentReply *sqlx.Stmt `yesql:"create_comment_reply"` + DeleteComment *sqlx.Stmt `yesql:"delete_comment"` + DeleteCommentReply *sqlx.Stmt `yesql:"delete_comment_reply"` + DeleteCommentThumbs *sqlx.Stmt `yesql:"delete_comment_thumbs"` + DeleteReplyThumbs *sqlx.Stmt `yesql:"delete_reply_thumbs"` + GetCommentReplyThumb *sqlx.Stmt `yesql:"get_comment_reply_thumb"` + GetTweetCommentThumb *sqlx.Stmt `yesql:"get_tweet_comment_thumb"` + UpdateCommentThumbsCount *sqlx.Stmt `yesql:"update_comment_thumbs_count"` + UpdateReplyThumbsCount *sqlx.Stmt `yesql:"update_reply_thumbs_count"` + CreateThumbsUpdownComment *sqlx.NamedStmt `yesql:"create_thumbs_updown_comment"` + UpdateThumbsUpdownComment *sqlx.NamedStmt `yesql:"update_thumbs_updown_comment"` } type ContactManager struct { @@ -390,49 +386,43 @@ func BuildCommentManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *C c = context.Background() } obj = &CommentManage{} - if obj.DeleteComment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_DeleteComment))); err != nil { + if obj.CreateComment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_CreateComment))); err != nil { return } - if obj.DeleteCommentReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_DeleteCommentReply))); err != nil { + if obj.CreateCommentContent, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_CreateCommentContent))); err != nil { return } - if obj.DeleteCommentThumbs, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_DeleteCommentThumbs))); err != nil { + if obj.CreateCommentReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_CreateCommentReply))); err != nil { return } - if obj.DeleteReplyThumbs, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_DeleteReplyThumbs))); err != nil { + if obj.DeleteComment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_DeleteComment))); err != nil { return } - if obj.GetCommentReplyThumb, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_GetCommentReplyThumb))); err != nil { + if obj.DeleteCommentReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_DeleteCommentReply))); err != nil { return } - if obj.GetTweetCommentThumb, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_GetTweetCommentThumb))); err != nil { + if obj.DeleteCommentThumbs, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_DeleteCommentThumbs))); err != nil { return } - if obj.ThumbsDownComment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_ThumbsDownComment))); err != nil { + if obj.DeleteReplyThumbs, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_DeleteReplyThumbs))); err != nil { return } - if obj.ThumbsDownReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_ThumbsDownReply))); err != nil { + if obj.GetCommentReplyThumb, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_GetCommentReplyThumb))); err != nil { return } - if obj.ThumbsUpReply, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_ThumbsUpReply))); err != nil { + if obj.GetTweetCommentThumb, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_GetTweetCommentThumb))); err != nil { return } if obj.UpdateCommentThumbsCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_UpdateCommentThumbsCount))); err != nil { return } - if obj.CreateComment, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CommentManage_CreateComment))); err != nil { - return - } - if obj.CreateCommentContent, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CommentManage_CreateCommentContent))); err != nil { - return - } - if obj.CreateCommentReply, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CommentManage_CreateCommentReply))); err != nil { + if obj.UpdateReplyThumbsCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_CommentManage_UpdateReplyThumbsCount))); err != nil { return } - if obj.CreateThumbsUpComment, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CommentManage_CreateThumbsUpComment))); err != nil { + if obj.CreateThumbsUpdownComment, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CommentManage_CreateThumbsUpdownComment))); err != nil { return } - if obj.UpdateThumbsUpComment, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CommentManage_UpdateThumbsUpComment))); err != nil { + if obj.UpdateThumbsUpdownComment, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_CommentManage_UpdateThumbsUpdownComment))); err != nil { return } return diff --git a/internal/dao/sakila/yesql/yesql.sql b/internal/dao/sakila/yesql/yesql.sql index 5603e3ab..cb08e721 100644 --- a/internal/dao/sakila/yesql/yesql.sql +++ b/internal/dao/sakila/yesql/yesql.sql @@ -59,63 +59,55 @@ SELECT * FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=?; -- name: delete_comment@comment_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +UPDATE @comment SET deleted_on=?, is_del=1 WHERE id=? AND is_del=0; -- name: delete_comment_thumbs@comment_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +UPDATE @tweet_comment_thumbs SET deleted_on=?, is_del=1 WHERE user_id=? AND tweet_id=? AND comment_id=? AND is_del=0; -- name: create_comment@comment_manage --- prepare: named_stmt -SELECT * FROM @user WHERE username=? +-- prepare: stmt +INSERT INTO @comment (post_id, user_id, ip, ip_loc, created_on) VALUES (?, ?, ?, ?, ?); -- name: create_comment_reply@comment_manage --- prepare: named_stmt -SELECT * FROM @user WHERE username=? +-- prepare: stmt +INSERT INTO @comment_reply (comment_id, user_id, content, at_user_id, ip, ip_loc, created_on) VALUES (?, ?, ?, ?, ?, ?, ?); -- name: delete_comment_reply@comment_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +UPDATE @comment_reply SET deleted_on=?, is_del=1 WHERE id=? AND is_del=0; -- name: delete_reply_thumbs@comment_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +UPDATE @tweet_comment_thumbs SET deleted_on=?, is_del=1 WHERE user_id=? AND comment_id=? AND reply_id=? AND is_del=0; -- name: create_comment_content@comment_manage --- prepare: named_stmt -SELECT * FROM @user WHERE username=? +-- prepare: stmt +INSERT INTO @comment_content (comment_id, user_id, content, type, sort, created_on) VALUES (?, ?, ?, ?, ?, ?); --- name: update_thumbs_up_comment@comment_manage +-- name: update_thumbs_updown_comment@comment_manage -- prepare: named_stmt -SELECT * FROM @user WHERE username=? +UPDATE @tweet_comment_thumbs SET is_thumbs_up=:is_thumbs_up, is_thumbs_down=:is_thumbs_down, modified_on=:modified_on WHERE id=:id AND is_del=0; --- name: create_thumbs_up_comment@comment_manage +-- name: create_thumbs_updown_comment@comment_manage -- prepare: named_stmt -SELECT * FROM @user WHERE username=? +INSERT INTO @tweet_comment_thumbs (user_id, tweet_id, comment_id, reply_id, is_thumbs_up, is_thumbs_down, comment_type, created_on) VALUES (:user_id, :tweet_id, :comment_id, :reply_id, :is_thumbs_up, :is_thumbs_down, :comment_type, :created_on); -- name: update_comment_thumbs_count@comment_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +UPDATE @comment SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? WHERE id=? AND is_del=0; -- name: get_tweet_comment_thumb@comment_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT * FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=? AND comment_id=? AND comment_type=0 AND is_del=0; -- name: get_comment_reply_thumb@comment_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? - --- name: thumbs_down_comment@comment_manage --- prepare: stmt -SELECT * FROM @user WHERE username=? - --- name: thumbs_up_reply@comment_manage --- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT * FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=? AND comment_id=? AND reply_id=? AND comment_type=1 AND is_del=0; --- name: thumbs_down_reply@comment_manage +-- name: update_reply_thumbs_count@comment_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +UPDATE @comment_reply SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? WHERE id=? AND is_del=0; -------------------------------------------------------------------------------- -- contact_manager sql dml 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 { From 7daa78cb121b757bd2528636457620f57ae7e46a Mon Sep 17 00:00:00 2001 From: Michael Li Date: Sat, 5 Aug 2023 12:38:27 +0800 Subject: [PATCH 11/19] sqlx: contact logic is implemented complete. WIP %30 --- internal/core/cs/contact.go | 2 + internal/core/ms/user.go | 2 +- internal/dao/sakila/contacts.go | 167 +++++++++++++++++++++----- internal/dao/sakila/yesql/cc/yesql.go | 63 +++++++--- internal/dao/sakila/yesql/yesql.sql | 44 +++++-- 5 files changed, 219 insertions(+), 59 deletions(-) diff --git a/internal/core/cs/contact.go b/internal/core/cs/contact.go index 27d87cfd..ed774631 100644 --- a/internal/core/cs/contact.go +++ b/internal/core/cs/contact.go @@ -21,4 +21,6 @@ type Contact struct { 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/ms/user.go b/internal/core/ms/user.go index 4c7ea8ab..88cc6e73 100644 --- a/internal/core/ms/user.go +++ b/internal/core/ms/user.go @@ -7,7 +7,7 @@ package ms type ( ContactItem struct { UserId int64 `json:"user_id"` - UserName string `json:"username"` + UserName string `db:"username" json:"username"` Nickname string `json:"nickname"` Avatar string `json:"avatar"` Phone string `json:"phone"` diff --git a/internal/dao/sakila/contacts.go b/internal/dao/sakila/contacts.go index 32d03047..0690c23a 100644 --- a/internal/dao/sakila/contacts.go +++ b/internal/dao/sakila/contacts.go @@ -5,11 +5,14 @@ package sakila import ( + "time" + "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" "github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" + "github.com/sirupsen/logrus" ) var ( @@ -29,49 +32,159 @@ type contactManageSrv struct { q *cc.ContactManager } -func (s *contactManageSrv) RequestingFriend(userId int64, friendId int64, greetings string) (err error) { - _, err = s.q.RejectFriend.Query(userId, friendId, greetings) - return +func (s *contactManageSrv) RequestingFriend(userId int64, friendId int64, greetings string) error { + return s.with(func(tx *sqlx.Tx) error { + contact, err := s.fetchOrNewContact(tx, userId, friendId, cs.ContactStatusRequesting) + if err != nil { + return err + } + now := time.Now().Unix() + // 如果已经好友,啥也不干 + if contact.Status == cs.ContactStatusAgree { + return nil + } else if contact.Status == cs.ContactStatusReject || contact.Status == cs.ContactStatusDeleted { + contact.Status = cs.ContactStatusRequesting + contact.IsDel = 0 // remove deleted flag if needed + args := []any{cs.ContactStatusRequesting, now, contact.ID} + if _, err = tx.Stmtx(s.q.FreshContactStatus).Exec(args...); err != nil { + return err + } + } + msg := &ms.Message{ + SenderUserID: userId, + ReceiverUserID: friendId, + Type: ms.MsgTypeRequestingFriend, + Brief: "请求添加好友,并附言:", + Content: greetings, + ReplyID: int64(cs.ContactStatusRequesting), + Model: &ms.Model{ + CreatedOn: now, + }, + } + if _, err = tx.NamedStmt(s.q.CreateMessage).Exec(msg); err != nil { + logrus.Errorf("contactManageSrv.RequestingFriend create message err:%s", err) + return err + } + return nil + }) } -func (s *contactManageSrv) AddFriend(userId int64, friendId int64) (err error) { - _, err = s.q.AddFriend.Exec(userId, friendId) - return +func (s *contactManageSrv) AddFriend(userId int64, friendId int64) error { + return s.with(func(tx *sqlx.Tx) error { + contact := &cs.Contact{} + err := tx.Stmtx(s.q.GetUserFriend).Get(contact, userId, friendId) + if err != nil { + return err + } + // 如果还不是请求好友,啥也不干 + if contact.Status != cs.ContactStatusRequesting { + logrus.Debugf("contactManageSrv.AddFriend not reuesting status now so skip") + return nil + } + now := time.Now().Unix() + args := []any{cs.ContactStatusAgree, now, contact.ID} + if _, err = tx.Stmtx(s.q.FreshContactStatus).Exec(args...); err != nil { + return err + } + contact, err = s.fetchOrNewContact(tx, userId, friendId, cs.ContactStatusAgree) + if err != nil { + return err + } + // 如果已经好友,啥也不干 + if contact.Status != cs.ContactStatusAgree { + args = []any{cs.ContactStatusAgree, now, contact.ID} + if _, err = tx.Stmtx(s.q.FreshContactStatus).Exec(args); err != nil { + return err + } + } + args = []any{cs.ContactStatusAgree, now, userId, friendId, friendId, userId, ms.MsgTypeRequestingFriend, cs.ContactStatusRequesting} + if _, err = tx.Stmtx(s.q.AddFriendMsgsUpdate).Exec(args...); err != nil { + return err + } + return nil + }) } -func (s *contactManageSrv) RejectFriend(userId int64, friendId int64) (err error) { - _, err = s.q.RejectFriend.Exec(userId, friendId) - return +func (s *contactManageSrv) RejectFriend(userId int64, friendId int64) error { + return s.with(func(tx *sqlx.Tx) error { + contact := &cs.Contact{} + err := tx.Stmtx(s.q.GetUserFriend).Get(contact, userId, friendId) + if err != nil { + return err + } + // 如果还不是请求好友,啥也不干 + if contact.Status != cs.ContactStatusRequesting { + return nil + } + now := time.Now().Unix() + args := []any{cs.ContactStatusReject, now, contact.ID} + if _, err = tx.Stmtx(s.q.FreshContactStatus).Exec(args...); err != nil { + return err + } + args = []any{cs.ContactStatusReject, now, friendId, userId, ms.MsgTypeRequestingFriend, cs.ContactStatusRequesting} + if _, err = tx.Stmtx(s.q.RejectFriendMsgsUpdate).Exec(args...); err != nil { + return err + } + return nil + }) } -func (s *contactManageSrv) DeleteFriend(userId int64, friendId int64) (err error) { - _, err = s.q.DelFriend.Exec(userId, friendId) - return +func (s *contactManageSrv) DeleteFriend(userId int64, friendId int64) error { + return s.with(func(tx *sqlx.Tx) error { + var contacts []cs.Contact + err := tx.Stmtx(s.q.GetContacts).Select(&contacts, userId, friendId, friendId, userId) + if err != nil { + return err + } + for _, contact := range contacts { + // 如果还不是好友,啥也不干 + if contact.Status != cs.ContactStatusAgree { + continue + } + if _, err = tx.Stmtx(s.q.DelFriend).Exec(time.Now().Unix(), contact.ID); err != nil { + return err + } + } + return nil + }) } -func (s *contactManageSrv) GetContacts(userId int64, offset int, limit int) (*ms.ContactList, error) { - res := &ms.ContactList{ +func (s *contactManageSrv) GetContacts(userId int64, offset int, limit int) (res *ms.ContactList, err error) { + res = &ms.ContactList{ Contacts: []ms.ContactItem{}, } - if err := s.q.GetContacts.Select(&res.Contacts, userId, limit, offset); err != nil { - return nil, err + if err = s.q.ListFriend.Select(&res.Contacts, userId, limit, offset); err != nil { + return } - if err := s.q.TotalContactsById.Get(&res.Total, userId); err != nil { - return nil, err + if err = s.q.TotalFriendsById.Get(&res.Total, userId); err != nil { + return } - return res, nil + return } -func (s *contactManageSrv) IsFriend(userId int64, friendId int64) bool { - ct := &contact{ - UserId: friendId, - FriendId: userId, +func (s *contactManageSrv) IsFriend(userId int64, friendId int64) (res bool) { + s.q.IsFriend.Get(&res, userId, friendId) + return +} + +func (s *contactManageSrv) fetchOrNewContact(tx *sqlx.Tx, userId int64, friendId int64, status int8) (res *cs.Contact, err error) { + if err = tx.Stmtx(s.q.GetContact).Get(res, userId, friendId); err == nil { + return + } + result, xerr := tx.Stmtx(s.q.CreateContact).Exec(userId, friendId, status, time.Now().Unix()) + if xerr != nil { + return nil, xerr } - err := s.q.GetUserFriend.Get(ct, userId, friendId) - if err == nil && ct.Status == cs.ContactStatusAgree { - return true + id, xerr := result.LastInsertId() + if xerr != nil { + return nil, xerr } - return false + return &cs.Contact{ + ID: id, + UserId: userId, + FriendId: friendId, + Status: status, + }, nil } func newContactManageService(db *sqlx.DB) core.ContactManageService { diff --git a/internal/dao/sakila/yesql/cc/yesql.go b/internal/dao/sakila/yesql/cc/yesql.go index 1a937406..fdbec867 100644 --- a/internal/dao/sakila/yesql/cc/yesql.go +++ b/internal/dao/sakila/yesql/cc/yesql.go @@ -36,13 +36,18 @@ const ( _CommentManage_UpdateCommentThumbsCount = `UPDATE @comment SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? WHERE id=? AND is_del=0` _CommentManage_UpdateReplyThumbsCount = `UPDATE @comment_reply SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? WHERE id=? AND is_del=0` _CommentManage_UpdateThumbsUpdownComment = `UPDATE @tweet_comment_thumbs SET is_thumbs_up=:is_thumbs_up, is_thumbs_down=:is_thumbs_down, modified_on=:modified_on WHERE id=:id AND is_del=0` - _ContactManager_AddFriend = `SELECT * FROM @user WHERE username=?` - _ContactManager_DelFriend = `SELECT * FROM @user WHERE username=?` - _ContactManager_GetContacts = `SELECT * FROM @user WHERE username=?` - _ContactManager_GetUserFriend = `SELECT * FROM @user WHERE username=?` - _ContactManager_RejectFriend = `SELECT * FROM @user WHERE username=?` - _ContactManager_RequestingFriend = `SELECT * FROM @user WHERE username=?` - _ContactManager_TotalContactsById = `SELECT * FROM @user WHERE username=?` + _ContactManager_AddFriendMsgsUpdate = `UPDATE @message SET reply_id=?, modified_on=? WHERE ((sender_user_id = ? AND receiver_user_id = ?) OR (sender_user_id = ? AND receiver_user_id = ?)) AND type = ? AND reply_id = ?` + _ContactManager_CreateContact = `INSERT INTO @contact (user_id, friend_id, status, created_on) VALUES (?, ?, ?, ?)` + _ContactManager_CreateMessage = `INSERT INTO @message (sender_user_id, receiver_user_id, type, brief, content, reply_id, created_on) VALUES (:sender_user_id, :receiver_user_id, :type, :brief, :content, :reply_id, :created_on)` + _ContactManager_DelFriend = `UPDATE @contact SET status=4, is_del=1, deleted_on=? WHERE id=?` + _ContactManager_FreshContactStatus = `UPDATE @contact SET status=?, modified_on=?, is_del=0 WHERE id=?` + _ContactManager_GetContact = `SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del FROM @contact WHERE user_id=? AND friend_id=?` + _ContactManager_GetContacts = `SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del FROM @contact WHERE (user_id=? AND friend_id=?) OR (user_id=? AND friend_id=?)` + _ContactManager_GetUserFriend = `SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0` + _ContactManager_IsFriend = `SELECT true FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0 AND status=2` + _ContactManager_ListFriend = `SELECT c.friend_id user_id, u.username username, u.nickname nickname, u.avatar avatar, u.phone phone FROM @contact c JOIN @user u ON c.friend_id=u.id WHERE user_id=? AND status=2 AND is_del=0 ORDER BY u.nickname ASC LIMIT ? OFFSET ?` + _ContactManager_RejectFriendMsgsUpdate = `UPDATE @message SET reply_id=?, modified_on=? WHERE sender_user_id = ? AND receiver_user_id = ? AND type = ? AND reply_id = ?` + _ContactManager_TotalFriendsById = `SELECT count(*) FROM @contact WHERE user_id=? AND status=2 AND is_del=0 LIMIT ? OFFSET ?` _FollowIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` _FollowIndex_UserInfo = `SELECT * FROM @user WHERE username=?` _FriendIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` @@ -163,14 +168,19 @@ type CommentManage struct { } type ContactManager struct { - yesql.Namespace `yesql:"contact_manager"` - AddFriend *sqlx.Stmt `yesql:"add_friend"` - DelFriend *sqlx.Stmt `yesql:"del_friend"` - GetContacts *sqlx.Stmt `yesql:"get_contacts"` - GetUserFriend *sqlx.Stmt `yesql:"get_user_friend"` - RejectFriend *sqlx.Stmt `yesql:"reject_friend"` - RequestingFriend *sqlx.Stmt `yesql:"requesting_friend"` - TotalContactsById *sqlx.Stmt `yesql:"total_contacts_by_id"` + yesql.Namespace `yesql:"contact_manager"` + AddFriendMsgsUpdate *sqlx.Stmt `yesql:"add_friend_msgs_update"` + CreateContact *sqlx.Stmt `yesql:"create_contact"` + DelFriend *sqlx.Stmt `yesql:"del_friend"` + FreshContactStatus *sqlx.Stmt `yesql:"fresh_contact_status"` + GetContact *sqlx.Stmt `yesql:"get_contact"` + GetContacts *sqlx.Stmt `yesql:"get_contacts"` + GetUserFriend *sqlx.Stmt `yesql:"get_user_friend"` + IsFriend *sqlx.Stmt `yesql:"is_friend"` + ListFriend *sqlx.Stmt `yesql:"list_friend"` + RejectFriendMsgsUpdate *sqlx.Stmt `yesql:"reject_friend_msgs_update"` + TotalFriendsById *sqlx.Stmt `yesql:"total_friends_by_id"` + CreateMessage *sqlx.NamedStmt `yesql:"create_message"` } type FollowIndex struct { @@ -436,25 +446,40 @@ func BuildContactManager(p yesql.PreparexBuilder, ctx ...context.Context) (obj * c = context.Background() } obj = &ContactManager{} - if obj.AddFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_AddFriend))); err != nil { + if obj.AddFriendMsgsUpdate, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_AddFriendMsgsUpdate))); err != nil { + return + } + if obj.CreateContact, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_CreateContact))); err != nil { return } if obj.DelFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_DelFriend))); err != nil { return } + if obj.FreshContactStatus, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_FreshContactStatus))); err != nil { + return + } + if obj.GetContact, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_GetContact))); err != nil { + return + } if obj.GetContacts, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_GetContacts))); err != nil { return } if obj.GetUserFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_GetUserFriend))); err != nil { return } - if obj.RejectFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_RejectFriend))); err != nil { + if obj.IsFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_IsFriend))); err != nil { + return + } + if obj.ListFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_ListFriend))); err != nil { + return + } + if obj.RejectFriendMsgsUpdate, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_RejectFriendMsgsUpdate))); err != nil { return } - if obj.RequestingFriend, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_RequestingFriend))); err != nil { + if obj.TotalFriendsById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_TotalFriendsById))); err != nil { return } - if obj.TotalContactsById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_ContactManager_TotalContactsById))); err != nil { + if obj.CreateMessage, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_ContactManager_CreateMessage))); err != nil { return } return diff --git a/internal/dao/sakila/yesql/yesql.sql b/internal/dao/sakila/yesql/yesql.sql index cb08e721..181b8458 100644 --- a/internal/dao/sakila/yesql/yesql.sql +++ b/internal/dao/sakila/yesql/yesql.sql @@ -113,33 +113,53 @@ UPDATE @comment_reply SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? -- contact_manager sql dml -------------------------------------------------------------------------------- --- name: requesting_friend@contact_manager +-- name: create_contact@contact_manager -- prepare: stmt -SELECT * FROM @user WHERE username=? +INSERT INTO @contact (user_id, friend_id, status, created_on) VALUES (?, ?, ?, ?); --- name: add_friend@contact_manager +-- name: fresh_contact_status@contact_manager -- prepare: stmt -SELECT * FROM @user WHERE username=? +UPDATE @contact SET status=?, modified_on=?, is_del=0 WHERE id=?; --- name: reject_friend@contact_manager +-- name: create_message@contact_manager +-- prepare: named_stmt +INSERT INTO @message (sender_user_id, receiver_user_id, type, brief, content, reply_id, created_on) VALUES (:sender_user_id, :receiver_user_id, :type, :brief, :content, :reply_id, :created_on); + +-- name: add_friend_msgs_update@contact_manager -- prepare: stmt -SELECT * FROM @user WHERE username=? +UPDATE @message SET reply_id=?, modified_on=? WHERE ((sender_user_id = ? AND receiver_user_id = ?) OR (sender_user_id = ? AND receiver_user_id = ?)) AND type = ? AND reply_id = ?; + +-- name: reject_friend_msgs_update@contact_manager +-- prepare: stmt +UPDATE @message SET reply_id=?, modified_on=? WHERE sender_user_id = ? AND receiver_user_id = ? AND type = ? AND reply_id = ?; -- name: del_friend@contact_manager -- prepare: stmt -SELECT * FROM @user WHERE username=? +UPDATE @contact SET status=4, is_del=1, deleted_on=? WHERE id=?; --- name: get_contacts@contact_manager +-- name: list_friend@contact_manager -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT c.friend_id user_id, u.username username, u.nickname nickname, u.avatar avatar, u.phone phone FROM @contact c JOIN @user u ON c.friend_id=u.id WHERE user_id=? AND status=2 AND is_del=0 ORDER BY u.nickname ASC LIMIT ? OFFSET ?; --- name: total_contacts_by_id@contact_manager +-- name: total_friends_by_id@contact_manager -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT count(*) FROM @contact WHERE user_id=? AND status=2 AND is_del=0 LIMIT ? OFFSET ?; + +-- name: get_contacts@contact_manager +-- prepare: stmt +SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del FROM @contact WHERE (user_id=? AND friend_id=?) OR (user_id=? AND friend_id=?); -- name: get_user_friend@contact_manager -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0; + +-- name: get_contact@contact_manager +-- prepare: stmt +SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del FROM @contact WHERE user_id=? AND friend_id=?; + +-- name: is_friend@contact_manager +-- prepare: stmt +SELECT true FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0 AND status=2; -------------------------------------------------------------------------------- -- message sql dml From 7665c1fd0ceadcfb58fb206ffadc63dea99401cd Mon Sep 17 00:00:00 2001 From: Michael Li Date: Sat, 5 Aug 2023 12:50:46 +0800 Subject: [PATCH 12/19] sqlx: yesql gen script add go:build generate tag --- internal/dao/sakila/yesql/gen.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/dao/sakila/yesql/gen.go b/internal/dao/sakila/yesql/gen.go index 241ab0e3..eacbcdf2 100644 --- a/internal/dao/sakila/yesql/gen.go +++ b/internal/dao/sakila/yesql/gen.go @@ -1,3 +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. + +//go:build generate +// +build generate + package main import ( From a9743e25bd38ce6626f145d893ab16bcc06c54ea Mon Sep 17 00:00:00 2001 From: Michael Li Date: Sat, 5 Aug 2023 13:28:10 +0800 Subject: [PATCH 13/19] sqlx: messages logic is implemented complete. WIP %35 --- internal/dao/sakila/messages.go | 38 +++++++++++++++++---------- internal/dao/sakila/yesql/cc/yesql.go | 20 +++++++------- internal/dao/sakila/yesql/yesql.sql | 14 +++++----- 3 files changed, 41 insertions(+), 31 deletions(-) diff --git a/internal/dao/sakila/messages.go b/internal/dao/sakila/messages.go index 767e949f..8967b8c5 100644 --- a/internal/dao/sakila/messages.go +++ b/internal/dao/sakila/messages.go @@ -5,6 +5,8 @@ package sakila import ( + "time" + "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/ms" @@ -21,17 +23,19 @@ type messageSrv struct { q *cc.Message } -func (s *messageSrv) CreateMessage(msg *ms.Message) (*ms.Message, error) { - res, err := s.q.CreateMessage.Exec(msg) +func (s *messageSrv) CreateMessage(r *ms.Message) (*ms.Message, error) { + r.Model = &dbr.Model{ + CreatedOn: time.Now().Unix(), + } + res, err := s.q.CreateMessage.Exec(r) if err != nil { return nil, err } - id, err := res.LastInsertId() + r.ID, err = res.LastInsertId() if err != nil { return nil, err } - msg.Model = &dbr.Model{ID: id} - return msg, nil + return r, nil } func (s *messageSrv) GetUnreadCount(userID int64) (res int64, err error) { @@ -39,22 +43,28 @@ func (s *messageSrv) GetUnreadCount(userID int64) (res int64, err error) { return } -func (s *messageSrv) GetMessageByID(id int64) (*ms.Message, error) { - res := &ms.Message{} - err := s.q.GetMessageById.Get(res, id) - return res, err +func (s *messageSrv) GetMessageByID(id int64) (res *ms.Message, err error) { + err = s.q.GetMessageById.Get(res, id) + return } -func (s *messageSrv) ReadMessage(message *ms.Message) (err error) { - _, err = s.q.ReadMessage.Exec(message) +func (s *messageSrv) ReadMessage(r *ms.Message) (err error) { + _, err = s.q.ReadMessage.Exec(time.Now().Unix(), r.ID) return } func (s *messageSrv) GetMessages(r *ms.ConditionsT, offset, limit int) ([]*ms.MessageFormated, error) { - res := []*ms.MessageFormated{} + var messages []*ms.Message (*r)["limit"], (*r)["offset"] = limit, offset - err := s.q.GetMessages.Select(&res, r) - return res, err + if err := s.q.GetMessages.Select(&messages, r); err != nil { + return nil, err + } + mfs := make([]*dbr.MessageFormated, 0, len(messages)) + for _, message := range messages { + mf := message.Format() + mfs = append(mfs, mf) + } + return mfs, nil } func (s *messageSrv) GetMessageCount(r *ms.ConditionsT) (res int64, err error) { diff --git a/internal/dao/sakila/yesql/cc/yesql.go b/internal/dao/sakila/yesql/cc/yesql.go index fdbec867..3e979936 100644 --- a/internal/dao/sakila/yesql/cc/yesql.go +++ b/internal/dao/sakila/yesql/cc/yesql.go @@ -54,12 +54,12 @@ const ( _FriendIndex_UserInfo = `SELECT * FROM @user WHERE username=?` _LightIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` _LightIndex_UserInfo = `SELECT * FROM @user WHERE username=?` - _Message_CreateMessage = `SELECT * FROM @user WHERE username=?` - _Message_GetMessageById = `SELECT * FROM @user WHERE username=?` - _Message_GetMessageCount = `SELECT * FROM @user WHERE username=?` - _Message_GetMessages = `SELECT * FROM @user WHERE username=?` - _Message_GetUnreadCount = `SELECT * FROM @user WHERE username=?` - _Message_ReadMessage = `SELECT * FROM @user WHERE username=?` + _Message_CreateMessage = `INSERT INTO @message (sender_user_id, receiver_user_id, type, brief, content, post_id, comment_id, reply_id, created_on) VALUES (:sender_user_id, :receiver_user_id, :type, :brief, :content, :post_id, :comment_id, :reply_id, :created_on)` + _Message_GetMessageById = `SELECT * FROM @message WHERE id=? AND is_del=0` + _Message_GetMessageCount = `SELECT count(*) FROM @message WHERE receiver_user_id=:recerver_user_id AND is_del=0` + _Message_GetMessages = `SELECT * FROM @message WHERE receiver_user_id=:recerver_user_id AND is_del=0 ORDER BY id DESC LIMIT :limit OFFSET :offset` + _Message_GetUnreadCount = `SELECT count(*) FROM @message WHERE receiver_user_id=? AND is_read=0 AND is_del=0` + _Message_ReadMessage = `UPDATE @message SET is_read=1, modified_on=? WHERE id=?` _Security_CreatePhoneCaptcha = `SELECT * FROM @user WHERE username=?` _Security_GetLatestPhoneCaptcha = `SELECT * FROM @user WHERE username=?` _Security_SendPhoneCaptcha = `SELECT * FROM @user WHERE username=?` @@ -217,10 +217,10 @@ type Message struct { yesql.Namespace `yesql:"message"` GetMessageById *sqlx.Stmt `yesql:"get_message_by_id"` GetUnreadCount *sqlx.Stmt `yesql:"get_unread_count"` + ReadMessage *sqlx.Stmt `yesql:"read_message"` CreateMessage *sqlx.NamedStmt `yesql:"create_message"` GetMessageCount *sqlx.NamedStmt `yesql:"get_message_count"` GetMessages *sqlx.NamedStmt `yesql:"get_messages"` - ReadMessage *sqlx.NamedStmt `yesql:"read_message"` } type Security struct { @@ -583,6 +583,9 @@ func BuildMessage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Message if obj.GetUnreadCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_GetUnreadCount))); err != nil { return } + if obj.ReadMessage, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_ReadMessage))); err != nil { + return + } if obj.CreateMessage, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_Message_CreateMessage))); err != nil { return } @@ -592,9 +595,6 @@ func BuildMessage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Message if obj.GetMessages, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_Message_GetMessages))); err != nil { return } - if obj.ReadMessage, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_Message_ReadMessage))); err != nil { - return - } return } diff --git a/internal/dao/sakila/yesql/yesql.sql b/internal/dao/sakila/yesql/yesql.sql index 181b8458..bf08bbe6 100644 --- a/internal/dao/sakila/yesql/yesql.sql +++ b/internal/dao/sakila/yesql/yesql.sql @@ -167,27 +167,27 @@ SELECT true FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0 AND statu -- name: create_message@message -- prepare: named_stmt -SELECT * FROM @user WHERE username=? +INSERT INTO @message (sender_user_id, receiver_user_id, type, brief, content, post_id, comment_id, reply_id, created_on) VALUES (:sender_user_id, :receiver_user_id, :type, :brief, :content, :post_id, :comment_id, :reply_id, :created_on); -- name: get_unread_count@message -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT count(*) FROM @message WHERE receiver_user_id=? AND is_read=0 AND is_del=0; -- name: get_message_by_id@message -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT * FROM @message WHERE id=? AND is_del=0; -- name: read_message@message --- prepare: named_stmt -SELECT * FROM @user WHERE username=? +-- prepare: stmt +UPDATE @message SET is_read=1, modified_on=? WHERE id=?; -- name: get_messages@message -- prepare: named_stmt -SELECT * FROM @user WHERE username=? +SELECT * FROM @message WHERE receiver_user_id=:recerver_user_id AND is_del=0 ORDER BY id DESC LIMIT :limit OFFSET :offset -- name: get_message_count@message -- prepare: named_stmt -SELECT * FROM @user WHERE username=? +SELECT count(*) FROM @message WHERE receiver_user_id=:recerver_user_id AND is_del=0; -------------------------------------------------------------------------------- -- security sql dml From 5957eeacc3aa3c3b7897e32e18b0ea3c61cb5b99 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Sat, 5 Aug 2023 13:47:42 +0800 Subject: [PATCH 14/19] sqlx: security logic is implemented complete. WIP %40 --- internal/dao/jinzhu/security.go | 5 +++-- internal/dao/sakila/security.go | 18 ++++++++++-------- internal/dao/sakila/yesql/cc/yesql.go | 15 +++++---------- internal/dao/sakila/yesql/yesql.sql | 10 +++------- 4 files changed, 21 insertions(+), 27 deletions(-) diff --git a/internal/dao/jinzhu/security.go b/internal/dao/jinzhu/security.go index d4d99d0d..18a8ccae 100644 --- a/internal/dao/jinzhu/security.go +++ b/internal/dao/jinzhu/security.go @@ -21,12 +21,14 @@ 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, } } @@ -49,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/sakila/security.go b/internal/dao/sakila/security.go index 49707281..c24af9ce 100644 --- a/internal/dao/sakila/security.go +++ b/internal/dao/sakila/security.go @@ -23,20 +23,19 @@ var ( type securitySrv struct { *sqlxSrv q *cc.Security + rand *rand.Rand phoneVerify core.PhoneVerifyService } // GetLatestPhoneCaptcha 获取最新短信验证码 -func (s *securitySrv) GetLatestPhoneCaptcha(phone string) (*ms.Captcha, error) { - res := &ms.Captcha{} - err := s.q.GetLatestPhoneCaptcha.Get(res, phone) - return res, err +func (s *securitySrv) GetLatestPhoneCaptcha(phone string) (res *ms.Captcha, err error) { + err = s.q.GetLatestPhoneCaptcha.Get(res, phone) + return } // UsePhoneCaptcha 更新短信验证码 func (s *securitySrv) UsePhoneCaptcha(r *ms.Captcha) error { - r.UseTimes++ - _, err := s.q.UsePhoneCaptcha.Exec(r) + _, err := s.q.UsePhoneCaptcha.Exec(time.Now().Unix(), r.ID) return err } @@ -44,13 +43,15 @@ func (s *securitySrv) UsePhoneCaptcha(r *ms.Captcha) error { 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 } // 写入表 phoneCaptcha := &dbr.Captcha{ + Model: &ms.Model{ + CreatedOn: time.Now().Unix(), + }, Phone: phone, Captcha: captcha, ExpiredOn: time.Now().Add(expire * time.Minute).Unix(), @@ -63,6 +64,7 @@ func newSecurityService(db *sqlx.DB, phoneVerify core.PhoneVerifyService) core.S return &securitySrv{ sqlxSrv: newSqlxSrv(db), q: mustBuild(db, cc.BuildSecurity), + rand: rand.New(rand.NewSource(time.Now().UnixNano())), phoneVerify: phoneVerify, } } diff --git a/internal/dao/sakila/yesql/cc/yesql.go b/internal/dao/sakila/yesql/cc/yesql.go index 3e979936..fc4eb48d 100644 --- a/internal/dao/sakila/yesql/cc/yesql.go +++ b/internal/dao/sakila/yesql/cc/yesql.go @@ -60,10 +60,9 @@ const ( _Message_GetMessages = `SELECT * FROM @message WHERE receiver_user_id=:recerver_user_id AND is_del=0 ORDER BY id DESC LIMIT :limit OFFSET :offset` _Message_GetUnreadCount = `SELECT count(*) FROM @message WHERE receiver_user_id=? AND is_read=0 AND is_del=0` _Message_ReadMessage = `UPDATE @message SET is_read=1, modified_on=? WHERE id=?` - _Security_CreatePhoneCaptcha = `SELECT * FROM @user WHERE username=?` - _Security_GetLatestPhoneCaptcha = `SELECT * FROM @user WHERE username=?` - _Security_SendPhoneCaptcha = `SELECT * FROM @user WHERE username=?` - _Security_UsePhoneCaptcha = `SELECT * FROM @user WHERE username=?` + _Security_CreatePhoneCaptcha = `INSERT INTO @captcha (phone, captcha, expired_on, created_on) VALUES (:phone, :captcha, :expired_on, :created_on)` + _Security_GetLatestPhoneCaptcha = `SELECT * FROM @captcha WHERE phone=:phone AND is_del=0` + _Security_UsePhoneCaptcha = `UPDATE @captcha SET use_times=use_times+1, modified_on=? WHERE id=? AND is_del=0` _SimpleIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` _SimpleIndex_UserInfo = `SELECT * FROM @user WHERE username=?` _TopicA_DecrTagsById = `UPDATE @tag SET quote_num=quote_num-1, modified_on=? WHERE id IN (?)` @@ -226,9 +225,8 @@ type Message struct { type Security struct { yesql.Namespace `yesql:"security"` GetLatestPhoneCaptcha *sqlx.Stmt `yesql:"get_latest_phone_captcha"` - SendPhoneCaptcha *sqlx.Stmt `yesql:"send_phone_captcha"` + UsePhoneCaptcha *sqlx.Stmt `yesql:"use_phone_captcha"` CreatePhoneCaptcha *sqlx.NamedStmt `yesql:"create_phone_captcha"` - UsePhoneCaptcha *sqlx.NamedStmt `yesql:"use_phone_captcha"` } type SimpleIndex struct { @@ -609,15 +607,12 @@ func BuildSecurity(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Securi if obj.GetLatestPhoneCaptcha, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Security_GetLatestPhoneCaptcha))); err != nil { return } - if obj.SendPhoneCaptcha, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Security_SendPhoneCaptcha))); err != nil { + if obj.UsePhoneCaptcha, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Security_UsePhoneCaptcha))); err != nil { return } if obj.CreatePhoneCaptcha, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_Security_CreatePhoneCaptcha))); err != nil { return } - if obj.UsePhoneCaptcha, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_Security_UsePhoneCaptcha))); err != nil { - return - } return } diff --git a/internal/dao/sakila/yesql/yesql.sql b/internal/dao/sakila/yesql/yesql.sql index bf08bbe6..ba23f083 100644 --- a/internal/dao/sakila/yesql/yesql.sql +++ b/internal/dao/sakila/yesql/yesql.sql @@ -195,19 +195,15 @@ SELECT count(*) FROM @message WHERE receiver_user_id=:recerver_user_id AND is_de -- name: get_latest_phone_captcha@security -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT * FROM @captcha WHERE phone=? AND is_del=0; -- name: use_phone_captcha@security --- prepare: named_stmt -SELECT * FROM @user WHERE username=? - --- name: send_phone_captcha@security -- prepare: stmt -SELECT * FROM @user WHERE username=? +UPDATE @captcha SET use_times=use_times+1, modified_on=? WHERE id=? AND is_del=0; -- name: create_phone_captcha@security -- prepare: named_stmt -SELECT * FROM @user WHERE username=? +INSERT INTO @captcha (phone, captcha, expired_on, created_on) VALUES (:phone, :captcha, :expired_on, :created_on); -------------------------------------------------------------------------------- -- friend_index sql dml From 250fd0af152069c7480620309dcf59027f3ed779 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Sat, 5 Aug 2023 14:18:06 +0800 Subject: [PATCH 15/19] sqlx: user logic is implemented complete. WIP %45 --- internal/dao/sakila/user.go | 51 +++++++++++++++------------ internal/dao/sakila/yesql/cc/yesql.go | 39 +++++++++++--------- internal/dao/sakila/yesql/yesql.sql | 24 ++++++++----- 3 files changed, 65 insertions(+), 49 deletions(-) diff --git a/internal/dao/sakila/user.go b/internal/dao/sakila/user.go index 6910df62..48e2b0d8 100644 --- a/internal/dao/sakila/user.go +++ b/internal/dao/sakila/user.go @@ -5,6 +5,9 @@ package sakila import ( + "strings" + "time" + "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/ms" @@ -21,48 +24,50 @@ type userManageSrv struct { q *cc.UserManage } -func (s *userManageSrv) GetUserByID(id int64) (*ms.User, error) { - res := &ms.User{} - err := s.q.GetUserById.Get(res, id) - return res, err +func (s *userManageSrv) GetUserByID(id int64) (res *ms.User, err error) { + err = s.q.GetUserById.Get(res, id) + return } -func (s *userManageSrv) GetUserByUsername(username string) (*ms.User, error) { - res := &ms.User{} - err := s.q.GetUserByUsername.Get(res, username) - return res, err +func (s *userManageSrv) GetUserByUsername(username string) (res *ms.User, err error) { + err = s.q.GetUserByUsername.Get(res, username) + return } -func (s *userManageSrv) GetUserByPhone(phone string) (*ms.User, error) { - res := &ms.User{} - err := s.q.GetUserByPhone.Get(res, phone) - return res, err +func (s *userManageSrv) GetUserByPhone(phone string) (res *ms.User, err error) { + err = s.q.GetUserByPhone.Get(res, phone) + return } -func (s *userManageSrv) GetUsersByIDs(ids []int64) ([]*ms.User, error) { - res := []*ms.User{} - err := s.inSelect(&res, s.q.GetUsersByIds, ids) - return res, err +func (s *userManageSrv) GetUsersByIDs(ids []int64) (res []*ms.User, err error) { + err = s.inSelect(&res, s.q.GetUsersByIds, ids) + return } -func (s *userManageSrv) GetUsersByKeyword(keyword string) ([]*ms.User, error) { - res := []*ms.User{} - err := s.q.GetUsersByKeyword.Select(&res, keyword) - return res, err +func (s *userManageSrv) GetUsersByKeyword(keyword string) (res []*ms.User, err error) { + keyword = strings.Trim(keyword, " ") + "%" + if keyword == "%" { + err = s.q.GetAnyUsers.Get(&res) + } else { + err = s.q.GetUsersByKeyword.Select(&res, keyword) + } + return } func (s *userManageSrv) CreateUser(r *ms.User) (*ms.User, error) { - res, err := s.q.AddUser.Exec(r.Username, r.Nickname, r.Password, r.Salt, r.Avatar) + r.Model = &ms.Model{ + CreatedOn: time.Now().Unix(), + } + res, err := s.q.CreateUser.Exec(r) if err != nil { return nil, err } - r.Model = &dbr.Model{} r.ID, err = res.LastInsertId() return r, err } func (s *userManageSrv) UpdateUser(r *ms.User) error { - _, err := s.q.UpdateUser.Exec(r.Nickname, r.Password, r.Salt, r.Phone, r.Status) + _, err := s.q.UpdateUser.Exec(r) return err } diff --git a/internal/dao/sakila/yesql/cc/yesql.go b/internal/dao/sakila/yesql/cc/yesql.go index fc4eb48d..b181baee 100644 --- a/internal/dao/sakila/yesql/cc/yesql.go +++ b/internal/dao/sakila/yesql/cc/yesql.go @@ -61,7 +61,7 @@ const ( _Message_GetUnreadCount = `SELECT count(*) FROM @message WHERE receiver_user_id=? AND is_read=0 AND is_del=0` _Message_ReadMessage = `UPDATE @message SET is_read=1, modified_on=? WHERE id=?` _Security_CreatePhoneCaptcha = `INSERT INTO @captcha (phone, captcha, expired_on, created_on) VALUES (:phone, :captcha, :expired_on, :created_on)` - _Security_GetLatestPhoneCaptcha = `SELECT * FROM @captcha WHERE phone=:phone AND is_del=0` + _Security_GetLatestPhoneCaptcha = `SELECT * FROM @captcha WHERE phone=? AND is_del=0` _Security_UsePhoneCaptcha = `UPDATE @captcha SET use_times=use_times+1, modified_on=? WHERE id=? AND is_del=0` _SimpleIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` _SimpleIndex_UserInfo = `SELECT * FROM @user WHERE username=?` @@ -115,13 +115,14 @@ const ( _TweetManage_StickPost = `SELECT * FROM @user WHERE username=?` _TweetManage_UpdatePost = `SELECT * FROM @user WHERE username=?` _TweetManage_VisiblePost = `SELECT * FROM @user WHERE username=?` - _UserManage_AddUser = `SELECT * FROM @user WHERE username=?` - _UserManage_GetUserById = `SELECT * FROM @user WHERE username=?` - _UserManage_GetUserByPhone = `SELECT * FROM @user WHERE username=?` - _UserManage_GetUserByUsername = `SELECT * FROM @user WHERE username=?` - _UserManage_GetUsersByIds = `SELECT * FROM @user WHERE username=?` - _UserManage_GetUsersByKeyword = `SELECT * FROM @user WHERE username=?` - _UserManage_UpdateUser = `SELECT * FROM @user WHERE username=?` + _UserManage_CreateUser = `INSERT INTO @user (username, nickname, password, salt, avatar, status, created_on) VALUES (:username, :nickname, :password, :salt, :avatar, :status, :created_on)` + _UserManage_GetAnyUsers = `SELECT * FROM @user WHERE is_del=0 ORDER BY id ASC limit 6` + _UserManage_GetUserById = `SELECT * FROM @user WHERE id=? AND is_del=0` + _UserManage_GetUserByPhone = `SELECT * FROM @user WHERE phone=? AND is_del=0` + _UserManage_GetUserByUsername = `SELECT * FROM @user WHERE username=? AND is_del=0` + _UserManage_GetUsersByIds = `SELECT * FROM @user WHERE id IN ? AND is_del=0` + _UserManage_GetUsersByKeyword = `SELECT * FROM @user WHERE username LIKE ? AND is_del=0 limit 6` + _UserManage_UpdateUser = `UPDATE @user SET username=:username, nickname=:nickname, phone=:phone, password=:password, salt=:salt, status=:status, avatar=:avatar, balance=:balance, is_admin=:is_admin, modified_on=:modified_on WHERE id=? AND is_del=0` _Wallet_CreateRecharge = `SELECT * FROM @user WHERE username=?` _Wallet_GetRechargeById = `SELECT * FROM @user WHERE username=?` _Wallet_GetUserWalletBillCount = `SELECT * FROM @user WHERE username=?` @@ -319,13 +320,14 @@ type TweetManageA struct { type UserManage struct { yesql.Namespace `yesql:"user_manage"` - GetUsersByIds string `yesql:"get_users_by_ids"` - AddUser *sqlx.Stmt `yesql:"add_user"` - GetUserById *sqlx.Stmt `yesql:"get_user_by_id"` - GetUserByPhone *sqlx.Stmt `yesql:"get_user_by_phone"` - GetUserByUsername *sqlx.Stmt `yesql:"get_user_by_username"` - GetUsersByKeyword *sqlx.Stmt `yesql:"get_users_by_keyword"` - UpdateUser *sqlx.Stmt `yesql:"update_user"` + GetUsersByIds string `yesql:"get_users_by_ids"` + GetAnyUsers *sqlx.Stmt `yesql:"get_any_users"` + GetUserById *sqlx.Stmt `yesql:"get_user_by_id"` + GetUserByPhone *sqlx.Stmt `yesql:"get_user_by_phone"` + GetUserByUsername *sqlx.Stmt `yesql:"get_user_by_username"` + GetUsersByKeyword *sqlx.Stmt `yesql:"get_users_by_keyword"` + CreateUser *sqlx.NamedStmt `yesql:"create_user"` + UpdateUser *sqlx.NamedStmt `yesql:"update_user"` } type Wallet struct { @@ -862,7 +864,7 @@ func BuildUserManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *User obj = &UserManage{ GetUsersByIds: p.QueryHook(_UserManage_GetUsersByIds), } - if obj.AddUser, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserManage_AddUser))); err != nil { + if obj.GetAnyUsers, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserManage_GetAnyUsers))); err != nil { return } if obj.GetUserById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserManage_GetUserById))); err != nil { @@ -877,7 +879,10 @@ func BuildUserManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *User if obj.GetUsersByKeyword, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserManage_GetUsersByKeyword))); err != nil { return } - if obj.UpdateUser, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserManage_UpdateUser))); err != nil { + if obj.CreateUser, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_UserManage_CreateUser))); err != nil { + return + } + if obj.UpdateUser, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_UserManage_UpdateUser))); err != nil { return } return diff --git a/internal/dao/sakila/yesql/yesql.sql b/internal/dao/sakila/yesql/yesql.sql index ba23f083..71620aa2 100644 --- a/internal/dao/sakila/yesql/yesql.sql +++ b/internal/dao/sakila/yesql/yesql.sql @@ -521,32 +521,38 @@ UPDATE @tag SET quote_num=quote_num+1, is_del=0, modified_on=? WHERE id IN (?); -- name: get_user_by_id@user_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT * FROM @user WHERE id=? AND is_del=0; -- name: get_user_by_username@user_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT * FROM @user WHERE username=? AND is_del=0; -- name: get_user_by_phone@user_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT * FROM @user WHERE phone=? AND is_del=0; -- name: get_users_by_ids@user_manage -- prepare: raw -- clause: in -SELECT * FROM @user WHERE username=? +SELECT * FROM @user WHERE id IN ? AND is_del=0; -- name: get_users_by_keyword@user_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT * FROM @user WHERE username LIKE ? AND is_del=0 limit 6; --- name: add_user@user_manage +-- name: get_any_users@user_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT * FROM @user WHERE is_del=0 ORDER BY id ASC limit 6; + +-- name: create_user@user_manage +-- prepare: named_stmt +INSERT INTO @user (username, nickname, password, salt, avatar, status, created_on) VALUES (:username, :nickname, :password, :salt, :avatar, :status, :created_on); -- name: update_user@user_manage --- prepare: stmt -SELECT * FROM @user WHERE username=? +-- prepare: named_stmt +UPDATE @user SET username=:username, nickname=:nickname, phone=:phone, + password=:password, salt=:salt, status=:status, avatar=:avatar, balance=:balance, + is_admin=:is_admin, modified_on=:modified_on WHERE id=? AND is_del=0; -------------------------------------------------------------------------------- -- wallet sql dml From fc8a33a14d8b42ae3fdbe28a3f82b5cb23ce9ba4 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Sat, 5 Aug 2023 15:23:42 +0800 Subject: [PATCH 16/19] sqlx: wallet logic is implemented complete. WIP %55 --- internal/dao/sakila/user.go | 1 - internal/dao/sakila/wallet.go | 90 +++++++++++++++++++++------ internal/dao/sakila/yesql/cc/yesql.go | 74 +++++++++++++++++----- internal/dao/sakila/yesql/yesql.sql | 40 +++++++++--- 4 files changed, 163 insertions(+), 42 deletions(-) diff --git a/internal/dao/sakila/user.go b/internal/dao/sakila/user.go index 48e2b0d8..7fb64e07 100644 --- a/internal/dao/sakila/user.go +++ b/internal/dao/sakila/user.go @@ -11,7 +11,6 @@ import ( "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/ms" - "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" ) diff --git a/internal/dao/sakila/wallet.go b/internal/dao/sakila/wallet.go index 3fff19fe..29ad1cd1 100644 --- a/internal/dao/sakila/wallet.go +++ b/internal/dao/sakila/wallet.go @@ -5,12 +5,14 @@ package sakila import ( + "time" + "github.com/jmoiron/sqlx" + "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" "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" - "github.com/rocboss/paopao-ce/pkg/debug" ) var ( @@ -22,14 +24,14 @@ type walletSrv struct { q *cc.Wallet } -func (s *walletSrv) GetRechargeByID(id int64) (*ms.WalletRecharge, error) { - res := &ms.WalletRecharge{} - err := s.q.GetRechargeById.Get(res, id) - return res, err +func (s *walletSrv) GetRechargeByID(id int64) (res *ms.WalletRecharge, err error) { + err = s.q.GetRechargeById.Get(res, id) + return } func (s *walletSrv) CreateRecharge(userId, amount int64) (*ms.WalletRecharge, error) { - res, err := s.q.CreateRecharge.Exec(userId, amount) + now := time.Now().Unix() + res, err := s.q.CreateRecharge.Exec(userId, amount, now) if err != nil { return nil, err } @@ -39,17 +41,17 @@ func (s *walletSrv) CreateRecharge(userId, amount int64) (*ms.WalletRecharge, er } return &ms.WalletRecharge{ Model: &dbr.Model{ - ID: id, + ID: id, + CreatedOn: now, }, UserID: userId, Amount: amount, }, nil } -func (s *walletSrv) GetUserWalletBills(userID int64, offset, limit int) ([]*ms.WalletStatement, error) { - res := []*ms.WalletStatement{} - err := s.q.GetUserWalletBills.Select(&res, userID, limit, offset) - return res, err +func (s *walletSrv) GetUserWalletBills(userID int64, offset, limit int) (res []*ms.WalletStatement, err error) { + err = s.q.GetUserWalletBills.Select(&res, userID, limit, offset) + return } func (s *walletSrv) GetUserWalletBillCount(userID int64) (res int64, err error) { @@ -57,16 +59,68 @@ func (s *walletSrv) GetUserWalletBillCount(userID int64) (res int64, err error) return } -func (s *walletSrv) HandleRechargeSuccess(recharge *ms.WalletRecharge, tradeNo string) error { - // TODO - debug.NotImplemented() - return nil +func (s *walletSrv) HandleRechargeSuccess(r *ms.WalletRecharge, tradeNo string) error { + return s.with(func(tx *sqlx.Tx) error { + var oldBalance int64 + // 获取当前金额 + err := tx.Stmtx(s.q.GetUserBalance).Get(&oldBalance, r.UserID) + if err != nil { + return err + } + now := time.Now().Unix() + // 更新金额 + if _, err := tx.Stmtx(s.q.AddUserBalance).Exec(r.Amount, now, r.UserID); err != nil { + return err + } + // 新增账单 + args := []any{r.UserID, r.Amount, oldBalance + r.Amount, "用户充值", now} + if _, err = tx.Stmtx(s.q.CreateWalletStatement).Exec(args...); err != nil { + return err + } + // 标记为已付款 + if _, err = tx.Stmtx(s.q.MarkSuccessRecharge).Exec(tradeNo, now, r.ID); err != nil { + return err + } + return nil + }) } func (s *walletSrv) HandlePostAttachmentBought(post *ms.Post, user *ms.User) error { - // TODO - debug.NotImplemented() - return nil + return s.with(func(tx *sqlx.Tx) error { + now := time.Now().Unix() + // 扣除金额 + _, err := tx.Stmtx(s.q.MinusUserBalance).Exec(post.AttachmentPrice, now, user.ID) + if err != nil { + return err + } + // 新增账单 + args := []any{post.ID, user.ID, -post.AttachmentPrice, user.Balance - post.AttachmentPrice, "购买附件支出", now} + if _, err = tx.Stmtx(s.q.NewPostBill).Exec(args...); err != nil { + return err + } + // 新增附件购买记录 + args = []any{post.ID, user.ID, post.AttachmentPrice, now} + if _, err = tx.Stmtx(s.q.NewPostBill).Exec(args...); err != nil { + return err + } + // 对附件主新增账单 + income := int64(float64(post.AttachmentPrice) * conf.AppSetting.AttachmentIncomeRate) + if income > 0 { + var oldBalance int64 + if err = tx.Stmtx(s.q.GetUserBalance).Get(&oldBalance, post.UserID); err != nil { + return err + } + if _, err = tx.Stmtx(s.q.AddUserBalance).Exec(income, now, post.UserID); err != nil { + return err + } + // 新增账单 + args = []any{post.ID, post.UserID, income, oldBalance + income, "出售附件收入", now} + if _, err = tx.Stmtx(s.q.NewPostBill).Exec(args...); err != nil { + return err + } + } + return nil + }) } func newWalletService(db *sqlx.DB) core.WalletService { diff --git a/internal/dao/sakila/yesql/cc/yesql.go b/internal/dao/sakila/yesql/cc/yesql.go index b181baee..fae1338f 100644 --- a/internal/dao/sakila/yesql/cc/yesql.go +++ b/internal/dao/sakila/yesql/cc/yesql.go @@ -12,6 +12,7 @@ import ( ) const ( + _NewPostAttachmentBill = `INSERT INTO @post_attachment_bill (post_id, user_id, paid_amount) VALUES (?, ?, ?)` _AuthorizationManage_BeFriendIds = `SELECT user_id FROM @contact WHERE friend_id=? AND status=2 AND is_del=0` _AuthorizationManage_IsFriend = `SELECT status FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0` _AuthorizationManage_MyFriendSet = `SELECT friend_id FROM @contact WHERE user_id=? AND status=2 AND is_del=0` @@ -123,14 +124,23 @@ const ( _UserManage_GetUsersByIds = `SELECT * FROM @user WHERE id IN ? AND is_del=0` _UserManage_GetUsersByKeyword = `SELECT * FROM @user WHERE username LIKE ? AND is_del=0 limit 6` _UserManage_UpdateUser = `UPDATE @user SET username=:username, nickname=:nickname, phone=:phone, password=:password, salt=:salt, status=:status, avatar=:avatar, balance=:balance, is_admin=:is_admin, modified_on=:modified_on WHERE id=? AND is_del=0` - _Wallet_CreateRecharge = `SELECT * FROM @user WHERE username=?` - _Wallet_GetRechargeById = `SELECT * FROM @user WHERE username=?` - _Wallet_GetUserWalletBillCount = `SELECT * FROM @user WHERE username=?` - _Wallet_GetUserWalletBills = `SELECT * FROM @user WHERE username=?` - _Wallet_HandlePostAttachementBought = `SELECT * FROM @user WHERE username=?` - _Wallet_HandleRechargeSuccess = `SELECT * FROM @user WHERE username=?` + _Wallet_AddUserBalance = `UPDATE @user SET balance=balance+?, modified_on=? WHERE id=? AND is_del=0` + _Wallet_CreateRecharge = `INSERT INTO @wallet_recharge (user_id, amount, created_on) VALUES (?, ?, ?)` + _Wallet_CreateWalletStatement = `INSERT INTO @wallet_statement (user_id, change_amount, balance_snapshot, reason, created_on) VALUES (?, ?, ?, ?, ?)` + _Wallet_GetRechargeById = `SELECT * FROM @wallet_recharge WHERE id=? AND is_del=?` + _Wallet_GetUserBalance = `SELECT balance FROM @user WHERE id=? AND is_del=0` + _Wallet_GetUserByUid = `SELECT * FROM @user WHERE id=? AND is_del=0` + _Wallet_GetUserWalletBillCount = `SELECT count(*) FROM @wallet_statement WHERE user_id=? AND is_del=0` + _Wallet_GetUserWalletBills = `SELECT * FROM @wallet_statement WHERE user_id=? AND is_del=0 ORDER BY id DESC LIMIT ? OFFSET ?` + _Wallet_MarkSuccessRecharge = `UPDATE @wallet_recharge SET trade_no=?, trade_status='TRADE_SUCCESS', modified_on=? WHERE id=? AND is_del=0` + _Wallet_MinusUserBalance = `UPDATE @user SET balance=balance-?, modified_on=? WHERE id=? AND is_del=0` + _Wallet_NewPostBill = `INSERT INTO @wallet_statement (post_id, user_id, change_amount, balance_snapshot, reason, created_on) VALUES (?, ?, ?, ?, ?, ?)` ) +type Yesql struct { + NewPostAttachmentBill *sqlx.Stmt `yesql:"new_post_attachment_bill"` +} + type AuthorizationManage struct { yesql.Namespace `yesql:"authorization_manage"` BeFriendIds *sqlx.Stmt `yesql:"be_friend_ids"` @@ -331,13 +341,32 @@ type UserManage struct { } type Wallet struct { - yesql.Namespace `yesql:"wallet"` - CreateRecharge *sqlx.Stmt `yesql:"create_recharge"` - GetRechargeById *sqlx.Stmt `yesql:"get_recharge_by_id"` - GetUserWalletBillCount *sqlx.Stmt `yesql:"get_user_wallet_bill_count"` - GetUserWalletBills *sqlx.Stmt `yesql:"get_user_wallet_bills"` - HandlePostAttachementBought *sqlx.Stmt `yesql:"handle_post_attachement_bought"` - HandleRechargeSuccess *sqlx.Stmt `yesql:"handle_recharge_success"` + yesql.Namespace `yesql:"wallet"` + AddUserBalance *sqlx.Stmt `yesql:"add_user_balance"` + CreateRecharge *sqlx.Stmt `yesql:"create_recharge"` + CreateWalletStatement *sqlx.Stmt `yesql:"create_wallet_statement"` + GetRechargeById *sqlx.Stmt `yesql:"get_recharge_by_id"` + GetUserBalance *sqlx.Stmt `yesql:"get_user_balance"` + GetUserByUid *sqlx.Stmt `yesql:"get_user_by_uid"` + GetUserWalletBillCount *sqlx.Stmt `yesql:"get_user_wallet_bill_count"` + GetUserWalletBills *sqlx.Stmt `yesql:"get_user_wallet_bills"` + MarkSuccessRecharge *sqlx.Stmt `yesql:"mark_success_recharge"` + MinusUserBalance *sqlx.Stmt `yesql:"minus_user_balance"` + NewPostBill *sqlx.Stmt `yesql:"new_post_bill"` +} + +func BuildYesql(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Yesql, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &Yesql{} + if obj.NewPostAttachmentBill, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_NewPostAttachmentBill))); err != nil { + return + } + return } func BuildAuthorizationManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *AuthorizationManage, err error) { @@ -896,22 +925,37 @@ func BuildWallet(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Wallet, c = context.Background() } obj = &Wallet{} + if obj.AddUserBalance, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_AddUserBalance))); err != nil { + return + } if obj.CreateRecharge, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_CreateRecharge))); err != nil { return } + if obj.CreateWalletStatement, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_CreateWalletStatement))); err != nil { + return + } if obj.GetRechargeById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_GetRechargeById))); err != nil { return } + if obj.GetUserBalance, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_GetUserBalance))); err != nil { + return + } + if obj.GetUserByUid, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_GetUserByUid))); err != nil { + return + } if obj.GetUserWalletBillCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_GetUserWalletBillCount))); err != nil { return } if obj.GetUserWalletBills, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_GetUserWalletBills))); err != nil { return } - if obj.HandlePostAttachementBought, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_HandlePostAttachementBought))); err != nil { + if obj.MarkSuccessRecharge, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_MarkSuccessRecharge))); err != nil { + return + } + if obj.MinusUserBalance, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_MinusUserBalance))); err != nil { return } - if obj.HandleRechargeSuccess, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_HandleRechargeSuccess))); err != nil { + if obj.NewPostBill, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_NewPostBill))); err != nil { return } return diff --git a/internal/dao/sakila/yesql/yesql.sql b/internal/dao/sakila/yesql/yesql.sql index 71620aa2..5944830c 100644 --- a/internal/dao/sakila/yesql/yesql.sql +++ b/internal/dao/sakila/yesql/yesql.sql @@ -560,24 +560,48 @@ UPDATE @user SET username=:username, nickname=:nickname, phone=:phone, -- name: get_user_wallet_bills@wallet -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT * FROM @wallet_statement WHERE user_id=? AND is_del=0 ORDER BY id DESC LIMIT ? OFFSET ?; -- name: get_user_wallet_bill_count@wallet -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT count(*) FROM @wallet_statement WHERE user_id=? AND is_del=0; -- name: get_recharge_by_id@wallet -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT * FROM @wallet_recharge WHERE id=? AND is_del=?; -- name: create_recharge@wallet -- prepare: stmt -SELECT * FROM @user WHERE username=? +INSERT INTO @wallet_recharge (user_id, amount, created_on) VALUES (?, ?, ?); --- name: handle_recharge_success@wallet +-- name: get_user_by_uid@wallet -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT * FROM @user WHERE id=? AND is_del=0; --- name: handle_post_attachement_bought@wallet +-- name: add_user_balance@wallet -- prepare: stmt -SELECT * FROM @user WHERE username=? +UPDATE @user SET balance=balance+?, modified_on=? WHERE id=? AND is_del=0; + +-- name: minus_user_balance@wallet +-- prepare: stmt +UPDATE @user SET balance=balance-?, modified_on=? WHERE id=? AND is_del=0; + +-- name: create_wallet_statement@wallet +-- prepare: stmt +INSERT INTO @wallet_statement (user_id, change_amount, balance_snapshot, reason, created_on) VALUES (?, ?, ?, ?, ?); + +-- name: get_user_balance@wallet +-- prepare: stmt +SELECT balance FROM @user WHERE id=? AND is_del=0; + +-- name: mark_success_recharge@wallet +-- prepare: stmt +UPDATE @wallet_recharge SET trade_no=?, trade_status='TRADE_SUCCESS', modified_on=? WHERE id=? AND is_del=0; + +-- name: new_post_attachment_bill +-- prepare: stmt +INSERT INTO @post_attachment_bill (post_id, user_id, paid_amount) VALUES (?, ?, ?); + +-- name: new_post_bill@wallet +-- prepare: stmt +INSERT INTO @wallet_statement (post_id, user_id, change_amount, balance_snapshot, reason, created_on) VALUES (?, ?, ?, ?, ?, ?); From 1a3edd3f8f3a30fb0f53081b85bb9643d02fd466 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Sat, 5 Aug 2023 15:37:04 +0800 Subject: [PATCH 17/19] sqlx: just format yesql.sql --- internal/dao/sakila/yesql/cc/yesql.go | 2 +- internal/dao/sakila/yesql/yesql.sql | 134 +++++++++++++++++++------- 2 files changed, 102 insertions(+), 34 deletions(-) diff --git a/internal/dao/sakila/yesql/cc/yesql.go b/internal/dao/sakila/yesql/cc/yesql.go index fae1338f..b1da4914 100644 --- a/internal/dao/sakila/yesql/cc/yesql.go +++ b/internal/dao/sakila/yesql/cc/yesql.go @@ -48,7 +48,7 @@ const ( _ContactManager_IsFriend = `SELECT true FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0 AND status=2` _ContactManager_ListFriend = `SELECT c.friend_id user_id, u.username username, u.nickname nickname, u.avatar avatar, u.phone phone FROM @contact c JOIN @user u ON c.friend_id=u.id WHERE user_id=? AND status=2 AND is_del=0 ORDER BY u.nickname ASC LIMIT ? OFFSET ?` _ContactManager_RejectFriendMsgsUpdate = `UPDATE @message SET reply_id=?, modified_on=? WHERE sender_user_id = ? AND receiver_user_id = ? AND type = ? AND reply_id = ?` - _ContactManager_TotalFriendsById = `SELECT count(*) FROM @contact WHERE user_id=? AND status=2 AND is_del=0 LIMIT ? OFFSET ?` + _ContactManager_TotalFriendsById = `SELECT count(*) FROM @contact WHERE user_id=? AND status=2 AND is_del=0` _FollowIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` _FollowIndex_UserInfo = `SELECT * FROM @user WHERE username=?` _FriendIndexA_UserInfo = `SELECT * FROM @user WHERE username=?` diff --git a/internal/dao/sakila/yesql/yesql.sql b/internal/dao/sakila/yesql/yesql.sql index 5944830c..6c6c941f 100644 --- a/internal/dao/sakila/yesql/yesql.sql +++ b/internal/dao/sakila/yesql/yesql.sql @@ -63,15 +63,19 @@ UPDATE @comment SET deleted_on=?, is_del=1 WHERE id=? AND is_del=0; -- name: delete_comment_thumbs@comment_manage -- prepare: stmt -UPDATE @tweet_comment_thumbs SET deleted_on=?, is_del=1 WHERE user_id=? AND tweet_id=? AND comment_id=? AND is_del=0; +UPDATE @tweet_comment_thumbs +SET deleted_on=?, is_del=1 +WHERE user_id=? AND tweet_id=? AND comment_id=? AND is_del=0; -- name: create_comment@comment_manage -- prepare: stmt -INSERT INTO @comment (post_id, user_id, ip, ip_loc, created_on) VALUES (?, ?, ?, ?, ?); +INSERT INTO @comment (post_id, user_id, ip, ip_loc, created_on) +VALUES (?, ?, ?, ?, ?); -- name: create_comment_reply@comment_manage -- prepare: stmt -INSERT INTO @comment_reply (comment_id, user_id, content, at_user_id, ip, ip_loc, created_on) VALUES (?, ?, ?, ?, ?, ?, ?); +INSERT INTO @comment_reply (comment_id, user_id, content, at_user_id, ip, ip_loc, created_on) +VALUES (?, ?, ?, ?, ?, ?, ?); -- name: delete_comment_reply@comment_manage -- prepare: stmt @@ -79,35 +83,49 @@ UPDATE @comment_reply SET deleted_on=?, is_del=1 WHERE id=? AND is_del=0; -- name: delete_reply_thumbs@comment_manage -- prepare: stmt -UPDATE @tweet_comment_thumbs SET deleted_on=?, is_del=1 WHERE user_id=? AND comment_id=? AND reply_id=? AND is_del=0; +UPDATE @tweet_comment_thumbs +SET deleted_on=?, is_del=1 +WHERE user_id=? AND comment_id=? AND reply_id=? AND is_del=0; -- name: create_comment_content@comment_manage -- prepare: stmt -INSERT INTO @comment_content (comment_id, user_id, content, type, sort, created_on) VALUES (?, ?, ?, ?, ?, ?); +INSERT INTO @comment_content (comment_id, user_id, content, type, sort, created_on) +VALUES (?, ?, ?, ?, ?, ?); -- name: update_thumbs_updown_comment@comment_manage -- prepare: named_stmt -UPDATE @tweet_comment_thumbs SET is_thumbs_up=:is_thumbs_up, is_thumbs_down=:is_thumbs_down, modified_on=:modified_on WHERE id=:id AND is_del=0; +UPDATE @tweet_comment_thumbs +SET is_thumbs_up=:is_thumbs_up, is_thumbs_down=:is_thumbs_down, modified_on=:modified_on +WHERE id=:id AND is_del=0; -- name: create_thumbs_updown_comment@comment_manage -- prepare: named_stmt -INSERT INTO @tweet_comment_thumbs (user_id, tweet_id, comment_id, reply_id, is_thumbs_up, is_thumbs_down, comment_type, created_on) VALUES (:user_id, :tweet_id, :comment_id, :reply_id, :is_thumbs_up, :is_thumbs_down, :comment_type, :created_on); +INSERT INTO @tweet_comment_thumbs (user_id, tweet_id, comment_id, reply_id, is_thumbs_up, is_thumbs_down, comment_type, created_on) +VALUES (:user_id, :tweet_id, :comment_id, :reply_id, :is_thumbs_up, :is_thumbs_down, :comment_type, :created_on); -- name: update_comment_thumbs_count@comment_manage -- prepare: stmt -UPDATE @comment SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? WHERE id=? AND is_del=0; +UPDATE @comment +SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? +WHERE id=? AND is_del=0; -- name: get_tweet_comment_thumb@comment_manage -- prepare: stmt -SELECT * FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=? AND comment_id=? AND comment_type=0 AND is_del=0; +SELECT * +FROM @tweet_comment_thumbs +WHERE user_id=? AND tweet_id=? AND comment_id=? AND comment_type=0 AND is_del=0; -- name: get_comment_reply_thumb@comment_manage -- prepare: stmt -SELECT * FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=? AND comment_id=? AND reply_id=? AND comment_type=1 AND is_del=0; +SELECT * +FROM @tweet_comment_thumbs +WHERE user_id=? AND tweet_id=? AND comment_id=? AND reply_id=? AND comment_type=1 AND is_del=0; -- name: update_reply_thumbs_count@comment_manage -- prepare: stmt -UPDATE @comment_reply SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? WHERE id=? AND is_del=0; +UPDATE @comment_reply +SET thumbs_up_count=?, thumbs_down_count=?, modified_on=? +WHERE id=? AND is_del=0; -------------------------------------------------------------------------------- -- contact_manager sql dml @@ -123,15 +141,20 @@ UPDATE @contact SET status=?, modified_on=?, is_del=0 WHERE id=?; -- name: create_message@contact_manager -- prepare: named_stmt -INSERT INTO @message (sender_user_id, receiver_user_id, type, brief, content, reply_id, created_on) VALUES (:sender_user_id, :receiver_user_id, :type, :brief, :content, :reply_id, :created_on); +INSERT INTO @message (sender_user_id, receiver_user_id, type, brief, content, reply_id, created_on) +VALUES (:sender_user_id, :receiver_user_id, :type, :brief, :content, :reply_id, :created_on); -- name: add_friend_msgs_update@contact_manager -- prepare: stmt -UPDATE @message SET reply_id=?, modified_on=? WHERE ((sender_user_id = ? AND receiver_user_id = ?) OR (sender_user_id = ? AND receiver_user_id = ?)) AND type = ? AND reply_id = ?; +UPDATE @message +SET reply_id=?, modified_on=? +WHERE ((sender_user_id = ? AND receiver_user_id = ?) OR (sender_user_id = ? AND receiver_user_id = ?)) AND type = ? AND reply_id = ?; -- name: reject_friend_msgs_update@contact_manager -- prepare: stmt -UPDATE @message SET reply_id=?, modified_on=? WHERE sender_user_id = ? AND receiver_user_id = ? AND type = ? AND reply_id = ?; +UPDATE @message +SET reply_id=?, modified_on=? +WHERE sender_user_id = ? AND receiver_user_id = ? AND type = ? AND reply_id = ?; -- name: del_friend@contact_manager -- prepare: stmt @@ -139,23 +162,36 @@ UPDATE @contact SET status=4, is_del=1, deleted_on=? WHERE id=?; -- name: list_friend@contact_manager -- prepare: stmt -SELECT c.friend_id user_id, u.username username, u.nickname nickname, u.avatar avatar, u.phone phone FROM @contact c JOIN @user u ON c.friend_id=u.id WHERE user_id=? AND status=2 AND is_del=0 ORDER BY u.nickname ASC LIMIT ? OFFSET ?; +SELECT c.friend_id user_id, u.username username, u.nickname nickname, u.avatar avatar, u.phone phone +FROM @contact c JOIN @user u +ON c.friend_id=u.id +WHERE user_id=? AND status=2 AND is_del=0 +ORDER BY u.nickname ASC +LIMIT ? OFFSET ?; -- name: total_friends_by_id@contact_manager -- prepare: stmt -SELECT count(*) FROM @contact WHERE user_id=? AND status=2 AND is_del=0 LIMIT ? OFFSET ?; +SELECT count(*) +FROM @contact +WHERE user_id=? AND status=2 AND is_del=0; -- name: get_contacts@contact_manager -- prepare: stmt -SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del FROM @contact WHERE (user_id=? AND friend_id=?) OR (user_id=? AND friend_id=?); +SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del +FROM @contact +WHERE (user_id=? AND friend_id=?) OR (user_id=? AND friend_id=?); -- name: get_user_friend@contact_manager -- prepare: stmt -SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0; +SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del +FROM @contact +WHERE user_id=? AND friend_id=? AND is_del=0; -- name: get_contact@contact_manager -- prepare: stmt -SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del FROM @contact WHERE user_id=? AND friend_id=?; +SELECT id, user_id, friend_id, group_id, remark, status, is_top, is_black, notice_enable, is_del +FROM @contact +WHERE user_id=? AND friend_id=?; -- name: is_friend@contact_manager -- prepare: stmt @@ -167,7 +203,8 @@ SELECT true FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0 AND statu -- name: create_message@message -- prepare: named_stmt -INSERT INTO @message (sender_user_id, receiver_user_id, type, brief, content, post_id, comment_id, reply_id, created_on) VALUES (:sender_user_id, :receiver_user_id, :type, :brief, :content, :post_id, :comment_id, :reply_id, :created_on); +INSERT INTO @message (sender_user_id, receiver_user_id, type, brief, content, post_id, comment_id, reply_id, created_on) +VALUES (:sender_user_id, :receiver_user_id, :type, :brief, :content, :post_id, :comment_id, :reply_id, :created_on); -- name: get_unread_count@message -- prepare: stmt @@ -183,7 +220,11 @@ UPDATE @message SET is_read=1, modified_on=? WHERE id=?; -- name: get_messages@message -- prepare: named_stmt -SELECT * FROM @message WHERE receiver_user_id=:recerver_user_id AND is_del=0 ORDER BY id DESC LIMIT :limit OFFSET :offset +SELECT * +FROM @message +WHERE receiver_user_id=:recerver_user_id AND is_del=0 +ORDER BY id DESC +LIMIT :limit OFFSET :offset -- name: get_message_count@message -- prepare: named_stmt @@ -203,7 +244,8 @@ UPDATE @captcha SET use_times=use_times+1, modified_on=? WHERE id=? AND is_del=0 -- name: create_phone_captcha@security -- prepare: named_stmt -INSERT INTO @captcha (phone, captcha, expired_on, created_on) VALUES (:phone, :captcha, :expired_on, :created_on); +INSERT INTO @captcha (phone, captcha, expired_on, created_on) +VALUES (:phone, :captcha, :expired_on, :created_on); -------------------------------------------------------------------------------- -- friend_index sql dml @@ -482,13 +524,21 @@ LIMIT ? OFFSET ?; -- name: tags_by_keyword_a@topic_a -- get tags by keyword -SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 ORDER BY quote_num DESC LIMIT 6; +SELECT id, user_id, tag, quote_num +FROM @tag +WHERE is_del = 0 +ORDER BY quote_num DESC +LIMIT 6; -- name: tags_by_keyword_b@topic_a -SELECT id, user_id, tag, quote_num FROM @tag WHERE is_del = 0 AND tag LIKE ? ORDER BY quote_num DESC LIMIT 6; +SELECT id, user_id, tag, quote_num +FROM @tag WHERE is_del = 0 AND tag LIKE ? +ORDER BY quote_num DESC +LIMIT 6; -- name: insert_tag@topic_a -INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) VALUES (?, ?, ?, ?, 1); +INSERT INTO @tag (user_id, tag, created_on, modified_on, quote_num) +VALUES (?, ?, ?, ?, 1); -- name: tags_by_id_a@topic_a -- prepare: raw @@ -546,13 +596,23 @@ SELECT * FROM @user WHERE is_del=0 ORDER BY id ASC limit 6; -- name: create_user@user_manage -- prepare: named_stmt -INSERT INTO @user (username, nickname, password, salt, avatar, status, created_on) VALUES (:username, :nickname, :password, :salt, :avatar, :status, :created_on); +INSERT INTO @user (username, nickname, password, salt, avatar, status, created_on) +VALUES (:username, :nickname, :password, :salt, :avatar, :status, :created_on); -- name: update_user@user_manage -- prepare: named_stmt -UPDATE @user SET username=:username, nickname=:nickname, phone=:phone, - password=:password, salt=:salt, status=:status, avatar=:avatar, balance=:balance, - is_admin=:is_admin, modified_on=:modified_on WHERE id=? AND is_del=0; +UPDATE @user +SET username=:username, + nickname=:nickname, + phone=:phone, + password=:password, + salt=:salt, + status=:status, + avatar=:avatar, + balance=:balance, + is_admin=:is_admin, + modified_on=:modified_on +WHERE id=? AND is_del=0; -------------------------------------------------------------------------------- -- wallet sql dml @@ -560,7 +620,11 @@ UPDATE @user SET username=:username, nickname=:nickname, phone=:phone, -- name: get_user_wallet_bills@wallet -- prepare: stmt -SELECT * FROM @wallet_statement WHERE user_id=? AND is_del=0 ORDER BY id DESC LIMIT ? OFFSET ?; +SELECT * +FROM @wallet_statement +WHERE user_id=? AND is_del=0 +ORDER BY id DESC +LIMIT ? OFFSET ?; -- name: get_user_wallet_bill_count@wallet -- prepare: stmt @@ -588,7 +652,8 @@ UPDATE @user SET balance=balance-?, modified_on=? WHERE id=? AND is_del=0; -- name: create_wallet_statement@wallet -- prepare: stmt -INSERT INTO @wallet_statement (user_id, change_amount, balance_snapshot, reason, created_on) VALUES (?, ?, ?, ?, ?); +INSERT INTO @wallet_statement (user_id, change_amount, balance_snapshot, reason, created_on) +VALUES (?, ?, ?, ?, ?); -- name: get_user_balance@wallet -- prepare: stmt @@ -596,7 +661,9 @@ SELECT balance FROM @user WHERE id=? AND is_del=0; -- name: mark_success_recharge@wallet -- prepare: stmt -UPDATE @wallet_recharge SET trade_no=?, trade_status='TRADE_SUCCESS', modified_on=? WHERE id=? AND is_del=0; +UPDATE @wallet_recharge +SET trade_no=?, trade_status='TRADE_SUCCESS', modified_on=? +WHERE id=? AND is_del=0; -- name: new_post_attachment_bill -- prepare: stmt @@ -604,4 +671,5 @@ INSERT INTO @post_attachment_bill (post_id, user_id, paid_amount) VALUES (?, ?, -- name: new_post_bill@wallet -- prepare: stmt -INSERT INTO @wallet_statement (post_id, user_id, change_amount, balance_snapshot, reason, created_on) VALUES (?, ?, ?, ?, ?, ?); +INSERT INTO @wallet_statement (post_id, user_id, change_amount, balance_snapshot, reason, created_on) +VALUES (?, ?, ?, ?, ?, ?); From 8bf268af0a550be16d6a92effa4b885e7834e337 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Sat, 5 Aug 2023 15:44:49 +0800 Subject: [PATCH 18/19] sqlx: fixed wallet logic for HandlePostAttachmentBought error --- internal/dao/sakila/wallet.go | 2 +- internal/dao/sakila/yesql/cc/yesql.go | 24 +++++------------------- internal/dao/sakila/yesql/yesql.sql | 5 +++-- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/internal/dao/sakila/wallet.go b/internal/dao/sakila/wallet.go index 29ad1cd1..68d4042e 100644 --- a/internal/dao/sakila/wallet.go +++ b/internal/dao/sakila/wallet.go @@ -100,7 +100,7 @@ func (s *walletSrv) HandlePostAttachmentBought(post *ms.Post, user *ms.User) err } // 新增附件购买记录 args = []any{post.ID, user.ID, post.AttachmentPrice, now} - if _, err = tx.Stmtx(s.q.NewPostBill).Exec(args...); err != nil { + if _, err = tx.Stmtx(s.q.NewPostAttachmentBill).Exec(args...); err != nil { return err } // 对附件主新增账单 diff --git a/internal/dao/sakila/yesql/cc/yesql.go b/internal/dao/sakila/yesql/cc/yesql.go index b1da4914..4730e234 100644 --- a/internal/dao/sakila/yesql/cc/yesql.go +++ b/internal/dao/sakila/yesql/cc/yesql.go @@ -12,7 +12,6 @@ import ( ) const ( - _NewPostAttachmentBill = `INSERT INTO @post_attachment_bill (post_id, user_id, paid_amount) VALUES (?, ?, ?)` _AuthorizationManage_BeFriendIds = `SELECT user_id FROM @contact WHERE friend_id=? AND status=2 AND is_del=0` _AuthorizationManage_IsFriend = `SELECT status FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0` _AuthorizationManage_MyFriendSet = `SELECT friend_id FROM @contact WHERE user_id=? AND status=2 AND is_del=0` @@ -134,13 +133,10 @@ const ( _Wallet_GetUserWalletBills = `SELECT * FROM @wallet_statement WHERE user_id=? AND is_del=0 ORDER BY id DESC LIMIT ? OFFSET ?` _Wallet_MarkSuccessRecharge = `UPDATE @wallet_recharge SET trade_no=?, trade_status='TRADE_SUCCESS', modified_on=? WHERE id=? AND is_del=0` _Wallet_MinusUserBalance = `UPDATE @user SET balance=balance-?, modified_on=? WHERE id=? AND is_del=0` + _Wallet_NewPostAttachmentBill = `INSERT INTO @post_attachment_bill (post_id, user_id, paid_amount, created_on) VALUES (?, ?, ?, ?)` _Wallet_NewPostBill = `INSERT INTO @wallet_statement (post_id, user_id, change_amount, balance_snapshot, reason, created_on) VALUES (?, ?, ?, ?, ?, ?)` ) -type Yesql struct { - NewPostAttachmentBill *sqlx.Stmt `yesql:"new_post_attachment_bill"` -} - type AuthorizationManage struct { yesql.Namespace `yesql:"authorization_manage"` BeFriendIds *sqlx.Stmt `yesql:"be_friend_ids"` @@ -352,23 +348,10 @@ type Wallet struct { GetUserWalletBills *sqlx.Stmt `yesql:"get_user_wallet_bills"` MarkSuccessRecharge *sqlx.Stmt `yesql:"mark_success_recharge"` MinusUserBalance *sqlx.Stmt `yesql:"minus_user_balance"` + NewPostAttachmentBill *sqlx.Stmt `yesql:"new_post_attachment_bill"` NewPostBill *sqlx.Stmt `yesql:"new_post_bill"` } -func BuildYesql(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Yesql, err error) { - var c context.Context - if len(ctx) > 0 && ctx[0] != nil { - c = ctx[0] - } else { - c = context.Background() - } - obj = &Yesql{} - if obj.NewPostAttachmentBill, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_NewPostAttachmentBill))); err != nil { - return - } - return -} - func BuildAuthorizationManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *AuthorizationManage, err error) { var c context.Context if len(ctx) > 0 && ctx[0] != nil { @@ -955,6 +938,9 @@ func BuildWallet(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Wallet, if obj.MinusUserBalance, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_MinusUserBalance))); err != nil { return } + if obj.NewPostAttachmentBill, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_NewPostAttachmentBill))); err != nil { + return + } if obj.NewPostBill, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Wallet_NewPostBill))); err != nil { return } diff --git a/internal/dao/sakila/yesql/yesql.sql b/internal/dao/sakila/yesql/yesql.sql index 6c6c941f..84596ec0 100644 --- a/internal/dao/sakila/yesql/yesql.sql +++ b/internal/dao/sakila/yesql/yesql.sql @@ -665,9 +665,10 @@ UPDATE @wallet_recharge SET trade_no=?, trade_status='TRADE_SUCCESS', modified_on=? WHERE id=? AND is_del=0; --- name: new_post_attachment_bill +-- name: new_post_attachment_bill@wallet -- prepare: stmt -INSERT INTO @post_attachment_bill (post_id, user_id, paid_amount) VALUES (?, ?, ?); +INSERT INTO @post_attachment_bill (post_id, user_id, paid_amount, created_on) +VALUES (?, ?, ?, ?); -- name: new_post_bill@wallet -- prepare: stmt From 1e9f65626aef2ae07277f8a67e0bfd18f7c0cb90 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Sat, 5 Aug 2023 21:08:00 +0800 Subject: [PATCH 19/19] sqlx: tweet_help/tweet_manage logic is implemented complete. WIP %75 --- internal/core/ms/tweets.go | 8 ++ internal/core/tweets.go | 4 +- internal/dao/jinzhu/dbr/post.go | 8 +- internal/dao/jinzhu/tweets.go | 4 +- internal/dao/sakila/sqlx.go | 3 + internal/dao/sakila/tweets.go | 161 ++++++++++++++++++-------- internal/dao/sakila/utils.go | 55 +++++++++ internal/dao/sakila/yesql/cc/yesql.go | 138 +++++++++++++--------- internal/dao/sakila/yesql/yesql.sql | 110 +++++++++++++----- internal/servants/base/base.go | 9 +- internal/servants/web/loose.go | 2 +- 11 files changed, 357 insertions(+), 145 deletions(-) create mode 100644 internal/dao/sakila/utils.go diff --git a/internal/core/ms/tweets.go b/internal/core/ms/tweets.go index 230775ff..eab6d85c 100644 --- a/internal/core/ms/tweets.go +++ b/internal/core/ms/tweets.go @@ -24,6 +24,13 @@ const ( ContentTypeChargeAttachment = dbr.ContentTypeChargeAttachment ) +const ( + PostVisitPublic PostVisibleT = iota + PostVisitPrivate + PostVisitFriend + PostVisitInvalid +) + type ( PostStar = dbr.PostStar PostCollection = dbr.PostCollection @@ -32,4 +39,5 @@ type ( Attachment = dbr.Attachment AttachmentType = dbr.AttachmentType PostContentT = dbr.PostContentT + PostVisibleT = dbr.PostVisibleT ) diff --git a/internal/core/tweets.go b/internal/core/tweets.go index 15ec3a9f..97fda8e3 100644 --- a/internal/core/tweets.go +++ b/internal/core/tweets.go @@ -12,8 +12,8 @@ import ( // TweetService 推文检索服务 type TweetService interface { GetPostByID(id int64) (*ms.Post, error) - GetPosts(conditions *ms.ConditionsT, offset, limit int) ([]*ms.Post, error) - GetPostCount(conditions *ms.ConditionsT) (int64, 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) 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/tweets.go b/internal/dao/jinzhu/tweets.go index 49cc2d56..d661831d 100644 --- a/internal/dao/jinzhu/tweets.go +++ b/internal/dao/jinzhu/tweets.go @@ -370,11 +370,11 @@ func (s *tweetSrv) GetPostByID(id int64) (*ms.Post, error) { return post.Get(s.db) } -func (s *tweetSrv) GetPosts(conditions *ms.ConditionsT, offset, limit int) ([]*ms.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 *ms.ConditionsT) (int64, error) { +func (s *tweetSrv) GetPostCount(conditions ms.ConditionsT) (int64, error) { return (&dbr.Post{}).Count(s.db, conditions) } diff --git a/internal/dao/sakila/sqlx.go b/internal/dao/sakila/sqlx.go index 2e5819ea..25190b01 100644 --- a/internal/dao/sakila/sqlx.go +++ b/internal/dao/sakila/sqlx.go @@ -13,6 +13,7 @@ import ( "github.com/alimy/yesql" "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/conf" + "github.com/rocboss/paopao-ce/internal/dao/sakila/yesql/cc" "github.com/sirupsen/logrus" ) @@ -23,6 +24,7 @@ var ( type sqlxSrv struct { db *sqlx.DB + y *cc.Yesql } func (s *sqlxSrv) with(handle func(tx *sqlx.Tx) error) error { @@ -111,6 +113,7 @@ func (s *sqlxSrv) inGetx(queryer sqlx.Queryer, dest any, query string, args ...a func newSqlxSrv(db *sqlx.DB) *sqlxSrv { return &sqlxSrv{ db: db, + y: mustBuild(db, cc.BuildYesql), } } diff --git a/internal/dao/sakila/tweets.go b/internal/dao/sakila/tweets.go index 5c494dfa..cb0d3c21 100644 --- a/internal/dao/sakila/tweets.go +++ b/internal/dao/sakila/tweets.go @@ -5,6 +5,9 @@ package sakila import ( + "strings" + "time" + "github.com/jmoiron/sqlx" "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" @@ -123,20 +126,19 @@ func (s *tweetHelpSrv) RevampPosts(posts []*ms.PostFormated) ([]*ms.PostFormated return posts, nil } -func (s *tweetHelpSrv) getPostContentsByIDs(ids []int64) ([]*dbr.PostContentFormated, error) { - res := []*dbr.PostContentFormated{} - err := s.inSelect(&res, s.q.GetPostContentByIds, ids) - return res, err +func (s *tweetHelpSrv) getPostContentsByIDs(ids []int64) (res []*dbr.PostContentFormated, err error) { + err = s.inSelect(&res, s.q.GetPostContentByIds, ids) + return } -func (s *tweetHelpSrv) getUsersByIDs(ids []int64) ([]*dbr.UserFormated, error) { - res := []*dbr.UserFormated{} - err := s.inSelect(&res, s.q.GetUsersByIds, ids) - return res, err +func (s *tweetHelpSrv) getUsersByIDs(ids []int64) (res []*dbr.UserFormated, err error) { + err = s.inSelect(&res, s.q.GetUsersByIds, ids) + return } func (s *tweetManageSrv) CreatePostCollection(postID, userID int64) (*ms.PostCollection, error) { - res, err := s.q.AddPostCollection.Exec(postID, userID) + now := time.Now().Unix() + res, err := s.q.AddPostCollection.Exec(postID, userID, now) if err != nil { return nil, err } @@ -146,7 +148,8 @@ func (s *tweetManageSrv) CreatePostCollection(postID, userID int64) (*ms.PostCol } return &ms.PostCollection{ Model: &dbr.Model{ - ID: id, + ID: id, + CreatedOn: now, }, PostID: postID, UserID: userID, @@ -154,16 +157,16 @@ func (s *tweetManageSrv) CreatePostCollection(postID, userID int64) (*ms.PostCol } func (s *tweetManageSrv) DeletePostCollection(r *ms.PostCollection) error { - _, err := s.q.DelPostCollection.Exec(r.ID) + _, err := s.q.DelPostCollection.Exec(time.Now().Unix(), r.ID) return err } func (s *tweetManageSrv) CreatePostContent(r *ms.PostContent) (*ms.PostContent, error) { - res, err := s.q.AddPostContent.Exec(r.PostID, r.UserID, r.Content, r.Type, r.Sort) + r.Model = &ms.Model{CreatedOn: time.Now().Unix()} + res, err := s.q.AddPostContent.Exec(r) if err != nil { return nil, err } - r.Model = &dbr.Model{} r.ID, err = res.LastInsertId() if err != nil { return nil, err @@ -172,7 +175,8 @@ func (s *tweetManageSrv) CreatePostContent(r *ms.PostContent) (*ms.PostContent, } func (s *tweetManageSrv) CreateAttachment(r *ms.Attachment) (int64, error) { - res, err := s.q.AddAttachment.Exec(r.UserID, r.FileSize, r.ImgWidth, r.ImgHeight, r.Type, r.Content) + args := []any{r.UserID, r.FileSize, r.ImgWidth, r.ImgHeight, r.Type, r.Content, time.Now().Unix()} + res, err := s.q.AddAttachment.Exec(args...) if err != nil { return 0, err } @@ -180,43 +184,96 @@ func (s *tweetManageSrv) CreateAttachment(r *ms.Attachment) (int64, error) { } func (s *tweetManageSrv) CreatePost(r *ms.Post) (*ms.Post, error) { - res, err := s.q.AddPost.Exec(r.UserID, r.Visibility, r.Tags, r.AttachmentPrice, r.IP, r.IPLoc) + now := time.Now().Unix() + r.Model = &dbr.Model{CreatedOn: now} + r.LatestRepliedOn = now + res, err := s.q.AddPost.Exec(r) if err != nil { return nil, err } - if id, err := res.LastInsertId(); err == nil { - r.Model = &dbr.Model{ - ID: id, - } - } else { + if r.ID, err = res.LastInsertId(); err != nil { return nil, err } + s.cis.SendAction(core.IdxActCreatePost, r) return r, nil } -func (s *tweetManageSrv) DeletePost(post *ms.Post) ([]string, error) { +func (s *tweetManageSrv) DeletePost(post *ms.Post) (mediaContents []string, err error) { + s.with(func(tx *sqlx.Tx) error { + // 获取多媒体内容 + if err = tx.Stmtx(s.q.MediaContentByPostId).Get(&mediaContents, post.ID); err != nil { + return err + } + // 删推文 + now := time.Now().Unix() + if _, err = tx.Stmtx(s.q.DelPostById).Exec(now, post.ID); err != nil { + return err + } + // 删评论 + contents, err := s.deleteCommentByPostId(tx, post.ID) + if err != nil { + return err + } + mediaContents = append(mediaContents, contents...) + if tags := strings.Split(post.Tags, ","); len(tags) > 0 { + // 删tag,宽松处理错误,有错误不会回滚 + s.deleteTags(tx, tags) + } + return nil + }) + s.cis.SendAction(core.IdxActDeletePost, post) + return +} + +func (s *tweetManageSrv) deleteCommentByPostId(tx *sqlx.Tx, postId int64) ([]string, error) { // TODO - debug.NotImplemented() return nil, nil } func (s *tweetManageSrv) LockPost(r *ms.Post) error { - _, err := s.q.LockPost.Exec(r.ID) + _, err := s.q.LockPost.Exec(time.Now().Unix(), r.ID) return err } func (s *tweetManageSrv) StickPost(r *ms.Post) error { - _, err := s.q.StickPost.Exec(r.ID) + _, err := s.q.StickPost.Exec(time.Now().Unix(), r.ID) return err } -func (s *tweetManageSrv) VisiblePost(r *ms.Post, visibility core.PostVisibleT) error { - _, err := s.q.VisiblePost.Exec(r.ID, visibility) - return err +func (s *tweetManageSrv) VisiblePost(post *ms.Post, visibility core.PostVisibleT) (err error) { + oldVisibility := post.Visibility + post.Visibility = visibility + // TODO: 这个判断是否可以不要呢 + if oldVisibility == visibility { + return nil + } + // 私密推文 特殊处理 + if visibility == ms.PostVisitPrivate { + // 强制取消置顶 + // TODO: 置顶推文用户是否有权设置成私密? 后续完善 + post.IsTop = 0 + } + s.with(func(tx *sqlx.Tx) error { + _, err = s.q.VisiblePost.Exec(visibility, post.IsTop, time.Now().Unix(), post.ID) + // tag处理 + tags := strings.Split(post.Tags, ",") + // TODO: 暂时宽松不处理错误,这里或许可以有优化,后续完善 + if oldVisibility == dbr.PostVisitPrivate { + // 从私密转为非私密才需要重新创建tag + s.createTags(tx, post.UserID, tags) + } else if visibility == dbr.PostVisitPrivate { + // 从非私密转为私密才需要删除tag + s.deleteTags(tx, tags) + } + return nil + }) + s.cis.SendAction(core.IdxActVisiblePost, post) + return } func (s *tweetManageSrv) UpdatePost(r *ms.Post) error { - if _, err := s.q.UpdatePost.Exec(r.CommentCount, r.UpvoteCount, r.ID); err != nil { + r.ModifiedOn = time.Now().Unix() + if _, err := s.q.UpdatePost.Exec(r); err != nil { return err } s.cis.SendAction(core.IdxActUpdatePost, r) @@ -224,7 +281,8 @@ func (s *tweetManageSrv) UpdatePost(r *ms.Post) error { } func (s *tweetManageSrv) CreatePostStar(postID, userID int64) (*ms.PostStar, error) { - res, err := s.q.AddPostStar.Exec(postID, userID) + now := time.Now().Unix() + res, err := s.q.AddPostStar.Exec(postID, userID, now) if err != nil { return nil, err } @@ -234,7 +292,8 @@ func (s *tweetManageSrv) CreatePostStar(postID, userID int64) (*ms.PostStar, err } return &ms.PostStar{ Model: &dbr.Model{ - ID: id, + ID: id, + CreatedOn: now, }, PostID: postID, UserID: userID, @@ -242,26 +301,35 @@ func (s *tweetManageSrv) CreatePostStar(postID, userID int64) (*ms.PostStar, err } func (s *tweetManageSrv) DeletePostStar(r *ms.PostStar) error { - _, err := s.q.DelPostStar.Exec(r.ID) + _, err := s.q.DelPostStar.Exec(time.Now().Unix(), r.ID) return err } -func (s *tweetSrv) GetPostByID(id int64) (*ms.Post, error) { - res := &ms.Post{} - err := s.q.GetPostById.Get(res, id) - return res, err +func (s *tweetSrv) GetPostByID(id int64) (res *ms.Post, err error) { + err = s.q.GetPostById.Get(res, id) + return } -func (s *tweetSrv) GetPosts(conditions *ms.ConditionsT, offset, limit int) ([]*ms.Post, error) { - // TODO 需要精细化接口 - debug.NotImplemented() - return nil, nil +func (s *tweetSrv) GetPosts(c ms.ConditionsT, offset, limit int) (res []*ms.Post, err error) { + userId, exist := c["user_id"] + visibility := c["visibility IN ?"] + if exist { + err = s.inSelect(&res, s.q.GetUserPosts, userId, visibility, limit, offset) + } else { + err = s.inSelect(&res, s.q.GetAnyPosts, visibility, limit, offset) + } + return } -func (s *tweetSrv) GetPostCount(conditions *ms.ConditionsT) (int64, error) { - // TODO 需要精细化接口 - debug.NotImplemented() - return 0, nil +func (s *tweetSrv) GetPostCount(c ms.ConditionsT) (res int64, err error) { + userId, exist := c["user_id"] + visibility := c["visibility IN ?"] + if exist { + err = s.inGet(&res, s.q.GetUserPostCount, userId, visibility) + } else { + err = s.inGet(&res, s.q.GetAnyPostCount, visibility) + } + return } func (s *tweetSrv) GetUserPostStar(postID, userID int64) (*ms.PostStar, error) { @@ -304,10 +372,9 @@ func (s *tweetSrv) GetPostAttatchmentBill(postID, userID int64) (*ms.PostAttachm return res, err } -func (s *tweetSrv) GetPostContentsByIDs(ids []int64) ([]*ms.PostContent, error) { - res := []*ms.PostContent{} - err := s.inSelect(&res, s.q.GetPostContetnsByIds, ids) - return res, err +func (s *tweetSrv) GetPostContentsByIDs(ids []int64) (res []*ms.PostContent, err error) { + err = s.inSelect(&res, s.q.GetPostContentsByIds, ids) + return } func (s *tweetSrv) GetPostContentByID(id int64) (*ms.PostContent, error) { diff --git a/internal/dao/sakila/utils.go b/internal/dao/sakila/utils.go new file mode 100644 index 00000000..7f1edbaa --- /dev/null +++ b/internal/dao/sakila/utils.go @@ -0,0 +1,55 @@ +// Copyright 2023 ROC. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +package sakila + +import ( + "time" + + "github.com/jmoiron/sqlx" + "github.com/rocboss/paopao-ce/internal/core/cs" +) + +func (s *sqlxSrv) deleteTags(tx *sqlx.Tx, tags []string) (err error) { + var tagInfos []cs.TagInfo + if err = tx.Stmtx(s.y.TagsFromNames).Select(&tagInfos, tags); err != nil { + return + } + now := time.Now().Unix() + for _, tag := range tagInfos { + tag.QuoteNum-- + if _, err = tx.Stmtx(s.y.UpdateTagQuote).Exec(tag.QuoteNum, now, tag.ID); err != nil { + return + } + } + return +} + +func (s *sqlxSrv) createTags(tx *sqlx.Tx, userId int64, tags []string) (res cs.TagInfoList, err error) { + // for _, name := range tags { + // tag := &dbr.Tag{Tag: name} + // if tag, err = tag.Get(db); err == nil { + // // 更新 + // tag.QuoteNum++ + // if err = tag.Update(db); err != nil { + // return + // } + // } else { + // if tag, err = (&dbr.Tag{ + // UserID: userId, + // QuoteNum: 1, + // Tag: name, + // }).Create(db); err != nil { + // return + // } + // } + // res = append(res, &cs.TagInfo{ + // ID: tag.ID, + // UserID: tag.UserID, + // Tag: tag.Tag, + // QuoteNum: tag.QuoteNum, + // }) + // } + return +} diff --git a/internal/dao/sakila/yesql/cc/yesql.go b/internal/dao/sakila/yesql/cc/yesql.go index 4730e234..be651d40 100644 --- a/internal/dao/sakila/yesql/cc/yesql.go +++ b/internal/dao/sakila/yesql/cc/yesql.go @@ -12,17 +12,19 @@ import ( ) const ( + _TagsFromNames = `SELECT * FROM @tag WHERE tag IN (?) AND is_del=0` + _UpdateTagQuote = `UPDATE @tag SET quote_num=?, modified_on=? WHERE id=? AND is_del=0` _AuthorizationManage_BeFriendIds = `SELECT user_id FROM @contact WHERE friend_id=? AND status=2 AND is_del=0` _AuthorizationManage_IsFriend = `SELECT status FROM @contact WHERE user_id=? AND friend_id=? AND is_del=0` _AuthorizationManage_MyFriendSet = `SELECT friend_id FROM @contact WHERE user_id=? AND status=2 AND is_del=0` _Comment_GetCommentById = `SELECT * FROM @comment WHERE id=? AND is_del=0` - _Comment_GetCommentContentsByIds = `SELECT * FROM @comment_content WHERE comment_id IN ?` + _Comment_GetCommentContentsByIds = `SELECT * FROM @comment_content WHERE comment_id IN (?)` _Comment_GetCommentCount = `SELECT count(*) FROM @comment WHERE post_id=:post_id AND is_del=0` _Comment_GetCommentReplyById = `SELECT * FROM @comment_reply WHERE id=? AND is_del=0` _Comment_GetCommentThumbs = `SELECT * FROM @tweet_comment_thumbs WHERE user_id=? AND tweet_id=?` _Comment_GetComments = `SELECT * FROM @comment WHERE post_id=? AND is_del=0 ORDER BY %order% LIMIT ? OFFSET ?` - _Comment_GetCommmentRepliesByIds = `SELECT * FROM @comment_reply WHERE comment_id IN ? ORDER BY id ASC` - _Comment_GetUsersByIds = `SELECT id, nickname, username, status, avatar, is_admin FROM @user WHERE id IN ?` + _Comment_GetCommmentRepliesByIds = `SELECT * FROM @comment_reply WHERE comment_id IN (?) ORDER BY id ASC` + _Comment_GetUsersByIds = `SELECT id, nickname, username, status, avatar, is_admin FROM @user WHERE id IN (?)` _CommentManage_CreateComment = `INSERT INTO @comment (post_id, user_id, ip, ip_loc, created_on) VALUES (?, ?, ?, ?, ?)` _CommentManage_CreateCommentContent = `INSERT INTO @comment_content (comment_id, user_id, content, type, sort, created_on) VALUES (?, ?, ?, ?, ?, ?)` _CommentManage_CreateCommentReply = `INSERT INTO @comment_reply (comment_id, user_id, content, at_user_id, ip, ip_loc, created_on) VALUES (?, ?, ?, ?, ?, ?, ?)` @@ -87,40 +89,43 @@ const ( _TweetA_UserTweetsByFriend = `SELECT * FROM @user WHERE username=?` _TweetA_UserTweetsByGuest = `SELECT * FROM @user WHERE username=?` _TweetA_UserTweetsBySelf = `SELECT * FROM @user WHERE username=?` + _Tweet_GetAnyPostCount = `SELECT count(*) FROM @post WHERE visibility IN (?)` + _Tweet_GetAnyPosts = `SELECT * FROM @post WHERE visibility IN (?) AND is_del=0 LIMIT ? OFFSET ?` _Tweet_GetPostAttachmentBill = `SELECT * FROM @user WHERE username=?` - _Tweet_GetPostById = `SELECT * FROM @user WHERE username=?` + _Tweet_GetPostById = `SELECT * FROM @post WHERE id=? AND is_del=0` _Tweet_GetPostContentById = `SELECT * FROM @user WHERE username=?` - _Tweet_GetPostContetnsByIds = `SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?)` - _Tweet_GetPostCount = `SELECT * FROM @user WHERE username=?` - _Tweet_GetPosts = `SELECT * FROM @user WHERE username=?` + _Tweet_GetPostContentsByIds = `SELECT * FROM @post_content WHERE post_id IN (?) AND is_del=0` _Tweet_GetUserPostCollection = `SELECT * FROM @user WHERE username=?` _Tweet_GetUserPostCollectionCount = `SELECT * FROM @user WHERE username=?` _Tweet_GetUserPostCollections = `SELECT * FROM @user WHERE username=?` + _Tweet_GetUserPostCount = `SELECT count(*) FROM @post WHERE user_id=? AND visibility IN (?)` _Tweet_GetUserPostStar = `SELECT * FROM @user WHERE username=?` _Tweet_GetUserPostStarCount = `SELECT * FROM @user WHERE username=?` _Tweet_GetUserPostStars = `SELECT * FROM @user WHERE username=?` + _Tweet_GetUserPosts = `SELECT * FROM @post WHERE user_id=? AND visibility IN (?) ORDER BY latest_replies_on DESC LIMIT ? OFFSET ?` _TweetHelpA_UserInfo = `SELECT * FROM @user WHERE username=?` - _TweetHelp_GetPostContentByIds = `SELECT * FROM @user WHERE username=?` - _TweetHelp_GetUsersByIds = `SELECT * FROM @user WHERE username=?` + _TweetHelp_GetPostContentByIds = `SELECT id, post_id, content, type, sort FROM @post_content WHERE post_id IN (?) AND is_del=0` + _TweetHelp_GetUsersByIds = `SELECT id, username, nickname, status, avatar, is_admin FROM @user WHERE id IN (?) AND is_del=0` _TweetManageA_UserInfo = `SELECT * FROM @user WHERE username=?` - _TweetManage_AddAttachment = `SELECT * FROM @user WHERE username=?` - _TweetManage_AddPost = `SELECT * FROM @user WHERE username=?` - _TweetManage_AddPostCollection = `SELECT * FROM @user WHERE username=?` - _TweetManage_AddPostContent = `SELECT * FROM @user WHERE username=?` - _TweetManage_AddPostStar = `SELECT * FROM @user WHERE username=?` - _TweetManage_DelPost = `SELECT * FROM @user WHERE username=?` - _TweetManage_DelPostCollection = `SELECT * FROM @user WHERE username=?` - _TweetManage_DelPostStar = `SELECT * FROM @user WHERE username=?` - _TweetManage_LockPost = `SELECT * FROM @user WHERE username=?` - _TweetManage_StickPost = `SELECT * FROM @user WHERE username=?` - _TweetManage_UpdatePost = `SELECT * FROM @user WHERE username=?` - _TweetManage_VisiblePost = `SELECT * FROM @user WHERE username=?` + _TweetManage_AddAttachment = `INSERT INTO @attachment (user_id, file_size, img_width, img_height, type, content, created_on) VALUES (?, ?, ?, ?, ?, ?, ?)` + _TweetManage_AddPost = `INSERT INTO @post (user_id, tags, ip, ip_loc, attachment_price, visibility, latest_replies_on, created_on) VALUES (:user_id, :tags, :ip, :ip_loc, :attachment_price, :visibility, :latest_replies_on, :created_on)` + _TweetManage_AddPostCollection = `INSERT INTO @post_collection (post_id, user_id, created_on) VALUES (?, ?, ?)` + _TweetManage_AddPostContent = `INSERT INTO @post_content (post_id, user_id, content, type, sort, created_on) VALUES (:post_id, :user_id, :content, :type, :sort, :created_on)` + _TweetManage_AddPostStar = `INSERT INTO @post_star (post_id, user_id, created_on) VALUES (?, ?, ?)` + _TweetManage_DelPostById = `UPDATE @post SET is_del=1, deleted_on=? WHERE id=? AND is_del=0` + _TweetManage_DelPostCollection = `UPDATE @post_collection SET is_del=1, deleted_on=? WHERE id=? AND is_del=0` + _TweetManage_DelPostStar = `UPDATE @post_star SET is_del=1, deleted_on=? WHERE id=? AND is_del=0` + _TweetManage_LockPost = `UPDATE @post SET is_lock=1-is_lock, modified_on=? WHERE id=? AND is_del=0` + _TweetManage_MediaContentByPostId = `SELECT content FROM post_content WHERE post_id=? AND is_del=0 AND type IN (3, 4, 5, 7, 8)` + _TweetManage_StickPost = `UPDATE @post SET is_top=1-is_top, modified_on=? WHERE id=? AND is_del=0` + _TweetManage_UpdatePost = `UPDATE @post SET comment_count=:comment_count, upvote_count=:upvote_count, collection_count=:collection_count, latest_replies_on=:latest_replies_on, modified_on=:modified_on WHERE id=:id AND is_del=0` + _TweetManage_VisiblePost = `UPDATE @post SET visibility=?, is_top=?, modified_on=? WHERE id=? AND is_del=0` _UserManage_CreateUser = `INSERT INTO @user (username, nickname, password, salt, avatar, status, created_on) VALUES (:username, :nickname, :password, :salt, :avatar, :status, :created_on)` _UserManage_GetAnyUsers = `SELECT * FROM @user WHERE is_del=0 ORDER BY id ASC limit 6` _UserManage_GetUserById = `SELECT * FROM @user WHERE id=? AND is_del=0` _UserManage_GetUserByPhone = `SELECT * FROM @user WHERE phone=? AND is_del=0` _UserManage_GetUserByUsername = `SELECT * FROM @user WHERE username=? AND is_del=0` - _UserManage_GetUsersByIds = `SELECT * FROM @user WHERE id IN ? AND is_del=0` + _UserManage_GetUsersByIds = `SELECT * FROM @user WHERE id IN (?) AND is_del=0` _UserManage_GetUsersByKeyword = `SELECT * FROM @user WHERE username LIKE ? AND is_del=0 limit 6` _UserManage_UpdateUser = `UPDATE @user SET username=:username, nickname=:nickname, phone=:phone, password=:password, salt=:salt, status=:status, avatar=:avatar, balance=:balance, is_admin=:is_admin, modified_on=:modified_on WHERE id=? AND is_del=0` _Wallet_AddUserBalance = `UPDATE @user SET balance=balance+?, modified_on=? WHERE id=? AND is_del=0` @@ -137,6 +142,11 @@ const ( _Wallet_NewPostBill = `INSERT INTO @wallet_statement (post_id, user_id, change_amount, balance_snapshot, reason, created_on) VALUES (?, ?, ?, ?, ?, ?)` ) +type Yesql struct { + TagsFromNames string `yesql:"tags_from_names"` + UpdateTagQuote *sqlx.Stmt `yesql:"update_tag_quote"` +} + type AuthorizationManage struct { yesql.Namespace `yesql:"authorization_manage"` BeFriendIds *sqlx.Stmt `yesql:"be_friend_ids"` @@ -262,12 +272,14 @@ type TopicA struct { type Tweet struct { yesql.Namespace `yesql:"tweet"` - GetPostContetnsByIds string `yesql:"get_post_contetns_by_ids"` + GetAnyPostCount string `yesql:"get_any_post_count"` + GetAnyPosts string `yesql:"get_any_posts"` + GetPostContentsByIds string `yesql:"get_post_contents_by_ids"` + GetUserPostCount string `yesql:"get_user_post_count"` + GetUserPosts string `yesql:"get_user_posts"` GetPostAttachmentBill *sqlx.Stmt `yesql:"get_post_attachment_bill"` GetPostById *sqlx.Stmt `yesql:"get_post_by_id"` GetPostContentById *sqlx.Stmt `yesql:"get_post_content_by_id"` - GetPostCount *sqlx.Stmt `yesql:"get_post_count"` - GetPosts *sqlx.Stmt `yesql:"get_posts"` GetUserPostCollection *sqlx.Stmt `yesql:"get_user_post_collection"` GetUserPostCollectionCount *sqlx.Stmt `yesql:"get_user_post_collection_count"` GetUserPostCollections *sqlx.Stmt `yesql:"get_user_post_collections"` @@ -304,19 +316,20 @@ type TweetHelpA struct { } type TweetManage struct { - yesql.Namespace `yesql:"tweet_manage"` - AddAttachment *sqlx.Stmt `yesql:"add_attachment"` - AddPost *sqlx.Stmt `yesql:"add_post"` - AddPostCollection *sqlx.Stmt `yesql:"add_post_collection"` - AddPostContent *sqlx.Stmt `yesql:"add_post_content"` - AddPostStar *sqlx.Stmt `yesql:"add_post_star"` - DelPost *sqlx.Stmt `yesql:"del_post"` - DelPostCollection *sqlx.Stmt `yesql:"del_post_collection"` - DelPostStar *sqlx.Stmt `yesql:"del_post_star"` - LockPost *sqlx.Stmt `yesql:"lock_post"` - StickPost *sqlx.Stmt `yesql:"stick_post"` - UpdatePost *sqlx.Stmt `yesql:"update_post"` - VisiblePost *sqlx.Stmt `yesql:"visible_post"` + yesql.Namespace `yesql:"tweet_manage"` + AddAttachment *sqlx.Stmt `yesql:"add_attachment"` + AddPostCollection *sqlx.Stmt `yesql:"add_post_collection"` + AddPostStar *sqlx.Stmt `yesql:"add_post_star"` + DelPostById *sqlx.Stmt `yesql:"del_post_by_id"` + DelPostCollection *sqlx.Stmt `yesql:"del_post_collection"` + DelPostStar *sqlx.Stmt `yesql:"del_post_star"` + LockPost *sqlx.Stmt `yesql:"lock_post"` + MediaContentByPostId *sqlx.Stmt `yesql:"media_content_by_post_id"` + StickPost *sqlx.Stmt `yesql:"stick_post"` + VisiblePost *sqlx.Stmt `yesql:"visible_post"` + AddPost *sqlx.NamedStmt `yesql:"add_post"` + AddPostContent *sqlx.NamedStmt `yesql:"add_post_content"` + UpdatePost *sqlx.NamedStmt `yesql:"update_post"` } type TweetManageA struct { @@ -352,6 +365,22 @@ type Wallet struct { NewPostBill *sqlx.Stmt `yesql:"new_post_bill"` } +func BuildYesql(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Yesql, err error) { + var c context.Context + if len(ctx) > 0 && ctx[0] != nil { + c = ctx[0] + } else { + c = context.Background() + } + obj = &Yesql{ + TagsFromNames: p.QueryHook(_TagsFromNames), + } + if obj.UpdateTagQuote, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UpdateTagQuote))); err != nil { + return + } + return +} + func BuildAuthorizationManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *AuthorizationManage, err error) { var c context.Context if len(ctx) > 0 && ctx[0] != nil { @@ -698,7 +727,11 @@ func BuildTweet(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Tweet, er c = context.Background() } obj = &Tweet{ - GetPostContetnsByIds: p.QueryHook(_Tweet_GetPostContetnsByIds), + GetAnyPostCount: p.QueryHook(_Tweet_GetAnyPostCount), + GetAnyPosts: p.QueryHook(_Tweet_GetAnyPosts), + GetPostContentsByIds: p.QueryHook(_Tweet_GetPostContentsByIds), + GetUserPostCount: p.QueryHook(_Tweet_GetUserPostCount), + GetUserPosts: p.QueryHook(_Tweet_GetUserPosts), } if obj.GetPostAttachmentBill, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetPostAttachmentBill))); err != nil { return @@ -709,12 +742,6 @@ func BuildTweet(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Tweet, er if obj.GetPostContentById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetPostContentById))); err != nil { return } - if obj.GetPostCount, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetPostCount))); err != nil { - return - } - if obj.GetPosts, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetPosts))); err != nil { - return - } if obj.GetUserPostCollection, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_GetUserPostCollection))); err != nil { return } @@ -816,19 +843,13 @@ func BuildTweetManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Twe if obj.AddAttachment, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_AddAttachment))); err != nil { return } - if obj.AddPost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_AddPost))); err != nil { - return - } if obj.AddPostCollection, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_AddPostCollection))); err != nil { return } - if obj.AddPostContent, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_AddPostContent))); err != nil { - return - } if obj.AddPostStar, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_AddPostStar))); err != nil { return } - if obj.DelPost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_DelPost))); err != nil { + if obj.DelPostById, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_DelPostById))); err != nil { return } if obj.DelPostCollection, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_DelPostCollection))); err != nil { @@ -840,15 +861,24 @@ func BuildTweetManage(p yesql.PreparexBuilder, ctx ...context.Context) (obj *Twe if obj.LockPost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_LockPost))); err != nil { return } - if obj.StickPost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_StickPost))); err != nil { + if obj.MediaContentByPostId, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_MediaContentByPostId))); err != nil { return } - if obj.UpdatePost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_UpdatePost))); err != nil { + if obj.StickPost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_StickPost))); err != nil { return } if obj.VisiblePost, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_TweetManage_VisiblePost))); err != nil { return } + if obj.AddPost, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_TweetManage_AddPost))); err != nil { + return + } + if obj.AddPostContent, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_TweetManage_AddPostContent))); err != nil { + return + } + if obj.UpdatePost, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_TweetManage_UpdatePost))); err != nil { + return + } return } diff --git a/internal/dao/sakila/yesql/yesql.sql b/internal/dao/sakila/yesql/yesql.sql index 84596ec0..48a0175a 100644 --- a/internal/dao/sakila/yesql/yesql.sql +++ b/internal/dao/sakila/yesql/yesql.sql @@ -1,3 +1,17 @@ +-------------------------------------------------------------------------------- +-- global sql dml +-------------------------------------------------------------------------------- + +-- name: tags_from_names +-- prepare: raw +-- clause: in +SELECT * FROM @tag WHERE tag IN (?) AND is_del=0; + +-- name: update_tag_quote +-- prepare: stmt +UPDATE @tag SET quote_num=?, modified_on=? +WHERE id=? AND is_del=0; + -------------------------------------------------------------------------------- -- authorization_manage sql dml -------------------------------------------------------------------------------- @@ -37,17 +51,17 @@ SELECT * FROM @comment_reply WHERE id=? AND is_del=0; -- name: get_comment_contents_by_ids@comment -- prepare: raw -- clause: in -SELECT * FROM @comment_content WHERE comment_id IN ?; +SELECT * FROM @comment_content WHERE comment_id IN (?); -- name: get_commment_replies_by_ids@comment -- prepare: raw -- clause: in -SELECT * FROM @comment_reply WHERE comment_id IN ? ORDER BY id ASC; +SELECT * FROM @comment_reply WHERE comment_id IN (?) ORDER BY id ASC; -- name: get_users_by_ids@comment -- prepare: raw -- clause: in -SELECT id, nickname, username, status, avatar, is_admin FROM @user WHERE id IN ?; +SELECT id, nickname, username, status, avatar, is_admin FROM @user WHERE id IN (?); -- name: get_comment_thumbs@comment -- prepare: stmt @@ -317,15 +331,30 @@ SELECT * FROM @user WHERE username=? -- name: get_post_by_id@tweet -- prepare: stmt -SELECT * FROM @user WHERE username=? +SELECT * FROM @post WHERE id=? AND is_del=0; --- name: get_posts@tweet --- prepare: stmt -SELECT * FROM @user WHERE username=? +-- name: get_user_posts@tweet +-- prepare: raw +-- clause: in +SELECT * FROM @post +WHERE user_id=? AND visibility IN (?) +ORDER BY latest_replies_on DESC +LIMIT ? OFFSET ?; --- name: get_post_count@tweet --- prepare: stmt -SELECT * FROM @user WHERE username=? +-- name: get_any_posts@tweet +-- prepare: raw +-- clause: in +SELECT * FROM @post WHERE visibility IN (?) AND is_del=0 LIMIT ? OFFSET ?; + +-- name: get_user_post_count@tweet +-- prepare: raw +-- clause: in +SELECT count(*) FROM @post WHERE user_id=? AND visibility IN (?); + +-- name: get_any_post_count@tweet +-- prepare: raw +-- clause: in +SELECT count(*) FROM @post WHERE visibility IN (?); -- name: get_user_post_star@tweet -- prepare: stmt @@ -355,10 +384,11 @@ SELECT * FROM @user WHERE username=? -- prepare: stmt SELECT * FROM @user WHERE username=? --- name: get_post_contetns_by_ids@tweet +-- name: get_post_contents_by_ids@tweet -- prepare: raw -- clause: in -SELECT id, user_id, tag, quote_num FROM @tag WHERE tag IN (?); +SELECT * FROM @post_content +WHERE post_id IN (?) AND is_del=0; -- name: get_post_content_by_id@tweet -- prepare: stmt @@ -369,52 +399,66 @@ SELECT * FROM @user WHERE username=? -------------------------------------------------------------------------------- -- name: add_post@tweet_manage --- prepare: stmt -SELECT * FROM @user WHERE username=? +-- prepare: named_stmt +INSERT INTO @post (user_id, tags, ip, ip_loc, attachment_price, visibility, latest_replies_on, created_on) +VALUES (:user_id, :tags, :ip, :ip_loc, :attachment_price, :visibility, :latest_replies_on, :created_on); + +-- name: media_content_by_post_id@tweet_manage +-- prepare stmt +SELECT content FROM post_content WHERE post_id=? AND is_del=0 AND type IN (3, 4, 5, 7, 8); --- name: del_post@tweet_manage +-- name: del_post_by_id@tweet_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +UPDATE @post SET is_del=1, deleted_on=? WHERE id=? AND is_del=0; -- name: lock_post@tweet_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +UPDATE @post SET is_lock=1-is_lock, modified_on=? WHERE id=? AND is_del=0; -- name: stick_post@tweet_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +UPDATE @post SET is_top=1-is_top, modified_on=? WHERE id=? AND is_del=0; -- name: visible_post@tweet_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +UPDATE @post SET visibility=?, is_top=?, modified_on=? WHERE id=? AND is_del=0; -- name: update_post@tweet_manage --- prepare: stmt -SELECT * FROM @user WHERE username=? +-- prepare: named_stmt +UPDATE @post SET comment_count=:comment_count, + upvote_count=:upvote_count, + collection_count=:collection_count, + latest_replies_on=:latest_replies_on, + modified_on=:modified_on +WHERE id=:id AND is_del=0; -- name: add_post_star@tweet_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +INSERT INTO @post_star (post_id, user_id, created_on) +VALUES (?, ?, ?); -- name: del_post_star@tweet_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +UPDATE @post_star SET is_del=1, deleted_on=? WHERE id=? AND is_del=0; -- name: add_post_collection@tweet_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +INSERT INTO @post_collection (post_id, user_id, created_on) +VALUES (?, ?, ?); -- name: del_post_collection@tweet_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +UPDATE @post_collection SET is_del=1, deleted_on=? WHERE id=? AND is_del=0; -- name: add_post_content@tweet_manage --- prepare: stmt -SELECT * FROM @user WHERE username=? +-- prepare: named_stmt +INSERT INTO @post_content (post_id, user_id, content, type, sort, created_on) +VALUES (:post_id, :user_id, :content, :type, :sort, :created_on); -- name: add_attachment@tweet_manage -- prepare: stmt -SELECT * FROM @user WHERE username=? +INSERT INTO @attachment (user_id, file_size, img_width, img_height, type, content, created_on) +VALUES (?, ?, ?, ?, ?, ?, ?); -------------------------------------------------------------------------------- -- tweet_help sql dml @@ -423,12 +467,16 @@ SELECT * FROM @user WHERE username=? -- name: get_post_content_by_ids@tweet_help -- prepare: raw -- clause: in -SELECT * FROM @user WHERE username=? +SELECT id, post_id, content, type, sort +FROM @post_content +WHERE post_id IN (?) AND is_del=0; -- name: get_users_by_ids@tweet_help -- prepare: raw -- clause: in -SELECT * FROM @user WHERE username=? +SELECT id, username, nickname, status, avatar, is_admin +FROM @user +WHERE id IN (?) AND is_del=0; -------------------------------------------------------------------------------- -- tweet_a sql dml @@ -584,7 +632,7 @@ SELECT * FROM @user WHERE phone=? AND is_del=0; -- name: get_users_by_ids@user_manage -- prepare: raw -- clause: in -SELECT * FROM @user WHERE id IN ? AND is_del=0; +SELECT * FROM @user WHERE id IN (?) AND is_del=0; -- name: get_users_by_keyword@user_manage -- prepare: stmt diff --git a/internal/servants/base/base.go b/internal/servants/base/base.go index 70fb3183..1825fe98 100644 --- a/internal/servants/base/base.go +++ b/internal/servants/base/base.go @@ -207,13 +207,14 @@ func (s *DaoServant) PushPostsToSearch(c context.Context) { defer s.Redis.DelPushToSearchJob(c) splitNum := 1000 - totalRows, _ := s.Ds.GetPostCount(&ms.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(&ms.ConditionsT{}, i*splitNum, splitNum) + posts, postsFormated, err := s.GetTweetList(conditions, i*splitNum, splitNum) if err != nil || len(posts) != len(postsFormated) { continue } @@ -264,7 +265,7 @@ func (s *DaoServant) DeleteSearchPost(post *ms.Post) error { return s.Ts.DeleteDocuments([]string{fmt.Sprintf("%d", post.ID)}) } -func (s *DaoServant) GetTweetList(conditions *ms.ConditionsT, offset, limit int) ([]*ms.Post, []*ms.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/web/loose.go b/internal/servants/web/loose.go index 3e5ca1d4..81875441 100644 --- a/internal/servants/web/loose.go +++ b/internal/servants/web/loose.go @@ -152,7 +152,7 @@ func (s *looseSrv) getUserPostTweets(req *web.GetUserTweetsReq) (*web.GetUserTwe visibilities = append(visibilities, core.PostVisitFriend) } } - conditions := &ms.ConditionsT{ + conditions := ms.ConditionsT{ "user_id": other.ID, "visibility IN ?": visibilities, "ORDER": "latest_replied_on DESC",