66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
package controller
|
|
|
|
import (
|
|
"service/api/consts"
|
|
"service/api/errcode"
|
|
notificationproto "service/api/proto/notification/proto"
|
|
"service/app/mix/service"
|
|
"service/bizcommon/util"
|
|
"service/library/logger"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func ApiGetUnreadNotificationListByMid(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*notificationproto.ApiListUnreadByMidReq)
|
|
|
|
//设置默认页长
|
|
if req.Limit == 0 {
|
|
req.Limit = consts.DefaultPageSize
|
|
}
|
|
|
|
list, ec := service.DefaultService.ApiGetUnreadNotificationListByMid(ctx, req)
|
|
if ec != errcode.ErrCodeNotificationSrvOk {
|
|
logger.Error("ApiGetUnreadNotificationListByMid fail, req: %v, ec: %v", util.ToJson(req), ec)
|
|
ReplyErrCodeMsg(ctx, ec)
|
|
return
|
|
}
|
|
|
|
data := ¬ificationproto.ApiListUnreadByMidData{
|
|
List: list,
|
|
Offset: req.Offset + len(list),
|
|
}
|
|
if len(list) >= req.Limit {
|
|
data.More = 1
|
|
}
|
|
ReplyOk(ctx, data)
|
|
}
|
|
|
|
func ApiGetUnreadNotificationCountByMid(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*notificationproto.ApiCountUnreadByMidReq)
|
|
|
|
unreadCount, ec := service.DefaultService.ApiGetUnreadNotificationCountByMid(ctx, req)
|
|
if ec != errcode.ErrCodeNotificationSrvOk {
|
|
logger.Error("ApiGetUnreadNotificationCountByMid fail, req: %v, ec: %v", util.ToJson(req), ec)
|
|
ReplyErrCodeMsg(ctx, ec)
|
|
return
|
|
}
|
|
|
|
data := ¬ificationproto.ApiCountUnreadByMidData{
|
|
UnreadCount: unreadCount,
|
|
}
|
|
ReplyOk(ctx, data)
|
|
}
|
|
|
|
func ApiReadNotification(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*notificationproto.ApiReadReq)
|
|
ec := service.DefaultService.ApiReadNotification(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)
|
|
}
|