Skip to content

refactor: extract shared utilities for duplicated code patterns - #3

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1783177280-dedupe-shared-utils
Open

refactor: extract shared utilities for duplicated code patterns#3
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1783177280-dedupe-shared-utils

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Refactors three duplicated patterns into shared utilities. Behavior is unchanged — all 7 existing tests pass and API serialization (category_ru, emoji, discount) is verified identical.

1. models.py — duplicated computed fields. Box and Order each defined byte-identical category_ru/emoji computed properties. Hoisted into a shared base both now inherit:

class CategoryLabeled(BaseModel):
    category: BoxCategory
    @computed_field @property
    def category_ru(self) -> str: return CATEGORY_RU.get(self.category, self.category)
    @computed_field @property
    def emoji(self) -> str: return CATEGORY_EMOJI.get(self.category, _DEFAULT_EMOJI)

class Box(CategoryLabeled): ...   # keeps its own `discount`
class Order(CategoryLabeled): ...

2. db.py — repeated SQL / row-mapping. Both _box_from_row and _order_from_row re-derived partner fields with the same p["..."] if p else <default> fallbacks; the case-insensitive code lookup was duplicated across order_by_code/redeem; and SELECT * FROM {orders,boxes} WHERE id=? was repeated in create/redeem/refund/box paths. Extracted helpers:

_partner_fields(c, pid)      # -> {partner_name, district, address, rating} with fallbacks
_order_row_by_code(c, code)  # SELECT ... WHERE code=? (code.strip().upper())
_order_row_by_id(c, id)
_box_row_by_id(c, id)

3. app/static/index.html — repeated fetch boilerplate. The let x=[];try{x=await get(url)}catch(e){} idiom appeared in every loader. Replaced with one helper:

const getSafe=(u,fallback=[])=>get(u).catch(()=>fallback);

used by loadStore, loadPartner, loadPartnerData, loadAdmin.

No functional changes; net -47/+59 lines across 3 files.

Link to Devin session: https://app.devin.ai/sessions/30bd78e5e39c432abf0292dcecc4d4eb
Requested by: @wpalish

- models: hoist duplicated category_ru/emoji computed fields into a
  shared CategoryLabeled base (Box, Order inherit)
- db: add _partner_fields, _order_row_by_code, _order_row_by_id,
  _box_row_by_id helpers to remove repeated SQL/row-mapping
- frontend: add getSafe() to collapse repeated try/catch GET calls

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@wpalish wpalish self-assigned this Jul 4, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

wpalish pushed a commit that referenced this pull request Jul 16, 2026
…арточка); +контраст футера

По UX-ревью:
- #1 localStorage-нотис был плавающей центр-карточкой (читалось как «глюк»
  поверх секций) → тонкая полоса во всю ширину, приклеена к низу (над bottom-nav
  на мобиле, к краю на десктопе). Показ один раз (флаг ym_cookies уже был).
- #6 контраст копирайта/FAQ-текста в футере поднят (.6→.78, .7→.82 opacity) —
  запас под WCAG AA.
Уже было в коде: #4 срочность («🔥 осталось N» + окно выдачи), #7 соцсети на
светлом --on-ink (не бледные). Требуют ассетов (отдельно): #2 превью карты,
#3 логотипы партнёров/отзывы, #5 лого-марка, #8 PWA-бейджи.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant