Merge branch 'r/paopao-ce-plus' into r/paopao-ce-xtra

r/paopao-ce-xtra
Michael Li 1 year ago
commit 26330980cb
No known key found for this signature in database

@ -22,6 +22,7 @@ const (
_CommentManage_CreateCommentReply = `INSERT INTO @comment_reply (comment_id, user_id, content, at_user_id, ip, ip_loc, created_on) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING *` _CommentManage_CreateCommentReply = `INSERT INTO @comment_reply (comment_id, user_id, content, at_user_id, ip, ip_loc, created_on) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING *`
_ContactManager_CreateContact = `INSERT INTO @contact (user_id, friend_id, status, created_on) VALUES (?, ?, ?, ?) RETURNING *` _ContactManager_CreateContact = `INSERT INTO @contact (user_id, friend_id, status, created_on) VALUES (?, ?, ?, ?) RETURNING *`
_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) RETURNING id` _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) RETURNING id`
_Tweet_ListIndexHotsTweets = `SELECT post.* FROM @post post LEFT JOIN @post_metric metric ON post.id=metric.post_id WHERE post.visibility>=90 AND post.is_del=0 ORDER BY post.is_top DESC, metric.rank_score DESC NULLS LAST, post.latest_replied_on DESC LIMIT ? OFFSET ?`
_TweetManage_AddAttachment = `INSERT INTO @attachment (user_id, file_size, img_width, img_height, type, content, created_on) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING id` _TweetManage_AddAttachment = `INSERT INTO @attachment (user_id, file_size, img_width, img_height, type, content, created_on) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING id`
_TweetManage_AddPost = `INSERT INTO @post (user_id, tags, ip, ip_loc, attachment_price, visibility, latest_replied_on, created_on) VALUES (:user_id, :tags, :ip, :ip_loc, :attachment_price, :visibility, :latest_replied_on, :created_on) RETURNING id` _TweetManage_AddPost = `INSERT INTO @post (user_id, tags, ip, ip_loc, attachment_price, visibility, latest_replied_on, created_on) VALUES (:user_id, :tags, :ip, :ip_loc, :attachment_price, :visibility, :latest_replied_on, :created_on) RETURNING id`
_TweetManage_AddPostCollection = `INSERT INTO @post_collection (post_id, user_id, created_on) VALUES (?, ?, ?) RETURNING *` _TweetManage_AddPostCollection = `INSERT INTO @post_collection (post_id, user_id, created_on) VALUES (?, ?, ?) RETURNING *`
@ -68,6 +69,11 @@ type Message struct {
CreateMessage *sqlx.NamedStmt `yesql:"create_message"` CreateMessage *sqlx.NamedStmt `yesql:"create_message"`
} }
type Tweet struct {
yesql.Namespace `yesql:"tweet"`
ListIndexHotsTweets *sqlx.Stmt `yesql:"list_index_hots_tweets"`
}
type TweetManage struct { type TweetManage struct {
yesql.Namespace `yesql:"tweet_manage"` yesql.Namespace `yesql:"tweet_manage"`
AddAttachment *sqlx.Stmt `yesql:"add_attachment"` AddAttachment *sqlx.Stmt `yesql:"add_attachment"`
@ -135,6 +141,20 @@ func BuildMessage(p PreparexBuilder, ctx ...context.Context) (obj *Message, err
return return
} }
func BuildTweet(p PreparexBuilder, ctx ...context.Context) (obj *Tweet, err error) {
var c context.Context
if len(ctx) > 0 && ctx[0] != nil {
c = ctx[0]
} else {
c = context.Background()
}
obj = &Tweet{}
if obj.ListIndexHotsTweets, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Tweet_ListIndexHotsTweets))); err != nil {
return nil, fmt.Errorf("prepare _Tweet_ListIndexHotsTweets error: %w", err)
}
return
}
func BuildTweetManage(p PreparexBuilder, ctx ...context.Context) (obj *TweetManage, err error) { func BuildTweetManage(p PreparexBuilder, ctx ...context.Context) (obj *TweetManage, err error) {
var c context.Context var c context.Context
if len(ctx) > 0 && ctx[0] != nil { if len(ctx) > 0 && ctx[0] != nil {

@ -562,11 +562,19 @@ func (s *tweetSrv) GetPostContentByID(id int64) (res *ms.PostContent, err error)
return db.Get[ms.PostContent](s.q.GetPostContentById, &res, id) return db.Get[ms.PostContent](s.q.GetPostContentById, &res, id)
} }
func newTweetService(db *sqlx.DB) core.TweetService { func newTweetService(db *sqlx.DB) (s core.TweetService) {
return &tweetSrv{ ts := &tweetSrv{
sqlxSrv: newSqlxSrv(db), sqlxSrv: newSqlxSrv(db),
q: ccBuild(db, cc.BuildTweet), q: ccBuild(db, cc.BuildTweet),
} }
s = ts
if cfg.Any("PostgreSQL", "PgSQL", "Postgres") {
s = &pgcTweetSrv{
tweetSrv: ts,
p: pgcBuild(db, pgc.BuildTweet),
}
}
return
} }
func newTweetManageService(db *sqlx.DB, cacheIndex core.CacheIndexService) (s core.TweetManageService) { func newTweetManageService(db *sqlx.DB, cacheIndex core.CacheIndexService) (s core.TweetManageService) {

@ -17,11 +17,23 @@ var (
_ core.TweetManageService = (*pgcTweetManageSrv)(nil) _ core.TweetManageService = (*pgcTweetManageSrv)(nil)
) )
type pgcTweetSrv struct {
*tweetSrv
p *pgc.Tweet
}
type pgcTweetManageSrv struct { type pgcTweetManageSrv struct {
*tweetManageSrv *tweetManageSrv
p *pgc.TweetManage p *pgc.TweetManage
} }
func (s *pgcTweetSrv) ListIndexHotsTweets(limit int, offset int) (res []*ms.Post, total int64, err error) {
if err = s.p.ListIndexHotsTweets.Select(&res, limit, offset); err == nil {
err = s.q.CountIndexHotsTweets.Get(&total)
}
return
}
func (s *pgcTweetManageSrv) CreatePost(r *ms.Post) (*ms.Post, error) { func (s *pgcTweetManageSrv) CreatePost(r *ms.Post) (*ms.Post, error) {
now := time.Now().Unix() now := time.Now().Unix()
r.Model = &ms.Model{CreatedOn: now} r.Model = &ms.Model{CreatedOn: now}

@ -4,6 +4,20 @@
-- version is c* -- version is c*
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- tweet sql dml
--------------------------------------------------------------------------------
-- name: list_index_hots_tweets@tweet
-- prepare: stmt
SELECT post.*
FROM @post post
LEFT JOIN @post_metric metric
ON post.id=metric.post_id
WHERE post.visibility>=90 AND post.is_del=0
ORDER BY post.is_top DESC, metric.rank_score DESC NULLS LAST, post.latest_replied_on DESC
LIMIT ? OFFSET ?;
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- tweet_manage sql dml -- tweet_manage sql dml
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

Loading…
Cancel
Save