74 lines
1.9 KiB
Go
74 lines
1.9 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 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)
|
||
|
}
|
||
|
|
||
|
func OpGetNotificationList(ctx *gin.Context) {
|
||
|
req := ctx.MustGet("client_req").(*notificationproto.OpListReq)
|
||
|
|
||
|
//设置默认页长
|
||
|
if req.Limit == 0 {
|
||
|
req.Limit = consts.DefaultPageSize
|
||
|
}
|
||
|
|
||
|
list, ec := service.DefaultService.OpGetNotificationList(ctx, req)
|
||
|
if ec != errcode.ErrCodeNotificationSrvOk {
|
||
|
logger.Error("OpGetNotificationList fail, req: %v, ec: %v", util.ToJson(req), ec)
|
||
|
ReplyErrCodeMsg(ctx, ec)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
data := ¬ificationproto.OpListData{
|
||
|
List: list,
|
||
|
Offset: req.Offset + len(list),
|
||
|
}
|
||
|
if len(list) >= req.Limit {
|
||
|
data.More = 1
|
||
|
}
|
||
|
ReplyOk(ctx, data)
|
||
|
}
|