...
|
...
|
@@ -2,6 +2,10 @@ package user |
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
"github.com/samber/lo"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
|
...
|
...
|
@@ -23,8 +27,42 @@ func NewMiniUserFollowingLogic(ctx context.Context, svcCtx *svc.ServiceContext) |
|
|
}
|
|
|
}
|
|
|
|
|
|
func (l *MiniUserFollowingLogic) MiniUserFollowing(req *types.UserSearchRequest) (resp *types.UserSearchResponse, err error) {
|
|
|
// todo: add your logic here and delete this line
|
|
|
|
|
|
func (l *MiniUserFollowingLogic) MiniUserFollowing(req *types.MiniUserFollowedSearchRequest) (resp *types.MiniUserFollowedSearchResponse, err error) {
|
|
|
var (
|
|
|
conn = l.svcCtx.DefaultDBConn()
|
|
|
user *domain.User
|
|
|
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
|
|
|
companyMap = make(map[int64]*domain.Company)
|
|
|
)
|
|
|
if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId); err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("用户不存在", err)
|
|
|
}
|
|
|
var (
|
|
|
users = user.Following
|
|
|
total = int64(len(users))
|
|
|
offset, limit = domain.OffsetLimit(req.Page, req.Size)
|
|
|
)
|
|
|
users = lo.Slice(users, offset, offset+limit)
|
|
|
resp = &types.MiniUserFollowedSearchResponse{
|
|
|
Total: total,
|
|
|
List: make([]*types.UserFollowItem, 0),
|
|
|
}
|
|
|
lo.ForEach(users, func(item int64, index int) {
|
|
|
if foundUser, _ := l.svcCtx.UserRepository.FindOne(l.ctx, conn, item); foundUser != nil {
|
|
|
var companyName = ""
|
|
|
if company, _ := domain.LazyLoad(companyMap, l.ctx, conn, foundUser.CompanyId, l.svcCtx.CompanyRepository.FindOne); company != nil {
|
|
|
companyName = company.Name
|
|
|
}
|
|
|
resp.List = append(resp.List, &types.UserFollowItem{
|
|
|
Id: foundUser.Id,
|
|
|
Name: foundUser.Name,
|
|
|
CompanyName: companyName,
|
|
|
Avatar: foundUser.Avatar,
|
|
|
Position: foundUser.Position,
|
|
|
Followed: true,
|
|
|
//MutualFollowed: lo.Contains(user.Following, foundUser.Id),
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
return
|
|
|
} |
...
|
...
|
|