2023-07-03 21:42:04 +08:00
|
|
|
package api
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"mayfly-go/internal/msg/application"
|
|
|
|
|
"mayfly-go/internal/msg/domain/entity"
|
2023-10-26 17:15:49 +08:00
|
|
|
"mayfly-go/pkg/biz"
|
2023-07-03 21:42:04 +08:00
|
|
|
"mayfly-go/pkg/req"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Msg struct {
|
2024-12-16 23:29:18 +08:00
|
|
|
msgApp application.Msg `inject:"T"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *Msg) ReqConfs() *req.Confs {
|
|
|
|
|
reqs := [...]*req.Conf{
|
|
|
|
|
req.NewGet("/self", m.GetMsgs),
|
2025-07-27 21:02:48 +08:00
|
|
|
req.NewGet("/self/unread/count", m.GetUnreadCount),
|
|
|
|
|
req.NewGet("/self/read", m.ReadMsg),
|
2024-12-16 23:29:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return req.NewConfs("/msgs", reqs[:]...)
|
2023-07-03 21:42:04 +08:00
|
|
|
}
|
|
|
|
|
|
2025-07-27 21:02:48 +08:00
|
|
|
// GetMsgs 获取账号接收的消息列表
|
2023-07-03 21:42:04 +08:00
|
|
|
func (m *Msg) GetMsgs(rc *req.Ctx) {
|
|
|
|
|
condition := &entity.Msg{
|
2023-11-07 21:05:21 +08:00
|
|
|
RecipientId: int64(rc.GetLoginAccount().Id),
|
2023-07-03 21:42:04 +08:00
|
|
|
}
|
2025-05-20 21:04:47 +08:00
|
|
|
res, err := m.msgApp.GetPageList(condition, rc.GetPageParam())
|
2023-10-26 17:15:49 +08:00
|
|
|
biz.ErrIsNil(err)
|
|
|
|
|
rc.ResData = res
|
2023-07-03 21:42:04 +08:00
|
|
|
}
|
2025-07-27 21:02:48 +08:00
|
|
|
|
|
|
|
|
// GetUnreadCount 获取账号接收的未读消息数量
|
|
|
|
|
func (m *Msg) GetUnreadCount(rc *req.Ctx) {
|
|
|
|
|
condition := &entity.Msg{
|
|
|
|
|
RecipientId: int64(rc.GetLoginAccount().Id),
|
|
|
|
|
Status: entity.MsgStatusUnRead,
|
|
|
|
|
}
|
|
|
|
|
rc.ResData = m.msgApp.CountByCond(condition)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ReadMsg 将账号接收的未读消息标记为已读
|
|
|
|
|
func (m *Msg) ReadMsg(rc *req.Ctx) {
|
|
|
|
|
cond := &entity.Msg{
|
|
|
|
|
RecipientId: int64(rc.GetLoginAccount().Id),
|
|
|
|
|
Status: entity.MsgStatusUnRead,
|
|
|
|
|
}
|
|
|
|
|
cond.Id = uint64(rc.QueryInt("id"))
|
|
|
|
|
|
|
|
|
|
biz.ErrIsNil(m.msgApp.UpdateByCond(rc.MetaCtx, &entity.Msg{
|
|
|
|
|
Status: entity.MsgStatusRead,
|
|
|
|
|
}, cond))
|
|
|
|
|
}
|