2.1 KiB
2.1 KiB
MOC Number Auto-Generation (Global Numbering)
Date: 2025-12-15 Project: lego-instructions-manager Status: resolved Tags: moc, numbering, flask-blueprint, api, services
Context
MOCs (My Own Creations) have no official set number, so users were typing IDs by hand, which led to gaps and duplicates. Jess wanted the app to suggest the next MOC number automatically.
Key Decisions
- Dedicated
MOCNumberGeneratorservice + MOC blueprint — keeps numbering logic out of the set routes and makes it testable. - Global numbering across all users is the default (
user_scoped=false). Per-user sequences were built first and then rejected: they produce the same "MOC-0001" for different users, so IDs aren't unique system-wide. - Zero-padded format
MOC-0001— sorts correctly as text. - Auto-fill with a refresh button on the form — the number is suggested, not forced, and can be regenerated if another user took it meanwhile.
- Validation endpoint so manually entered MOC numbers are checked for format and uniqueness.
Technical Details
- Service:
MOCNumberGenerator(exported from the services package). - Blueprint: MOC API routes for "next number" and "validate", registered in the Flask app factory.
- Format:
MOC-+ 4-digit zero-padded sequence. - Config flag:
user_scoped(defaultfalse).
Code Changes
app/services/— MOC auto-generation service; exported in services__init__.app/routes/— MOC blueprint with generation/validation routes; registered in the app.- Set form template/JS — auto-fill MOC number with refresh button.
- Docs — feature documentation,
FEATURE_UPDATE_SUMMARY.md.
Open Questions / Next Steps
- Two users generating at the same moment could get the same suggestion; the unique check on save is the safeguard — confirm there's a DB-level unique constraint.
Artifacts
cd0b5f1— Add MOC generator with leading zeros support (MOC-0001 format)fdb9211— Change to GLOBAL numbering as default (user_scoped=false)944a679— Add MOC auto-generation service with sequential numbering