Skip to content

Commit

Permalink
fix: fix dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sixwaaaay committed Jan 18, 2024
1 parent 30e8cc7 commit 16f39d6
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/users.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
go-version: "1.21"
- name: Install dependencies
run: |
go mod download
go mod tidy
- name: Run tests
run: |
go test -v ./... -coverprofile=coverage.txt -covermode=atomic
Expand Down
4 changes: 1 addition & 3 deletions cmd/shauser/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module github.com/sixwaaaay/shauser

go 1.21

toolchain go1.21.4

require (
codeberg.org/sixwaaaay/sharing-pb v0.1.2
github.com/golang-jwt/jwt/v5 v5.2.0
Expand All @@ -12,7 +10,7 @@ require (
github.com/labstack/gommon v0.4.2
github.com/redis/go-redis/v9 v9.3.1
github.com/sixwaaaay/cq v0.2.1
github.com/sixwaaaay/must v0.1.0
github.com/sixwaaaay/must v0.1.1
github.com/sixwaaaay/token v0.1.1
github.com/sixwaaaay/token/rpc v0.0.0-20231226141924-56a2e6246033
github.com/sony/sonyflake v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions cmd/shauser/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6g
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/sixwaaaay/cq v0.2.1 h1:QXgufobF7+qKMFNZyLLxV8oTUF2JBUMS2WUuZcsH8s8=
github.com/sixwaaaay/cq v0.2.1/go.mod h1:cl2LPmz7hwVbMETra/ivogeKi/Z0OjXV3OkRyZ9irY8=
github.com/sixwaaaay/must v0.1.0 h1:gYi55InyvD/YyGlQ+n+4N1gqoHIckGG6ijmN2F6bm8g=
github.com/sixwaaaay/must v0.1.0/go.mod h1:bBuLkVjzfoV+irwm9eGmnGz1OCX4EC61I1S9aODuBjo=
github.com/sixwaaaay/must v0.1.1 h1:hF1DoR1dDtu/n0jI7MQM14Tai7SkJcbgDuyFtisFX0Q=
github.com/sixwaaaay/must v0.1.1/go.mod h1:bBuLkVjzfoV+irwm9eGmnGz1OCX4EC61I1S9aODuBjo=
github.com/sixwaaaay/token v0.1.1 h1:rBT4TyxwgKXpB0U9m9bGOt+oGX2yu1rh+33P44QlQ24=
github.com/sixwaaaay/token v0.1.1/go.mod h1:fIi4mw8eC8nQG3WKySLkUlvzanhCtafc5Lad6B+DzSQ=
github.com/sixwaaaay/token/rpc v0.0.0-20231226141924-56a2e6246033 h1:TEZnJipBuBXT2s1BR6soTwlZu5x+at7cvQigP3tssnM=
Expand Down
12 changes: 4 additions & 8 deletions cmd/shauser/internal/logic/queryfollow.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,15 @@ func (l *FollowQueryLogic) GetFollowings(ctx context.Context, in *user.FollowQue
return nil, status.Errorf(codes.Internal, "failed to find following for user %v: %v", in.UserId, err)
}

users, err := l.users(ctx, list, userID)
users, err := l.users(ctx, list.IDs, userID)
if err != nil {
l.logger.Error("get users failed", zap.Error(err))
return nil, status.Errorf(codes.Internal, "failed to find following for user %v: %v", in.UserId, err)
}

nextToken := l.nextPage(list, in.Limit)

return &user.UsersPage{
Users: users,
NextPage: nextToken,
NextPage: list.NextPageToken,
AllCount: following,
}, nil

Expand Down Expand Up @@ -110,17 +108,15 @@ func (l *FollowQueryLogic) GetFollowers(ctx context.Context, in *user.FollowQuer
return nil, status.Errorf(codes.Internal, "failed to find followers for user %v: %v", in.UserId, err)
}

users, err := l.users(ctx, list, userID)
users, err := l.users(ctx, list.IDs, userID)
if err != nil {
l.logger.Error("get users failed", zap.Error(err))
return nil, status.Errorf(codes.Internal, "failed to find followers for user %v: %v", in.UserId, err)
}
nextToken := l.nextPage(list, in.Limit)

l.logger.Info("GetFollowers completed")
return &user.UsersPage{
Users: users,
NextPage: nextToken,
NextPage: list.NextPageToken,
AllCount: followers,
}, nil
}
Expand Down
71 changes: 60 additions & 11 deletions cmd/shauser/internal/repository/follow.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ import (

type FollowQuery interface {
FindFollowExits(ctx context.Context, userid int64, followTo []int64) ([]int64, error)
FindFollowing(ctx context.Context, userid int64, token int64, limit int) ([]int64, error)
FindFollowers(ctx context.Context, userid int64, token int64, limit int) ([]int64, error)
FindFollowing(ctx context.Context, userid int64, token int64, limit int) (Result, error)
FindFollowers(ctx context.Context, userid int64, token int64, limit int) (Result, error)
}

type Result struct {
NextPageToken int64
IDs []int64
}

var _ FollowQuery = (*followQuery)(nil)
Expand Down Expand Up @@ -56,19 +61,63 @@ func (c *followQuery) FindFollowExits(ctx context.Context, userid int64, followT
}

// FindFollowing query the user follow list
func (c *followQuery) FindFollowing(ctx context.Context, userid int64, token int64, limit int) ([]int64, error) {
func (c *followQuery) FindFollowing(ctx context.Context, userid int64, token int64, limit int) (Result, error) {
var result []int64
var nextToken int64
var res Result
session := c.db.WithContext(ctx)
tx := session.Raw("SELECT target FROM follows WHERE user_id = ? AND id < ? ORDER BY id desc LIMIT ?", userid, token, limit).Scan(&result)
err := tx.Error
return result, err
/*
"SELECT target, id FROM follows WHERE user_id = ? AND id < ? ORDER BY id desc LIMIT ?"
*/

rows, err := session.Raw("SELECT target, id FROM follows WHERE user_id = ? AND id < ? ORDER BY id desc LIMIT ?", userid, token, limit).Rows()
if err != nil {
return res, err
}

Check warning on line 76 in cmd/shauser/internal/repository/follow.go

View check run for this annotation

Codecov / codecov/patch

cmd/shauser/internal/repository/follow.go#L75-L76

Added lines #L75 - L76 were not covered by tests
defer rows.Close()
for rows.Next() {
var id int64
var target int64
err := rows.Scan(&target, &id)
if err != nil {
return res, err
}
result = append(result, target)
nextToken = id

Check warning on line 86 in cmd/shauser/internal/repository/follow.go

View check run for this annotation

Codecov / codecov/patch

cmd/shauser/internal/repository/follow.go#L79-L86

Added lines #L79 - L86 were not covered by tests
}

res.NextPageToken = nextToken
res.IDs = result

return res, nil
}

// FindFollowers query the user's follower list
func (c *followQuery) FindFollowers(ctx context.Context, userid int64, token int64, limit int) ([]int64, error) {
var result []int64
func (c *followQuery) FindFollowers(ctx context.Context, userid int64, token int64, limit int) (Result, error) {
result := make([]int64, 0, limit)
var nextToken int64
var res Result
session := c.db.WithContext(ctx)
tx := session.Raw("SELECT user_id FROM follows WHERE target = ? AND id < ? ORDER BY id desc LIMIT ?", userid, token, limit).Scan(&result)
err := tx.Error
return result, err
/*
"SELECT user_id, id FROM follows WHERE target = ? AND id < ? ORDER BY id desc LIMIT ?"
*/
rows, err := session.Raw("SELECT user_id, id FROM follows WHERE target = ? AND id < ? ORDER BY id desc LIMIT ?", userid, token, limit).Rows()
if err != nil {
return res, err
}

Check warning on line 107 in cmd/shauser/internal/repository/follow.go

View check run for this annotation

Codecov / codecov/patch

cmd/shauser/internal/repository/follow.go#L106-L107

Added lines #L106 - L107 were not covered by tests
defer rows.Close()
for rows.Next() {
var id int64
var target int64
err := rows.Scan(&target, &id)
if err != nil {
return res, err
}
result = append(result, target)
nextToken = id

Check warning on line 117 in cmd/shauser/internal/repository/follow.go

View check run for this annotation

Codecov / codecov/patch

cmd/shauser/internal/repository/follow.go#L110-L117

Added lines #L110 - L117 were not covered by tests
}

res.NextPageToken = nextToken
res.IDs = result
return res, nil
}

0 comments on commit 16f39d6

Please sign in to comment.