Scanner write-read-delete workflow working!

This commit is contained in:
2026-05-23 00:30:03 +02:00
parent 30b86dad5e
commit 495535a6de
2 changed files with 83 additions and 78 deletions

View File

@@ -1,6 +1,7 @@
from fastapi import APIRouter, Depends, HTTPException, status
from sqlmodel import Session, select
from typing import List
from sqlalchemy.exc import NoResultFound
from ..model.models import Card
from ..services.database import engine, get_session, add_and_refresh
@@ -26,13 +27,16 @@ def add_card(*, db: Session = Depends(get_session), group_id: int, admin: bool =
@card_router.get("/delete")
def del_card(*, db: Session = Depends(get_session), admin: bool = Depends(auth_is_admin)):
key = DeleteCard()
# card = db.get(Card, card_id)
# if card is None:
# raise HTTPException(status_code=404, detail="Card not found")
# db.delete(card)
# db.commit()
# return {"message": "Card deleted successfully"}
##TBH not a big fan of having creation using group_id but deletion using card_id
print(key)
try:
card = db.exec(select(Card).where(Card.uuid == key)).one()
except NoResultFound:
print(f"The key:'{key}' was not found in db!")
raise HTTPException(status_code=500, detail="Key on card not found in DB. Please tell an admin about this. KEY={key}")
db.delete(card)
db.commit()
return {"message": "Card deleted successfully"}
@card_router.get("/{group_id}", response_model=List[Card])
def get_cards(*, db: Session = Depends(get_session), group_id: int, admin: bool = Depends(auth_is_admin)):
cards = db.exec(select(Card).where(Card.group_id == group_id)).all()