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(user): fetch profile_id for sample data #3358

Merged
merged 7 commits into from
Jan 18, 2024

Conversation

apoorvdixit88
Copy link
Contributor

@apoorvdixit88 apoorvdixit88 commented Jan 16, 2024

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

Currently for user with multiple business profiles. We are getting 500 if the profile id is not passed in the payload. Therefore, need to fetch the profile_id (the first one) from list of business profiles, for the sample data generation.

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

Getting 500, for users with multiple business profiles for sample data generation.

How did you test it?

Singup

curl --location 'http://localhost:8080/user/signup' \
--header 'Content-Type: application/json' \
--header 'Cookie: token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMWZjNzgyOTUtM2JiMy00OGJjLThlZDgtNzFjMzVjMzMxYWU2IiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNjk3NzE2ODcwIiwicm9sZV9pZCI6Im1lcmNoYW50X2FkbWluIiwiZXhwIjoxNjk3ODg5NjcxLCJvcmdfaWQiOiJvcmdfejQ5ZExMeTdmbllUODN5TDY3clEifQ.CJzEQ2qbhn-qUiiVBSdvCJiLvWp-5wCF9R54gth6QbQ' \
--data-raw '{
    "email": "[email protected]",
    "password": "Test@12345",
    "country": "IN"
}'

Creating New business profile:
pass current merchant_id for the endpoint

curl --location 'http://localhost:8080/account/merchant_1705399107/business_profile' \
--header 'Content-Type: application/json' \
--header 'Cookie: token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMWZjNzgyOTUtM2JiMy00OGJjLThlZDgtNzFjMzVjMzMxYWU2IiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNjk3NzE2ODcwIiwicm9sZV9pZCI6Im1lcmNoYW50X2FkbWluIiwiZXhwIjoxNjk3ODg5NjcxLCJvcmdfaWQiOiJvcmdfejQ5ZExMeTdmbllUODN5TDY3clEifQ.CJzEQ2qbhn-qUiiVBSdvCJiLvWp-5wCF9R54gth6QbQ' \
--header 'Authorization: Bearer JWT' \
--data '{
    "profile_name": "default5"
}'

Generate Sample Data:

curl --location 'http://localhost:8080/user/sample_data' \
--header 'Content-Type: application/json' \
--header 'Cookie: token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMWZjNzgyOTUtM2JiMy00OGJjLThlZDgtNzFjMzVjMzMxYWU2IiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNjk3NzE2ODcwIiwicm9sZV9pZCI6Im1lcmNoYW50X2FkbWluIiwiZXhwIjoxNjk3ODg5NjcxLCJvcmdfaWQiOiJvcmdfejQ5ZExMeTdmbllUODN5TDY3clEifQ.CJzEQ2qbhn-qUiiVBSdvCJiLvWp-5wCF9R54gth6QbQ' \
--header 'Authorization: Bearer JWT' \
--data '{
}'

Response will be 200

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible
  • I added a CHANGELOG entry if applicable

@apoorvdixit88 apoorvdixit88 added C-bug Category: Bug S-waiting-on-review Status: This PR has been implemented and needs to be reviewed A-users Area: Users labels Jan 16, 2024
@apoorvdixit88 apoorvdixit88 self-assigned this Jan 16, 2024
@apoorvdixit88 apoorvdixit88 requested a review from a team as a code owner January 16, 2024 10:08
Comment on lines 55 to 65
let business_profile = match state
.store
.list_business_profile_by_merchant_id(&merchant_id)
.await
.change_context(SampleDataError::InternalServerError)
.attach_printable("Failed to get business profile")
.map(|profiles| profiles.first().cloned())?
{
Some(profile) => profile,
None => return Err(SampleDataError::InternalServerError.into()),
};
Copy link
Member

@Narayanbhat166 Narayanbhat166 Jan 16, 2024

Choose a reason for hiding this comment

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

let the previous logic be there, add this logic of listing business profiles on top of that.
If profile_id cannot be found by the previous logic, then apply the list logic

Copy link
Member

Choose a reason for hiding this comment

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

This is because, let's have the option of passing the profile_id in the request, we might need it later on.

ThisIsMani
ThisIsMani previously approved these changes Jan 16, 2024
ThisIsMani
ThisIsMani previously approved these changes Jan 16, 2024
.attach_printable("Failed to get business profile")?;
{
Ok(id) => id.clone(),
Err(_) => {
Copy link
Member

Choose a reason for hiding this comment

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

log this error

@likhinbopanna likhinbopanna added this pull request to the merge queue Jan 18, 2024
@likhinbopanna likhinbopanna removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Jan 18, 2024
Merged via the queue into main with commit 2f693ad Jan 18, 2024
9 checks passed
@likhinbopanna likhinbopanna deleted the fix-profile-id-for-sample-data branch January 18, 2024 07:36
pixincreate added a commit that referenced this pull request Jan 18, 2024
* 'main' of github.com:juspay/hyperswitch:
  feat(users): Added get role from jwt api (#3385)
  feat(users): Add `preferred_merchant_id` column and update user details API (#3373)
  chore(version): 2024.01.18.1
  refactor(core): add locker config to enable or disable locker  (#3352)
  fix(connector): [Cashtocode] update amount from i64 to f64 in webhook payload (#3382)
  fix(metrics): Add TASKS_ADDED_COUNT and TASKS_RESET_COUNT metrics in router scheduler flow (#3189)
  fix(connector): Trustpay zen error mapping (#3255)
  fix(user): fetch profile_id for sample data (#3358)
  refactor(connector): [Volt] Refactor Payments and Refunds Webhooks (#3377)
  chore(version): 2024.01.18.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-users Area: Users C-bug Category: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: sample data generation with profile id
4 participants