feat(router): add blocklist count and lookup endpoints - #13887
Open
ayush22667 wants to merge 2 commits into
Open
feat(router): add blocklist count and lookup endpoints#13887ayush22667 wants to merge 2 commits into
ayush22667 wants to merge 2 commits into
Conversation
Add GET /blocklist/count, returning a total plus a counts_by_length breakdown aggregated with GROUP BY length(fingerprint_id), and GET /blocklist/lookup, a single yes/no check for one value across every data_kind. Both resolve the business profile the same way add/delete do, via get_profile_id_from_business_details, so X-Profile-Id falls back to default_profile and the profile is validated against the caller's merchant. Bound the lookup value with a new BlocklistLookupData newtype (LengthString<20, 1>), 20 being the longest a fingerprint_id can be, and collapse the CardBin -> [CardBin, ExtendedCardBin] expansion duplicated at six call sites into expand_data_kinds.
Changed Files
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Change
Description
Two read-only endpoints on the profile-scoped blocklist:
GET /blocklist/count?data_kind=<kind>returns{ "data_kind": "card_bin", "total_count": 16, "counts_by_length": { "6": 12, "8": 3, "10": 1 } }counts_by_lengthbuckets by BIN digit length, computed in Postgres withGROUP BY length(fingerprint_id)rather than paging every row (and itsmetadatablob) into theapp to count them.
GET /blocklist/lookup?data=<value>returns{ "data": "411111", "blocked": true }- one yes/nocheck for a single value, across every
data_kind.Both resolve the business profile exactly as
add/deletealready do, throughget_profile_id_from_business_details:X-Profile-Idwhen present, otherwise the merchant'sdefault_profile, otherwiseIR_04. That also validates the profile belongs to the caller'smerchant, so one merchant cannot count or probe another's entries.
Two supporting changes:
common_utils::types::BlocklistLookupData, aLengthString<20, 1>newtype bounding the lookupvalue at the API boundary. 20 is the longest a
fingerprint_idcan legitimately be - a card BIN isat most 10 digits, and a locker fingerprint id is a 20-character nano id. Validating in the type
rather than in core means a future caller cannot skip it.
expand_data_kindsindiesel_models, collapsing theCardBin -> [CardBin, ExtendedCardBin]expansion that was copy-pasted at six call sites in that file.
Additional Changes
Two additive endpoints; no existing request or response shape changes, no schema change, no config
change. Both new routes sit inside the existing
#[cfg(all(feature = "olap", feature = "v1"))]blocklist scope, so there is no v2 surface.
Motivation and Context
GET /blocklistpages full rows, which is the only way to read the blocklist today. Answering "howmany entries do I have, and of what BIN lengths?" means paging everything and counting client-side,
and there is no way at all to ask "is this one value blocked?" without scanning. Both are cheap
questions that deserve cheap answers, and
counts_by_lengthin particular is what makes the 6-10digit BIN work legible to a merchant.
Linked Issues
How did you test it?
Compile-verified under
v1:cargo checkpasses forcommon_utils,api_models,diesel_models,routerandopenapi;cargo +nightly fmtclean; no lint warnings from the new code.Postman requests covering both endpoints are staged in the
Blocklist Profile Scopingfolder(
13. Count blocked BINs,14. Look up whether a BIN is blocked), asserting status, thatcounts_by_lengthsums tototal_count, and that a BIN blocked under one profile reportsblocked: truefor that profile.Not yet done, and worth a reviewer's attention before merge:
from the response types, not observed output.
just check_v2,just clippyandjust clippy_v2have not been run.common_utilsis touchedand feature-gated, so v2 is the one to check.
Checklist
cargo +nightly fmt --allcargo clippy