add internal/servants/web servants init logic

pull/196/head
Michael Li 2 years ago
parent 3a1626efb4
commit 63bc1c57e6
No known key found for this signature in database

@ -1,5 +1,5 @@
package web package web
type ChangeUserStatusReq struct { type ChangeUserStatusReq struct {
*BaseInfo *BaseInfo `json:"-"`
} }

@ -1,7 +1,7 @@
package web package web
type UserWalletBillsReq struct { type UserWalletBillsReq struct {
*BaseInfo *BaseInfo `json:"-"`
} }
type UserWalletBillsResp struct { type UserWalletBillsResp struct {

@ -5,11 +5,11 @@
package web package web
type ChangeAvatarReq struct { type ChangeAvatarReq struct {
*BaseInfo *BaseInfo `json:"-"`
} }
type UserInfoReq struct { type UserInfoReq struct {
*BaseInfo *BaseInfo `json:"-"`
} }
type UserInfoResp struct { type UserInfoResp struct {

@ -5,7 +5,7 @@
package web package web
type ListFollowersReq struct { type ListFollowersReq struct {
*BaseInfo *BaseInfo `json:"-"`
} }
type ListFollowersResp struct { type ListFollowersResp struct {

@ -5,7 +5,7 @@
package web package web
type GetContactsReq struct { type GetContactsReq struct {
*BaseInfo *BaseInfo `json:"-"`
} }
type GetContactsResp struct { type GetContactsResp struct {

@ -1,7 +1,7 @@
package web package web
type TimelineReq struct { type TimelineReq struct {
*BaseInfo *BaseInfo `json:"-"`
} }
type TimelineResp struct { type TimelineResp struct {

@ -1,7 +1,7 @@
package web package web
type CreateTweetReq struct { type CreateTweetReq struct {
*BaseInfo *BaseInfo `json:"-"`
} }
type CreateTweetResp struct { type CreateTweetResp struct {

@ -11,3 +11,7 @@ import (
type BaseInfo struct { type BaseInfo struct {
User *core.User User *core.User
} }
func (b *BaseInfo) SetUser(user *core.User) {
b.User = user
}

@ -31,6 +31,10 @@ type JsonResp struct {
Data any `json:",omitempty"` Data any `json:",omitempty"`
} }
type UserSetter interface {
SetUser(*core.User)
}
func UserFrom(c *gin.Context) (*core.User, bool) { func UserFrom(c *gin.Context) (*core.User, bool) {
if u, exists := c.Get("USER"); exists { if u, exists := c.Get("USER"); exists {
user, ok := u.(*core.User) user, ok := u.(*core.User)
@ -45,6 +49,11 @@ func BindAny(c *gin.Context, obj any) mir.Error {
if err != nil { if err != nil {
return mir.NewError(xerror.InvalidParams.Code(), xerror.InvalidParams.WithDetails(errs.Error())) return mir.NewError(xerror.InvalidParams.Code(), xerror.InvalidParams.WithDetails(errs.Error()))
} }
// setup *core.User if needed
if setter, ok := obj.(UserSetter); ok {
user, _ := UserFrom(c)
setter.SetUser(user)
}
return nil return nil
} }

@ -4,6 +4,92 @@
package web package web
type webAlipaySrv struct { import (
// TODO "github.com/gin-gonic/gin"
api "github.com/rocboss/paopao-ce/auto/api/v1"
"github.com/rocboss/paopao-ce/internal/servants/base"
"github.com/rocboss/paopao-ce/internal/servants/chain"
)
var (
_ api.WebAlipayPub = (*webAlipayPubSrv)(nil)
_ api.WebAlipayPubBinding = (*webAlipayPubBinding)(nil)
_ api.WebAlipayPubRender = (*webAlipayPubRender)(nil)
_ api.WebAlipayPriv = (*webAlipayPrivSrv)(nil)
_ api.WebAlipayPrivBinding = (*webAlipayPrivBinding)(nil)
_ api.WebAlipayPrivRender = (*webAlipayPrivRender)(nil)
)
type webAlipayPubSrv struct {
base.BaseServant
api.UnimplementedWebAlipayPubServant
}
type webAlipayPubBinding struct {
base.BaseBinding
*api.UnimplementedWebAlipayPubBinding
}
type webAlipayPubRender struct {
base.BaseRender
*api.UnimplementedWebAlipayPubRender
}
type webAlipayPrivSrv struct {
base.BaseServant
api.UnimplementedWebAlipayPrivServant
}
type webAlipayPrivBinding struct {
base.BaseBinding
*api.UnimplementedWebAlipayPrivBinding
}
type webAlipayPrivRender struct {
base.BaseRender
*api.UnimplementedWebAlipayPrivRender
}
func (s *webAlipayPrivSrv) Chain() gin.HandlersChain {
return gin.HandlersChain{chain.JWT()}
}
func newWebAlipayPubSrv() api.WebAlipayPub {
return &webAlipayPubSrv{}
}
func newWebAlipayPubBinding() api.WebAlipayPubBinding {
return &webAlipayPubBinding{
UnimplementedWebAlipayPubBinding: &api.UnimplementedWebAlipayPubBinding{
BindAny: base.BindAny,
},
}
}
func newWebAlipayPubRender() api.WebAlipayPubRender {
return &webAlipayPubRender{
UnimplementedWebAlipayPubRender: &api.UnimplementedWebAlipayPubRender{
RenderAny: base.RenderAny,
},
}
}
func newWebAlipayPrivSrv() api.WebAlipayPriv {
return &webAlipayPrivSrv{}
}
func newWebAlipayPrivBinding() api.WebAlipayPrivBinding {
return &webAlipayPrivBinding{
UnimplementedWebAlipayPrivBinding: &api.UnimplementedWebAlipayPrivBinding{
BindAny: base.BindAny,
},
}
}
func newWebAlipayPrivRender() api.WebAlipayPrivRender {
return &webAlipayPrivRender{
UnimplementedWebAlipayPrivRender: &api.UnimplementedWebAlipayPrivRender{
RenderAny: base.RenderAny,
},
}
} }

@ -4,6 +4,54 @@
package web package web
import (
"github.com/gin-gonic/gin"
api "github.com/rocboss/paopao-ce/auto/api/v1"
"github.com/rocboss/paopao-ce/internal/servants/base"
"github.com/rocboss/paopao-ce/internal/servants/chain"
)
var (
_ api.WebFollowship = (*webFollowshipSrv)(nil)
_ api.WebFollowshipBinding = (*webFollowshipBinding)(nil)
_ api.WebFollowshipRender = (*webFollowshipRender)(nil)
)
type webFollowshipSrv struct { type webFollowshipSrv struct {
// TODO base.BaseServant
api.UnimplementedWebFollowshipServant
}
type webFollowshipBinding struct {
base.BaseBinding
*api.UnimplementedWebFollowshipBinding
}
type webFollowshipRender struct {
base.BaseRender
*api.UnimplementedWebFollowshipRender
}
func (s *webFollowshipSrv) Chain() gin.HandlersChain {
return gin.HandlersChain{chain.JWT()}
}
func newWebFollowshipSrv() api.WebFollowship {
return &webFollowshipSrv{}
}
func newWebFollowshipBinding() api.WebFollowshipBinding {
return &webFollowshipBinding{
UnimplementedWebFollowshipBinding: &api.UnimplementedWebFollowshipBinding{
BindAny: base.BindAny,
},
}
}
func newWebFollowshipRender() api.WebFollowshipRender {
return &webFollowshipRender{
UnimplementedWebFollowshipRender: &api.UnimplementedWebFollowshipRender{
RenderAny: base.RenderAny,
},
}
} }

@ -4,6 +4,54 @@
package web package web
import (
"github.com/gin-gonic/gin"
api "github.com/rocboss/paopao-ce/auto/api/v1"
"github.com/rocboss/paopao-ce/internal/servants/base"
"github.com/rocboss/paopao-ce/internal/servants/chain"
)
var (
_ api.WebFriendship = (*webFriendshipSrv)(nil)
_ api.WebFriendshipBinding = (*webFriendshipBinding)(nil)
_ api.WebFriendshipRender = (*webFriendshipRender)(nil)
)
type webFriendshipSrv struct { type webFriendshipSrv struct {
// TODO base.BaseServant
api.UnimplementedWebFriendshipServant
}
type webFriendshipBinding struct {
base.BaseBinding
*api.UnimplementedWebFriendshipBinding
}
type webFriendshipRender struct {
base.BaseRender
*api.UnimplementedWebFriendshipRender
}
func (s *webFriendshipSrv) Chain() gin.HandlersChain {
return gin.HandlersChain{chain.JWT()}
}
func newWebFriendshipSrv() api.WebFriendship {
return &webFriendshipSrv{}
}
func newWebFriendshipBinding() api.WebFriendshipBinding {
return &webFriendshipBinding{
UnimplementedWebFriendshipBinding: &api.UnimplementedWebFriendshipBinding{
BindAny: base.BindAny,
},
}
}
func newWebFriendshipRender() api.WebFriendshipRender {
return &webFriendshipRender{
UnimplementedWebFriendshipRender: &api.UnimplementedWebFriendshipRender{
RenderAny: base.RenderAny,
},
}
} }

@ -4,6 +4,54 @@
package web package web
import (
"github.com/gin-gonic/gin"
api "github.com/rocboss/paopao-ce/auto/api/v1"
"github.com/rocboss/paopao-ce/internal/servants/base"
"github.com/rocboss/paopao-ce/internal/servants/chain"
)
var (
_ api.WebLoose = (*webLooseSrv)(nil)
_ api.WebLooseBinding = (*webLooseBinding)(nil)
_ api.WebLooseRender = (*webLooseRender)(nil)
)
type webLooseSrv struct { type webLooseSrv struct {
// TODO base.BaseServant
api.UnimplementedWebLooseServant
}
type webLooseBinding struct {
base.BaseBinding
*api.UnimplementedWebLooseBinding
}
type webLooseRender struct {
base.BaseRender
*api.UnimplementedWebLooseRender
}
func (s *webLooseSrv) Chain() gin.HandlersChain {
return gin.HandlersChain{chain.JwtLoose()}
}
func newWebLooseSrv() api.WebLoose {
return &webLooseSrv{}
}
func newWebLooseBinding() api.WebLooseBinding {
return &webLooseBinding{
UnimplementedWebLooseBinding: &api.UnimplementedWebLooseBinding{
BindAny: base.BindAny,
},
}
}
func newWebLooseRender() api.WebLooseRender {
return &webLooseRender{
UnimplementedWebLooseRender: &api.UnimplementedWebLooseRender{
RenderAny: base.RenderAny,
},
}
} }

@ -4,6 +4,54 @@
package web package web
import (
"github.com/gin-gonic/gin"
api "github.com/rocboss/paopao-ce/auto/api/v1"
"github.com/rocboss/paopao-ce/internal/servants/base"
"github.com/rocboss/paopao-ce/internal/servants/chain"
)
var (
_ api.WebPriv = (*webPrivSrv)(nil)
_ api.WebPrivBinding = (*webPrivBinding)(nil)
_ api.WebPrivRender = (*webPrivRender)(nil)
)
type webPrivSrv struct { type webPrivSrv struct {
// TODO base.BaseServant
api.UnimplementedWebPrivServant
}
type webPrivBinding struct {
base.BaseBinding
*api.UnimplementedWebPrivBinding
}
type webPrivRender struct {
base.BaseRender
*api.UnimplementedWebPrivRender
}
func (s *webPrivSrv) Chain() gin.HandlersChain {
return gin.HandlersChain{chain.JWT(), chain.Priv()}
}
func newWebPrivSrv() api.WebPriv {
return &webPrivSrv{}
}
func newWebPrivBinding() api.WebPrivBinding {
return &webPrivBinding{
UnimplementedWebPrivBinding: &api.UnimplementedWebPrivBinding{
BindAny: base.BindAny,
},
}
}
func newWebPrivRender() api.WebPrivRender {
return &webPrivRender{
UnimplementedWebPrivRender: &api.UnimplementedWebPrivRender{
RenderAny: base.RenderAny,
},
}
} }

@ -4,6 +4,54 @@
package web package web
import (
"github.com/gin-gonic/gin"
api "github.com/rocboss/paopao-ce/auto/api/v1"
"github.com/rocboss/paopao-ce/internal/servants/base"
"github.com/rocboss/paopao-ce/internal/servants/chain"
)
var (
_ api.WebPub = (*webPubSrv)(nil)
_ api.WebPubBinding = (*webPubBinding)(nil)
_ api.WebPubRender = (*webPubRender)(nil)
)
type webPubSrv struct { type webPubSrv struct {
// TODO base.BaseServant
api.UnimplementedWebPubServant
}
type webPubBinding struct {
base.BaseBinding
*api.UnimplementedWebPubBinding
}
type webPubRender struct {
base.BaseRender
*api.UnimplementedWebPubRender
}
func (s *webPubSrv) Chain() gin.HandlersChain {
return gin.HandlersChain{chain.JwtLoose()}
}
func newWebPubSrv() api.WebPub {
return &webPubSrv{}
}
func newWebPubBinding() api.WebPubBinding {
return &webPubBinding{
UnimplementedWebPubBinding: &api.UnimplementedWebPubBinding{
BindAny: base.BindAny,
},
}
}
func newWebPubRender() api.WebPubRender {
return &webPubRender{
UnimplementedWebPubRender: &api.UnimplementedWebPubRender{
RenderAny: base.RenderAny,
},
}
} }

@ -5,12 +5,29 @@
package web package web
import ( import (
"github.com/alimy/cfg"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
api "github.com/rocboss/paopao-ce/auto/api/v1" api "github.com/rocboss/paopao-ce/auto/api/v1"
) )
// RouteWeb register web route // RouteWeb register web route
func RouteWeb(e *gin.Engine) { func RouteWeb(e *gin.Engine) {
api.RegisterWebCoreServant(e, newWebCoreSrv(), newWebCoreBinding(), newWebCoreRender())
api.RegisterWebAdminServant(e, newWebAdminSrv(), newWebAdminBinding(), newWebAdminRender()) api.RegisterWebAdminServant(e, newWebAdminSrv(), newWebAdminBinding(), newWebAdminRender())
api.RegisterWebCoreServant(e, newWebCoreSrv(), newWebCoreBinding(), newWebCoreRender())
api.RegisterWebLooseServant(e, newWebLooseSrv(), newWebLooseBinding(), newWebLooseRender())
api.RegisterWebPrivServant(e, newWebPrivSrv(), newWebPrivBinding(), newWebPrivRender())
api.RegisterWebPubServant(e, newWebPubSrv(), newWebPubBinding(), newWebPubRender())
cfg.In(cfg.Actions{
"Alipay": func() {
api.RegisterWebAlipayPubServant(e, newWebAlipayPubSrv(), newWebAlipayPubBinding(), newWebAlipayPubRender())
api.RegisterWebAlipayPrivServant(e, newWebAlipayPrivSrv(), newWebAlipayPrivBinding(), newWebAlipayPrivRender())
},
"Followship": func() {
api.RegisterWebFollowshipServant(e, newWebFollowshipSrv(), newWebFollowshipBinding(), newWebFollowshipRender())
},
"Friendship": func() {
api.RegisterWebFriendshipServant(e, newWebFriendshipSrv(), newWebFriendshipBinding(), newWebFriendshipRender())
},
})
} }

@ -8,42 +8,43 @@ import (
"github.com/rocboss/paopao-ce/pkg/xerror" "github.com/rocboss/paopao-ce/pkg/xerror"
) )
// nolint
var ( var (
errUsernameHasExisted = xerror.NewError(20001, "用户名已存在") _errUsernameHasExisted = xerror.NewError(20001, "用户名已存在")
errUsernameLengthLimit = xerror.NewError(20002, "用户名长度3~12") _errUsernameLengthLimit = xerror.NewError(20002, "用户名长度3~12")
errUsernameCharLimit = xerror.NewError(20003, "用户名只能包含字母、数字") _errUsernameCharLimit = xerror.NewError(20003, "用户名只能包含字母、数字")
errPasswordLengthLimit = xerror.NewError(20004, "密码长度6~16") _errPasswordLengthLimit = xerror.NewError(20004, "密码长度6~16")
errUserRegisterFailed = xerror.NewError(20005, "用户注册失败") _errUserRegisterFailed = xerror.NewError(20005, "用户注册失败")
errUserHasBeenBanned = xerror.NewError(20006, "该账户已被封停") _errUserHasBeenBanned = xerror.NewError(20006, "该账户已被封停")
errNoPermission = xerror.NewError(20007, "无权限执行该请求") _errNoPermission = xerror.NewError(20007, "无权限执行该请求")
errUserHasBindOTP = xerror.NewError(20008, "当前用户已绑定二次验证") _errUserHasBindOTP = xerror.NewError(20008, "当前用户已绑定二次验证")
errUserOTPInvalid = xerror.NewError(20009, "二次验证码验证失败") _errUserOTPInvalid = xerror.NewError(20009, "二次验证码验证失败")
errUserNoBindOTP = xerror.NewError(20010, "当前用户未绑定二次验证") _errUserNoBindOTP = xerror.NewError(20010, "当前用户未绑定二次验证")
errErrorOldPassword = xerror.NewError(20011, "当前用户密码验证失败") _errErrorOldPassword = xerror.NewError(20011, "当前用户密码验证失败")
errErrorCaptchaPassword = xerror.NewError(20012, "图形验证码验证失败") _errErrorCaptchaPassword = xerror.NewError(20012, "图形验证码验证失败")
errAccountNoPhoneBind = xerror.NewError(20013, "拒绝操作: 账户未绑定手机号") _errAccountNoPhoneBind = xerror.NewError(20013, "拒绝操作: 账户未绑定手机号")
errTooManyLoginError = xerror.NewError(20014, "登录失败次数过多,请稍后再试") _errTooManyLoginError = xerror.NewError(20014, "登录失败次数过多,请稍后再试")
errGetPhoneCaptchaError = xerror.NewError(20015, "短信验证码获取失败") _errGetPhoneCaptchaError = xerror.NewError(20015, "短信验证码获取失败")
errTooManyPhoneCaptchaSend = xerror.NewError(20016, "短信验证码获取次数已达今日上限") _errTooManyPhoneCaptchaSend = xerror.NewError(20016, "短信验证码获取次数已达今日上限")
errExistedUserPhone = xerror.NewError(20017, "该手机号已被绑定") _errExistedUserPhone = xerror.NewError(20017, "该手机号已被绑定")
errErrorPhoneCaptcha = xerror.NewError(20018, "手机验证码不正确") _errErrorPhoneCaptcha = xerror.NewError(20018, "手机验证码不正确")
errMaxPhoneCaptchaUseTimes = xerror.NewError(20019, "手机验证码已达最大使用次数") _errMaxPhoneCaptchaUseTimes = xerror.NewError(20019, "手机验证码已达最大使用次数")
errNicknameLengthLimit = xerror.NewError(20020, "昵称长度2~12") _errNicknameLengthLimit = xerror.NewError(20020, "昵称长度2~12")
errNoExistUsername = xerror.NewError(20021, "用户不存在") _errNoExistUsername = xerror.NewError(20021, "用户不存在")
errNoAdminPermission = xerror.NewError(20022, "无管理权限") _errNoAdminPermission = xerror.NewError(20022, "无管理权限")
errGetPostsFailed = xerror.NewError(30001, "获取动态列表失败") _errGetPostsFailed = xerror.NewError(30001, "获取动态列表失败")
errCreatePostFailed = xerror.NewError(30002, "动态发布失败") _errCreatePostFailed = xerror.NewError(30002, "动态发布失败")
errGetPostFailed = xerror.NewError(30003, "获取动态详情失败") _errGetPostFailed = xerror.NewError(30003, "获取动态详情失败")
errDeletePostFailed = xerror.NewError(30004, "动态删除失败") _errDeletePostFailed = xerror.NewError(30004, "动态删除失败")
errLockPostFailed = xerror.NewError(30005, "动态锁定失败") _errLockPostFailed = xerror.NewError(30005, "动态锁定失败")
errGetPostTagsFailed = xerror.NewError(30006, "获取话题列表失败") _errGetPostTagsFailed = xerror.NewError(30006, "获取话题列表失败")
errInvalidDownloadReq = xerror.NewError(30007, "附件下载请求不合法") _errInvalidDownloadReq = xerror.NewError(30007, "附件下载请求不合法")
errDownloadReqError = xerror.NewError(30008, "附件下载请求失败") _errDownloadReqError = xerror.NewError(30008, "附件下载请求失败")
errInsuffientDownloadMoney = xerror.NewError(30009, "附件下载失败:账户资金不足") _errInsuffientDownloadMoney = xerror.NewError(30009, "附件下载失败:账户资金不足")
errDownloadExecFail = xerror.NewError(30010, "附件下载失败:扣费失败") _errDownloadExecFail = xerror.NewError(30010, "附件下载失败:扣费失败")
errStickPostFailed = xerror.NewError(30011, "动态置顶失败") _errStickPostFailed = xerror.NewError(30011, "动态置顶失败")
errVisblePostFailed = xerror.NewError(30012, "更新可见性失败") _errVisblePostFailed = xerror.NewError(30012, "更新可见性失败")
errGetCommentsFailed = xerror.NewError(40001, "获取评论列表失败") errGetCommentsFailed = xerror.NewError(40001, "获取评论列表失败")
errCreateCommentFailed = xerror.NewError(40002, "评论发布失败") errCreateCommentFailed = xerror.NewError(40002, "评论发布失败")

Loading…
Cancel
Save