forked from polka_billy/porridger
Merge branch 'asynchronous-porridger' of https://git.dm1sh.ru/dm1sh/porridger into asynchronous-porridger
This commit is contained in:
@ -89,7 +89,7 @@ async def put_in_db(name: Annotated[str, Form()], category: Annotated[str, Form(
|
||||
if f.tell() > 0:
|
||||
f.seek(0)
|
||||
destination = pathlib.Path("./uploads/" + str(hash(f)) + pathlib.Path(src.filename).suffix.lower())
|
||||
async with destination.open('wb') as buffer:
|
||||
with destination.open('wb') as buffer:
|
||||
shutil.copyfileobj(f, buffer)
|
||||
|
||||
# изменяем название директории загруженного файла
|
||||
@ -103,6 +103,8 @@ async def put_in_db(name: Annotated[str, Form()], category: Annotated[str, Form(
|
||||
db.add(temp_ancmt) # добавляем в бд
|
||||
await db.commit() # сохраняем изменения
|
||||
await db.refresh(temp_ancmt) # обновляем состояние объекта
|
||||
|
||||
return {"Success": True}
|
||||
except:
|
||||
raise HTTPException(status_code=500, detail="problem with adding object to db")
|
||||
|
||||
@ -119,6 +121,8 @@ async def delete_from_db(announcement: pydantic_schemas.DelAnnouncement, db: Ann
|
||||
try:
|
||||
await db.delete(to_delete) # удаление из БД
|
||||
await db.commit() # сохраняем изменения
|
||||
|
||||
return {"Success": True}
|
||||
except:
|
||||
raise HTTPException(status_code=500, detail="Problem with adding to database")
|
||||
|
||||
|
Reference in New Issue
Block a user