mirror of https://github.com/rocboss/paopao-ce
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
227 lines
6.4 KiB
227 lines
6.4 KiB
// Code generated by go-mir. DO NOT EDIT.
|
|
// versions:
|
|
// - mir v3.2.0
|
|
|
|
package v1
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/alimy/mir/v3"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/rocboss/paopao-ce/internal/model/web"
|
|
)
|
|
|
|
type Friendship interface {
|
|
// Chain provide handlers chain for gin
|
|
Chain() gin.HandlersChain
|
|
|
|
GetContacts(*web.GetContactsReq) (*web.GetContactsResp, mir.Error)
|
|
DeleteFriend(*web.DeleteFriendReq) mir.Error
|
|
RejectFriend(*web.RejectFriendReq) mir.Error
|
|
AddFriend(*web.AddFriendReq) mir.Error
|
|
RequestingFriend(*web.RequestingFriendReq) mir.Error
|
|
|
|
mustEmbedUnimplementedFriendshipServant()
|
|
}
|
|
|
|
type FriendshipBinding interface {
|
|
BindGetContacts(*gin.Context) (*web.GetContactsReq, mir.Error)
|
|
BindDeleteFriend(*gin.Context) (*web.DeleteFriendReq, mir.Error)
|
|
BindRejectFriend(*gin.Context) (*web.RejectFriendReq, mir.Error)
|
|
BindAddFriend(*gin.Context) (*web.AddFriendReq, mir.Error)
|
|
BindRequestingFriend(*gin.Context) (*web.RequestingFriendReq, mir.Error)
|
|
|
|
mustEmbedUnimplementedFriendshipBinding()
|
|
}
|
|
|
|
type FriendshipRender interface {
|
|
RenderGetContacts(*gin.Context, *web.GetContactsResp, mir.Error)
|
|
RenderDeleteFriend(*gin.Context, mir.Error)
|
|
RenderRejectFriend(*gin.Context, mir.Error)
|
|
RenderAddFriend(*gin.Context, mir.Error)
|
|
RenderRequestingFriend(*gin.Context, mir.Error)
|
|
|
|
mustEmbedUnimplementedFriendshipRender()
|
|
}
|
|
|
|
// RegisterFriendshipServant register Friendship servant to gin
|
|
func RegisterFriendshipServant(e *gin.Engine, s Friendship, b FriendshipBinding, r FriendshipRender) {
|
|
router := e.Group("v1")
|
|
// use chain for router
|
|
middlewares := s.Chain()
|
|
router.Use(middlewares...)
|
|
|
|
// register routes info to router
|
|
router.Handle("GET", "/user/contacts", func(c *gin.Context) {
|
|
select {
|
|
case <-c.Request.Context().Done():
|
|
return
|
|
default:
|
|
}
|
|
|
|
req, err := b.BindGetContacts(c)
|
|
if err != nil {
|
|
r.RenderGetContacts(c, nil, err)
|
|
return
|
|
}
|
|
resp, err := s.GetContacts(req)
|
|
r.RenderGetContacts(c, resp, err)
|
|
})
|
|
|
|
router.Handle("POST", "/friend/delete", func(c *gin.Context) {
|
|
select {
|
|
case <-c.Request.Context().Done():
|
|
return
|
|
default:
|
|
}
|
|
|
|
req, err := b.BindDeleteFriend(c)
|
|
if err != nil {
|
|
r.RenderDeleteFriend(c, err)
|
|
return
|
|
}
|
|
r.RenderDeleteFriend(c, s.DeleteFriend(req))
|
|
})
|
|
|
|
router.Handle("POST", "/friend/reject", func(c *gin.Context) {
|
|
select {
|
|
case <-c.Request.Context().Done():
|
|
return
|
|
default:
|
|
}
|
|
|
|
req, err := b.BindRejectFriend(c)
|
|
if err != nil {
|
|
r.RenderRejectFriend(c, err)
|
|
return
|
|
}
|
|
r.RenderRejectFriend(c, s.RejectFriend(req))
|
|
})
|
|
|
|
router.Handle("POST", "/friend/add", func(c *gin.Context) {
|
|
select {
|
|
case <-c.Request.Context().Done():
|
|
return
|
|
default:
|
|
}
|
|
|
|
req, err := b.BindAddFriend(c)
|
|
if err != nil {
|
|
r.RenderAddFriend(c, err)
|
|
return
|
|
}
|
|
r.RenderAddFriend(c, s.AddFriend(req))
|
|
})
|
|
|
|
router.Handle("POST", "/friend/requesting", func(c *gin.Context) {
|
|
select {
|
|
case <-c.Request.Context().Done():
|
|
return
|
|
default:
|
|
}
|
|
|
|
req, err := b.BindRequestingFriend(c)
|
|
if err != nil {
|
|
r.RenderRequestingFriend(c, err)
|
|
return
|
|
}
|
|
r.RenderRequestingFriend(c, s.RequestingFriend(req))
|
|
})
|
|
|
|
}
|
|
|
|
// UnimplementedFriendshipServant can be embedded to have forward compatible implementations.
|
|
type UnimplementedFriendshipServant struct {
|
|
}
|
|
|
|
func (UnimplementedFriendshipServant) Chain() gin.HandlersChain {
|
|
return nil
|
|
}
|
|
|
|
func (UnimplementedFriendshipServant) GetContacts(req *web.GetContactsReq) (*web.GetContactsResp, mir.Error) {
|
|
return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
|
}
|
|
|
|
func (UnimplementedFriendshipServant) DeleteFriend(req *web.DeleteFriendReq) mir.Error {
|
|
return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
|
}
|
|
|
|
func (UnimplementedFriendshipServant) RejectFriend(req *web.RejectFriendReq) mir.Error {
|
|
return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
|
}
|
|
|
|
func (UnimplementedFriendshipServant) AddFriend(req *web.AddFriendReq) mir.Error {
|
|
return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
|
}
|
|
|
|
func (UnimplementedFriendshipServant) RequestingFriend(req *web.RequestingFriendReq) mir.Error {
|
|
return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
|
|
}
|
|
|
|
func (UnimplementedFriendshipServant) mustEmbedUnimplementedFriendshipServant() {}
|
|
|
|
// UnimplementedFriendshipRender can be embedded to have forward compatible implementations.
|
|
type UnimplementedFriendshipRender struct {
|
|
RenderAny func(*gin.Context, any, mir.Error)
|
|
}
|
|
|
|
func (r *UnimplementedFriendshipRender) RenderGetContacts(c *gin.Context, data *web.GetContactsResp, err mir.Error) {
|
|
r.RenderAny(c, data, err)
|
|
}
|
|
|
|
func (r *UnimplementedFriendshipRender) RenderDeleteFriend(c *gin.Context, err mir.Error) {
|
|
r.RenderAny(c, nil, err)
|
|
}
|
|
|
|
func (r *UnimplementedFriendshipRender) RenderRejectFriend(c *gin.Context, err mir.Error) {
|
|
r.RenderAny(c, nil, err)
|
|
}
|
|
|
|
func (r *UnimplementedFriendshipRender) RenderAddFriend(c *gin.Context, err mir.Error) {
|
|
r.RenderAny(c, nil, err)
|
|
}
|
|
|
|
func (r *UnimplementedFriendshipRender) RenderRequestingFriend(c *gin.Context, err mir.Error) {
|
|
r.RenderAny(c, nil, err)
|
|
}
|
|
|
|
func (r *UnimplementedFriendshipRender) mustEmbedUnimplementedFriendshipRender() {}
|
|
|
|
// UnimplementedFriendshipBinding can be embedded to have forward compatible implementations.
|
|
type UnimplementedFriendshipBinding struct {
|
|
BindAny func(*gin.Context, any) mir.Error
|
|
}
|
|
|
|
func (b *UnimplementedFriendshipBinding) BindGetContacts(c *gin.Context) (*web.GetContactsReq, mir.Error) {
|
|
obj := new(web.GetContactsReq)
|
|
err := b.BindAny(c, obj)
|
|
return obj, err
|
|
}
|
|
|
|
func (b *UnimplementedFriendshipBinding) BindDeleteFriend(c *gin.Context) (*web.DeleteFriendReq, mir.Error) {
|
|
obj := new(web.DeleteFriendReq)
|
|
err := b.BindAny(c, obj)
|
|
return obj, err
|
|
}
|
|
|
|
func (b *UnimplementedFriendshipBinding) BindRejectFriend(c *gin.Context) (*web.RejectFriendReq, mir.Error) {
|
|
obj := new(web.RejectFriendReq)
|
|
err := b.BindAny(c, obj)
|
|
return obj, err
|
|
}
|
|
|
|
func (b *UnimplementedFriendshipBinding) BindAddFriend(c *gin.Context) (*web.AddFriendReq, mir.Error) {
|
|
obj := new(web.AddFriendReq)
|
|
err := b.BindAny(c, obj)
|
|
return obj, err
|
|
}
|
|
|
|
func (b *UnimplementedFriendshipBinding) BindRequestingFriend(c *gin.Context) (*web.RequestingFriendReq, mir.Error) {
|
|
obj := new(web.RequestingFriendReq)
|
|
err := b.BindAny(c, obj)
|
|
return obj, err
|
|
}
|
|
|
|
func (b *UnimplementedFriendshipBinding) mustEmbedUnimplementedFriendshipBinding() {}
|