From 8f9e25d8d54f0f6d1aa3044dbc514cfdae9dc699 Mon Sep 17 00:00:00 2001 From: hanfi <ccc@spahan.ch> Date: Fri, 11 Aug 2023 08:21:04 +0200 Subject: [PATCH] add checkout --- backend/main.py | 13 +++++++++++++ backend/utils.py | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/backend/main.py b/backend/main.py index 6231161..9b25894 100644 --- a/backend/main.py +++ b/backend/main.py @@ -149,6 +149,19 @@ def checkin_item_by_uuid( return utils.receive_item(db, item, storage) +@app.get("/checkout/{item_uuid}", response_model=schemas.Item) +def checkout_item( + item_uuid: str, + token: str = Depends(oauth2_scheme), + db: Session = Depends(get_db), +): + check_token(token, None) + item = utils.get_item_by_uuid(db, UUID(item_uuid)) + if item is None: + raise HTTPException(status_code=404, detail="Item not found") + return utils.deliver_item(db, item) + + @app.post("/token") def verify_supporter(form_data: OAuth2PasswordRequestForm = Depends()): if form_data.password != settings.shared_secret: diff --git a/backend/utils.py b/backend/utils.py index 390758e..1af3057 100644 --- a/backend/utils.py +++ b/backend/utils.py @@ -113,3 +113,10 @@ def receive_item(db: Session, item: schemas.Item, storage: schemas.Storage): db.commit() db.refresh(item) return item + + +def deliver_item(db: Session, item: schemas.Item): + item.deployed_at = datetime.now() + db.commit() + db.refresh(item) + return item -- GitLab