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

feat: add a domain type for customer_id #4705

Merged
merged 19 commits into from
May 30, 2024

Conversation

Narayanbhat166
Copy link
Member

@Narayanbhat166 Narayanbhat166 commented May 20, 2024

Type of Change

  • New feature

Description

This PR adds an id type to validate the reference id that we receive in the api.

Additional Changes

  • This PR modifies the API contract
    Validations are added to the customer id
  • Max length of 64 characters
  • Min length of 1 character
  • Should only contain alphanumeric characters and - and _.

Motivation and Context

How did you test it?

  • Create a payment with valid customer_id - Success
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_eitT2K5ygdDjO4uYYKCMoZP0VWK9L9IkLJlfCjbaDzUygNUimJUWKTJx2IMLFYW6' \
--data '{
    "amount": 6540,
    "currency": "USD",
    "customer_id": "valid_customer_id"
}'
  • customer_id with invalid characters
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_eitT2K5ygdDjO4uYYKCMoZP0VWK9L9IkLJlfCjbaDzUygNUimJUWKTJx2IMLFYW6' \
--data '{
    "amount": 6540,
    "currency": "USD",
    "customer_id": "invalid id"
}'
{
    "error": "Json deserialize error: value `invalid id` contains invalid character ` ` at line 5 column 1"
}
  • customer_id with min length
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_eitT2K5ygdDjO4uYYKCMoZP0VWK9L9IkLJlfCjbaDzUygNUimJUWKTJx2IMLFYW6' \
--data '{
    "amount": 6540,
    "currency": "USD",
    "customer_id": ""
}'
{
    "error": "Json deserialize error: the minimum required length for this field is 1 at line 5 column 1"
}
  • customer_id with max length
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_eitT2K5ygdDjO4uYYKCMoZP0VWK9L9IkLJlfCjbaDzUygNUimJUWKTJx2IMLFYW6' \
--data '{
    "amount": 6540,
    "currency": "USD",
    "customer_id": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv"
}'
{
    "error": "Json deserialize error: the maximum allowed length for this field is 64 at line 5 column 1"
}

Unit test cases
image

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

@Narayanbhat166 Narayanbhat166 added the A-core Area: Core flows label May 20, 2024
@Narayanbhat166 Narayanbhat166 added this to the May 2024 Release milestone May 20, 2024
@Narayanbhat166 Narayanbhat166 self-assigned this May 20, 2024
@Narayanbhat166 Narayanbhat166 requested a review from a team as a code owner May 20, 2024 13:18
@Narayanbhat166 Narayanbhat166 requested review from a team as code owners May 20, 2024 14:15
crates/common_utils/src/id_type.rs Outdated Show resolved Hide resolved
crates/common_utils/src/id_type.rs Outdated Show resolved Hide resolved
@Narayanbhat166 Narayanbhat166 changed the title feat: add api model type for customer_id feat: add a domain type for customer_id May 24, 2024
@Narayanbhat166 Narayanbhat166 force-pushed the 5093-feature-create-a-domain-type-for-customer_id branch from e905b18 to d810206 Compare May 24, 2024 10:31
@Narayanbhat166 Narayanbhat166 requested review from a team as code owners May 24, 2024 10:31
sahkal
sahkal previously approved these changes May 28, 2024
hrithikesh026
hrithikesh026 previously approved these changes May 29, 2024
jarnura
jarnura previously approved these changes May 29, 2024
apoorvdixit88
apoorvdixit88 previously approved these changes May 29, 2024
Comment on lines +15 to +17
self.customer_id
.clone()
.map(|customer_id| ApiEventsType::Customer { customer_id })
Copy link
Member

Choose a reason for hiding this comment

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

we can store the new type inside ApiEvents as long as it implements valid serialization

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I have already added the new type for ApiEvents

customer_id: id_type::CustomerId,

The change here is that the mandatory field is made optional

@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue May 30, 2024
Merged via the queue into main with commit 93d61d1 May 30, 2024
10 checks passed
@Gnanasundari24 Gnanasundari24 deleted the 5093-feature-create-a-domain-type-for-customer_id branch May 30, 2024 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants