feat(backend): add publish readiness contract and pricing diagnostics

add backend readiness contract for publish prechecks

add pricing diagnostics to explain publish-blocking conditions
make publish decisions more explicit and easier to debug for clients
This commit is contained in:
greebo
2026-03-19 20:29:58 +03:00
parent 7b6c12f924
commit 8d4255181b
11 changed files with 251 additions and 301 deletions

View File

@@ -1,3 +1,5 @@
from fastapi import HTTPException, status
from app.repositories.scheme_versions import get_current_scheme_version
from app.repositories.schemes import get_scheme_record_by_scheme_id
from app.services.api_errors import raise_conflict
@@ -27,19 +29,20 @@ async def get_current_draft_context(
)
if version.status != "draft" or scheme.status != "draft":
raise_conflict(
code="draft_not_editable",
message="Current scheme version is not editable because it is not in draft state",
scheme_status=scheme.status,
scheme_version_status=version.status,
actual_scheme_version_id=version.scheme_version_id,
raise HTTPException(
status_code=status.HTTP_409_CONFLICT,
detail="Current scheme version is not editable because it is not in draft state",
)
if expected_scheme_version_id and expected_scheme_version_id != version.scheme_version_id:
raise_conflict(**build_stale_draft_version_detail(
expected_scheme_version_id=expected_scheme_version_id,
actual_scheme_version_id=version.scheme_version_id,
))
raise_conflict(
code="stale_draft_version",
message="Draft scheme version is stale. Reload current draft state before applying mutation.",
details={
"expected_scheme_version_id": expected_scheme_version_id,
"actual_scheme_version_id": version.scheme_version_id,
},
)
return scheme, version