作者 tangxvhui

Merge branch 'dev-tangxvhui' into dev

... ... @@ -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"` //经度
... ... @@ -96,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"` // 点赞记录的时间
}
)
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
// 人员点赞文章/评论
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
... ...
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"),
... ...
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
}
... ...
... ... @@ -349,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"` //现有的点赞数量
}
... ...
... ... @@ -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,24 @@ 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 {
//
return nil
}
// 浏览数量变动
func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error {
//
return nil
}
// 评论数量变动
func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error {
//
return nil
}
func NewArticleRepository(cache *cache.CachedRepository) domain.ArticleRepository {
return &ArticleRepository{CachedRepository: cache}
}
... ...
... ... @@ -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 //点赞数量变动
}
... ...