Files
mayfly-go/server/internal/msg/api/msg.go

55 lines
1.3 KiB
Go
Raw Normal View History

2023-07-03 21:42:04 +08:00
package api
import (
"mayfly-go/internal/msg/application"
"mayfly-go/internal/msg/domain/entity"
"mayfly-go/pkg/biz"
2023-07-03 21:42:04 +08:00
"mayfly-go/pkg/req"
)
type Msg struct {
msgApp application.Msg `inject:"T"`
}
func (m *Msg) ReqConfs() *req.Confs {
reqs := [...]*req.Conf{
req.NewGet("/self", m.GetMsgs),
req.NewGet("/self/unread/count", m.GetUnreadCount),
req.NewGet("/self/read", m.ReadMsg),
}
return req.NewConfs("/msgs", reqs[:]...)
2023-07-03 21:42:04 +08:00
}
// GetMsgs 获取账号接收的消息列表
2023-07-03 21:42:04 +08:00
func (m *Msg) GetMsgs(rc *req.Ctx) {
condition := &entity.Msg{
RecipientId: int64(rc.GetLoginAccount().Id),
2023-07-03 21:42:04 +08:00
}
res, err := m.msgApp.GetPageList(condition, rc.GetPageParam())
biz.ErrIsNil(err)
rc.ResData = res
2023-07-03 21:42:04 +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))
}