forked from polka_billy/porridger
Change rating and dispose endpoints fixed
This commit is contained in:
11
back/main.py
11
back/main.py
@ -183,6 +183,8 @@ def add_points(data: schemas.AddRating, current_user: Annotated[schemas.User, De
|
||||
raise HTTPException(status_code=404, detail="Item not found")
|
||||
user.rating = (user.rating*user.num_of_ratings + data.rate)/(user.num_of_ratings + 1)
|
||||
user.num_of_ratings += 1
|
||||
database.commit()
|
||||
database.refresh(user) # обновляем состояние объекта
|
||||
return {"Success": True}
|
||||
|
||||
|
||||
@ -245,11 +247,12 @@ async def react_app(req: Request, rest_of_path: str):
|
||||
return templates.TemplateResponse('index.html', { 'request': req })
|
||||
|
||||
|
||||
@app.post("api/announcement/dispose")
|
||||
def dispose(data: schemas.TrashboxResponse, current_user: Annotated[schemas.User, Depends(utils.get_current_user)]):
|
||||
@app.post("/api/announcement/dispose")
|
||||
def dispose(data: schemas.DisposeRequest, current_user_schema: Annotated[schemas.User, Depends(utils.get_current_user)]):
|
||||
current_user = utils.get_user_by_id(database, current_user_schema.id)
|
||||
current_user.points += 60
|
||||
new_trashox = models.Trashbox(user_id=current_user.id, date_of_chose=datetime.date.today(), name=data.Name,
|
||||
latitude=data.Lat, longtitude=data.Lng, address=data.Address, category=data.Categories)
|
||||
new_trashox = models.Trashbox(user_id=current_user.id, date_of_choice=datetime.date.today(), name=data.Name,
|
||||
latitude=data.Lat, longtitude=data.Lng, address=data.Address, categories=data.Categories)
|
||||
database.add(new_trashox)
|
||||
database.commit()
|
||||
database.refresh(new_trashox) # обновляем состояние объекта
|
||||
|
@ -1,4 +1,4 @@
|
||||
from sqlalchemy import Column, Integer, String, Boolean, Float, DateTime, Date, ForeignKey, Enum, UniqueConstraint
|
||||
from sqlalchemy import Column, Integer, String, Boolean, Float, DateTime, ARRAY, Date, ForeignKey, Enum, UniqueConstraint
|
||||
from fastapi import Depends
|
||||
from .db import Base, engine
|
||||
from sqlalchemy.orm import relationship
|
||||
@ -30,8 +30,8 @@ class Announcement(Base): #класс объявления
|
||||
category = Column(String) #категория продукта из объявления
|
||||
best_by = Column(Date) #срок годности продукта из объявления
|
||||
address = Column(String)
|
||||
longtitude = Column(Integer)
|
||||
latitude = Column(Integer)
|
||||
longtitude = Column(Float)
|
||||
latitude = Column(Float)
|
||||
description = Column(String) #описание продукта в объявлении
|
||||
src = Column(String, nullable=True) #изображение продукта в объявлении
|
||||
metro = Column(String) #ближайщее метро от адреса нахождения продукта
|
||||
@ -50,10 +50,10 @@ class Trashbox(Base): #класс мусорных баков
|
||||
user_id = Column(Integer, ForeignKey("users.id")) # айди выбравшего мусорку
|
||||
name = Column(String, nullable=True)#название мусорки
|
||||
address = Column(String)
|
||||
latitude = Column(Integer)
|
||||
longtitude = Column(Integer)
|
||||
category = Column(String) #типы мусора (из тех, что возвращает API мусорки)
|
||||
date_of_chose = Column(Date) # Дата выбора мусорки пользователем
|
||||
latitude = Column(Float)
|
||||
longtitude = Column(Float)
|
||||
categories = Column(String) #типы мусора (из тех, что возвращает API мусорки)
|
||||
date_of_choice = Column(Date) # Дата выбора мусорки пользователем
|
||||
|
||||
user = relationship("User", back_populates="trashboxes_chosen")
|
||||
|
||||
|
@ -77,20 +77,20 @@ class Poem(BaseModel):
|
||||
author: str
|
||||
|
||||
class TrashboxBase(BaseModel):
|
||||
Name: str
|
||||
Lat: float
|
||||
Lng: float
|
||||
|
||||
class TrashboxResponse(TrashboxBase):
|
||||
Name: str
|
||||
Address: str
|
||||
Categories: List[str]
|
||||
Categories: str
|
||||
|
||||
class TrashboxRequest(TrashboxBase):
|
||||
Category: str
|
||||
|
||||
class DisposeRequest(BaseModel):
|
||||
class DisposeRequest(TrashboxResponse):
|
||||
ann_id: int
|
||||
trashbox: TrashboxRequest
|
||||
|
||||
|
||||
class SortAnnouncements(BaseModel):
|
||||
obsolete: Union[int, None] = False
|
||||
|
Reference in New Issue
Block a user