Skip to content

Commit

Permalink
fix(friend.tech/job): add user not found check logic (#711)
Browse files Browse the repository at this point in the history
fix: add user not found check logic
  • Loading branch information
brucexc authored Sep 12, 2023
1 parent d9d6182 commit 8470608
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
12 changes: 9 additions & 3 deletions common/datasource/friendtech/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package friendtech

import (
"context"
"encoding/json"
"strconv"
"time"

Expand Down Expand Up @@ -40,7 +41,7 @@ func (c *Client) GetUserMeta(ctx context.Context, address string) (*UserResponse
func (c *Client) GetUserMetaByID(ctx context.Context, id int64) (*UserResponse, error) {
var result UserResponse

_, err := c.restyClient.R().SetPathParams(
r, err := c.restyClient.R().SetPathParams(
map[string]string{
"id": strconv.FormatInt(id, 10),
},
Expand All @@ -49,9 +50,14 @@ func (c *Client) GetUserMetaByID(ctx context.Context, id int64) (*UserResponse,
return nil, err
}

if result.TwitterUserID == "" && result.Address == "" {
return nil, nil
if r.RawResponse.StatusCode != 200 {
var message MessageResponse
_ = json.Unmarshal(r.Body(), &message)
if message.Message == "Address/User not found." {
result.ID = -1
}
}

return &result, nil
}

Expand Down
4 changes: 4 additions & 0 deletions common/datasource/friendtech/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ type UserResponse struct {
ShareSupply int `json:"shareSupply"`
DisplayPrice string `json:"displayPrice"`
}

type MessageResponse struct {
Message string `json:"message"`
}
16 changes: 13 additions & 3 deletions service/indexer/internal/worker/collectible/friendtech/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,20 @@ func (job *Job) fetchFriendTechUser(ctx context.Context) (bool, error) {
return false, err
}

user, err := job.client.GetUserMetaByID(ctx, id+1)
var (
user *friendtechClient.UserResponse
flag = true
)
for ; flag; id++ {
user, err = job.client.GetUserMetaByID(ctx, id+1)

if err != nil || user == nil {
return false, err
if err != nil {
return false, err
}

if user.ID != -1 {
flag = false
}
}

err = job.setItemToDB(ctx, *user)
Expand Down

0 comments on commit 8470608

Please sign in to comment.