feat: 添加店铺邀请列表查询接口并修复 responded_at 未写入

This commit is contained in:
zetaloop
2026-04-23 15:54:12 +08:00
parent d596d41e1a
commit 83a2f243f4
9 changed files with 300 additions and 13 deletions
+12
View File
@@ -75,6 +75,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/shops/:id/invitations",
Handler: shop.InvitePlayerHandler(serverCtx),
},
{
// 获取店铺邀请列表
Method: http.MethodGet,
Path: "/shops/:id/invitations",
Handler: shop.ListShopInvitationsHandler(serverCtx),
},
{
// 移除打手
Method: http.MethodDelete,
@@ -99,6 +105,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/shops/invitations/:id/accept",
Handler: shop.AcceptInvitationHandler(serverCtx),
},
{
// 获取我收到的邀请
Method: http.MethodGet,
Path: "/shops/invitations/mine",
Handler: shop.MyInvitationsHandler(serverCtx),
},
{
// 获取当前用户的店铺
Method: http.MethodGet,
@@ -0,0 +1,32 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1
package shop
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"juwan-backend/app/shop/api/internal/logic/shop"
"juwan-backend/app/shop/api/internal/svc"
"juwan-backend/app/shop/api/internal/types"
)
// 获取店铺邀请列表
func ListShopInvitationsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ShopIdReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := shop.NewListShopInvitationsLogic(r.Context(), svcCtx)
resp, err := l.ListShopInvitations(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
@@ -0,0 +1,25 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1
package shop
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"juwan-backend/app/shop/api/internal/logic/shop"
"juwan-backend/app/shop/api/internal/svc"
)
// 获取我收到的邀请
func MyInvitationsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := shop.NewMyInvitationsLogic(r.Context(), svcCtx)
resp, err := l.MyInvitations()
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
@@ -0,0 +1,72 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1
package shop
import (
"context"
"errors"
"juwan-backend/app/shop/api/internal/svc"
"juwan-backend/app/shop/api/internal/types"
"juwan-backend/app/shop/rpc/pb"
"juwan-backend/common/utils/contextj"
"github.com/zeromicro/go-zero/core/logx"
)
type ListShopInvitationsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 获取店铺邀请列表
func NewListShopInvitationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListShopInvitationsLogic {
return &ListShopInvitationsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListShopInvitationsLogic) ListShopInvitations(req *types.ShopIdReq) (resp *types.ShopInvitationListResp, err error) {
userID, err := contextj.UserIDFrom(l.ctx)
if err != nil {
return nil, err
}
shop, err := l.svcCtx.ShopRpc.GetShopsById(l.ctx, &pb.GetShopsByIdReq{Id: req.Id})
if err != nil {
return nil, err
}
if shop.Shops == nil {
return nil, errors.New("shop not found")
}
if shop.Shops.OwnerId != userID {
return nil, contextj.ERRILLEGALUSER
}
result, err := l.svcCtx.ShopRpc.SearchShopInvitations(l.ctx, &pb.SearchShopInvitationsReq{
ShopId: req.Id,
Limit: 100,
})
if err != nil {
return nil, err
}
items := make([]types.ShopInvitation, 0, len(result.ShopInvitations))
for _, inv := range result.ShopInvitations {
items = append(items, types.ShopInvitation{
Id: inv.Id,
ShopId: inv.ShopId,
PlayerId: inv.PlayerId,
Status: inv.Status,
InvitedBy: inv.InvitedBy,
CreatedAt: inv.CreatedAt,
RespondedAt: inv.RespondedAt,
})
}
return &types.ShopInvitationListResp{Items: items}, nil
}
@@ -0,0 +1,70 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1
package shop
import (
"context"
"juwan-backend/app/player/rpc/playerservice"
"juwan-backend/app/shop/api/internal/svc"
"juwan-backend/app/shop/api/internal/types"
"juwan-backend/app/shop/rpc/pb"
"juwan-backend/common/utils/contextj"
"github.com/zeromicro/go-zero/core/logx"
)
type MyInvitationsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 获取我收到的邀请
func NewMyInvitationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MyInvitationsLogic {
return &MyInvitationsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MyInvitationsLogic) MyInvitations() (resp *types.ShopInvitationListResp, err error) {
userID, err := contextj.UserIDFrom(l.ctx)
if err != nil {
return nil, err
}
playerResp, err := l.svcCtx.PlayerRpc.GetPlayerByUserId(l.ctx, &playerservice.SearchPlayersReq{UserId: &userID})
if err != nil {
return nil, err
}
player := playerResp.GetPlayers()
if player == nil {
return &types.ShopInvitationListResp{Items: []types.ShopInvitation{}}, nil
}
result, err := l.svcCtx.ShopRpc.SearchShopInvitations(l.ctx, &pb.SearchShopInvitationsReq{
PlayerId: player.Id,
Limit: 100,
})
if err != nil {
return nil, err
}
items := make([]types.ShopInvitation, 0, len(result.ShopInvitations))
for _, inv := range result.ShopInvitations {
items = append(items, types.ShopInvitation{
Id: inv.Id,
ShopId: inv.ShopId,
PlayerId: inv.PlayerId,
Status: inv.Status,
InvitedBy: inv.InvitedBy,
CreatedAt: inv.CreatedAt,
RespondedAt: inv.RespondedAt,
})
}
return &types.ShopInvitationListResp{Items: items}, nil
}
+14
View File
@@ -55,6 +55,20 @@ type ShopIdReq struct {
Id int64 `path:"id"`
}
type ShopInvitation struct {
Id int64 `json:"id"`
ShopId int64 `json:"shopId"`
PlayerId int64 `json:"playerId"`
Status string `json:"status"`
InvitedBy int64 `json:"invitedBy"`
CreatedAt int64 `json:"createdAt"`
RespondedAt int64 `json:"respondedAt,optional"`
}
type ShopInvitationListResp struct {
Items []ShopInvitation `json:"items"`
}
type ShopListResp struct {
Items []ShopProfile `json:"items"`
Meta PageMeta `json:"meta"`