作者 郑周

Merge remote-tracking branch 'origin/dev' into dev

正在显示 25 个修改的文件 包含 969 行增加41 行删除
... ... @@ -8,6 +8,30 @@ info(
version: "v1"
)
// 小程序接口
@server(
prefix: v1/mini
group: article
jwt: MiniAuth
)
service Core {
@doc "小程序创建发布内容"
@handler MiniCreateArticle
post /article (MiniArticleCreateRequest) returns (MiniArticleCreateResponse)
@doc "小程序获取我发布的文章"
@handler MiniArticleSearchMe
post /article/search/me (MiniArticleSearchMeRequest) returns (MiniArticleSearchMeResponse)
@doc "小程序获取文章内容详情"
@handler MiniGetArticle
get /article/:id (MiniArticleGetRequest) returns (MiniArticleGetResponse)
@doc "小程序获取文章的点赞人员列表"
@handler MiniUserLikeArticle
post /article/user_like/list (MiniUserLikeArticleRequest) returns (MiniUserLikeArticleResponse)
@doc "小程序人员操作点赞文章/评论"
@handler MiniSetUserLike
post /article/user_like/set (MiniSetUserLikeRequset) returns (MiniSetUserLikeResponse)
}
// 坐标地点描述
type Location {
Longitude float64 `json:"longitude,optional"` //经度
... ... @@ -22,6 +46,7 @@ type Author {
Avatar string `json:"avatar"` // 人员头像URL
Group string `json:"group"` // 人员的分组
Position string `json:"position"` // 职位
Company string `json:"company"` // 公司
}
//小程序端创建发布文章
... ... @@ -44,20 +69,29 @@ type (
type (
MiniArticleGetRequest {
Id int64 `path:"id"` //id
CompanyId int64 `path:"-"`
}
MiniArticleGetResponse {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
AuthorId int `json:"authorId"` //发布人id
AuthorId int64 `json:"authorId"` //发布人id
Author Author `json:"author"` //发布人
CreatedAt int64 `json:"createdAt"` //文章的发布时间
Section []string `json:"section"` //文章的文本内容
Section []ArticleSection `json:"section"` //文章的文本内容
Images []string `json:"images"` //图片
WhoRead []int64 `json:"whoRead"` //谁可查看
WhoReview []int64 `json:"whoReview"` //谁可评论
Location Location `json:"location"` //定位坐标
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
Show int `json:"showState"` // 评论的展示状态(0显示、1不显示)
CountRead int `json:"countRead"` // 浏览数量
Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
}
ArticleSection {
Id int64 `json:"id"` //段落id
Content string `json:"content"` // 文本内容
SortBy int `json:"sortBy"` // 排序
TotalComment int `json:"totalComment"` // 评论的数量
}
)
... ... @@ -86,20 +120,38 @@ type (
}
)
// 小程序接口
@server(
prefix: v1/mini
group: article
jwt: MiniAuth
//获取列表,文章有哪些人进行了点赞
type (
MiniUserLikeArticleRequest {
ArticleId int64 `json:"articleId"` // 文章id
CompanyId int64 `json:"-"` //公司id
Page int `json:"page"` //分页,第几页
Size int `json:"size"` //分页,每页几条
}
MiniUserLikeArticleResponse {
Total int64 `json:"total"` //总数
List []WhichUserLikeArticle `json:"list"` //列表
}
WhichUserLikeArticle {
ArticleId int64 `json:"articleId"` // 文章id
UserId int64 `json:"userId"` // 人员id
Name string `json:"name"` // 人员名称
Avatar string `json:"avatar"` // 人员头像
CreatedAt int64 `json:"createdAt"` // 点赞记录的时间
}
)
// 人员点赞文章/评论
type (
MiniSetUserLikeRequset {
ArticleId int64 `json:"articleId"` //文章id
CommentId int64 `json:"commentId"` //评论id
UserId int64 `json:"-"` //操作人
Flag int `json:"flag"` //点赞标志 1、点赞 2 、取消点赞
}
MiniSetUserLikeResponse {
ArticleId int64 `json:"articleId"` //文章id
CommentId int64 `json:"commentId"` //评论id
Count int `json:"count"` //现有的点赞数量
}
)
\ No newline at end of file
service Core {
@doc "小程序创建发布内容"
@handler MiniCreateArticle
post /article (MiniArticleCreateRequest) returns (MiniArticleCreateResponse)
@doc "小程序获取我发布的文章"
@handler MiniArticleSearchMe
post /article/search/me (MiniArticleSearchMeRequest) returns (MiniArticleSearchMeResponse)
@doc "小程序获取文章内容详情"
@handler MiniGetArticle
get /article/:id (MiniArticleGetRequest) returns (MiniArticleGetResponse)
}
\ No newline at end of file
... ...
... ... @@ -41,10 +41,10 @@ service Core {
post /mini/user/department-users (MiniUserDepartmentUsersRequest)returns (MiniUserInfoResponse)
@doc "关注我的人"
@handler miniUserFollower
post /mini/user/follower (UserSearchRequest)returns(UserSearchResponse)
post /mini/user/follower (MiniUserFollowedSearchRequest)returns(MiniUserFollowedSearchResponse)
@doc "我关注的人"
@handler miniUserFollowing
post /mini/user/following (UserSearchRequest)returns(UserSearchResponse)
post /mini/user/following (MiniUserFollowedSearchRequest)returns(MiniUserFollowedSearchResponse)
@doc "关注"
@handler miniUserFollow
post /mini/user/follow (FollowRequest)
... ... @@ -97,6 +97,14 @@ type(
Departments []*Department `json:"departments"`
Users []*UserItem `json:"users"`
}
MiniUserFollowedSearchRequest{
Page int `json:"page,optional"`
Size int `json:"size,optional"`
}
MiniUserFollowedSearchResponse{
List []*UserFollowItem `json:"users"`
Total int64 `json:"total"`
}
UserItem {
Id int64 `json:"id,omitempty"` // 用户ID
CompanyId int64 `json:"companyId,omitempty"` // 公司ID
... ... @@ -133,6 +141,15 @@ type(
FollowRequest{
UserId int64 `json:"userId"`
}
UserFollowItem struct {
Id int64 `json:"id"` // 用户ID
Name string `json:"name"` // 名称
CompanyName string `json:"companyName"` // 公司名称
Avatar string `json:"avatar"` // 头像
Position string `json:"position"` // 职位
Followed bool `json:"followed"` // 关注
MutualFollowed bool `json:"mutualFollowed"` // 互相关注标识
}
)
... ...
... ... @@ -7,6 +7,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
)
func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
... ... @@ -18,7 +19,8 @@ func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
l := article.NewMiniGetArticleLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
resp, err := l.MiniGetArticle(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
... ...
package article
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
)
func MiniSetUserLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniSetUserLikeRequset
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewMiniSetUserLikeLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.UserId = token.UserId
resp, err := l.MiniSetUserLike(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package article
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
)
func MiniUserLikeArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniUserLikeArticleRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewMiniUserLikeArticleLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
resp, err := l.MiniUserLikeArticle(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
... ... @@ -192,6 +192,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/article/:id",
Handler: article.MiniGetArticleHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/user_like/list",
Handler: article.MiniUserLikeArticleHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/user_like/set",
Handler: article.MiniSetUserLikeHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
rest.WithPrefix("/v1/mini"),
... ...
... ... @@ -12,7 +12,7 @@ import (
func MiniUserFollowerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.UserSearchRequest
var req types.MiniUserFollowedSearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
... ...
... ... @@ -12,7 +12,7 @@ import (
func MiniUserFollowingHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.UserSearchRequest
var req types.MiniUserFollowedSearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
... ...
... ... @@ -46,7 +46,9 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
Company: "",
CompanyId: author.CompanyId,
}
if len(req.Images) > 9 {
return nil, xerr.NewErrMsg("图片数量最多9张")
}
//TODO 获取图片的尺寸大小
images := []domain.Image{}
for _, val := range req.Images {
... ... @@ -56,6 +58,7 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
Height: 0,
})
}
//检查文章可被哪些人查看
whoRead := []int64{}
if len(req.WhoRead) > 0 {
... ...
... ... @@ -2,9 +2,12 @@ package article
import (
"context"
"sort"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
... ... @@ -24,7 +27,76 @@ func NewMiniGetArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mi
}
func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (resp *types.MiniArticleGetResponse, err error) {
// todo: add your logic here and delete this line
// 获取文章内容
var conn = l.svcCtx.DefaultDBConn()
articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("读取文章内容失败", err)
}
if articleInfo.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("没有查看权限")
}
if articleInfo.Show == domain.ArticleShowDisable {
resp = &types.MiniArticleGetResponse{
Id: articleInfo.Id,
Title: articleInfo.Title,
Show: int(domain.ArticleShowDisable),
}
return resp, nil
}
queryOption := domain.NewQueryOptions().
WithFindOnly().
MustWithKV("articleId", articleInfo.Id)
_, sectionList, err := l.svcCtx.ArticleSectionRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("读取文章内容失败", err)
}
sortBy := domain.SortArticleSection(sectionList)
sort.Sort(sortBy)
articleSection := []types.ArticleSection{}
for _, val := range sortBy {
articleSection = append(articleSection, types.ArticleSection{
Id: val.Id,
Content: val.Content,
SortBy: val.SortBy,
TotalComment: val.TotalComment,
})
}
resp = &types.MiniArticleGetResponse{
Id: articleInfo.Id,
Title: articleInfo.Title,
AuthorId: articleInfo.AuthorId,
Author: types.Author{
Id: articleInfo.Author.Id,
Name: articleInfo.Author.Name,
Avatar: articleInfo.Author.Avatar,
Group: articleInfo.Author.Group,
Position: articleInfo.Author.Position,
Company: articleInfo.Author.Company,
},
CreatedAt: articleInfo.CreatedAt,
Section: articleSection,
Images: []string{},
WhoRead: articleInfo.WhoRead,
WhoReview: articleInfo.WhoReview,
Location: types.Location{
Longitude: articleInfo.Location.Longitude,
Latitude: articleInfo.Location.Latitude,
Descript: articleInfo.Location.Descript,
},
CountLove: articleInfo.CountLove,
CountComment: articleInfo.CountComment,
CountRead: articleInfo.CountRead,
Show: int(articleInfo.Show),
}
for _, val := range articleInfo.Images {
resp.Images = append(resp.Images, val.Url)
}
return
}
... ...
package article
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniSetUserLikeLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniSetUserLikeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSetUserLikeLogic {
return &MiniSetUserLikeLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 设置点赞操作
func (l *MiniSetUserLikeLogic) MiniSetUserLike(req *types.MiniSetUserLikeRequset) (resp *types.MiniSetUserLikeResponse, err error) {
//取消点赞文章
if req.Flag == 2 && req.CommentId == 0 {
return l.cancelSetUserLikeArticle(req)
}
// 取消点赞评论
if req.Flag == 2 && req.CommentId > 0 {
return l.cancelSetUserLikeComment(req)
}
// 设置点赞文章
if req.Flag == 1 && req.CommentId == 0 {
return l.setUserLikeArticle(req)
}
// 设置点赞评论
if req.Flag == 1 && req.CommentId > 0 {
return l.setUserLikeComment(req)
}
return nil, xerr.NewErrMsg("操作失败")
}
// 取消文章点赞
func (l *MiniSetUserLikeLogic) cancelSetUserLikeArticle(req *types.MiniSetUserLikeRequset) (resp *types.MiniSetUserLikeResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
// 检查id
userInfo, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.UserId)
if err != nil {
//无法确认 文章的id
return nil, xerr.NewErrMsgErr("无法确认操作人员信息", err)
}
articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId)
if err != nil {
//无法确认 文章的id
return nil, xerr.NewErrMsgErr("取消点赞标识失败", err)
}
if userInfo.CompanyId != articleInfo.CompanyId {
// 公司无法对应
return nil, xerr.NewErrMsg("没有操作权限")
}
queryOption := domain.NewQueryOptions().
WithFindOnly().
MustWithKV("articleId", req.ArticleId).
MustWithKV("commentId", req.CommentId).
MustWithKV("userId", req.UserId)
_, flagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("取消点赞标识失败", err)
}
if len(flagList) == 0 {
//没有记录
resp = &types.MiniSetUserLikeResponse{
ArticleId: req.ArticleId,
CommentId: req.CommentId,
Count: articleInfo.CountLove,
}
return resp, nil
}
flagInfo := flagList[0]
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
// 去除点赞标识
_, err = l.svcCtx.UserLoveFlagRepository.Delete(ctx, c, flagInfo)
if err != nil {
return err
}
// 减少文章的点赞数量
err = l.svcCtx.ArticleRepository.IncreaseCountLove(ctx, c, -1, articleInfo)
if err != nil {
return err
}
return nil
}, true)
if err != nil {
return nil, xerr.NewErrMsgErr("取消点赞标识失败", err)
}
articleInfo, err = l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId)
if err == nil {
return nil, xerr.NewErrMsgErr("获取点赞数量失败", err)
}
resp = &types.MiniSetUserLikeResponse{
ArticleId: req.ArticleId,
CommentId: req.CommentId,
Count: articleInfo.CountLove,
}
return resp, nil
}
// 取消评论点赞
func (l *MiniSetUserLikeLogic) cancelSetUserLikeComment(req *types.MiniSetUserLikeRequset) (resp *types.MiniSetUserLikeResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
// 检查id
userInfo, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.UserId)
if err != nil {
//无法确认 文章的id
return nil, xerr.NewErrMsgErr("无法确认操作人员信息", err)
}
articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId)
if err != nil {
//无法确认 文章的id
return nil, xerr.NewErrMsgErr("取消点赞标识失败", err)
}
if userInfo.CompanyId != articleInfo.CompanyId {
// 文章和人员的公司无法对应
return nil, xerr.NewErrMsg("没有操作权限")
}
commentInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId)
if err != nil {
return nil, xerr.NewErrMsgErr("无法确认评论信息", err)
}
if commentInfo.ArticleId != articleInfo.Id {
return nil, xerr.NewErrMsg("评论和文章不能对应")
}
queryOption := domain.NewQueryOptions().
WithFindOnly().
MustWithKV("articleId", req.ArticleId).
MustWithKV("commentId", req.CommentId).
MustWithKV("userId", req.UserId)
_, flagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("取消点赞标识失败", err)
}
if len(flagList) == 0 {
//没有记录
resp = &types.MiniSetUserLikeResponse{
ArticleId: req.ArticleId,
CommentId: req.CommentId,
Count: commentInfo.CountUserLove,
}
return resp, nil
}
flagInfo := flagList[0]
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
// 去除点赞标识
_, err = l.svcCtx.UserLoveFlagRepository.Delete(ctx, c, flagInfo)
if err != nil {
return err
}
// 减少评论的点赞数量
err = l.svcCtx.ArticleCommentRepository.IncreaseCountUserLove(ctx, c, -1, commentInfo)
if err != nil {
return err
}
return nil
}, true)
if err != nil {
return nil, xerr.NewErrMsgErr("取消点赞标识失败", err)
}
commentInfo, err = l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId)
if err != nil {
return nil, xerr.NewErrMsgErr("获取评论的点赞数量失败", err)
}
resp = &types.MiniSetUserLikeResponse{
ArticleId: req.ArticleId,
CommentId: req.CommentId,
Count: commentInfo.CountUserLove,
}
return resp, nil
}
// 设置文章点赞
func (l *MiniSetUserLikeLogic) setUserLikeArticle(req *types.MiniSetUserLikeRequset) (resp *types.MiniSetUserLikeResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
// 检查id
userInfo, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.UserId)
if err != nil {
//无法确认 文章的id
return nil, xerr.NewErrMsgErr("无法确认操作人员信息", err)
}
articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId)
if err != nil {
//无法确认 文章的id
return nil, xerr.NewErrMsgErr("设置点赞标识失败", err)
}
if userInfo.CompanyId != articleInfo.CompanyId {
// 公司无法对应
return nil, xerr.NewErrMsg("没有操作权限")
}
queryOption := domain.NewQueryOptions().
WithFindOnly().
MustWithKV("articleId", req.ArticleId).
MustWithKV("commentId", req.CommentId).
MustWithKV("userId", req.UserId)
_, flagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("设置点赞标识失败", err)
}
if len(flagList) > 0 {
//已经有记录
resp = &types.MiniSetUserLikeResponse{
ArticleId: req.ArticleId,
CommentId: req.CommentId,
Count: articleInfo.CountLove,
}
return resp, nil
}
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
flagInfo := domain.UserLoveFlag{
Id: 0,
ArticleId: req.ArticleId,
CommentId: req.CommentId,
UserId: req.UserId,
}
// 去除点赞标识
_, err = l.svcCtx.UserLoveFlagRepository.Insert(ctx, c, &flagInfo)
if err != nil {
return err
}
// 增加文章的点赞数量
err = l.svcCtx.ArticleRepository.IncreaseCountLove(ctx, c, 1, articleInfo)
if err != nil {
return err
}
return nil
}, true)
if err != nil {
return nil, xerr.NewErrMsgErr("设置点赞标识失败", err)
}
articleInfo, err = l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId)
if err == nil {
return nil, xerr.NewErrMsgErr("获取点赞数量失败", err)
}
resp = &types.MiniSetUserLikeResponse{
ArticleId: req.ArticleId,
CommentId: req.CommentId,
Count: articleInfo.CountLove,
}
return resp, nil
}
// 设置评论点赞
func (l *MiniSetUserLikeLogic) setUserLikeComment(req *types.MiniSetUserLikeRequset) (resp *types.MiniSetUserLikeResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
// 检查id
userInfo, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.UserId)
if err != nil {
//无法确认 文章的id
return nil, xerr.NewErrMsgErr("无法确认操作人员信息", err)
}
articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId)
if err != nil {
//无法确认 文章的id
return nil, xerr.NewErrMsgErr("设置点赞标识失败", err)
}
if userInfo.CompanyId != articleInfo.CompanyId {
// 文章和人员的公司无法对应
return nil, xerr.NewErrMsg("没有操作权限")
}
commentInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId)
if err != nil {
return nil, xerr.NewErrMsgErr("无法确认评论信息", err)
}
if commentInfo.ArticleId != articleInfo.Id {
return nil, xerr.NewErrMsg("评论和文章不能对应")
}
queryOption := domain.NewQueryOptions().
WithFindOnly().
MustWithKV("articleId", req.ArticleId).
MustWithKV("commentId", req.CommentId).
MustWithKV("userId", req.UserId)
_, flagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("设置点赞标识失败", err)
}
if len(flagList) > 0 {
//已经有记录
resp = &types.MiniSetUserLikeResponse{
ArticleId: req.ArticleId,
CommentId: req.CommentId,
Count: commentInfo.CountUserLove,
}
return resp, nil
}
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
flagInfo := domain.UserLoveFlag{
Id: 0,
ArticleId: req.ArticleId,
CommentId: req.CommentId,
UserId: req.UserId,
}
// 设置赞标识
_, err = l.svcCtx.UserLoveFlagRepository.Insert(ctx, c, &flagInfo)
if err != nil {
return err
}
// 增加评论的点赞数量
err = l.svcCtx.ArticleCommentRepository.IncreaseCountUserLove(ctx, c, 1, commentInfo)
if err != nil {
return err
}
return nil
}, true)
if err != nil {
return nil, xerr.NewErrMsgErr("设置点赞标识失败", err)
}
commentInfo, err = l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId)
if err != nil {
return nil, xerr.NewErrMsgErr("获取评论的点赞数量失败", err)
}
resp = &types.MiniSetUserLikeResponse{
ArticleId: req.ArticleId,
CommentId: req.CommentId,
Count: commentInfo.CountUserLove,
}
return resp, nil
}
... ...
package article
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniUserLikeArticleLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniUserLikeArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniUserLikeArticleLogic {
return &MiniUserLikeArticleLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 获取点赞的人员列表
func (l *MiniUserLikeArticleLogic) MiniUserLikeArticle(req *types.MiniUserLikeArticleRequest) (resp *types.MiniUserLikeArticleResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
queryOption := domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
MustWithKV("articleId", req.ArticleId).
MustWithKV("commentId", 0)
cnt, flagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("获取人员列表失败", err)
}
uidList := []int64{}
for _, val := range flagList {
uidList = append(uidList, val.UserId)
}
queryOption = domain.NewQueryOptions().
WithFindOnly().
MustWithKV("ids", uidList)
// 获取人员列表
_, userList, err := l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("获取人员列表失败", err)
}
userMap := map[int64]*domain.User{}
for i := range userList {
if userList[i].CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("操作失败")
}
userMap[userList[i].Id] = userList[i]
}
resp = &types.MiniUserLikeArticleResponse{
Total: cnt,
List: make([]types.WhichUserLikeArticle, len(flagList)),
}
for i, val := range flagList {
item := types.WhichUserLikeArticle{
ArticleId: val.ArticleId,
UserId: val.UserId,
Name: "[用户已被清除]",
Avatar: "",
CreatedAt: val.CreatedAt,
}
if u, ok := userMap[val.UserId]; ok {
item.Name = u.Name
item.Avatar = u.Avatar
}
resp.List[i] = item
}
return resp, nil
}
... ...
... ... @@ -2,6 +2,10 @@ package user
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"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,32 @@ func NewMiniUserFollowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mi
}
}
func (l *MiniUserFollowLogic) MiniUserFollow(req *types.FollowRequest) error {
// todo: add your logic here and delete this line
func (l *MiniUserFollowLogic) MiniUserFollow(req *types.FollowRequest) (err error) {
var (
conn = l.svcCtx.DefaultDBConn()
user *domain.User
targetUser *domain.User
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId); err != nil {
return xerr.NewErrMsgErr("用户不存在", err)
}
if targetUser, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.UserId); err != nil {
return xerr.NewErrMsgErr("关注的用户不存在", err)
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
if err = user.Follow(targetUser); err != nil {
return err
}
if user, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, user); err != nil {
return err
}
if targetUser, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, targetUser); err != nil {
return err
}
return nil
}, true); err != nil {
return xerr.NewErrMsgErr("关注用户失败", err)
}
return nil
}
... ...
... ... @@ -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 NewMiniUserFollowerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
}
}
func (l *MiniUserFollowerLogic) MiniUserFollower(req *types.UserSearchRequest) (resp *types.UserSearchResponse, err error) {
// todo: add your logic here and delete this line
func (l *MiniUserFollowerLogic) MiniUserFollower(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.Follower
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, item),
})
}
})
return
}
... ...
... ... @@ -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
}
... ...
... ... @@ -2,6 +2,10 @@ package user
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"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,32 @@ func NewMiniUserUnFollowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
}
}
func (l *MiniUserUnFollowLogic) MiniUserUnFollow(req *types.FollowRequest) error {
// todo: add your logic here and delete this line
func (l *MiniUserUnFollowLogic) MiniUserUnFollow(req *types.FollowRequest) (err error) {
var (
conn = l.svcCtx.DefaultDBConn()
user *domain.User
targetUser *domain.User
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId); err != nil {
return xerr.NewErrMsgErr("用户不存在", err)
}
if targetUser, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.UserId); err != nil {
return xerr.NewErrMsgErr("关注的用户不存在", err)
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
if err = user.Unfollow(targetUser); err != nil {
return err
}
if user, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, user); err != nil {
return err
}
if targetUser, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, targetUser); err != nil {
return err
}
return nil
}, true); err != nil {
return xerr.NewErrMsgErr("关注用户失败", err)
}
return nil
}
... ...
... ... @@ -192,6 +192,16 @@ type MiniUserDepartmentUsersResponse struct {
Users []*UserItem `json:"users"`
}
type MiniUserFollowedSearchRequest struct {
Page int `json:"page,optional"`
Size int `json:"size,optional"`
}
type MiniUserFollowedSearchResponse struct {
List []*UserFollowItem `json:"users"`
Total int64 `json:"total"`
}
type UserItem struct {
Id int64 `json:"id,omitempty"` // 用户ID
CompanyId int64 `json:"companyId,omitempty"` // 公司ID
... ... @@ -231,6 +241,16 @@ type FollowRequest struct {
UserId int64 `json:"userId"`
}
type UserFollowItem struct {
Id int64 `json:"id"` // 用户ID
Name string `json:"name"` // 名称
CompanyName string `json:"companyName"` // 公司名称
Avatar string `json:"avatar"` // 头像
Position string `json:"position"` // 职位
Followed bool `json:"followed"` // 关注
MutualFollowed bool `json:"mutualFollowed"` // 互相关注标识
}
type CompanySearchRequest struct {
Page int `json:"page"`
Size int `json:"size"`
... ... @@ -262,6 +282,7 @@ type Author struct {
Avatar string `json:"avatar"` // 人员头像URL
Group string `json:"group"` // 人员的分组
Position string `json:"position"` // 职位
Company string `json:"company"` // 公司
}
type MiniArticleCreateRequest struct {
... ... @@ -280,21 +301,31 @@ type MiniArticleCreateResponse struct {
type MiniArticleGetRequest struct {
Id int64 `path:"id"` //id
CompanyId int64 `path:"-"`
}
type MiniArticleGetResponse struct {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
AuthorId int `json:"authorId"` //发布人id
AuthorId int64 `json:"authorId"` //发布人id
Author Author `json:"author"` //发布人
CreatedAt int64 `json:"createdAt"` //文章的发布时间
Section []string `json:"section"` //文章的文本内容
Section []ArticleSection `json:"section"` //文章的文本内容
Images []string `json:"images"` //图片
WhoRead []int64 `json:"whoRead"` //谁可查看
WhoReview []int64 `json:"whoReview"` //谁可评论
Location Location `json:"location"` //定位坐标
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
Show int `json:"showState"` // 评论的展示状态(0显示、1不显示)
CountRead int `json:"countRead"` // 浏览数量
Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
}
type ArticleSection struct {
Id int64 `json:"id"` //段落id
Content string `json:"content"` // 文本内容
SortBy int `json:"sortBy"` // 排序
TotalComment int `json:"totalComment"` // 评论的数量
}
type MiniArticleSearchMeRequest struct {
... ... @@ -318,3 +349,36 @@ type ArticleSearchMe struct {
CountComment int `json:"CountComment"` //评论数量
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
}
type MiniUserLikeArticleRequest struct {
ArticleId int64 `json:"articleId"` // 文章id
CompanyId int64 `json:"-"` //公司id
Page int `json:"page"` //分页,第几页
Size int `json:"size"` //分页,每页几条
}
type MiniUserLikeArticleResponse struct {
Total int64 `json:"total"` //总数
List []WhichUserLikeArticle `json:"list"` //列表
}
type WhichUserLikeArticle struct {
ArticleId int64 `json:"articleId"` // 文章id
UserId int64 `json:"userId"` // 人员id
Name string `json:"name"` // 人员名称
Avatar string `json:"avatar"` // 人员头像
CreatedAt int64 `json:"createdAt"` // 点赞记录的时间
}
type MiniSetUserLikeRequset struct {
ArticleId int64 `json:"articleId"` //文章id
CommentId int64 `json:"commentId"` //评论id
UserId int64 `json:"-"` //操作人
Flag int `json:"flag"` //点赞标志 1、点赞 2 、取消点赞
}
type MiniSetUserLikeResponse struct {
ArticleId int64 `json:"articleId"` //文章id
CommentId int64 `json:"commentId"` //评论id
Count int `json:"count"` //现有的点赞数量
}
... ...
... ... @@ -10,6 +10,10 @@ import (
type Role struct {
Id int64 // 唯一标识
Name string `json:"name"` // 角色名称
Auths []int64 `gorm:"type:jsonb;serializer:json"` // 角色权限列表
Remark string `json:"remark"` // 备注
Users []int64 `gorm:"type:jsonb;serializer:json"` // 绑定的用户
CreatedAt int64
UpdatedAt int64
... ...
... ... @@ -194,6 +194,11 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti
return to, nil
}
// TODO 点赞数量变动
func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, dm *domain.ArticleComment) error {
return nil
}
func NewArticleCommentRepository(cache *cache.CachedRepository) domain.ArticleCommentRepository {
return &ArticleCommentRepository{CachedRepository: cache}
}
... ...
... ... @@ -198,6 +198,61 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (*
return to, nil
}
// 点赞数量变动
func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error {
//
var (
err error
m *models.Article
tx = conn.DB()
)
m = &models.Article{Id: article.Id}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Update("count_love", gorm.Expr("count_love+?", incr))
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return err
}
return nil
}
// 浏览数量变动
func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error {
var (
err error
m *models.Article
tx = conn.DB()
)
m = &models.Article{Id: article.Id}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Update("count_read", gorm.Expr("count_read+?", incr))
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return err
}
return nil
}
// 评论数量变动
func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error {
var (
err error
m *models.Article
tx = conn.DB()
)
m = &models.Article{Id: article.Id}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Update("count_comment", gorm.Expr("count_comment+?", incr))
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return err
}
return nil
}
func NewArticleRepository(cache *cache.CachedRepository) domain.ArticleRepository {
return &ArticleRepository{CachedRepository: cache}
}
... ...
... ... @@ -120,6 +120,10 @@ func (repository *ArticleSectionRepository) Find(ctx context.Context, conn trans
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
if v, ok := queryOptions["articleId"]; ok {
tx = tx.Where("article_id = ?", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...
... ... @@ -120,6 +120,15 @@ func (repository *UserLoveFlagRepository) Find(ctx context.Context, conn transac
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
if v, ok := queryOptions["articleId"]; ok {
tx = tx.Where("article_id=?", v)
}
if v, ok := queryOptions["commentId"]; ok {
tx = tx.Where("comment_id=?", v)
}
if v, ok := queryOptions["userId"]; ok {
tx = tx.Where("user_id=?", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...
... ... @@ -37,6 +37,9 @@ type ArticleRepository interface {
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Article, error)
Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*Article, error)
IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, dm *Article) error //点赞数量变动
IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, dm *Article) error //评论数量变动
IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, dm *Article) error //浏览数量变动
}
type ArticleTarget int
... ...
... ... @@ -46,4 +46,5 @@ type ArticleCommentRepository interface {
Delete(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleComment, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleComment, error)
IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, dm *ArticleComment) error //点赞数量变动
}
... ...
... ... @@ -85,6 +85,23 @@ func (m *User) Audit(status int) error {
return nil
}
func (m *User) Follow(targetUser *User) error {
if lo.Contains(m.Following, targetUser.Id) {
return fmt.Errorf("已关注用户%v", targetUser.Name)
}
m.Following = append(m.Following, targetUser.Id)
if !lo.Contains(targetUser.Follower, m.Id) {
targetUser.Follower = append(targetUser.Follower, m.Id)
}
return nil
}
func (m *User) Unfollow(targetUser *User) error {
m.Following = lo.Without(m.Following, targetUser.Id)
targetUser.Follower = lo.Without(targetUser.Follower, m.Id)
return nil
}
type (
LoginCreator interface {
WechatLogin(r WechatLoginRequest) (*LoginInfo, error)
... ...