by Robin at 20241128

This commit is contained in:
Robin 2024-11-28 15:27:40 +08:00
parent 768e7b48af
commit 6a39c8925f
6 changed files with 76 additions and 2 deletions

View File

@ -52,7 +52,7 @@ type ApiCountUnreadResp struct {
Data *ApiCountUnreadData `json:"data"`
}
// op 计数
// op 阅读
type ApiReadReq struct {
base.BaseRequest
Ids []int64 `json:"ids"`
@ -66,3 +66,17 @@ type ApiReadResp struct {
base.BaseResponse
Data *ApiReadData `json:"data"`
}
// op 阅读所有
type ApiReadAllReq struct {
base.BaseRequest
NType int64 `json:"n_type"`
}
type ApiReadAllData struct {
}
type ApiReadAllResp struct {
base.BaseResponse
Data *ApiReadData `json:"data"`
}

View File

@ -322,6 +322,7 @@ func Init(r *gin.Engine) {
apiNotificationGroup.POST("list_by_mid", middleware.JSONParamValidator(notificationproto.ApiListByMidReq{}), middleware.JwtAuthenticator(), ApiGetNotificationListByMid)
apiNotificationGroup.POST("receive", middleware.JSONParamValidator(notificationproto.ApiReceiveReq{}), middleware.JwtAuthenticator(), ApiReceiveAllBcstedNotifs)
apiNotificationGroup.POST("read", middleware.JSONParamValidator(notificationproto.ApiReadReq{}), middleware.JwtAuthenticator(), ApiReadNotification)
apiNotificationGroup.POST("read_all", middleware.JSONParamValidator(notificationproto.ApiReadAllReq{}), middleware.JwtAuthenticator(), ApiReadAllNotification)
apiNotificationGroup.POST("get_unread_count", middleware.JSONParamValidator(notificationproto.ApiCountUnreadReq{}), middleware.JwtAuthenticator(), ApiGetNotificationUrcByMid)
apiNotificationGroup.POST("get_banner_info", middleware.JSONParamValidator(base.BaseRequest{}), middleware.JwtAuthenticator(), OpGetBannerInfo)

View File

@ -68,6 +68,18 @@ func ApiReadNotification(ctx *gin.Context) {
ReplyOk(ctx, nil)
}
func ApiReadAllNotification(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*notificationproto.ApiReadAllReq)
ec := service.DefaultService.ApiReadAllNotification(ctx, req)
if ec != errcode.ErrCodeNotificationSrvOk {
logger.Error("ApiReadNotification fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func ApiGetNotificationUrcByMid(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*notificationproto.ApiCountUnreadReq)
mp, ec := service.DefaultService.ApiGetNotificationUrcByMid(ctx, req)

View File

@ -6594,6 +6594,21 @@ func (m *Mongo) ReadNotifReceiveByIds(ctx *gin.Context, req *notificationproto.A
return result, err
}
func (m *Mongo) ReadAllNotifReceive(ctx *gin.Context, req *notificationproto.ApiReadAllReq) (*qmgo.UpdateResult, error) {
col := m.getColNotifReceive()
update := qmgo.M{
"$set": qmgo.M{
"is_read": consts.NotifReceive_Read,
},
}
filter := qmgo.M{
"is_read": consts.NotifReceive_NotRead,
"n_type": req.NType,
}
result, err := col.UpdateAll(ctx, filter, update)
return result, err
}
func (m *Mongo) DeleteNotifReceiveByIds(ctx *gin.Context, ids []int64) error {
col := m.getColNotifReceive()
update := qmgo.M{

View File

@ -4701,6 +4701,29 @@ func (s *Service) ApiReadNotification(ctx *gin.Context, req *notificationproto.A
return
}
func (s *Service) ApiReadAllNotification(ctx *gin.Context, req *notificationproto.ApiReadAllReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeNotificationSrvOk
// 标记已读
result, err := _DefaultNotifReceive.OpReadAll(ctx, req)
if err != nil {
logger.Error("_DefaultNotifReceive OpReadAll fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeNotificationSrvFail
return
}
// 以真更新的条数decr
key := util.GetNotifUrcIdForRedis(req.BaseRequest.Mid, req.NType)
_, err = redis.GetRedisClient().DecrBy(key, result.ModifiedCount)
if err != nil {
logger.Error("Redis DecrBy fail, err: %v", err)
ec = errcode.ErrCodeNotificationSrvFail
return
}
return
}
func (s *Service) ApiGetNotificationUrcByMid(ctx *gin.Context, req *notificationproto.ApiCountUnreadReq) (mp map[int64]int64, ec errcode.ErrCode) {
ec = errcode.ErrCodeNotificationSrvOk

View File

@ -48,7 +48,16 @@ func (p *NotifReceive) OpCreateBatch(ctx *gin.Context, notifReceives []*dbstruct
func (p *NotifReceive) OpReadByIds(ctx *gin.Context, req *notificationproto.ApiReadReq) (*qmgo.UpdateResult, error) {
result, err := p.store.ReadNotifReceiveByIds(ctx, req)
if err != nil {
logger.Error("DeleteNotifBcstByIds fail, err: %v", err)
logger.Error("ReadNotifReceiveByIds fail, err: %v", err)
return nil, err
}
return result, nil
}
func (p *NotifReceive) OpReadAll(ctx *gin.Context, req *notificationproto.ApiReadAllReq) (*qmgo.UpdateResult, error) {
result, err := p.store.ReadAllNotifReceive(ctx, req)
if err != nil {
logger.Error("ReadAllNotifReceive fail, err: %v", err)
return nil, err
}
return result, nil