Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add auth query profile #1239

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/entities/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (e *Entity) GetTopUsers(req request.GetTopUsersRequest) (*response.TopUser,
item := &leaderboard[i]

if item.User == nil {
profile, err := e.svc.MochiProfile.GetByID(item.ProfileID)
profile, err := e.svc.MochiProfile.GetByID(item.ProfileID, e.cfg.MochiBotSecret)
if err != nil {
return
}
Expand Down Expand Up @@ -544,7 +544,7 @@ func (e *Entity) GetUserBalance(profileId string) (*response.UserBalanceResponse
}

// get all onchain account
profile, err := e.svc.MochiProfile.GetByID(profileId)
profile, err := e.svc.MochiProfile.GetByID(profileId, e.cfg.MochiBotSecret)
if err != nil {
e.log.Fields(logger.Fields{"profileId": profileId}).Error(err, "[entity.GetUserBalance] - e.svc.MochiProfile.GetByID failed")
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/entities/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (e *Entity) CreateVault(req *request.CreateVaultRequest) (*model.Vault, err
}

userDiscordID := ""
profile, err := e.svc.MochiProfile.GetByID(req.VaultCreator)
profile, err := e.svc.MochiProfile.GetByID(req.VaultCreator, e.cfg.MochiBotSecret)
if err != nil {
e.log.Fields(logger.Fields{"req": req}).Errorf(err, "[entity.GetVaults] svc.MochiProfile.GetByID() failed")
return nil, err
Expand Down Expand Up @@ -229,7 +229,7 @@ func (e *Entity) CreateConfigThreshold(req *request.CreateConfigThresholdRequest

func (e *Entity) AddTreasurerToVault(req *request.AddTreasurerToVaultRequest) (*model.VaultTreasurer, error) {
userDiscordID := ""
profile, err := e.svc.MochiProfile.GetByID(req.UserProfileID)
profile, err := e.svc.MochiProfile.GetByID(req.UserProfileID, "")
if err != nil {
e.log.Fields(logger.Fields{"req": req}).Errorf(err, "[entity.GetVaults] svc.MochiProfile.GetByID() failed")
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/entities/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ func (e *Entity) SumarizeBinanceAsset(req request.BinanceRequest) (*response.Wal
}

func (e *Entity) GetBinanceAssets(req request.GetBinanceAssetsRequest) (*response.GetBinanceAsset, error) {
profile, err := e.svc.MochiProfile.GetByID(req.Id)
profile, err := e.svc.MochiProfile.GetByID(req.Id, e.cfg.MochiBotSecret)
if err != nil {
e.log.Fields(logger.Fields{"req": req}).Error(err, "[entities.GetBinanceAssets] Failed to get profile")
return nil, err
Expand Down Expand Up @@ -1479,7 +1479,7 @@ func (e *Entity) parseSkymavisInternalTxnsData(data *response.WalletTransactionD
}

func (e *Entity) GetBinanceFuturePosition(req request.GetBinanceFutureRequest) ([]response.BinanceFuturePositionInformation, error) {
profile, err := e.svc.MochiProfile.GetByID(req.Id)
profile, err := e.svc.MochiProfile.GetByID(req.Id, e.cfg.MochiBotSecret)
if err != nil {
e.log.Fields(logger.Fields{"req": req}).Error(err, "[entities.GetBinanceFuturePosition] Failed to get profile")
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/service/mochiprofile/mochiprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,14 @@ func (m *MochiProfile) CreateProfileApiKey(profileAccessToken string) (*ProfileA
return &res.Data, nil
}

func (m *MochiProfile) GetByID(profileID string) (*GetProfileResponse, error) {
func (m *MochiProfile) GetByID(profileID, authorization string) (*GetProfileResponse, error) {
url := fmt.Sprintf("%s/api/v1/profiles/%s", m.config.MochiProfileServerHost, profileID)

res := GetProfileResponse{}
req := util.SendRequestQuery{
URL: url,
ParseForm: &res,
Headers: map[string]string{"Content-Type": "application/json"},
Headers: map[string]string{"Content-Type": "application/json", "Authorization": "Bearer " + authorization},
}
statusCode, err := util.SendRequest(req)
if err != nil || statusCode != http.StatusOK {
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/mochiprofile/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ type Service interface {
GetByDiscordID(discordID string, noFetchAmount bool) (*GetProfileResponse, error)
GetApiKeyByProfileID(profileID string) (*ProfileApiKeyResponse, error)
CreateProfileApiKey(profileAccessToken string) (*ProfileApiKeyResponse, error)
GetByID(profileID string) (*GetProfileResponse, error)
GetByID(profileID, authorization string) (*GetProfileResponse, error)
GetByIds(profileIds []string) ([]GetProfileResponse, error)
GetByDiscordIds(discordIds []string) ([]GetProfileResponse, error)
GetAllEvmAccount() ([]*EvmAssociatedAccount, error)
Expand Down