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

[OTE-793] modify affiliate api stubs #2234

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

jerryfan01234
Copy link
Contributor

@jerryfan01234 jerryfan01234 commented Sep 11, 2024

Changelist

Changed api stubs according to modified design doc:
https://www.notion.so/dydx/Affiliates-Indexer-spec-78b1383d1e9a40178f021c3df006a06d#7f1568bef1834413a199588b84b1ea63

stubs enable testing for FE team

Test Plan

[Describe how this PR was tested (if applicable)]

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Summary by CodeRabbit

  • New Features

    • Updated API endpoint from /affiliates/referral_code to /affiliates/metadata, enhancing the functionality to retrieve metadata.
    • Introduced new properties, isVolumeEligible and isAffiliate, in the API response for more comprehensive affiliate metrics.
  • Documentation

    • Renamed API documentation section from GetReferralCode to GetMetadata to reflect the updated functionality.
    • Updated API documentation to include the new fields and revised endpoint details.
  • Bug Fixes

    • Corrected test cases to align with the new /metadata endpoint, ensuring accurate validation of API responses.

Copy link

linear bot commented Sep 11, 2024

Copy link
Contributor

coderabbitai bot commented Sep 11, 2024

Walkthrough

The changes involve a significant update to the API's AffiliatesController, transitioning the endpoint from GET /referral_code to GET /metadata. This includes renaming the getReferralCode method to getMetadata, modifying the response structure to include new properties such as isVolumeEligible and isAffiliate, and updating the test suite accordingly. Additionally, the API documentation and Swagger schema have been revised to reflect these modifications, ensuring consistency across the API's interface and its documentation.

Changes

Files Change Summary
indexer/services/comlink/__tests__/controllers/api/v4/affiliates-controller.test.ts Updated test case from GET /referral_code to GET /metadata, changing the request path and description while maintaining the expected response status of 200.
indexer/services/comlink/src/controllers/api/v4/affiliates-controller.ts Renamed getReferralCode to getMetadata, updated the endpoint to /metadata, and modified the response structure to include isVolumeEligible, isAffiliate, and affiliateReferredTotalVolume. Adjusted router configuration and error handling accordingly.
indexer/services/comlink/src/types.ts Renamed AffiliateReferralCodeRequest to AffiliateMetadataRequest and AffiliateReferralCodeResponse to AffiliateMetadataResponse. Added isVolumeEligible and isAffiliate to the response interface.
indexer/services/comlink/public/api-documentation.md Renamed operation from GetReferralCode to GetMetadata, updated endpoint from /affiliates/referral_code to /affiliates/metadata, and added isVolumeEligible, isAffiliate, and affiliateReferredTotalVolume to response structure.
indexer/services/comlink/public/swagger.json Renamed AffiliateReferralCodeResponse to AffiliateMetadataResponse, added isVolumeEligible, isAffiliate, and affiliateReferredTotalVolume to schema, modified endpoint from /affiliates/referral_code to /affiliates/metadata, and updated operation ID from GetReferralCode to GetMetadata.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    participant Controller
    participant Service

    Client->>API: GET /metadata?address={address}
    API->>Controller: Call getMetadata(address)
    Controller->>Service: Fetch metadata for address
    Service-->>Controller: Return metadata
    Controller-->>API: Return response with metadata
    API-->>Client: Respond with 200 and metadata
Loading

🐰 In the meadow, changes bloom,
A new path shines, dispelling gloom.
From codes of referral, we now see,
Metadata flows, happy and free!
With totals added, insights grow,
Hopping forward, let progress flow! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range and nitpick comments (2)
indexer/services/comlink/__tests__/controllers/api/v4/affiliates-controller.test.ts (1)

6-6: Update the test case description.

The change from GET /referral_code to GET /metadata is approved as it aligns with the updated endpoint path.

However, please update the test case description to reflect the purpose of the /metadata endpoint. For example:

-it('should return referral code for a valid address string', async () => {
+it('should return metadata for a valid address string', async () => {
indexer/services/comlink/src/controllers/api/v4/affiliates-controller.ts (1)

Line range hint 32-40: LGTM, but replace the stub implementation with real logic.

The changes to the method signature and endpoint are approved.

However, the method is currently a stub implementation that does not contain any real logic. Please replace the stub implementation with real logic that retrieves the metadata for the given address.

Do you want me to open a GitHub issue to track the task of replacing the stub implementation with real logic?

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0856095 and b2d0e59.

Files selected for processing (3)
  • indexer/services/comlink/tests/controllers/api/v4/affiliates-controller.test.ts (1 hunks)
  • indexer/services/comlink/src/controllers/api/v4/affiliates-controller.ts (4 hunks)
  • indexer/services/comlink/src/types.ts (1 hunks)
Additional comments not posted (2)
indexer/services/comlink/src/types.ts (2)

707-712: Approve addition of affiliateReferredTotalVolume, verify property order change.

The addition of the affiliateReferredTotalVolume property to the AffiliateSnapshotResponseObject interface is approved as it expands the data structure to include total volume metrics related to referred affiliates.

However, please verify if the change in the order of the affiliateEarnings property is intentional and consistent with the order of properties across the codebase. If not, consider reverting the order change for consistency.


Line range hint 715-717: LGTM!

The addition of the new interface AffiliateTotalVolumeResponse with the totalVolume property of type number | null is approved.

@jerryfan01234 jerryfan01234 force-pushed the affiliates-comlink-modify-stubs branch from b2d0e59 to 368742b Compare September 11, 2024 15:39
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
indexer/services/comlink/src/controllers/api/v4/affiliates-controller.ts (1)

Line range hint 32-40: LGTM! Replace the stub with real logic.

The method renaming from getReferralCode to getMetadata and the endpoint change from /referral_code to /metadata are approved. These changes align with the updated specifications related to the Affiliates Indexer.

However, the method implementation is currently a stub. Please replace the stub with real logic to retrieve the metadata.

Do you want me to open a GitHub issue to track the task of replacing the stub with real logic?

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b2d0e59 and 368742b.

Files selected for processing (5)
  • indexer/services/comlink/tests/controllers/api/v4/affiliates-controller.test.ts (1 hunks)
  • indexer/services/comlink/public/api-documentation.md (8 hunks)
  • indexer/services/comlink/public/swagger.json (3 hunks)
  • indexer/services/comlink/src/controllers/api/v4/affiliates-controller.ts (4 hunks)
  • indexer/services/comlink/src/types.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • indexer/services/comlink/tests/controllers/api/v4/affiliates-controller.test.ts
Files skipped from review as they are similar to previous changes (1)
  • indexer/services/comlink/src/types.ts
Additional comments not posted (9)
indexer/services/comlink/src/controllers/api/v4/affiliates-controller.ts (2)

Line range hint 106-141: LGTM!

The router configuration for the /metadata endpoint has been updated correctly to reflect the changes in the getMetadata method. The error handling and timing statistics have also been adjusted to align with the new method name and endpoint.

The changes are approved.


71-76: LGTM!

The response structure has been updated to include a new property, affiliateReferredTotalVolume, in the AffiliateSnapshotResponseObject. This addition enhances the data returned by the controller, providing more comprehensive insights into affiliate metrics.

The changes are approved.

indexer/services/comlink/public/swagger.json (3)

274-276: LGTM!

The addition of the affiliateReferralCode property to the AffiliateSnapshotResponseObject schema is approved. It aligns with the goal of providing more comprehensive affiliate data in the API response.


297-299: LGTM!

The addition of the affiliateReferredTotalVolume property to the AffiliateSnapshotResponseObject schema is approved. It enhances the data model by including total volume metrics related to referred trades, providing more insights into affiliate performance.


1676-1678: LGTM, but verify the endpoint usage.

The API endpoint and operation ID changes are approved.

However, ensure that this change is thoroughly tested to confirm that it behaves as expected and that all API calls to the affiliate metadata endpoint have been updated to use the new path.

Run the following script to verify the endpoint usage:

Verification successful

Endpoint change successfully implemented and tested.

The new endpoint /affiliates/metadata is correctly used in the API definition, documentation, and test files, indicating that the change has been thoroughly integrated and tested.

  • Files updated with new endpoint:
    • indexer/services/comlink/public/swagger.json
    • indexer/services/comlink/public/api-documentation.md
    • indexer/services/comlink/__tests__/controllers/api/v4/affiliates-controller.test.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all API calls to the affiliate metadata endpoint use the new path.

# Test: Search for the endpoint usage. Expect: Only occurrences of the new path.
rg --type typescript -A 5 $'/affiliates/metadata'

Length of output: 83


Script:

#!/bin/bash
# Description: Verify all API calls to the affiliate metadata endpoint use the new path.

# Test: Search for the endpoint usage without specifying a file type.
rg -A 5 '/affiliates/metadata'

Length of output: 2436

indexer/services/comlink/public/api-documentation.md (4)

Line range hint 371-419: LGTM!

The code changes that rename the GetReferralCode operation to GetMetadata and update the corresponding API endpoint and parameters look good. The changes align well with the broader shift in the API's functionality.


Line range hint 4074-4095: Looks good!

The addition of the new affiliateReferredTotalVolume property and the repositioning of the affiliateReferredNetProtocolEarnings property in the AffiliateSnapshotResponseObject schema look good. The changes match the description in the summary and enhance the data returned by the API.


4110-4115: LGTM!

The updates to the affiliateList array in the AffiliateSnapshotResponse schema look good. The changes ensure the AffiliateSnapshotResponse schema matches the updated AffiliateSnapshotResponseObject schema.


Line range hint 1-5000: Overall, the changes look great!

The modifications made to the API documentation, including renaming operations, updating endpoints, adjusting request parameters, and modifying response schemas, are consistent and align well with the broader functionality shift. The changes enhance the data returned by the API and improve its overall structure.

Great job on this PR! The changes are approved.

@jerryfan01234 jerryfan01234 force-pushed the affiliates-comlink-modify-stubs branch from 368742b to d834a24 Compare September 11, 2024 18:02
@jerryfan01234 jerryfan01234 force-pushed the affiliates-comlink-modify-stubs branch from d834a24 to e61c6c8 Compare September 11, 2024 18:02
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 368742b and e61c6c8.

Files selected for processing (5)
  • indexer/services/comlink/tests/controllers/api/v4/affiliates-controller.test.ts (1 hunks)
  • indexer/services/comlink/public/api-documentation.md (12 hunks)
  • indexer/services/comlink/public/swagger.json (4 hunks)
  • indexer/services/comlink/src/controllers/api/v4/affiliates-controller.ts (5 hunks)
  • indexer/services/comlink/src/types.ts (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • indexer/services/comlink/tests/controllers/api/v4/affiliates-controller.test.ts
  • indexer/services/comlink/src/controllers/api/v4/affiliates-controller.ts
Additional context used
LanguageTool
indexer/services/comlink/public/api-documentation.md

[misspelling] ~4027-~4027: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...="schemaaffiliatemetadataresponse"> <...

(EN_A_VS_AN)


[misspelling] ~4028-~4028: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ..."schema_AffiliateMetadataResponse"> ...

(EN_A_VS_AN)

Additional comments not posted (13)
indexer/services/comlink/src/types.ts (4)

672-674: LGTM!

The interface changes are approved.


690-694: LGTM!

The interface changes are approved.


Line range hint 717-719: LGTM!

The code is approved.


696-698: LGTM, but verify the property usage.

The interface changes are approved.

However, ensure that this change is thoroughly tested to confirm that it behaves as expected and that all usages of the address property have been updated to handle the non-nullable type.

Run the following script to verify the property usage:

indexer/services/comlink/public/swagger.json (3)

243-259: LGTM!

The changes to the AffiliateMetadataResponse schema definition look good. The new isVolumeEligible and isAffiliate boolean properties have been added to provide additional metadata, and the required array has been updated accordingly.


Line range hint 273-318: LGTM!

The changes to the AffiliateSnapshotResponseObject schema definition look good. The new affiliateReferralCode string property and affiliateReferredTotalVolume number property have been added to provide additional data points in the affiliate snapshot response, and the required array has been updated accordingly.


Line range hint 1682-1706: LGTM, but verify the API usage.

The changes to the /affiliates/metadata endpoint definition look good. The endpoint path, operationId, and response schema have been updated to reflect the broader scope of retrieving affiliate metadata.

However, ensure that this change is thoroughly tested to confirm that it behaves as expected and that all API calls have been updated to use the new endpoint.

Run the following script to verify the API usage:

Verification successful

API Usage Verified: Transition to /affiliates/metadata Complete

The new /affiliates/metadata endpoint is correctly used across the codebase, including in the swagger.json, API documentation, and test files. There are no occurrences of the old /affiliates/referral_code endpoint, confirming that the transition has been successfully completed.

  • indexer/services/comlink/public/swagger.json
  • indexer/services/comlink/public/api-documentation.md
  • indexer/services/comlink/__tests__/controllers/api/v4/affiliates-controller.test.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all API calls use the new `/affiliates/metadata` endpoint.

# Test: Search for the old and new endpoint usage. Expect: Only occurrences of the new endpoint.
rg --type-add 'api:*.go' --type api -A 5 $'/affiliates/referral_code|/affiliates/metadata'

Length of output: 91


Script:

#!/bin/bash
# Description: Verify all API calls use the new `/affiliates/metadata` endpoint across all file types.

# Test: Search for the old and new endpoint usage across all files. Expect: Only occurrences of the new endpoint.
rg '/affiliates/referral_code|/affiliates/metadata' -A 5

Length of output: 2464

indexer/services/comlink/public/api-documentation.md (6)

371-371: LGTM!

The code segment is approved.


Line range hint 373-387: LGTM!

The renaming of the operation and endpoint to GetMetadata looks good.


Line range hint 405-419: LGTM!

The API endpoint update in the code samples looks good.


433-435: LGTM!

The addition of the isVolumeEligible and isAffiliate fields to the response looks good.


443-443: LGTM!

The response schema reference update looks good.


Line range hint 4025-4047: LGTM!

The new schema definition for AffiliateMetadataResponse looks good.

Tools
LanguageTool

[misspelling] ~4027-~4027: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...="schemaaffiliatemetadataresponse"> <...

(EN_A_VS_AN)


[misspelling] ~4028-~4028: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ..."schema_AffiliateMetadataResponse"> ...

(EN_A_VS_AN)

Comment on lines 705 to 715

export interface AffiliateSnapshotResponseObject {
affiliateAddress: string,
affiliateEarnings: number,
affiliateReferralCode: string,
affiliateEarnings: number,
affiliateReferredTrades: number,
affiliateTotalReferredFees: number,
affiliateReferredUsers: number,
affiliateReferredNetProtocolEarnings: number,
affiliateReferredTotalVolume: number,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

Inconsistent affiliateEarnings Type Definition

The affiliateEarnings property is defined as a number in the AffiliateSnapshotResponseObject interface but is still defined as a string in several files within the postgres package. This inconsistency could lead to type mismatches and potential runtime errors.

  • Files with string type for affiliateEarnings:
    • indexer/packages/postgres/src/types/db-model-types.ts
    • indexer/packages/postgres/src/types/affiliate-info-types.ts
    • indexer/packages/postgres/src/models/affiliate-info-model.ts
    • indexer/packages/postgres/__tests__/helpers/constants.ts

Please review and update these files to ensure consistency with the number type definition in the AffiliateSnapshotResponseObject interface.

Analysis chain

LGTM, but verify the property usages.

The interface changes are approved.

However, ensure that these changes are thoroughly tested to confirm that they behave as expected and that all usages of the modified properties have been updated to handle the number type.

Run the following script to verify the property usages:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of the modified properties in `AffiliateSnapshotResponseObject` handle the `number` type.

# Test: Search for the interface usage. Expect: No type errors.
fd --type typescript --exec sh -c 'npx tsc --noEmit "$1"' sh {} \;

Length of output: 249


Script:

#!/bin/bash
# Description: Search for the usage of `AffiliateSnapshotResponseObject` and its properties in TypeScript files.

# Find all TypeScript files and search for the usage of `AffiliateSnapshotResponseObject`.
fd -e ts | xargs rg 'AffiliateSnapshotResponseObject'

# Search for the usage of each property to ensure they are handled as numbers.
properties=(
  "affiliateEarnings"
  "affiliateReferredTrades"
  "affiliateTotalReferredFees"
  "affiliateReferredUsers"
  "affiliateReferredNetProtocolEarnings"
  "affiliateReferredTotalVolume"
)

for property in "${properties[@]}"; do
  echo "Searching for property: $property"
  fd -e ts | xargs rg "$property"
done

Length of output: 4122

});

expect(response.status).toBe(200);
expect(response.body).toEqual({
referralCode: 'TempCode123',
isVolumeEligible: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this field needed since referral code already checks the volume eligibility before returning the code?

Comment on lines +17 to +18
isVolumeEligible: true,
isAffiliate: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will this be used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets sync offline, had discussion with Bill and Yi on this

@jerryfan01234 jerryfan01234 merged commit e48308b into main Sep 11, 2024
16 checks passed
@jerryfan01234 jerryfan01234 deleted the affiliates-comlink-modify-stubs branch September 11, 2024 19:40
@jerryfan01234 jerryfan01234 restored the affiliates-comlink-modify-stubs branch September 12, 2024 16:42
affanv14 pushed a commit that referenced this pull request Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants