feat(repairs): add repair estimates
This commit is contained in:
parent
6e7e75f864
commit
4436fe5f73
25 changed files with 1802 additions and 9 deletions
|
|
@ -11,6 +11,7 @@ from app.core.config import settings
|
|||
from app.models.repair import Repair, RepairPublicAccessToken
|
||||
from app.models.user import User
|
||||
from app.repositories.repair_repository import RepairRepository
|
||||
from app.repositories.repair_estimate_repository import RepairEstimateRepository
|
||||
from app.schemas.repair import (
|
||||
RepairPublicLinkCreateResponse,
|
||||
RepairPublicLinkResponse,
|
||||
|
|
@ -131,16 +132,12 @@ class RepairPublicLinkService:
|
|||
|
||||
@staticmethod
|
||||
def public_status(db: Session, token: str) -> RepairPublicStatusResponse:
|
||||
normalized_token = normalize_token(token)
|
||||
if not normalized_token:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Reparaturstatus nicht gefunden")
|
||||
|
||||
public_link = RepairRepository.get_public_link_by_hash(db, RepairPublicLinkService.hash_token(normalized_token))
|
||||
if public_link is None or public_link.repair is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Reparaturstatus nicht gefunden")
|
||||
|
||||
public_link = RepairPublicLinkService.get_public_link_or_404(db, token)
|
||||
repair = public_link.repair
|
||||
history = RepairRepository.get_history_public(db, repair.id)
|
||||
estimate = RepairEstimateRepository.get_latest_public(db, repair.id)
|
||||
from app.services.repair_estimate_service import RepairEstimateService
|
||||
|
||||
response = RepairPublicStatusResponse(
|
||||
repair_number=repair.repair_number,
|
||||
public_status_label=STATUS_LABELS.get(repair.status, repair.status),
|
||||
|
|
@ -155,6 +152,18 @@ class RepairPublicLinkService:
|
|||
for item in history
|
||||
],
|
||||
updated_at=repair.updated_at,
|
||||
estimate=RepairEstimateService.public_response(estimate),
|
||||
)
|
||||
RepairRepository.mark_public_link_used(db, public_link)
|
||||
return response
|
||||
|
||||
@staticmethod
|
||||
def get_public_link_or_404(db: Session, token: str) -> RepairPublicAccessToken:
|
||||
normalized_token = normalize_token(token)
|
||||
if not normalized_token:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Reparaturstatus nicht gefunden")
|
||||
|
||||
public_link = RepairRepository.get_public_link_by_hash(db, RepairPublicLinkService.hash_token(normalized_token))
|
||||
if public_link is None or public_link.repair is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Reparaturstatus nicht gefunden")
|
||||
return public_link
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue