57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.10.1
|
|
|
|
package review
|
|
|
|
import (
|
|
"context"
|
|
|
|
"juwan-backend/app/review/api/internal/svc"
|
|
"juwan-backend/app/review/api/internal/types"
|
|
reviewpb "juwan-backend/app/review/rpc/pb"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type ListUserReviewsLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 获取用户收到的评价
|
|
func NewListUserReviewsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListUserReviewsLogic {
|
|
return &ListUserReviewsLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *ListUserReviewsLogic) ListUserReviews(req *types.ListUserReviewsReq) (resp *types.ReviewListResp, err error) {
|
|
sealed := false
|
|
toUserId := req.Id
|
|
result, err := l.svcCtx.ReviewRpc.SearchReviews(l.ctx, &reviewpb.SearchReviewsReq{
|
|
Offset: req.Offset,
|
|
Limit: req.Limit,
|
|
ToUserId: &toUserId,
|
|
Sealed: &sealed,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
items := make([]types.Review, 0, len(result.GetReviews()))
|
|
for _, r := range result.GetReviews() {
|
|
items = append(items, toAPIReview(r))
|
|
}
|
|
return &types.ReviewListResp{
|
|
Items: items,
|
|
Meta: types.PageMeta{
|
|
Total: int64(len(items)),
|
|
Offset: req.Offset,
|
|
Limit: req.Limit,
|
|
},
|
|
}, nil
|
|
}
|