Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss into dev
正在显示
14 个修改的文件
包含
273 行增加
和
81 行删除
| @@ -41,10 +41,10 @@ service Core { | @@ -41,10 +41,10 @@ service Core { | ||
| 41 | post /mini/user/department-users (MiniUserDepartmentUsersRequest)returns (MiniUserInfoResponse) | 41 | post /mini/user/department-users (MiniUserDepartmentUsersRequest)returns (MiniUserInfoResponse) |
| 42 | @doc "关注我的人" | 42 | @doc "关注我的人" |
| 43 | @handler miniUserFollower | 43 | @handler miniUserFollower |
| 44 | - post /mini/user/follower (UserSearchRequest)returns(UserSearchResponse) | 44 | + post /mini/user/follower (MiniUserFollowedSearchRequest)returns(MiniUserFollowedSearchResponse) |
| 45 | @doc "我关注的人" | 45 | @doc "我关注的人" |
| 46 | @handler miniUserFollowing | 46 | @handler miniUserFollowing |
| 47 | - post /mini/user/following (UserSearchRequest)returns(UserSearchResponse) | 47 | + post /mini/user/following (MiniUserFollowedSearchRequest)returns(MiniUserFollowedSearchResponse) |
| 48 | @doc "关注" | 48 | @doc "关注" |
| 49 | @handler miniUserFollow | 49 | @handler miniUserFollow |
| 50 | post /mini/user/follow (FollowRequest) | 50 | post /mini/user/follow (FollowRequest) |
| @@ -97,6 +97,14 @@ type( | @@ -97,6 +97,14 @@ type( | ||
| 97 | Departments []*Department `json:"departments"` | 97 | Departments []*Department `json:"departments"` |
| 98 | Users []*UserItem `json:"users"` | 98 | Users []*UserItem `json:"users"` |
| 99 | } | 99 | } |
| 100 | + MiniUserFollowedSearchRequest{ | ||
| 101 | + Page int `json:"page,optional"` | ||
| 102 | + Size int `json:"size,optional"` | ||
| 103 | + } | ||
| 104 | + MiniUserFollowedSearchResponse{ | ||
| 105 | + List []*UserFollowItem `json:"users"` | ||
| 106 | + Total int64 `json:"total"` | ||
| 107 | + } | ||
| 100 | UserItem { | 108 | UserItem { |
| 101 | Id int64 `json:"id,omitempty"` // 用户ID | 109 | Id int64 `json:"id,omitempty"` // 用户ID |
| 102 | CompanyId int64 `json:"companyId,omitempty"` // 公司ID | 110 | CompanyId int64 `json:"companyId,omitempty"` // 公司ID |
| @@ -133,6 +141,15 @@ type( | @@ -133,6 +141,15 @@ type( | ||
| 133 | FollowRequest{ | 141 | FollowRequest{ |
| 134 | UserId int64 `json:"userId"` | 142 | UserId int64 `json:"userId"` |
| 135 | } | 143 | } |
| 144 | + UserFollowItem struct { | ||
| 145 | + Id int64 `json:"id"` // 用户ID | ||
| 146 | + Name string `json:"name"` // 名称 | ||
| 147 | + CompanyName string `json:"companyName"` // 公司名称 | ||
| 148 | + Avatar string `json:"avatar"` // 头像 | ||
| 149 | + Position string `json:"position"` // 职位 | ||
| 150 | + Followed bool `json:"followed"` // 关注 | ||
| 151 | + MutualFollowed bool `json:"mutualFollowed"` // 互相关注标识 | ||
| 152 | + } | ||
| 136 | ) | 153 | ) |
| 137 | 154 | ||
| 138 | 155 |
| @@ -12,7 +12,7 @@ import ( | @@ -12,7 +12,7 @@ import ( | ||
| 12 | 12 | ||
| 13 | func MiniUserFollowerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 13 | func MiniUserFollowerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
| 14 | return func(w http.ResponseWriter, r *http.Request) { | 14 | return func(w http.ResponseWriter, r *http.Request) { |
| 15 | - var req types.UserSearchRequest | 15 | + var req types.MiniUserFollowedSearchRequest |
| 16 | if err := httpx.Parse(r, &req); err != nil { | 16 | if err := httpx.Parse(r, &req); err != nil { |
| 17 | httpx.ErrorCtx(r.Context(), w, err) | 17 | httpx.ErrorCtx(r.Context(), w, err) |
| 18 | return | 18 | return |
| @@ -12,7 +12,7 @@ import ( | @@ -12,7 +12,7 @@ import ( | ||
| 12 | 12 | ||
| 13 | func MiniUserFollowingHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 13 | func MiniUserFollowingHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
| 14 | return func(w http.ResponseWriter, r *http.Request) { | 14 | return func(w http.ResponseWriter, r *http.Request) { |
| 15 | - var req types.UserSearchRequest | 15 | + var req types.MiniUserFollowedSearchRequest |
| 16 | if err := httpx.Parse(r, &req); err != nil { | 16 | if err := httpx.Parse(r, &req); err != nil { |
| 17 | httpx.ErrorCtx(r.Context(), w, err) | 17 | httpx.ErrorCtx(r.Context(), w, err) |
| 18 | return | 18 | return |
| @@ -27,9 +27,11 @@ func NewMiniBusinessLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mini | @@ -27,9 +27,11 @@ func NewMiniBusinessLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mini | ||
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (resp *types.MessageBusinessResponse, err error) { | 29 | func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (resp *types.MessageBusinessResponse, err error) { |
| 30 | + var userToken = contextdata.GetUserTokenFromCtx(l.ctx) | ||
| 31 | + var conn = l.svcCtx.DefaultDBConn() | ||
| 30 | var msgType = req.Type | 32 | var msgType = req.Type |
| 31 | 33 | ||
| 32 | - total, list, err := l.svcCtx.MessageBusinessRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), domain.NewQueryOptions(). | 34 | + total, list, err := l.svcCtx.MessageBusinessRepository.Find(l.ctx, conn, domain.NewQueryOptions(). |
| 33 | WithOffsetLimit(req.Page, req.Size). | 35 | WithOffsetLimit(req.Page, req.Size). |
| 34 | WithKV("type", msgType)) | 36 | WithKV("type", msgType)) |
| 35 | if err != nil { | 37 | if err != nil { |
| @@ -96,11 +98,10 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res | @@ -96,11 +98,10 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res | ||
| 96 | 98 | ||
| 97 | // 获取公司 | 99 | // 获取公司 |
| 98 | if len(companyIds) > 0 { | 100 | if len(companyIds) > 0 { |
| 99 | - _, companyList, err := l.svcCtx.CompanyRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), | ||
| 100 | - domain.NewQueryOptions(). | ||
| 101 | - WithFindOnly(). | ||
| 102 | - WithKV("ids", userIds). | ||
| 103 | - WithKV("limit", len(userIds))) | 101 | + _, companyList, err := l.svcCtx.CompanyRepository.Find(l.ctx, conn, domain.NewQueryOptions(). |
| 102 | + WithFindOnly(). | ||
| 103 | + WithKV("ids", userIds). | ||
| 104 | + WithKV("limit", len(userIds))) | ||
| 104 | if err != nil { | 105 | if err != nil { |
| 105 | return nil, err | 106 | return nil, err |
| 106 | } | 107 | } |
| @@ -111,11 +112,10 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res | @@ -111,11 +112,10 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res | ||
| 111 | 112 | ||
| 112 | // 获取用户 | 113 | // 获取用户 |
| 113 | if len(userIds) > 0 { | 114 | if len(userIds) > 0 { |
| 114 | - _, userList, err := l.svcCtx.UserRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), | ||
| 115 | - domain.NewQueryOptions(). | ||
| 116 | - WithFindOnly(). | ||
| 117 | - WithKV("ids", userIds). | ||
| 118 | - WithKV("limit", len(userIds))) | 115 | + _, userList, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions(). |
| 116 | + WithFindOnly(). | ||
| 117 | + WithKV("ids", userIds). | ||
| 118 | + WithKV("limit", len(userIds))) | ||
| 119 | if err != nil { | 119 | if err != nil { |
| 120 | return nil, err | 120 | return nil, err |
| 121 | } | 121 | } |
| @@ -126,11 +126,10 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res | @@ -126,11 +126,10 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res | ||
| 126 | 126 | ||
| 127 | // 获取评论 | 127 | // 获取评论 |
| 128 | if len(commentIds) > 0 { | 128 | if len(commentIds) > 0 { |
| 129 | - _, commentList, err := l.svcCtx.CommentRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), | ||
| 130 | - domain.NewQueryOptions(). | ||
| 131 | - WithFindOnly(). | ||
| 132 | - WithKV("ids", commentIds). | ||
| 133 | - WithKV("limit", len(commentIds))) | 129 | + _, commentList, err := l.svcCtx.CommentRepository.Find(l.ctx, conn, domain.NewQueryOptions(). |
| 130 | + WithFindOnly(). | ||
| 131 | + WithKV("ids", commentIds). | ||
| 132 | + WithKV("limit", len(commentIds))) | ||
| 134 | if err != nil { | 133 | if err != nil { |
| 135 | return nil, err | 134 | return nil, err |
| 136 | } | 135 | } |
| @@ -141,11 +140,10 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res | @@ -141,11 +140,10 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res | ||
| 141 | 140 | ||
| 142 | // 获取文章数据 | 141 | // 获取文章数据 |
| 143 | if len(articleIds) > 0 { | 142 | if len(articleIds) > 0 { |
| 144 | - _, articleList, err := l.svcCtx.ArticleRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), 0, | ||
| 145 | - domain.NewQueryOptions(). | ||
| 146 | - WithFindOnly(). | ||
| 147 | - WithKV("ids", articleIds). | ||
| 148 | - WithKV("limit", len(articleIds))) | 143 | + _, articleList, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, userToken.CompanyId, domain.NewQueryOptions(). |
| 144 | + WithFindOnly(). | ||
| 145 | + WithKV("ids", articleIds). | ||
| 146 | + WithKV("limit", len(articleIds))) | ||
| 149 | if err != nil { | 147 | if err != nil { |
| 150 | return nil, err | 148 | return nil, err |
| 151 | } | 149 | } |
| @@ -156,18 +154,18 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res | @@ -156,18 +154,18 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res | ||
| 156 | 154 | ||
| 157 | for _, item := range list { | 155 | for _, item := range list { |
| 158 | to := types.MessageBusinessItem{ | 156 | to := types.MessageBusinessItem{ |
| 159 | - Id: item.Id, | ||
| 160 | - Type: int(item.Type), | ||
| 161 | - OptType: int(item.OptType), | ||
| 162 | - CompanyId: item.CompanyId, | ||
| 163 | - UserId: item.UserId, | ||
| 164 | - RecipientId: item.RecipientId, | ||
| 165 | - ArticleId: item.ArticleId, | ||
| 166 | - CommentId: item.CommentId, | ||
| 167 | - DiscussionId: item.DiscussionId, | ||
| 168 | - DiscussionOpinionId: item.DiscussionOpinionId, | ||
| 169 | - Content: item.Content, | ||
| 170 | - CreatedAt: item.CreatedAt, | 157 | + Id: item.Id, |
| 158 | + Type: int(item.Type), | ||
| 159 | + OptType: int(item.OptType), | ||
| 160 | + CompanyId: item.CompanyId, | ||
| 161 | + UserId: item.UserId, | ||
| 162 | + RecipientId: item.RecipientId, | ||
| 163 | + ArticleId: item.ArticleId, | ||
| 164 | + CommentId: item.CommentId, | ||
| 165 | + //DiscussionId: item.DiscussionId, | ||
| 166 | + //DiscussionOpinionId: item.DiscussionOpinionId, | ||
| 167 | + Content: item.Content, | ||
| 168 | + CreatedAt: item.CreatedAt, | ||
| 171 | } | 169 | } |
| 172 | 170 | ||
| 173 | if v, ok := userIdMap[item.UserId]; ok { | 171 | if v, ok := userIdMap[item.UserId]; ok { |
| @@ -2,6 +2,10 @@ package user | @@ -2,6 +2,10 @@ package user | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "context" | 4 | "context" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
| 5 | 9 | ||
| 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
| 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
| @@ -23,8 +27,32 @@ func NewMiniUserFollowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mi | @@ -23,8 +27,32 @@ func NewMiniUserFollowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mi | ||
| 23 | } | 27 | } |
| 24 | } | 28 | } |
| 25 | 29 | ||
| 26 | -func (l *MiniUserFollowLogic) MiniUserFollow(req *types.FollowRequest) error { | ||
| 27 | - // todo: add your logic here and delete this line | ||
| 28 | - | 30 | +func (l *MiniUserFollowLogic) MiniUserFollow(req *types.FollowRequest) (err error) { |
| 31 | + var ( | ||
| 32 | + conn = l.svcCtx.DefaultDBConn() | ||
| 33 | + user *domain.User | ||
| 34 | + targetUser *domain.User | ||
| 35 | + userToken = contextdata.GetUserTokenFromCtx(l.ctx) | ||
| 36 | + ) | ||
| 37 | + if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId); err != nil { | ||
| 38 | + return xerr.NewErrMsgErr("用户不存在", err) | ||
| 39 | + } | ||
| 40 | + if targetUser, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.UserId); err != nil { | ||
| 41 | + return xerr.NewErrMsgErr("关注的用户不存在", err) | ||
| 42 | + } | ||
| 43 | + if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | ||
| 44 | + if err = user.Follow(targetUser); err != nil { | ||
| 45 | + return err | ||
| 46 | + } | ||
| 47 | + if user, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, user); err != nil { | ||
| 48 | + return err | ||
| 49 | + } | ||
| 50 | + if targetUser, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, targetUser); err != nil { | ||
| 51 | + return err | ||
| 52 | + } | ||
| 53 | + return nil | ||
| 54 | + }, true); err != nil { | ||
| 55 | + return xerr.NewErrMsgErr("关注用户失败", err) | ||
| 56 | + } | ||
| 29 | return nil | 57 | return nil |
| 30 | } | 58 | } |
| @@ -2,6 +2,10 @@ package user | @@ -2,6 +2,10 @@ package user | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "context" | 4 | "context" |
| 5 | + "github.com/samber/lo" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
| 5 | 9 | ||
| 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
| 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
| @@ -23,8 +27,42 @@ func NewMiniUserFollowerLogic(ctx context.Context, svcCtx *svc.ServiceContext) * | @@ -23,8 +27,42 @@ func NewMiniUserFollowerLogic(ctx context.Context, svcCtx *svc.ServiceContext) * | ||
| 23 | } | 27 | } |
| 24 | } | 28 | } |
| 25 | 29 | ||
| 26 | -func (l *MiniUserFollowerLogic) MiniUserFollower(req *types.UserSearchRequest) (resp *types.UserSearchResponse, err error) { | ||
| 27 | - // todo: add your logic here and delete this line | ||
| 28 | - | 30 | +func (l *MiniUserFollowerLogic) MiniUserFollower(req *types.MiniUserFollowedSearchRequest) (resp *types.MiniUserFollowedSearchResponse, err error) { |
| 31 | + var ( | ||
| 32 | + conn = l.svcCtx.DefaultDBConn() | ||
| 33 | + user *domain.User | ||
| 34 | + userToken = contextdata.GetUserTokenFromCtx(l.ctx) | ||
| 35 | + companyMap = make(map[int64]*domain.Company) | ||
| 36 | + ) | ||
| 37 | + if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId); err != nil { | ||
| 38 | + return nil, xerr.NewErrMsgErr("用户不存在", err) | ||
| 39 | + } | ||
| 40 | + var ( | ||
| 41 | + users = user.Follower | ||
| 42 | + total = int64(len(users)) | ||
| 43 | + offset, limit = domain.OffsetLimit(req.Page, req.Size) | ||
| 44 | + ) | ||
| 45 | + users = lo.Slice(users, offset, offset+limit) | ||
| 46 | + resp = &types.MiniUserFollowedSearchResponse{ | ||
| 47 | + Total: total, | ||
| 48 | + List: make([]*types.UserFollowItem, 0), | ||
| 49 | + } | ||
| 50 | + lo.ForEach(users, func(item int64, index int) { | ||
| 51 | + if foundUser, _ := l.svcCtx.UserRepository.FindOne(l.ctx, conn, item); foundUser != nil { | ||
| 52 | + var companyName = "" | ||
| 53 | + if company, _ := domain.LazyLoad(companyMap, l.ctx, conn, foundUser.CompanyId, l.svcCtx.CompanyRepository.FindOne); company != nil { | ||
| 54 | + companyName = company.Name | ||
| 55 | + } | ||
| 56 | + resp.List = append(resp.List, &types.UserFollowItem{ | ||
| 57 | + Id: foundUser.Id, | ||
| 58 | + Name: foundUser.Name, | ||
| 59 | + CompanyName: companyName, | ||
| 60 | + Avatar: foundUser.Avatar, | ||
| 61 | + Position: foundUser.Position, | ||
| 62 | + Followed: true, | ||
| 63 | + MutualFollowed: lo.Contains(user.Following, item), | ||
| 64 | + }) | ||
| 65 | + } | ||
| 66 | + }) | ||
| 29 | return | 67 | return |
| 30 | } | 68 | } |
| @@ -2,6 +2,10 @@ package user | @@ -2,6 +2,10 @@ package user | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "context" | 4 | "context" |
| 5 | + "github.com/samber/lo" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
| 5 | 9 | ||
| 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
| 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
| @@ -23,8 +27,42 @@ func NewMiniUserFollowingLogic(ctx context.Context, svcCtx *svc.ServiceContext) | @@ -23,8 +27,42 @@ func NewMiniUserFollowingLogic(ctx context.Context, svcCtx *svc.ServiceContext) | ||
| 23 | } | 27 | } |
| 24 | } | 28 | } |
| 25 | 29 | ||
| 26 | -func (l *MiniUserFollowingLogic) MiniUserFollowing(req *types.UserSearchRequest) (resp *types.UserSearchResponse, err error) { | ||
| 27 | - // todo: add your logic here and delete this line | ||
| 28 | - | 30 | +func (l *MiniUserFollowingLogic) MiniUserFollowing(req *types.MiniUserFollowedSearchRequest) (resp *types.MiniUserFollowedSearchResponse, err error) { |
| 31 | + var ( | ||
| 32 | + conn = l.svcCtx.DefaultDBConn() | ||
| 33 | + user *domain.User | ||
| 34 | + userToken = contextdata.GetUserTokenFromCtx(l.ctx) | ||
| 35 | + companyMap = make(map[int64]*domain.Company) | ||
| 36 | + ) | ||
| 37 | + if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId); err != nil { | ||
| 38 | + return nil, xerr.NewErrMsgErr("用户不存在", err) | ||
| 39 | + } | ||
| 40 | + var ( | ||
| 41 | + users = user.Following | ||
| 42 | + total = int64(len(users)) | ||
| 43 | + offset, limit = domain.OffsetLimit(req.Page, req.Size) | ||
| 44 | + ) | ||
| 45 | + users = lo.Slice(users, offset, offset+limit) | ||
| 46 | + resp = &types.MiniUserFollowedSearchResponse{ | ||
| 47 | + Total: total, | ||
| 48 | + List: make([]*types.UserFollowItem, 0), | ||
| 49 | + } | ||
| 50 | + lo.ForEach(users, func(item int64, index int) { | ||
| 51 | + if foundUser, _ := l.svcCtx.UserRepository.FindOne(l.ctx, conn, item); foundUser != nil { | ||
| 52 | + var companyName = "" | ||
| 53 | + if company, _ := domain.LazyLoad(companyMap, l.ctx, conn, foundUser.CompanyId, l.svcCtx.CompanyRepository.FindOne); company != nil { | ||
| 54 | + companyName = company.Name | ||
| 55 | + } | ||
| 56 | + resp.List = append(resp.List, &types.UserFollowItem{ | ||
| 57 | + Id: foundUser.Id, | ||
| 58 | + Name: foundUser.Name, | ||
| 59 | + CompanyName: companyName, | ||
| 60 | + Avatar: foundUser.Avatar, | ||
| 61 | + Position: foundUser.Position, | ||
| 62 | + Followed: true, | ||
| 63 | + //MutualFollowed: lo.Contains(user.Following, foundUser.Id), | ||
| 64 | + }) | ||
| 65 | + } | ||
| 66 | + }) | ||
| 29 | return | 67 | return |
| 30 | } | 68 | } |
| @@ -2,6 +2,10 @@ package user | @@ -2,6 +2,10 @@ package user | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "context" | 4 | "context" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
| 5 | 9 | ||
| 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
| 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
| @@ -23,8 +27,32 @@ func NewMiniUserUnFollowLogic(ctx context.Context, svcCtx *svc.ServiceContext) * | @@ -23,8 +27,32 @@ func NewMiniUserUnFollowLogic(ctx context.Context, svcCtx *svc.ServiceContext) * | ||
| 23 | } | 27 | } |
| 24 | } | 28 | } |
| 25 | 29 | ||
| 26 | -func (l *MiniUserUnFollowLogic) MiniUserUnFollow(req *types.FollowRequest) error { | ||
| 27 | - // todo: add your logic here and delete this line | ||
| 28 | - | 30 | +func (l *MiniUserUnFollowLogic) MiniUserUnFollow(req *types.FollowRequest) (err error) { |
| 31 | + var ( | ||
| 32 | + conn = l.svcCtx.DefaultDBConn() | ||
| 33 | + user *domain.User | ||
| 34 | + targetUser *domain.User | ||
| 35 | + userToken = contextdata.GetUserTokenFromCtx(l.ctx) | ||
| 36 | + ) | ||
| 37 | + if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId); err != nil { | ||
| 38 | + return xerr.NewErrMsgErr("用户不存在", err) | ||
| 39 | + } | ||
| 40 | + if targetUser, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.UserId); err != nil { | ||
| 41 | + return xerr.NewErrMsgErr("关注的用户不存在", err) | ||
| 42 | + } | ||
| 43 | + if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | ||
| 44 | + if err = user.Unfollow(targetUser); err != nil { | ||
| 45 | + return err | ||
| 46 | + } | ||
| 47 | + if user, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, user); err != nil { | ||
| 48 | + return err | ||
| 49 | + } | ||
| 50 | + if targetUser, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, targetUser); err != nil { | ||
| 51 | + return err | ||
| 52 | + } | ||
| 53 | + return nil | ||
| 54 | + }, true); err != nil { | ||
| 55 | + return xerr.NewErrMsgErr("关注用户失败", err) | ||
| 56 | + } | ||
| 29 | return nil | 57 | return nil |
| 30 | } | 58 | } |
| @@ -192,6 +192,16 @@ type MiniUserDepartmentUsersResponse struct { | @@ -192,6 +192,16 @@ type MiniUserDepartmentUsersResponse struct { | ||
| 192 | Users []*UserItem `json:"users"` | 192 | Users []*UserItem `json:"users"` |
| 193 | } | 193 | } |
| 194 | 194 | ||
| 195 | +type MiniUserFollowedSearchRequest struct { | ||
| 196 | + Page int `json:"page,optional"` | ||
| 197 | + Size int `json:"size,optional"` | ||
| 198 | +} | ||
| 199 | + | ||
| 200 | +type MiniUserFollowedSearchResponse struct { | ||
| 201 | + List []*UserFollowItem `json:"users"` | ||
| 202 | + Total int64 `json:"total"` | ||
| 203 | +} | ||
| 204 | + | ||
| 195 | type UserItem struct { | 205 | type UserItem struct { |
| 196 | Id int64 `json:"id,omitempty"` // 用户ID | 206 | Id int64 `json:"id,omitempty"` // 用户ID |
| 197 | CompanyId int64 `json:"companyId,omitempty"` // 公司ID | 207 | CompanyId int64 `json:"companyId,omitempty"` // 公司ID |
| @@ -231,6 +241,16 @@ type FollowRequest struct { | @@ -231,6 +241,16 @@ type FollowRequest struct { | ||
| 231 | UserId int64 `json:"userId"` | 241 | UserId int64 `json:"userId"` |
| 232 | } | 242 | } |
| 233 | 243 | ||
| 244 | +type UserFollowItem struct { | ||
| 245 | + Id int64 `json:"id"` // 用户ID | ||
| 246 | + Name string `json:"name"` // 名称 | ||
| 247 | + CompanyName string `json:"companyName"` // 公司名称 | ||
| 248 | + Avatar string `json:"avatar"` // 头像 | ||
| 249 | + Position string `json:"position"` // 职位 | ||
| 250 | + Followed bool `json:"followed"` // 关注 | ||
| 251 | + MutualFollowed bool `json:"mutualFollowed"` // 互相关注标识 | ||
| 252 | +} | ||
| 253 | + | ||
| 234 | type CompanySearchRequest struct { | 254 | type CompanySearchRequest struct { |
| 235 | Page int `json:"page"` | 255 | Page int `json:"page"` |
| 236 | Size int `json:"size"` | 256 | Size int `json:"size"` |
| @@ -10,22 +10,22 @@ import ( | @@ -10,22 +10,22 @@ import ( | ||
| 10 | 10 | ||
| 11 | // MessageBusiness 消息中心业务 | 11 | // MessageBusiness 消息中心业务 |
| 12 | type MessageBusiness struct { | 12 | type MessageBusiness struct { |
| 13 | - Id int64 // 唯一标识 | ||
| 14 | - Type int `json:"type"` // 分类 (1回复 2点赞 3被采纳) | ||
| 15 | - OptType int `json:"optType"` // 操作类型(1针对文章、1针对评论、2针对圆桌) | ||
| 16 | - CompanyId int64 `json:"companyId"` // 操作人公司ID | ||
| 17 | - UserId int64 `json:"userId"` // 操作人用户ID | ||
| 18 | - RecipientId int64 `json:"recipientId"` // 接收人用户ID | ||
| 19 | - ArticleId int64 `json:"articleId"` // 文章ID | ||
| 20 | - CommentId int64 `json:"commentId,omitempty"` // 评论ID | ||
| 21 | - DiscussionId int64 `json:"discussionId,omitempty"` // 圆桌ID | ||
| 22 | - DiscussionOpinionId int64 `json:"discussionOpinionId,omitempty"` // 观点ID | ||
| 23 | - Content string `json:"content,omitempty"` // 消息内容 | ||
| 24 | - CreatedAt int64 `json:",omitempty"` | ||
| 25 | - UpdatedAt int64 `json:",omitempty"` | ||
| 26 | - DeletedAt int64 `json:",omitempty"` | ||
| 27 | - Version int `json:",omitempty"` | ||
| 28 | - IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` | 13 | + Id int64 // 唯一标识 |
| 14 | + Type int `json:"type"` // 分类 (1回复 2点赞 3被采纳) | ||
| 15 | + OptType int `json:"optType"` // 操作类型(1针对文章、1针对评论、2针对圆桌) | ||
| 16 | + CompanyId int64 `json:"companyId"` // 操作人公司ID | ||
| 17 | + UserId int64 `json:"userId"` // 操作人用户ID | ||
| 18 | + RecipientId int64 `json:"recipientId"` // 接收人用户ID | ||
| 19 | + ArticleId int64 `json:"articleId,omitempty"` // 文章ID | ||
| 20 | + CommentId int64 `json:"commentId,omitempty"` // 评论ID | ||
| 21 | + Content string `json:"content,omitempty"` // 消息内容 | ||
| 22 | + CreatedAt int64 `json:",omitempty"` | ||
| 23 | + UpdatedAt int64 `json:",omitempty"` | ||
| 24 | + DeletedAt int64 `json:",omitempty"` | ||
| 25 | + Version int `json:",omitempty"` | ||
| 26 | + IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` | ||
| 27 | + //DiscussionId int64 `json:"discussionId,omitempty"` // 圆桌ID | ||
| 28 | + //DiscussionOpinionId int64 `json:"discussionOpinionId,omitempty"` // 观点ID | ||
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | func (m *MessageBusiness) TableName() string { | 31 | func (m *MessageBusiness) TableName() string { |
| @@ -9,7 +9,11 @@ import ( | @@ -9,7 +9,11 @@ import ( | ||
| 9 | ) | 9 | ) |
| 10 | 10 | ||
| 11 | type Role struct { | 11 | type Role struct { |
| 12 | - Id int64 // 唯一标识 | 12 | + Id int64 // 唯一标识 |
| 13 | + Name string `json:"name"` // 角色名称 | ||
| 14 | + Auths []int64 `gorm:"type:jsonb;serializer:json"` // 角色权限列表 | ||
| 15 | + Remark string `json:"remark"` // 备注 | ||
| 16 | + Users []int64 `gorm:"type:jsonb;serializer:json"` // 绑定的用户 | ||
| 13 | 17 | ||
| 14 | CreatedAt int64 | 18 | CreatedAt int64 |
| 15 | UpdatedAt int64 | 19 | UpdatedAt int64 |
| @@ -121,6 +121,9 @@ func (repository *MessageBusinessRepository) Find(ctx context.Context, conn tran | @@ -121,6 +121,9 @@ func (repository *MessageBusinessRepository) Find(ctx context.Context, conn tran | ||
| 121 | ) | 121 | ) |
| 122 | queryFunc := func() (interface{}, error) { | 122 | queryFunc := func() (interface{}, error) { |
| 123 | tx = tx.Model(&ms).Order("created_at desc") | 123 | tx = tx.Model(&ms).Order("created_at desc") |
| 124 | + if v, ok := queryOptions["companyId"]; ok { | ||
| 125 | + tx.Where("company_id = ?", v) | ||
| 126 | + } | ||
| 124 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | 127 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { |
| 125 | return dms, tx.Error | 128 | return dms, tx.Error |
| 126 | } | 129 | } |
| @@ -6,21 +6,22 @@ import ( | @@ -6,21 +6,22 @@ import ( | ||
| 6 | ) | 6 | ) |
| 7 | 7 | ||
| 8 | type MessageBusiness struct { | 8 | type MessageBusiness struct { |
| 9 | - Id int64 // 唯一标识 | ||
| 10 | - Type MsgBusinessType `json:"type"` // 分类 (1回复 2点赞 3被采纳) | ||
| 11 | - OptType MsgBusinessOpt `json:"optType"` // 操作类型(1针对文章、1针对评论、2针对圆桌) | ||
| 12 | - CompanyId int64 `json:"companyId"` // 操作人公司ID | ||
| 13 | - UserId int64 `json:"userId"` // 操作人用户ID | ||
| 14 | - RecipientId int64 `json:"recipientId"` // 接收人用户ID | ||
| 15 | - ArticleId int64 `json:"articleId"` // 文章ID | ||
| 16 | - CommentId int64 `json:"commentId"` // 评论ID | ||
| 17 | - DiscussionId int64 `json:"discussionId"` // 圆桌ID | ||
| 18 | - DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID | ||
| 19 | - Content string `json:"content"` // 消息内容 | ||
| 20 | - CreatedAt int64 `json:",omitempty"` | ||
| 21 | - UpdatedAt int64 `json:",omitempty"` | ||
| 22 | - DeletedAt int64 `json:",omitempty"` | ||
| 23 | - Version int `json:",omitempty"` | 9 | + Id int64 // 唯一标识 |
| 10 | + Type MsgBusinessType `json:"type"` // 分类 (1回复 2点赞 3被采纳) | ||
| 11 | + OptType MsgBusinessOpt `json:"optType"` // 操作类型(1针对文章、1针对评论、2针对圆桌) | ||
| 12 | + CompanyId int64 `json:"companyId"` // 操作人公司ID | ||
| 13 | + UserId int64 `json:"userId"` // 操作人用户ID | ||
| 14 | + RecipientId int64 `json:"recipientId"` // 接收人用户ID | ||
| 15 | + ArticleId int64 `json:"articleId"` // 文章ID | ||
| 16 | + CommentId int64 `json:"commentId"` // 评论ID | ||
| 17 | + Content string `json:"content"` // 消息内容 | ||
| 18 | + CreatedAt int64 `json:",omitempty"` | ||
| 19 | + UpdatedAt int64 `json:",omitempty"` | ||
| 20 | + DeletedAt int64 `json:",omitempty"` | ||
| 21 | + Version int `json:",omitempty"` | ||
| 22 | + | ||
| 23 | + //DiscussionId int64 `json:"discussionId"` // 圆桌ID | ||
| 24 | + //DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID | ||
| 24 | } | 25 | } |
| 25 | 26 | ||
| 26 | type MsgBusinessType int | 27 | type MsgBusinessType int |
| @@ -85,6 +85,23 @@ func (m *User) Audit(status int) error { | @@ -85,6 +85,23 @@ func (m *User) Audit(status int) error { | ||
| 85 | return nil | 85 | return nil |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | +func (m *User) Follow(targetUser *User) error { | ||
| 89 | + if lo.Contains(m.Following, targetUser.Id) { | ||
| 90 | + return fmt.Errorf("已关注用户%v", targetUser.Name) | ||
| 91 | + } | ||
| 92 | + m.Following = append(m.Following, targetUser.Id) | ||
| 93 | + if !lo.Contains(targetUser.Follower, m.Id) { | ||
| 94 | + targetUser.Follower = append(targetUser.Follower, m.Id) | ||
| 95 | + } | ||
| 96 | + return nil | ||
| 97 | +} | ||
| 98 | + | ||
| 99 | +func (m *User) Unfollow(targetUser *User) error { | ||
| 100 | + m.Following = lo.Without(m.Following, targetUser.Id) | ||
| 101 | + targetUser.Follower = lo.Without(targetUser.Follower, m.Id) | ||
| 102 | + return nil | ||
| 103 | +} | ||
| 104 | + | ||
| 88 | type ( | 105 | type ( |
| 89 | LoginCreator interface { | 106 | LoginCreator interface { |
| 90 | WechatLogin(r WechatLoginRequest) (*LoginInfo, error) | 107 | WechatLogin(r WechatLoginRequest) (*LoginInfo, error) |
-
请 注册 或 登录 后发表评论