auf Webseiten Modell umgestellt

This commit is contained in:
ecki
2026-04-18 14:23:24 +02:00
parent 5510d58e5a
commit 6cfbdba0a4
9 changed files with 890 additions and 30 deletions
+75 -1
View File
@@ -8,7 +8,7 @@ from sqlalchemy.orm import Session
from app.config import settings
from app.database import Base, engine, get_db
from app.models import TrackedEvent, WatchItem
from app.models import TrackedEvent, WatchItem, WatchSource
from app.scheduler import start_scheduler
from app.schemas import (
NotificationLogRead,
@@ -19,11 +19,15 @@ from app.schemas import (
WatchItemCreate,
WatchItemRead,
WatchItemUpdate,
WatchSourceCreate,
WatchSourceRead,
WatchSourceUpdate,
)
from app.services import (
list_events,
list_notifications,
list_provider_statuses,
list_watch_sources,
list_watch_items,
run_sync,
)
@@ -114,6 +118,66 @@ def delete_watch_item(watch_item_id: int, db: Session = Depends(get_db)):
db.commit()
@app.get("/watch-sources", response_model=list[WatchSourceRead])
def get_watch_sources(watch_item_id: int | None = None, db: Session = Depends(get_db)):
return list_watch_sources(db, watch_item_id)
@app.post(
"/watch-items/{watch_item_id}/sources",
response_model=WatchSourceRead,
status_code=201,
)
def create_watch_source(
watch_item_id: int,
payload: WatchSourceCreate,
db: Session = Depends(get_db),
):
watch_item = db.get(WatchItem, watch_item_id)
if watch_item is None:
raise HTTPException(status_code=404, detail="Watch item nicht gefunden.")
source = WatchSource(
watch_item=watch_item,
label=payload.label,
url=payload.url,
parser_type=payload.parser_type,
)
db.add(source)
db.commit()
db.refresh(source)
return source
@app.patch("/watch-sources/{source_id}", response_model=WatchSourceRead)
def update_watch_source(
source_id: int,
payload: WatchSourceUpdate,
db: Session = Depends(get_db),
):
source = db.get(WatchSource, source_id)
if source is None:
raise HTTPException(status_code=404, detail="Quelle nicht gefunden.")
updates = payload.model_dump(exclude_unset=True)
for field_name, value in updates.items():
setattr(source, field_name, value)
source.updated_at = datetime.utcnow()
db.commit()
db.refresh(source)
return source
@app.delete("/watch-sources/{source_id}", status_code=204)
def delete_watch_source(source_id: int, db: Session = Depends(get_db)):
source = db.get(WatchSource, source_id)
if source is None:
raise HTTPException(status_code=404, detail="Quelle nicht gefunden.")
db.delete(source)
db.commit()
@app.get("/events", response_model=list[TrackedEventRead])
def get_events(db: Session = Depends(get_db)):
return list_events(db)
@@ -137,6 +201,16 @@ def update_purchase_status(
return tracked_event
@app.delete("/events/{event_id}", status_code=204)
def delete_event(event_id: int, db: Session = Depends(get_db)):
tracked_event = db.get(TrackedEvent, event_id)
if tracked_event is None:
raise HTTPException(status_code=404, detail="Event nicht gefunden.")
db.delete(tracked_event)
db.commit()
@app.get("/notifications", response_model=list[NotificationLogRead])
def get_notifications(db: Session = Depends(get_db)):
return list_notifications(db)