mirror of https://github.com/rocboss/paopao-ce
upgrade github.com/golang-jwt/jwt/v5 => v5.0.0 and optimize /v1/user/msgcount/unread api process logic
parent
877944ba01
commit
537f64090e
@ -0,0 +1,82 @@
|
||||
// Code generated by go-mir. DO NOT EDIT.
|
||||
// versions:
|
||||
// - mir v4.0.0
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/alimy/mir/v4"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/rocboss/paopao-ce/internal/model/web"
|
||||
)
|
||||
|
||||
type Relax interface {
|
||||
_default_
|
||||
|
||||
// Chain provide handlers chain for gin
|
||||
Chain() gin.HandlersChain
|
||||
|
||||
GetUnreadMsgCount(*web.GetUnreadMsgCountReq) (*web.GetUnreadMsgCountResp, mir.Error)
|
||||
|
||||
mustEmbedUnimplementedRelaxServant()
|
||||
}
|
||||
|
||||
type RelaxChain interface {
|
||||
ChainGetUnreadMsgCount() gin.HandlersChain
|
||||
|
||||
mustEmbedUnimplementedRelaxChain()
|
||||
}
|
||||
|
||||
// RegisterRelaxServant register Relax servant to gin
|
||||
func RegisterRelaxServant(e *gin.Engine, s Relax, m ...RelaxChain) {
|
||||
var cc RelaxChain
|
||||
if len(m) > 0 {
|
||||
cc = m[0]
|
||||
} else {
|
||||
cc = &UnimplementedRelaxChain{}
|
||||
}
|
||||
router := e.Group("v1")
|
||||
// use chain for router
|
||||
middlewares := s.Chain()
|
||||
router.Use(middlewares...)
|
||||
|
||||
// register routes info to router
|
||||
router.Handle("GET", "/user/msgcount/unread", append(cc.ChainGetUnreadMsgCount(), func(c *gin.Context) {
|
||||
select {
|
||||
case <-c.Request.Context().Done():
|
||||
return
|
||||
default:
|
||||
}
|
||||
req := new(web.GetUnreadMsgCountReq)
|
||||
if err := s.Bind(c, req); err != nil {
|
||||
s.Render(c, nil, err)
|
||||
return
|
||||
}
|
||||
resp, err := s.GetUnreadMsgCount(req)
|
||||
s.Render(c, resp, err)
|
||||
})...)
|
||||
}
|
||||
|
||||
// UnimplementedRelaxServant can be embedded to have forward compatible implementations.
|
||||
type UnimplementedRelaxServant struct{}
|
||||
|
||||
func (UnimplementedRelaxServant) Chain() gin.HandlersChain {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (UnimplementedRelaxServant) GetUnreadMsgCount(req *web.GetUnreadMsgCountReq) (*web.GetUnreadMsgCountResp, mir.Error) {
|
||||
return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
||||
}
|
||||
|
||||
func (UnimplementedRelaxServant) mustEmbedUnimplementedRelaxServant() {}
|
||||
|
||||
// UnimplementedRelaxChain can be embedded to have forward compatible implementations.
|
||||
type UnimplementedRelaxChain struct{}
|
||||
|
||||
func (b *UnimplementedRelaxChain) ChainGetUnreadMsgCount() gin.HandlersChain {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *UnimplementedRelaxChain) mustEmbedUnimplementedRelaxChain() {}
|
@ -0,0 +1,13 @@
|
||||
// Copyright 2023 ROC. All rights reserved.
|
||||
// Use of this source code is governed by a MIT style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package web
|
||||
|
||||
type GetUnreadMsgCountReq struct {
|
||||
SimpleInfo `json:"-" binding:"-"`
|
||||
}
|
||||
|
||||
type GetUnreadMsgCountResp struct {
|
||||
Count int64 `json:"count"`
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
// Copyright 2023 ROC. All rights reserved.
|
||||
// Use of this source code is governed by a MIT style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package web
|
||||
|
||||
import (
|
||||
"github.com/alimy/mir/v4"
|
||||
"github.com/gin-gonic/gin"
|
||||
api "github.com/rocboss/paopao-ce/auto/api/v1"
|
||||
"github.com/rocboss/paopao-ce/internal/model/web"
|
||||
"github.com/rocboss/paopao-ce/internal/servants/base"
|
||||
"github.com/rocboss/paopao-ce/internal/servants/chain"
|
||||
"github.com/rocboss/paopao-ce/pkg/xerror"
|
||||
)
|
||||
|
||||
var (
|
||||
_ api.Relax = (*relaxSrv)(nil)
|
||||
_ api.RelaxChain = (*relaxChain)(nil)
|
||||
)
|
||||
|
||||
type relaxSrv struct {
|
||||
api.UnimplementedRelaxServant
|
||||
*base.DaoServant
|
||||
}
|
||||
|
||||
type relaxChain struct {
|
||||
api.UnimplementedRelaxChain
|
||||
}
|
||||
|
||||
func (s *relaxSrv) GetUnreadMsgCount(req *web.GetUnreadMsgCountReq) (*web.GetUnreadMsgCountResp, mir.Error) {
|
||||
count, err := s.Ds.GetUnreadCount(req.Uid)
|
||||
if err != nil {
|
||||
return nil, xerror.ServerError
|
||||
}
|
||||
return &web.GetUnreadMsgCountResp{
|
||||
Count: count,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (*relaxChain) ChainGetUnreadMsgCount() gin.HandlersChain {
|
||||
return gin.HandlersChain{chain.JwtSurely()}
|
||||
}
|
||||
|
||||
func newRelaxSrv(s *base.DaoServant) api.Relax {
|
||||
return &relaxSrv{
|
||||
DaoServant: s,
|
||||
}
|
||||
}
|
||||
|
||||
func newRelaxChain() api.RelaxChain {
|
||||
return &relaxChain{}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
. "github.com/alimy/mir/v4"
|
||||
. "github.com/alimy/mir/v4/engine"
|
||||
"github.com/rocboss/paopao-ce/internal/model/web"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Entry[Relax]()
|
||||
}
|
||||
|
||||
// Relax 放宽授权的服务
|
||||
type Relax struct {
|
||||
Chain `mir:"-"`
|
||||
Group `mir:"v1"`
|
||||
|
||||
// GetUnreadMsgCount 获取当前用户未读消息数量
|
||||
GetUnreadMsgCount func(Get, Chain, web.GetUnreadMsgCountReq) web.GetUnreadMsgCountResp `mir:"/user/msgcount/unread"`
|
||||
}
|
Loading…
Reference in new issue