service/app/mix/controller/zonemoment_api.go

116 lines
3.1 KiB
Go

package controller
import (
"service/api/consts"
"service/api/errcode"
zonemomentproto "service/api/proto/zonemoment/proto"
"service/app/mix/service"
"service/bizcommon/util"
"service/library/logger"
"github.com/gin-gonic/gin"
)
func ApiCreateZoneMoment(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zonemomentproto.ApiCreateReq)
ec, acctPunEndTime := service.DefaultService.ApiCreateZoneMoment(ctx, req)
if ec == errcode.ErrCodeFunctionBlocked {
logger.Error("ApiCreateMoment fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsgAndDetail(ctx, ec, acctPunEndTime)
return
}
if ec != errcode.ErrCodeZoneMomentSrvOk {
logger.Error("ApiCreateMoment fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func ApiUpdateZoneMoment(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zonemomentproto.ApiUpdateReq)
ec := service.DefaultService.ApiUpdateZoneMoment(ctx, req)
if ec != errcode.ErrCodeZoneMomentSrvOk {
logger.Error("ApiUpdateZoneMoment fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func ApiDeleteZoneMoment(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zonemomentproto.ApiDeleteReq)
ec := service.DefaultService.ApiDeleteZoneMoment(ctx, util.DerefInt64(req.Id))
if ec != errcode.ErrCodeZoneMomentSrvOk {
logger.Error("ApiDeleteZoneMoment fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func ApiGetZoneMomentListByVisitorMid(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zonemomentproto.ApiListByVisitorMidReq)
//设置默认页长
if req.Limit == 0 {
req.Limit = consts.DefaultPageSize
}
list, ec := service.DefaultService.ApiGetZoneMomentListByVisitorMid(ctx, req)
if ec != errcode.ErrCodeZoneMomentSrvOk {
logger.Error("ApiGetZoneMomentList fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
data := &zonemomentproto.ApiListByVisitorMidData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}
func ApiGetZoneMomentListByCreaterMid(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zonemomentproto.ApiListByCreaterMidReq)
//设置默认页长
if req.Limit == 0 {
req.Limit = consts.DefaultPageSize
}
list, ec := service.DefaultService.ApiGetZoneMomentListByCreaterMid(ctx, req)
if ec != errcode.ErrCodeZoneMomentSrvOk {
logger.Error("ApiGetZoneMomentList fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
data := &zonemomentproto.ApiListByCreaterMidData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}
func ApiZoneMomentThumbsUpMoment(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*zonemomentproto.ApiZoneMomentThumbsUpReq)
ec := service.DefaultService.ApiZoneMomentThumbsUpMoment(ctx, req)
if ec != errcode.ErrCodeMomentSrvOk {
logger.Error("ApiZoneMomentThumbsUpMoment fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}