feat(POST): add POST function to insert new data on the DB

This commit is contained in:
T0315986 2025-10-29 15:27:25 +01:00
parent daa1061dce
commit be1d1ff9a6

10
main.py
View File

@ -70,9 +70,9 @@ async def read_item(test_id: int):
return {"test_string": result}
@app.put("/test/add")
async def add_item(test_string: str):
if test_string != "":
@app.post("/test/add")
async def add_item(test_string: Union[str, None] = None):
if test_string:
with engine.connect() as conn:
trans = conn.begin()
insert = test.insert().values(testString=test_string)
@ -81,9 +81,11 @@ async def add_item(test_string: str):
rows = conn.execute(select(test))
for row in rows:
print(row)
msg = {"message": "Item added"}
else:
raise HTTPException(status_code=404, detail="Item not found")
return None
msg = {"message": "err"}
return msg
with engine.connect() as conn: