Skip to content

Commit d33d22e

Browse files
Merge pull request #58 from RandomProgramm3r/develop
refactor(core, business): unify pagination and promo serializers with enhanced validation Introduces a shared pagination serializer and consolidates promo-related serializers, validation logic, and country-code handling to improve structure, DRY-ness, and maintainability. Key changes: - **Core pagination** - Add `BaseLimitOffsetPaginationSerializer` to centralize `limit`/`offset` validation for all endpoints. - **Promo serializers overhaul** - Collapse `PromoValidator` into serializers to co‑locate validation and data representation. - Create `BasePromoSerializer` to extract common fields and methods, reducing duplication across create, detail, and read-only serializers. - Implement `CountryField` and `MultiCountryField` for reusable ISO 3166‑1 α‑2 code validation. - Simplify `PromoListQuerySerializer` by inheriting from the base pagination serializer and using `MultiCountryField`. - **Enhanced promo validation** - Support partial updates (`PATCH`), inferring `mode` from instance when absent in request data. - Prevent lowering `max_count` below the current `used_count`. - Ensure `get_used_codes_count` returns accurate counts for `COMMON`‑mode promotions.
2 parents c9bd58f + 6d2482a commit d33d22e

File tree

5 files changed

+284
-354
lines changed

5 files changed

+284
-354
lines changed

promo_code/business/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ def get_comment_count(self) -> int:
119119
def get_used_codes_count(self) -> int:
120120
if self.mode == business.constants.PROMO_MODE_UNIQUE:
121121
return self.unique_codes.filter(is_used=True).count()
122-
# TODO: COMMON Promo
123-
return 0
122+
return self.used_count
124123

125124
@property
126125
def get_available_unique_codes(self) -> list[str] | None:

0 commit comments

Comments
 (0)