Skip to content

Commit

Permalink
Merge pull request #28 from cpf2021-gif/main
Browse files Browse the repository at this point in the history
fix: Correct some sql statement errors
  • Loading branch information
zhoushuguang authored Dec 15, 2023
2 parents 2948c14 + 144c557 commit 462716d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion application/article/rpc/internal/logic/articleslogic.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (l *ArticlesLogic) Articles(in *pb.ArticlesRequest) (*pb.ArticlesResponse,
}
} else {
v, err, _ := l.svcCtx.SingleFlightGroup.Do(fmt.Sprintf("ArticlesByUserId:%d:%d", in.UserId, in.SortType), func() (interface{}, error) {
return l.svcCtx.ArticleModel.ArticlesByUserId(l.ctx, in.UserId, sortLikeNum, sortPublishTime, sortField, types.DefaultLimit)
return l.svcCtx.ArticleModel.ArticlesByUserId(l.ctx, in.UserId, types.ArticleStatusVisible, sortLikeNum, sortPublishTime, sortField, types.DefaultLimit)
})
if err != nil {
logx.Errorf("ArticlesByUserId userId: %d sortField: %s error: %v", in.UserId, sortField, err)
Expand Down
10 changes: 5 additions & 5 deletions application/article/rpc/internal/model/articlemodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type (
// and implement the added methods in customArticleModel.
ArticleModel interface {
articleModel
ArticlesByUserId(ctx context.Context, userId, likeNum int64, pubTime, sortField string, limit int) ([]*Article, error)
ArticlesByUserId(ctx context.Context, userId int64, status int, likeNum int64, pubTime, sortField string, limit int) ([]*Article, error)
UpdateArticleStatus(ctx context.Context, id int64, status int) error
}

Expand All @@ -31,7 +31,7 @@ func NewArticleModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option)
}
}

func (m *customArticleModel) ArticlesByUserId(ctx context.Context, userId, likeNum int64, pubTime, sortField string, limit int) ([]*Article, error) {
func (m *customArticleModel) ArticlesByUserId(ctx context.Context, userId int64, status int, likeNum int64, pubTime, sortField string, limit int) ([]*Article, error) {
var (
err error
sql string
Expand All @@ -40,12 +40,12 @@ func (m *customArticleModel) ArticlesByUserId(ctx context.Context, userId, likeN
)
if sortField == "like_num" {
anyField = likeNum
sql = fmt.Sprintf("select "+articleRows+" from "+m.table+" where author_id=? and like_num < ? order by %s desc limit ?", sortField)
sql = fmt.Sprintf("select "+articleRows+" from "+m.table+" where author_id=? and status=? and like_num < ? order by %s desc limit ?", sortField)
} else {
anyField = pubTime
sql = fmt.Sprintf("select "+articleRows+" from "+m.table+" where author_id=? and publish_time < ? order by %s desc limit ?", sortField)
sql = fmt.Sprintf("select "+articleRows+" from "+m.table+" where author_id=? and status=? and publish_time < ? order by %s desc limit ?", sortField)
}
err = m.QueryRowsNoCacheCtx(ctx, &articles, sql, userId, anyField, limit)
err = m.QueryRowsNoCacheCtx(ctx, &articles, sql, userId, status, anyField, limit)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion application/follow/rpc/internal/logic/followlistlogic.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (l *FollowListLogic) FollowList(in *pb.FollowListRequest) (*pb.FollowListRe
if len(followUserIds) == 0 {
return &pb.FollowListResponse{}, nil
}
follows, err = l.svcCtx.FollowModel.FindByFollowedUserIds(l.ctx, followUserIds)
follows, err = l.svcCtx.FollowModel.FindByFollowedUserIds(l.ctx, in.UserId, followUserIds)
if err != nil {
l.Logger.Errorf("[FollowList] FollowModel.FindByFollowedUserIds error: %v req: %v", err, in)
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion application/follow/rpc/internal/model/follow.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ func (m *FollowModel) FindByUserId(ctx context.Context, userId int64, limit int)
return result, err
}

func (m *FollowModel) FindByFollowedUserIds(ctx context.Context, followedUserIds []int64) ([]*Follow, error) {
func (m *FollowModel) FindByFollowedUserIds(ctx context.Context, userId int64, followedUserIds []int64) ([]*Follow, error) {
var result []*Follow
err := m.db.WithContext(ctx).
Where("user_id = ?", userId).
Where("followed_user_id in (?)", followedUserIds).
Find(&result).Error

Expand Down

0 comments on commit 462716d

Please sign in to comment.