2024-08-30 16:34:00 +08:00
|
|
|
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 OpCreateNotification(ctx *gin.Context) {
|
|
|
|
req := ctx.MustGet("client_req").(*notificationproto.OpCreateReq)
|
|
|
|
ec := service.DefaultService.OpCreateNotification(ctx, req)
|
|
|
|
if ec != errcode.ErrCodeNotificationSrvOk {
|
|
|
|
logger.Error("OpCreateNotification fail, req: %v, ec: %v", util.ToJson(req), ec)
|
|
|
|
ReplyErrorMsg(ctx, "server error")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ReplyOk(ctx, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func OpUpdateNotification(ctx *gin.Context) {
|
|
|
|
req := ctx.MustGet("client_req").(*notificationproto.OpUpdateReq)
|
|
|
|
ec := service.DefaultService.OpUpdateNotification(ctx, req)
|
|
|
|
if ec != errcode.ErrCodeNotificationSrvOk {
|
|
|
|
logger.Error("OpUpdateNotification fail, req: %v, ec: %v", util.ToJson(req), ec)
|
|
|
|
ReplyErrCodeMsg(ctx, ec)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ReplyOk(ctx, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func OpDeleteNotification(ctx *gin.Context) {
|
|
|
|
req := ctx.MustGet("client_req").(*notificationproto.OpDeleteReq)
|
|
|
|
ec := service.DefaultService.OpDeleteNotification(ctx, req.Id)
|
|
|
|
if ec != errcode.ErrCodeNotificationSrvOk {
|
|
|
|
logger.Error("OpDeleteNotification fail, req: %v, ec: %v", util.ToJson(req), ec)
|
|
|
|
ReplyErrCodeMsg(ctx, ec)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ReplyOk(ctx, nil)
|
|
|
|
}
|
|
|
|
|
2024-09-02 12:52:49 +08:00
|
|
|
func OpGetNotificationListByMid(ctx *gin.Context) {
|
|
|
|
req := ctx.MustGet("client_req").(*notificationproto.OpListByMidReq)
|
2024-08-30 16:34:00 +08:00
|
|
|
|
|
|
|
//设置默认页长
|
|
|
|
if req.Limit == 0 {
|
|
|
|
req.Limit = consts.DefaultPageSize
|
|
|
|
}
|
|
|
|
|
2024-09-02 12:52:49 +08:00
|
|
|
list, ec := service.DefaultService.OpGetNotificationListByMid(ctx, req)
|
2024-08-30 16:34:00 +08:00
|
|
|
if ec != errcode.ErrCodeNotificationSrvOk {
|
|
|
|
logger.Error("OpGetNotificationList fail, req: %v, ec: %v", util.ToJson(req), ec)
|
|
|
|
ReplyErrCodeMsg(ctx, ec)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-09-02 12:52:49 +08:00
|
|
|
data := ¬ificationproto.OpListByMidData{
|
2024-08-30 16:34:00 +08:00
|
|
|
List: list,
|
|
|
|
Offset: req.Offset + len(list),
|
|
|
|
}
|
|
|
|
if len(list) >= req.Limit {
|
|
|
|
data.More = 1
|
|
|
|
}
|
|
|
|
ReplyOk(ctx, data)
|
|
|
|
}
|