Merge branch 'main' of https://github.com/dm1sh/porridger_tmp
This commit is contained in:
commit
15d61ecc4b
21
back/main.py
21
back/main.py
@ -45,7 +45,7 @@ app.mount("/uploads", StaticFiles(directory = "./uploads"))
|
||||
|
||||
|
||||
@app.get("/api/announcements", response_model=List[schemas.Announcement])#адрес объявлений
|
||||
def annoncements_list(obsolete: Union[bool, None] = False, user_id: Union[int, None] = None, metro: Union[str, None] = None,
|
||||
def announcements_list(obsolete: Union[bool, None] = False, user_id: Union[int, None] = None, metro: Union[str, None] = None,
|
||||
category: Union[str, None] = None):
|
||||
# Считываем данные из Body и отображаем их на странице.
|
||||
# В последствии будем вставлять данные в html-форму
|
||||
@ -60,16 +60,16 @@ def annoncements_list(obsolete: Union[bool, None] = False, user_id: Union[int, N
|
||||
|
||||
|
||||
@app.get("/api/announcement")#адрес объявления
|
||||
def single_annoncement(user_id:int):
|
||||
def single_announcement(user_id:int):
|
||||
# Считываем данные из Body и отображаем их на странице.
|
||||
# В последствии будем вставлять данные в html-форму
|
||||
try:
|
||||
annoncement = database.get(models.Announcement, user_id)
|
||||
return {"id": annoncement.id, "user_id": annoncement.user_id, "name": annoncement.name,
|
||||
"category": annoncement.category, "best_by": annoncement.best_by, "address": annoncement.address,
|
||||
"description": annoncement.description, "metro": annoncement.metro, "latitude": annoncement.latitude,
|
||||
"longtitude":annoncement.longtitude, "trashId": annoncement.trashId, "src":annoncement.src,
|
||||
"booked_by":annoncement.booked_by}
|
||||
announcement = database.get(models.Announcement, user_id)
|
||||
return {"id": announcement.id, "user_id": announcement.user_id, "name": announcement.name,
|
||||
"category": announcement.category, "best_by": announcement.best_by, "address": announcement.address,
|
||||
"description": announcement.description, "metro": announcement.metro, "latitude": announcement.latitude,
|
||||
"longtitude":announcement.longtitude, "trashId": announcement.trashId, "src":announcement.src,
|
||||
"booked_by":announcement.booked_by}
|
||||
except:
|
||||
return {"Answer" : False} #если неуданый доступ, то сообщаем об этом
|
||||
|
||||
@ -94,7 +94,8 @@ def put_in_db(name: Annotated[str, Form()], category: Annotated[str, Form()], be
|
||||
uploaded_name = "/uploads/"+destination.name
|
||||
|
||||
temp_ancmt = models.Announcement(user_id=current_user.id, name=name, category=category, best_by=bestBy,
|
||||
address=address, longtitude=longtitude, latitude=latitude, description=description, metro=metro, trashId=trashId)
|
||||
address=address, longtitude=longtitude, latitude=latitude, description=description, metro=metro,
|
||||
trashId=trashId, booked_by=0)
|
||||
database.add(temp_ancmt) # добавляем в бд
|
||||
database.commit() # сохраняем изменения
|
||||
database.refresh(temp_ancmt) # обновляем состояние объекта
|
||||
@ -105,7 +106,7 @@ def put_in_db(name: Annotated[str, Form()], category: Annotated[str, Form()], be
|
||||
|
||||
# Удалить объявления из базы
|
||||
@app.delete("/api/announcement") #адрес объявления
|
||||
def delete_from_db(annoncement: schemas.DelAnnouncement): # функция удаления объекта из БД
|
||||
def delete_from_db(announcement: schemas.DelAnnouncement): # функция удаления объекта из БД
|
||||
try:
|
||||
to_delete = database.query(models.Announcement).filter(models.Announcement.id==announcement.id).first()
|
||||
database.delete(to_delete) # удаление из БД
|
||||
|
Loading…
x
Reference in New Issue
Block a user