Refactored trash category convertion

This commit is contained in:
Dmitriy Shishkov 2023-09-08 19:40:38 +03:00
parent 543b7b0c46
commit 22dc21bda1
Signed by: dm1sh
GPG Key ID: 027994B0AA357688
3 changed files with 19 additions and 21 deletions

View File

@ -4,9 +4,10 @@ from sqlalchemy.ext.asyncio import AsyncSession
from typing import Annotated
from fastapi import Depends
from sqlalchemy import select, or_, and_
from . import auth_utils, orm_models, pydantic_schemas
import datetime
from . import auth_utils, orm_models, pydantic_schemas
# Загружаем стихи
async def add_poems_to_db(async_db: AsyncSession):

View File

@ -240,6 +240,17 @@ async def poems_to_front(db: Annotated[Session, Depends(auth_utils.get_session)]
raise HTTPException(status_code=404, detail="Poem not found")
return poem
trashboxes_category = {
"PORRIDGE": ["Опасные отходы", "Иное"],
"conspects": ["Бумага"],
"milk": ["Стекло", "Тетра Пак", "Иное"],
"bred": ["Пластик", "Иное"],
"wathing": ["Пластик", "Опасные отходы", "Иное"],
"cloth": ["Одежда"],
"fruits_vegatables": ["Иное"],
"other_things": ["Металл", "Бумага", "Стекло", "Иное", "Тетра Пак", "Батарейки", "Крышечки", "Шины",
"Опасные отходы", "Лампочки", "Пластик"]
}
@app.get("/api/trashbox", response_model=List[pydantic_schemas.TrashboxResponse])
async def get_trashboxes(data: pydantic_schemas.TrashboxRequest = Depends()): #крутая функция для работы с api
@ -252,27 +263,12 @@ async def get_trashboxes(data: pydantic_schemas.TrashboxRequest = Depends()):#к
'limit' : '1'
}
# Перевод категории с фронта на категорию с сайта
match data.Category:
case "PORRIDGE":
list_of_category = ["Опасные отходы", "Иное"]
case "conspects":
list_of_category = ["Бумага"]
case "milk":
list_of_category = ["Стекло", "Тетра Пак", "Иное"]
case "bred":
list_of_category = ["Пластик", "Иное"]
case "wathing":
list_of_category = ["Пластик", "Опасные отходы", "Иное"]
case "cloth":
list_of_category = ["Одежда"]
case "fruits_vegatables":
list_of_category = ["Иное"]
case "other_things":
list_of_category = ["Металл", "Бумага", "Стекло", "Иное", "Тетра Пак", "Батарейки", "Крышечки", "Шины",
"Опасные отходы", "Лампочки", "Пластик"]
list_of_category = trashboxes_category[data.Category]
# Получение ответа от стороннего апи
response = requests.post(TRASHBOXES_BASE_URL + "/nearest_recycling/get", headers=head, data=my_data, timeout=10)
infos = response.json()
# Чтение ответа
trashboxes = []
for trashbox in infos["results"]:

View File

@ -1,7 +1,8 @@
from sqlalchemy import Column, Integer, String, Boolean, Float, Date, ForeignKey
from .db import Base, engine
from sqlalchemy.orm import relationship
from .db import Base, engine
class User(Base):#класс пользователя
__tablename__ = "users"