refactor: split buzz/api into domain packages - #295
Open
harshtandiya wants to merge 4 commits into
Open
Conversation
buzz/api/__init__.py held 1364 lines covering booking, tickets, sponsorships, check-in, account, campaigns and coupons in one module. Since a Frappe endpoint's URL is its dotted module path, that layout also made the public API surface unreadable. Each domain now owns a package, so an endpoint's URL names its domain: buzz.api.booking.process_booking rather than buzz.api.process_booking. forms.py, auth.py and proposals.py become packages of the same shape. Function bodies are unchanged; this is relocation only. Landed alongside are api/schemas.py and api/exceptions.py, the pydantic and error base classes later PRs build on, currently unused. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Follows the backend split: every createResource url moves from buzz.api.<fn> to buzz.api.<domain>.<fn>. String changes only. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
The base error carried only http_status_code, so every call site still had
to pass its own message string and no default copy existed.
Subclasses now declare title and message as class attributes, raised via a
throw() classmethod:
class AlreadyRegistered(Conflict):
title = _lt("Already Registered")
message = _lt("You have already registered your interest.")
AlreadyRegistered.throw()
throw() routes through frappe.throw so the text lands in _server_messages,
which is what the dashboard reads as err.messages[0]. A bare raise skips
msgprint and leaves the user with "Internal Server Error" — covered by a
test so the distinction stays visible.
Messages use _lt rather than _ because class bodies run at import, before a
request has a language. frappe's translation extractor already scans _lt.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
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.
Splits the 1364-line
buzz/api/__init__.pyinto one package per domain. In Frappe the module path is the URL, so this also renames every endpoint:buzz.api.process_booking→buzz.api.booking.process_booking.Move only. Bodies are verbatim — no models, no service classes, no dead-code removal. Those are per-domain follow-ups, and they stay independent because
api/__init__.pyis already empty by then.0856863adds the shared bases the follow-ups need. Two non-obvious bits:APIResponse.__json__—json_handlerchecks__json__beforeIterable, and BaseModel is iterable. Without it a returned model serializes as(key, value)pairs.BuzzAPIError.throw()— a bareraiseskipsmsgprint, so nothing lands in_server_messagesand the dashboard shows "Internal Server Error".throw()makes that unreachable. Copy uses_ltbecause class bodies run at import, before a request has a language.No back-compat shims. Callers updated:
hooks.py,event_booking.py, 6 test modules (incl. 18patch("buzz.api...")sites), 18 dashboard files,ARCHITECTURE.md.Checks: 171 tests green across the 8 affected modules, +7 new in
test_exceptions. All 31 endpoint paths resolve viafrappe.handler.get_attr.ruff/pre-commit/yarn typecheckclean. No dev server was up, so no live devtools diff.Deferred:
booking/is 679 lines,tickets/324 — both over the 300 target. Splitting them is scope for their own PRs.🤖 Generated with Claude Code