From c48fd362c5c82a777c9aab9e561f05fc20186011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patr=C3=ADcia=20Trevisan?= Date: Mon, 24 Jul 2023 09:54:00 -0300 Subject: [PATCH 1/2] Update controller.py query para retornar os dados de um campi filtrado pelo item "campus" (string) --- controller.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/controller.py b/controller.py index a06c2fa..6976a85 100644 --- a/controller.py +++ b/controller.py @@ -11,4 +11,7 @@ def create_item(db: Session, item: schemas.ItemCreate): db.add(db_item) db.commit() db.refresh(db_item) - return db_item \ No newline at end of file + return db_item + +def getItem(nome_campi: str, db: Session, skip: int = 0, limit: int = 100): + return db.query(models.Item).filter_by(campus = nome_campi).offset(skip).limit(limit).one() From 5ab17163fe8bbe345bacd19882e29e2b1d002b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patr=C3=ADcia=20Trevisan?= Date: Mon, 24 Jul 2023 09:57:06 -0300 Subject: [PATCH 2/2] Update main.py rota para obter dados de um campi selecionado --- main.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/main.py b/main.py index cce9c9f..a1df987 100644 --- a/main.py +++ b/main.py @@ -60,6 +60,13 @@ def read_items(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): items = controller.getItems(db, skip=skip, limit=limit) return items + # rota para obter os dados de um campi +@app.get("/item/{nome_campi}", response_model=schemas.Item) +def read_item(nome_campi: str, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): + item = controller.getItem(nome_campi, db, skip=skip, limit=limit) + print(item) + return item + @app.post("/items/") async def create_item(item: schemas.Item, db: Session = Depends(get_db)):