Stelle den Frontend-MVP und die v0.3-API auf develop bereit, damit Dev API und PWA zusammen deployen.
Deploy Development / deploy (push) Successful in 1m19s
Test Suite / pytest-backend (push) Successful in 31s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-checks (push) Successful in 28s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-04 13:04:59 +02:00
1 parent 827e6a2a11
commit b276758ee1
152 files changed
+25846 -34

No files matched your search

View File
Whitespace-only changes.
+125
View File
@@ -0,0 +1,125 @@
from uuid import UUID
from fastapi import APIRouter, Depends, Query
from sqlalchemy.orm import Session
from app.api.schemas import (
CriterionDefinitionIn,
CriterionMappingIn,
CriterionMappingPatch,
DiscoverySearchIn,
DiscoverySearchPatch,
SourceAttributeMappingIn,
SourceAttributeMappingPatch,
)
from app.persistence.db import get_session
from app.services.catalog_service import CatalogService
from app.services.discovery_service import (
CriterionDefinitionService,
CriterionMappingService,
DiscoverySearchService,
SourceAttributeMappingService,
TaxonomyService,
)
router = APIRouter(prefix="/api/v1")
@router.get("/sources/{source_id}/categories")
def list_source_categories(source_id: str, session: Session = Depends(get_session)):
return {"items": CatalogService(session).source_categories(source_id)}
@router.post("/sources/{source_id}/categories/{category}/discover-taxonomy", status_code=201)
def discover_taxonomy(source_id: str, category: str, session: Session = Depends(get_session)):
return TaxonomyService(session).discover(source_id, category)
@router.get("/sources/{source_id}/categories/{category}/filters")
def list_filters(source_id: str, category: str, session: Session = Depends(get_session)):
return TaxonomyService(session).filters(source_id, category)
@router.post("/criterion-definitions", status_code=201)
def create_criterion_definition(payload: CriterionDefinitionIn, session: Session = Depends(get_session)):
return CriterionDefinitionService(session).create(payload.model_dump())
@router.get("/criterion-definitions")
def list_criterion_definitions(category: str | None = None, session: Session = Depends(get_session)):
return {"items": CriterionDefinitionService(session).list(category)}
@router.get("/criterion-mappings")
def list_mappings(source_category_id: UUID | None = None, session: Session = Depends(get_session)):
return {"items": CriterionMappingService(session).list(source_category_id)}
@router.post("/criterion-mappings", status_code=201)
def create_mapping(payload: CriterionMappingIn, session: Session = Depends(get_session)):
return CriterionMappingService(session).create(payload.model_dump())
@router.patch("/criterion-mappings/{mapping_id}")
def patch_mapping(mapping_id: UUID, payload: CriterionMappingPatch, session: Session = Depends(get_session)):
return CriterionMappingService(session).patch(mapping_id, payload.model_dump(exclude_unset=True))
@router.get("/source-attribute-mappings")
def list_attribute_mappings(session: Session = Depends(get_session)):
return {"items": SourceAttributeMappingService(session).list()}
@router.post("/source-attribute-mappings", status_code=201)
def create_attribute_mapping(payload: SourceAttributeMappingIn, session: Session = Depends(get_session)):
return SourceAttributeMappingService(session).create(payload.model_dump())
@router.patch("/source-attribute-mappings/{mapping_id}")
def patch_attribute_mapping(
mapping_id: UUID,
payload: SourceAttributeMappingPatch,
session: Session = Depends(get_session),
):
return SourceAttributeMappingService(session).patch(mapping_id, payload.model_dump(exclude_unset=True))
@router.post("/discovery-searches", status_code=201)
def create_search(payload: DiscoverySearchIn, session: Session = Depends(get_session)):
return DiscoverySearchService(session).create(payload.model_dump())
@router.get("/discovery-searches")
def list_searches(due: bool = Query(default=False), session: Session = Depends(get_session)):
service = DiscoverySearchService(session)
return {"items": service.list_due() if due else service.list_all()}
@router.get("/discovery-searches/{search_id}")
def get_search(search_id: UUID, session: Session = Depends(get_session)):
return DiscoverySearchService(session).get(search_id)
@router.patch("/discovery-searches/{search_id}")
def patch_search(search_id: UUID, payload: DiscoverySearchPatch, session: Session = Depends(get_session)):
return DiscoverySearchService(session).patch(search_id, payload.model_dump(exclude_unset=True))
@router.post("/discovery-searches/{search_id}/generate-query")
def generate_query(search_id: UUID, session: Session = Depends(get_session)):
return DiscoverySearchService(session).generate_query(search_id)
@router.post("/discovery-searches/{search_id}/run", status_code=201)
def run_search(search_id: UUID, session: Session = Depends(get_session)):
return DiscoverySearchService(session).run(search_id)
@router.get("/discovery-searches/{search_id}/runs")
def list_runs(search_id: UUID, session: Session = Depends(get_session)):
return {"items": DiscoverySearchService(session).list_runs(search_id)}
@router.get("/search-runs/{run_id}")
def get_run(run_id: UUID, session: Session = Depends(get_session)):
return DiscoverySearchService(session).get_run(run_id)
+20
View File
@@ -0,0 +1,20 @@
from uuid import UUID
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from app.api.schemas import EvaluateIn
from app.persistence.db import get_session
from app.services.evaluation_service import evaluate_and_store, load_evaluation
router = APIRouter(prefix="/api/v1")
@router.post("/evaluate/{variant_id}", status_code=201)
def evaluate(variant_id: UUID, payload: EvaluateIn):
return evaluate_and_store(variant_id=variant_id, payload=payload.model_dump())
@router.get("/evaluations/{evaluation_id}")
def get_evaluation(evaluation_id: UUID, session: Session = Depends(get_session)):
return load_evaluation(session, evaluation_id)
+45
View File
@@ -0,0 +1,45 @@
from fastapi import APIRouter
from fastapi.responses import JSONResponse
from sqlalchemy import text
from alembic.config import Config
from alembic.runtime.migration import MigrationContext
from alembic.script import ScriptDirectory
from app.persistence.db import engine
from app.settings import get_settings
router = APIRouter()
def _alembic_at_head() -> bool:
config = Config("alembic.ini")
script = ScriptDirectory.from_config(config)
with engine.connect() as connection:
context = MigrationContext.configure(connection)
return set(context.get_current_heads()) == set(script.get_heads())
@router.get("/health/live")
def live() -> dict[str, str]:
return {"status": "ok"}
@router.get("/health/ready", response_model=None)
def ready() -> JSONResponse | dict[str, str]:
settings = get_settings()
try:
with engine.connect() as connection:
connection.execute(text("SELECT 1"))
if not _alembic_at_head():
return JSONResponse(
{"status": "not_ready", "reason": "migration_behind_head"},
status_code=503,
)
except Exception:
return JSONResponse({"status": "not_ready", "reason": "database"}, status_code=503)
return {
"status": "ready",
"environment": settings.environment,
"engine_build": settings.engine_build,
}
+42
View File
@@ -0,0 +1,42 @@
from uuid import UUID
from fastapi import APIRouter, Depends, Response
from sqlalchemy.orm import Session
from app.api.schemas import OfferIn, OfferOut, PriceIn, PriceOut, page, parse_page
from app.errors import AppError
from app.persistence.db import get_session
from app.persistence.repositories import CatalogRepository
from app.services.ingestion_service import IngestionService
router = APIRouter(prefix="/api/v1")
@router.post("/variants/{variant_id}/offers", status_code=201)
def create_offer(variant_id: UUID, payload: OfferIn, session: Session = Depends(get_session)) -> OfferOut:
offer = IngestionService(session).create_offer(variant_id, payload.model_dump())
return OfferOut.model_validate(offer.__dict__)
@router.get("/offers/{offer_id}")
def get_offer(offer_id: UUID, session: Session = Depends(get_session)) -> OfferOut:
offer = CatalogRepository(session).get_offer(offer_id)
if offer is None:
raise AppError(404, "NOT_FOUND", "offer not found", {"id": str(offer_id)})
return OfferOut.model_validate(offer.__dict__)
@router.post("/offers/{offer_id}/prices")
def add_price(offer_id: UUID, payload: PriceIn, response: Response, session: Session = Depends(get_session)) -> PriceOut:
observation, created = IngestionService(session).add_price(offer_id, payload.model_dump())
response.status_code = 201 if created else 200
return PriceOut.model_validate(observation.__dict__)
@router.get("/offers/{offer_id}/prices")
def list_prices(offer_id: UUID, limit: int = 50, offset: int = 0, session: Session = Depends(get_session)):
if CatalogRepository(session).get_offer(offer_id) is None:
raise AppError(404, "NOT_FOUND", "offer not found", {"id": str(offer_id)})
limit, offset = parse_page(limit, offset)
items, total = CatalogRepository(session).list_observations(offer_id, limit, offset)
return page([PriceOut.model_validate(item.__dict__) for item in items], limit, offset, total)
+63
View File
@@ -0,0 +1,63 @@
from uuid import UUID
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from app.api.schemas import AttributeIn, AttributeOut, ProductIn, ProductOut, VariantIn, VariantOut
from app.errors import AppError
from app.persistence.db import get_session
from app.persistence.repositories import CatalogRepository
from app.services.ingestion_service import IngestionService
router = APIRouter(prefix="/api/v1")
@router.post("/products", status_code=201)
def create_product(payload: ProductIn, session: Session = Depends(get_session)) -> ProductOut:
product = IngestionService(session).create_product(payload.model_dump())
return ProductOut.model_validate(product.__dict__)
@router.get("/products/{product_id}")
def get_product(product_id: UUID, session: Session = Depends(get_session)) -> ProductOut:
product = CatalogRepository(session).get_product(product_id)
if product is None:
raise AppError(404, "NOT_FOUND", "product not found", {"id": str(product_id)})
return ProductOut.model_validate(product.__dict__)
@router.post("/products/{product_id}/variants", status_code=201)
def create_variant(product_id: UUID, payload: VariantIn, session: Session = Depends(get_session)):
variant = IngestionService(session).create_variant(product_id, payload.model_dump())
return {
"id": variant.id,
"product_id": variant.product_id,
"name": variant.name,
"manufacturer_sku": variant.manufacturer_sku,
"identifiers": variant.identifiers,
"created_at": variant.created_at,
}
@router.get("/variants/{variant_id}")
def get_variant(variant_id: UUID, session: Session = Depends(get_session)) -> VariantOut:
repo = CatalogRepository(session)
variant = repo.get_variant(variant_id)
if variant is None:
raise AppError(404, "NOT_FOUND", "variant not found", {"id": str(variant_id)})
attributes = [AttributeOut.model_validate(item.__dict__) for item in repo.list_attributes(variant_id)]
return VariantOut(
id=variant.id,
product_id=variant.product_id,
name=variant.name,
manufacturer_sku=variant.manufacturer_sku,
identifiers=variant.identifiers,
created_at=variant.created_at,
attributes=attributes,
)
@router.post("/variants/{variant_id}/attributes", status_code=201)
def add_attribute(variant_id: UUID, payload: AttributeIn, session: Session = Depends(get_session)) -> AttributeOut:
statement = IngestionService(session).add_attribute(variant_id, payload.model_dump())
return AttributeOut.model_validate(statement.__dict__)
+100
View File
@@ -0,0 +1,100 @@
from typing import Any
from fastapi import APIRouter, Body, Depends
from sqlalchemy.orm import Session
from app.api.schemas import AttributeDefinitionIn, page, parse_page
from app.domain.serialize import jsonable
from app.errors import AppError
from app.persistence.db import get_session
from app.persistence.repositories import CatalogRepository
from app.services.ingestion_service import IngestionService
router = APIRouter(prefix="/api/v1")
@router.post("/attribute-definitions", status_code=201)
def create_attribute_definition(payload: AttributeDefinitionIn, session: Session = Depends(get_session)):
definition = IngestionService(session).create_definition(payload.model_dump())
return jsonable(definition.__dict__)
@router.get("/attribute-definitions")
def list_attribute_definitions(limit: int = 50, offset: int = 0, session: Session = Depends(get_session)):
limit, offset = parse_page(limit, offset)
items, total = CatalogRepository(session).list_definitions(limit, offset)
return page([jsonable(item.__dict__) for item in items], limit, offset, total)
@router.get("/sources")
def list_sources(session: Session = Depends(get_session)):
items = CatalogRepository(session).list_sources()
return {
"items": [{"id": item.id, "name": item.name, "adapter_type": item.adapter_type} for item in items],
"limit": len(items),
"offset": 0,
"total": len(items),
}
@router.get("/scoring-models/{version}")
def get_scoring_model(version: str, session: Session = Depends(get_session)):
model = CatalogRepository(session).get_scoring_model(version)
if model is None:
raise AppError(404, "NOT_FOUND", "scoring model not found", {"version": version})
return {
"version": model.version,
"algorithm_id": model.algorithm_id,
"definition": model.definition,
"definition_hash": model.definition_hash,
}
@router.post("/profiles", status_code=201)
def create_profile(payload: dict[str, Any] = Body(...), session: Session = Depends(get_session)):
if not isinstance(payload, dict):
raise AppError(422, "PROFILE_INVALID", "profile must be an object")
row = IngestionService(session).create_profile(payload)
return {
"id": row.id,
"version": row.version,
"name": row.name,
"category": row.category,
"scoring_version": row.scoring_version,
"definition": row.definition,
"definition_hash": row.definition_hash,
"created_at": row.created_at,
}
@router.get("/profiles")
def list_profiles(limit: int = 50, offset: int = 0, session: Session = Depends(get_session)):
limit, offset = parse_page(limit, offset)
items, total = CatalogRepository(session).list_profiles(limit, offset)
return page(
[
{
"id": row.id,
"version": row.version,
"name": row.name,
"category": row.category,
"scoring_version": row.scoring_version,
"definition_hash": row.definition_hash,
"created_at": row.created_at,
}
for row in items
],
limit,
offset,
total,
)
@router.get("/profiles/{profile_id}")
def get_profile(profile_id: str, version: int | None = None, session: Session = Depends(get_session)):
if version is None:
raise AppError(422, "VERSION_REQUIRED", "query parameter version is required")
profile = CatalogRepository(session).get_profile(profile_id, version)
if profile is None:
raise AppError(404, "NOT_FOUND", "profile version not found")
return profile.definition
+125
View File
@@ -0,0 +1,125 @@
from uuid import UUID
from fastapi import APIRouter, Depends, Query
from sqlalchemy.orm import Session
from app.api.schemas import (
BuyingProjectIn,
BuyingProjectPatch,
DiscoverySearchIn,
ProjectCriteriaIn,
page,
parse_page,
)
from app.persistence.db import get_session
from app.services.catalog_service import CatalogService
from app.services.discovery_service import CandidateRankingService, DiscoverySearchService
from app.services.project_service import ProjectService
router = APIRouter(prefix="/api/v1")
@router.get("/product-categories")
def list_product_categories(session: Session = Depends(get_session)):
return {"items": CatalogService(session).list_product_categories()}
@router.get("/product-categories/{product_category_id}/sources")
def list_category_sources(product_category_id: str, session: Session = Depends(get_session)):
return {"items": CatalogService(session).sources_for_category(product_category_id)}
@router.get("/product-categories/{product_category_id}/available-criteria")
def available_criteria_for_category(
product_category_id: str,
source: str = Query(...),
session: Session = Depends(get_session),
):
return CatalogService(session).available_criteria(product_category_id, source)
@router.get("/buying-templates")
def list_buying_templates(session: Session = Depends(get_session)):
return {"items": CatalogService(session).list_templates()}
@router.post("/buying-projects", status_code=201)
def create_buying_project(payload: BuyingProjectIn, session: Session = Depends(get_session)):
return ProjectService(session).create(payload.model_dump())
@router.get("/buying-projects")
def list_buying_projects(limit: int = 50, offset: int = 0, session: Session = Depends(get_session)):
limit, offset = parse_page(limit, offset)
items, total = ProjectService(session).list(limit, offset)
return page(items, limit, offset, total)
@router.get("/buying-projects/{project_id}")
def get_buying_project(project_id: UUID, session: Session = Depends(get_session)):
return ProjectService(session).get(project_id)
@router.patch("/buying-projects/{project_id}")
def patch_buying_project(project_id: UUID, payload: BuyingProjectPatch, session: Session = Depends(get_session)):
return ProjectService(session).patch(project_id, payload.model_dump(exclude_unset=True))
@router.post("/buying-projects/{project_id}/criteria", status_code=201)
def add_buying_project_criteria(
project_id: UUID,
payload: ProjectCriteriaIn,
session: Session = Depends(get_session),
):
return ProjectService(session).replace_criteria(project_id, payload.model_dump())
@router.put("/buying-projects/{project_id}/criteria")
def put_buying_project_criteria(
project_id: UUID,
payload: ProjectCriteriaIn,
session: Session = Depends(get_session),
):
return ProjectService(session).replace_criteria(project_id, payload.model_dump())
@router.get("/buying-projects/{project_id}/criteria")
def get_buying_project_criteria(project_id: UUID, session: Session = Depends(get_session)):
return ProjectService(session).get_criteria(project_id)
@router.get("/buying-projects/{project_id}/available-criteria")
def available_criteria(project_id: UUID, session: Session = Depends(get_session)):
return ProjectService(session).available_criteria(project_id)
@router.get("/buying-projects/{project_id}/discovery-searches")
def list_project_searches(project_id: UUID, session: Session = Depends(get_session)):
return {"items": DiscoverySearchService(session).list_for_project(project_id)}
@router.post("/buying-projects/{project_id}/discovery-searches", status_code=201)
def create_project_search(project_id: UUID, payload: DiscoverySearchIn, session: Session = Depends(get_session)):
body = payload.model_dump()
body["buying_project_id"] = project_id
return DiscoverySearchService(session).create(body)
@router.get("/buying-projects/{project_id}/candidates")
def list_candidates(project_id: UUID, session: Session = Depends(get_session)):
return {"items": CandidateRankingService(session).list_candidates(project_id)}
@router.get("/buying-projects/{project_id}/candidates/{candidate_id}")
def get_candidate(project_id: UUID, candidate_id: UUID, session: Session = Depends(get_session)):
return CandidateRankingService(session).get_candidate(project_id, candidate_id)
@router.get("/buying-projects/{project_id}/candidates/{candidate_id}/observations")
def list_candidate_observations(project_id: UUID, candidate_id: UUID, session: Session = Depends(get_session)):
return {"items": CandidateRankingService(session).list_observations(project_id, candidate_id)}
@router.get("/buying-projects/{project_id}/shortlist")
def list_shortlist(project_id: UUID, session: Session = Depends(get_session)):
return {"items": CandidateRankingService(session).list_candidates(project_id, shortlisted_only=True)}
+274
View File
@@ -0,0 +1,274 @@
from datetime import datetime
from decimal import Decimal
from typing import Any
from uuid import UUID
from pydantic import BaseModel, ConfigDict, Field, field_serializer
class StrictModel(BaseModel):
model_config = ConfigDict(extra="forbid")
class AttributeDefinitionIn(StrictModel):
key: str
value_type: str
canonical_unit: str | None = None
minimum: Decimal | None = None
maximum: Decimal | None = None
description: str | None = None
class AttributeDefinitionOut(StrictModel):
key: str
value_type: str
canonical_unit: str | None
minimum: Decimal | None
maximum: Decimal | None
description: str | None
class ProductIn(StrictModel):
id: UUID | None = None
category: str
brand: str
name: str
model: str | None = None
class ProductOut(StrictModel):
id: UUID
category: str
brand: str
name: str
model: str | None
created_at: datetime
class VariantIn(StrictModel):
id: UUID | None = None
name: str
manufacturer_sku: str | None = None
identifiers: dict[str, Any] = Field(default_factory=dict)
class AttributeIn(StrictModel):
id: UUID | None = None
attribute: str
raw_value: Any
normalized_value: Any | None = None
unit: str | None = None
normalization_status: str
normalizer_version: str | None = None
confidence: Decimal
source_id: str
source_reference: str
observed_at: datetime
normalization_error: str | None = None
class AttributeOut(StrictModel):
id: UUID
variant_id: UUID
attribute: str
raw_value: Any
normalized_value: Any | None
unit: str | None
normalization_status: str
normalizer_version: str
confidence: Decimal
source_id: str
source_reference: str
observed_at: datetime
ingested_at: datetime
normalization_error: str | None
class VariantOut(StrictModel):
id: UUID
product_id: UUID
name: str
manufacturer_sku: str | None
identifiers: dict[str, Any]
created_at: datetime
attributes: list[AttributeOut]
class OfferIn(StrictModel):
id: UUID | None = None
source_id: str
external_id: str
seller: str
url: str | None = None
market: str
currency: str
condition: str
class OfferOut(StrictModel):
id: UUID
variant_id: UUID
source_id: str
external_id: str
seller: str
url: str | None
market: str
currency: str
condition: str
created_at: datetime
class PriceIn(StrictModel):
id: UUID | None = None
source_id: str
external_observation_id: str
observed_at: datetime
item_price: Decimal
shipping_price: Decimal | None = None
currency: str
availability: str
raw_payload: Any
confidence: Decimal
@field_serializer("item_price", "shipping_price")
def serialize_money(self, value: Decimal | None) -> str | None:
return None if value is None else format(value, "f")
class PriceOut(StrictModel):
id: UUID
offer_id: UUID
source_id: str
external_observation_id: str
observed_at: datetime
ingested_at: datetime
item_price: Decimal
shipping_price: Decimal | None
currency: str
availability: str
raw_payload: Any
confidence: Decimal
@field_serializer("item_price", "shipping_price")
def serialize_money(self, value: Decimal | None) -> str | None:
return None if value is None else format(Decimal(value).quantize(Decimal("0.01")), "f")
class EvaluateIn(StrictModel):
profile_id: str
profile_version: int
offer_id: UUID
as_of: datetime | None = None
class BuyingProjectIn(StrictModel):
id: UUID | None = None
name: str
product_category_id: str | None = None
market: str | None = None
currency: str | None = None
target_budget: Decimal | None = None
template_id: str | None = None
template_version: int | None = None
profile_id: str | None = None
profile_version: int | None = None
workspace_id: str | None = None
shortlist_size: int = 5
schedule_interval_minutes: int | None = None
criteria: dict[str, Any]
class BuyingProjectPatch(StrictModel):
name: str | None = None
target_budget: Decimal | None = None
shortlist_size: int | None = None
status: str | None = None
class ProjectCriteriaIn(StrictModel):
items: list[dict[str, Any]]
class CriterionDefinitionIn(StrictModel):
key: str
value_type: str
unit: str | None = None
semantic: str | None = None
category: str | None = None
description: str | None = None
origin: str | None = None
source: str | None = None
product_category_id: str | None = None
label: str | None = None
scoring_attribute_key: str | None = None
class DiscoverySearchIn(StrictModel):
buying_project_id: UUID | None = None
source_id: str
source_category_id: UUID
schedule_interval_minutes: int = 180
broad_result_threshold: int = 300
class DiscoverySearchPatch(StrictModel):
schedule_interval_minutes: int | None = None
status: str | None = None
class SourceAttributeMappingIn(StrictModel):
source_id: str
source_category_id: UUID | None = None
raw_name: str
criterion_definition_id: UUID
status: str | None = None
class SourceAttributeMappingPatch(StrictModel):
raw_name: str | None = None
criterion_definition_id: UUID | None = None
status: str | None = None
class CriterionMappingIn(StrictModel):
criterion_definition_id: UUID | None = None
criterion_key: str | None = None
source_id: str
source_category_id: UUID
external_filter_key: str
source_value: str | None = None
encoding: dict[str, Any] = Field(default_factory=lambda: {"url_param": "xf"})
status: str | None = None
value_type: str | None = None
unit: str | None = None
semantic: str | None = None
description: str | None = None
operator: str | None = None
probe_value: Any = None
class CriterionMappingPatch(StrictModel):
source_value: str | None = None
encoding: dict[str, Any] | None = None
status: str | None = None
probe_value: Any = None
operator: str | None = None
class Page(StrictModel):
items: list[Any]
limit: int
offset: int
total: int
def page(items: list[Any], limit: int, offset: int, total: int) -> dict[str, Any]:
return {"items": items, "limit": limit, "offset": offset, "total": total}
def parse_page(limit: int = 50, offset: int = 0) -> tuple[int, int]:
from app.errors import AppError
if limit < 1 or limit > 200 or offset < 0:
raise AppError(422, "PAGINATION", "limit must be 1-200 and offset >= 0")
return limit, offset