sqlx: add read all message logic

r/paopao-ce-plus
Michael Li 1 year ago
parent 900b0ddfbe
commit 4634305258
No known key found for this signature in database

@ -82,6 +82,7 @@ const (
_Message_GetUnreadCount = `SELECT count(*) FROM @message WHERE receiver_user_id=? AND is_read=0 AND is_del=0` _Message_GetUnreadCount = `SELECT count(*) FROM @message WHERE receiver_user_id=? AND is_read=0 AND is_del=0`
_Message_GetUnreadMessages = `SELECT * FROM @message WHERE receiver_user_id=? AND is_read=0 AND is_del=0 ORDER BY id DESC LIMIT ? OFFSET ?` _Message_GetUnreadMessages = `SELECT * FROM @message WHERE receiver_user_id=? AND is_read=0 AND is_del=0 ORDER BY id DESC LIMIT ? OFFSET ?`
_Message_GetWhisperMessages = `SELECT * FROM @message WHERE ((receiver_user_id=? OR sender_user_id=?) AND type=4) AND is_del=0 ORDER BY id DESC LIMIT ? OFFSET ?` _Message_GetWhisperMessages = `SELECT * FROM @message WHERE ((receiver_user_id=? OR sender_user_id=?) AND type=4) AND is_del=0 ORDER BY id DESC LIMIT ? OFFSET ?`
_Message_ReadAllMessage = `UPDATE @message SET is_read=1, modified_on=? WHERE receiver_user_id=?`
_Message_ReadMessage = `UPDATE @message SET is_read=1, modified_on=? WHERE id=?` _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_CreatePhoneCaptcha = `INSERT INTO @captcha (phone, captcha, expired_on, created_on) VALUES (:phone, :captcha, :expired_on, :created_on)`
_Security_GetLatestPhoneCaptcha = `SELECT * FROM @captcha WHERE phone=? AND is_del=0` _Security_GetLatestPhoneCaptcha = `SELECT * FROM @captcha WHERE phone=? AND is_del=0`
@ -314,6 +315,7 @@ type Message struct {
GetUnreadCount *sqlx.Stmt `yesql:"get_unread_count"` GetUnreadCount *sqlx.Stmt `yesql:"get_unread_count"`
GetUnreadMessages *sqlx.Stmt `yesql:"get_unread_messages"` GetUnreadMessages *sqlx.Stmt `yesql:"get_unread_messages"`
GetWhisperMessages *sqlx.Stmt `yesql:"get_whisper_messages"` GetWhisperMessages *sqlx.Stmt `yesql:"get_whisper_messages"`
ReadAllMessage *sqlx.Stmt `yesql:"read_all_message"`
ReadMessage *sqlx.Stmt `yesql:"read_message"` ReadMessage *sqlx.Stmt `yesql:"read_message"`
CreateMessage *sqlx.NamedStmt `yesql:"create_message"` CreateMessage *sqlx.NamedStmt `yesql:"create_message"`
} }
@ -746,6 +748,9 @@ func BuildMessage(p PreparexBuilder, ctx ...context.Context) (obj *Message, err
if obj.GetWhisperMessages, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_GetWhisperMessages))); err != nil { if obj.GetWhisperMessages, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_GetWhisperMessages))); err != nil {
return nil, fmt.Errorf("prepare _Message_GetWhisperMessages error: %w", err) return nil, fmt.Errorf("prepare _Message_GetWhisperMessages error: %w", err)
} }
if obj.ReadAllMessage, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_ReadAllMessage))); err != nil {
return nil, fmt.Errorf("prepare _Message_ReadAllMessage error: %w", err)
}
if obj.ReadMessage, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_ReadMessage))); err != nil { if obj.ReadMessage, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_Message_ReadMessage))); err != nil {
return nil, fmt.Errorf("prepare _Message_ReadMessage error: %w", err) return nil, fmt.Errorf("prepare _Message_ReadMessage error: %w", err)
} }

@ -55,6 +55,11 @@ func (s *messageSrv) ReadMessage(r *ms.Message) (err error) {
return return
} }
func (s *messageSrv) ReadAllMessage(userId int64) (err error) {
_, err = s.q.ReadAllMessage.Exec(time.Now().Unix(), userId)
return
}
func (s *messageSrv) GetMessages(userId int64, style cs.MessageStyle, limit, offset int) (res []*ms.MessageFormated, total int64, err error) { func (s *messageSrv) GetMessages(userId int64, style cs.MessageStyle, limit, offset int) (res []*ms.MessageFormated, total int64, err error) {
var messages []*ms.Message var messages []*ms.Message
// 1动态2评论3回复4私信5好友申请99系统通知 // 1动态2评论3回复4私信5好友申请99系统通知

@ -351,6 +351,10 @@ SELECT * FROM @message WHERE id=? AND is_del=0;
-- prepare: stmt -- prepare: stmt
UPDATE @message SET is_read=1, modified_on=? WHERE id=?; UPDATE @message SET is_read=1, modified_on=? WHERE id=?;
-- name: read_all_message@message
-- prepare: stmt
UPDATE @message SET is_read=1, modified_on=? WHERE receiver_user_id=?;
-- name: get_system_messages@message -- name: get_system_messages@message
-- prepare: stmt -- prepare: stmt
SELECT * SELECT *

Loading…
Cancel
Save