39 lines
856 B
Go
39 lines
856 B
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"juwan-backend/app/chat/rpc/internal/svc"
|
|
"juwan-backend/app/chat/rpc/pb"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetChatSessionsByIdLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewGetChatSessionsByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetChatSessionsByIdLogic {
|
|
return &GetChatSessionsByIdLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *GetChatSessionsByIdLogic) GetChatSessionsById(in *pb.GetChatSessionsByIdReq) (*pb.GetChatSessionsByIdResp, error) {
|
|
store := l.svcCtx.Store
|
|
store.Mu.RLock()
|
|
defer store.Mu.RUnlock()
|
|
|
|
session, ok := store.Sessions[in.GetId()]
|
|
if !ok {
|
|
return nil, errors.New("session not found")
|
|
}
|
|
|
|
return &pb.GetChatSessionsByIdResp{ChatSessions: session}, nil
|
|
}
|