51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"juwan-backend/app/shop/rpc/internal/models/shopinvitations"
|
|
|
|
//"juwan-backend/app/game/rpc/internal/models/shopinvitations"
|
|
|
|
"juwan-backend/app/shop/rpc/internal/svc"
|
|
"juwan-backend/app/shop/rpc/pb"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetShopInvitationsByIdLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewGetShopInvitationsByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetShopInvitationsByIdLogic {
|
|
return &GetShopInvitationsByIdLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *GetShopInvitationsByIdLogic) GetShopInvitationsById(in *pb.GetShopInvitationsByIdReq) (*pb.GetShopInvitationsByIdResp, error) {
|
|
shopInvitation, err := l.svcCtx.ShopModelRO.ShopInvitations.Query().Where(shopinvitations.IDEQ(in.Id)).First(l.ctx)
|
|
if err != nil {
|
|
logx.WithContext(l.ctx).Errorf("GetShopInvitationsByIdLogic err: %v", err)
|
|
return nil, errors.New("get shop invitations by id failed")
|
|
}
|
|
|
|
pbShopInvitation := pb.ShopInvitations{
|
|
Id: shopInvitation.ID,
|
|
ShopId: shopInvitation.ShopID,
|
|
PlayerId: shopInvitation.PlayerID,
|
|
Status: shopInvitation.Status,
|
|
InvitedBy: shopInvitation.InvitedBy,
|
|
CreatedAt: shopInvitation.CreatedAt.Unix(),
|
|
}
|
|
if shopInvitation.RespondedAt != nil {
|
|
pbShopInvitation.RespondedAt = shopInvitation.RespondedAt.Unix()
|
|
}
|
|
|
|
return &pb.GetShopInvitationsByIdResp{ShopInvitations: &pbShopInvitation}, nil
|
|
}
|