service/codecreate/template/service_center.txt

55 lines
1.7 KiB
Plaintext
Raw Normal View History

2023-12-21 22:17:40 +08:00
#{moduleName}proto "service/api/proto/#{moduleName}/proto"
_Default#{EntityName} *logic.#{EntityName}
_Default#{EntityName} = logic.New#{EntityName}(store)
// #{EntityName}
func (s *Service) OpCreate#{EntityName}(ctx *gin.Context, req *#{moduleName}proto.OpCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCode#{EntityName}SrvOk
err := _Default#{EntityName}.OpCreate(ctx, req)
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCode#{EntityName}SrvFail
return
}
return
}
func (s *Service) OpUpdate#{EntityName}(ctx *gin.Context, req *#{moduleName}proto.OpUpdateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCode#{EntityName}SrvOk
err := _Default#{EntityName}.OpUpdate(ctx, req)
if err == qmgo.ErrNoSuchDocuments {
ec = errcode.ErrCode#{EntityName}NotExist
err = nil
return
}
if err != nil {
logger.Error("OpUpdate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCode#{EntityName}SrvFail
return
}
return
}
func (s *Service) OpDelete#{EntityName}(ctx *gin.Context, id int64) (ec errcode.ErrCode) {
ec = errcode.ErrCode#{EntityName}SrvOk
err := _Default#{EntityName}.OpDelete(ctx, id)
if err != nil {
logger.Error("OpDelete fail, id: %v, err: %v", id, err)
ec = errcode.ErrCode#{EntityName}SrvFail
return
}
return
}
func (s *Service) OpGet#{EntityName}List(ctx *gin.Context, req *#{moduleName}proto.OpListReq) (list []*dbstruct.#{EntityName}, ec errcode.ErrCode) {
ec = errcode.ErrCode#{EntityName}SrvOk
list, err := _Default#{EntityName}.OpList(ctx, req)
if err != nil {
logger.Error("OpGet#{EntityName}List fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCode#{EntityName}SrvFail
return
}
return
}