Pass json with id and announc. will be deleted
This commit is contained in:
parent
9e98a224e3
commit
eb19113d78
18
back/main.py
18
back/main.py
@ -126,7 +126,10 @@ def single_annoncement(user_id:int):
|
||||
|
||||
# Занести объявление в базу
|
||||
@app.put("/api/announcement")#адрес объявлений
|
||||
def put_in_db(name: Annotated[str, Form()], category: Annotated[str, Form()], bestBy: Annotated[int, Form()], address: Annotated[str, Form()], longtitude: Annotated[float, Form()], latitude: Annotated[float, Form()], description: Annotated[str, Form()], src: UploadFile, metro: Annotated[str, Form()], trashId: Annotated[int, Form()] = None):
|
||||
def put_in_db(name: Annotated[str, Form()], category: Annotated[str, Form()], bestBy: Annotated[int, Form()],
|
||||
address: Annotated[str, Form()], longtitude: Annotated[float, Form()], latitude: Annotated[float, Form()],
|
||||
description: Annotated[str, Form()], src: UploadFile, metro: Annotated[str, Form()],
|
||||
trashId: Annotated[int, Form()] = None):
|
||||
# try:
|
||||
userId = 1 # temporary
|
||||
|
||||
@ -143,9 +146,9 @@ def put_in_db(name: Annotated[str, Form()], category: Annotated[str, Form()], be
|
||||
uploaded_name = "/uploads/"+destination.name
|
||||
|
||||
temp_ancmt = Announcement(user_id=userId, name=name, category=category, best_by=bestBy, address=address, longtitude=longtitude, latitude=latitude, description=description, src=uploaded_name, metro=metro, trashId=trashId, booked_by=-1)
|
||||
db.add(temp_ancmt) # добавляем в бд
|
||||
db.commit() # сохраняем изменения
|
||||
db.refresh(temp_ancmt) # обновляем состояние объекта
|
||||
database.add(temp_ancmt) # добавляем в бд
|
||||
database.commit() # сохраняем изменения
|
||||
database.refresh(temp_ancmt) # обновляем состояние объекта
|
||||
return {"Answer" : True}
|
||||
# except:
|
||||
# return {"Answer" : False}
|
||||
@ -153,14 +156,15 @@ def put_in_db(name: Annotated[str, Form()], category: Annotated[str, Form()], be
|
||||
|
||||
# Удалить объявления из базы
|
||||
@app.delete("/api/announcement") #адрес объявления
|
||||
def delete_from_db(data = Body()):#функция удаления объекта из БД
|
||||
def delete_from_db(annoncement: schemas.DelAnnouncement): # функция удаления объекта из БД
|
||||
try:
|
||||
database.delete(user_id=data.user_id)#удаление из БД
|
||||
to_delete = database.query(Announcement).filter(Announcement.id==announcement.id).first()
|
||||
database.delete(to_delete) # удаление из БД
|
||||
database.commit() # сохраняем изменения
|
||||
return {"Answer" : True}
|
||||
except:
|
||||
return {"Answer" : False}
|
||||
|
||||
|
||||
|
||||
# Забронировать объявление
|
||||
@app.post("/api/book")
|
||||
|
@ -30,3 +30,7 @@ class UserInDB(User):
|
||||
hashed_password: str
|
||||
|
||||
|
||||
class DelAnnouncement(BaseModel):
|
||||
id: int
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user