fix: Поправил TypeHints и убраз неиспользуемые сущности

develop
Сергей Ванюшкин 2024-02-14 15:34:24 +03:00
parent 5ef6aaeb6f
commit 8189aaedd4
14 changed files with 32 additions and 69 deletions

View File

@ -1,4 +1,5 @@
import os
from typing import Any
import gspread
import openpyxl
@ -43,7 +44,9 @@ async def local_xlsx_to_rows() -> list[list[str | int | float]]:
return data
async def rows_to_dict(rows: list[list]) -> tuple:
async def rows_to_dict(
rows: list[list],
) -> tuple[dict[int, Any], dict[Any, Any], dict[Any, Any]]:
"""Парсит строки полученные и источников в словарь"""
menus = {}

View File

@ -1,5 +1,6 @@
import os
import pickle
from typing import Any
import redis.asyncio as redis # type: ignore
from sqlalchemy import delete, update
@ -43,7 +44,9 @@ async def is_changed_xls() -> bool:
return True
async def on_menu_change(new_menu: dict, old_menu: dict, session: AsyncSession) -> dict:
async def on_menu_change(
new_menu: dict, old_menu: dict, session: AsyncSession
) -> dict[str, Any]:
"""Изменение, удаление или создание меню"""
if new_menu and not old_menu:
# Создаем меню
@ -104,7 +107,7 @@ async def menus_updater(menus: dict, session: AsyncSession) -> None:
async def on_submenu_change(
new_sub: dict, old_sub: dict, session: AsyncSession
) -> dict:
) -> dict[str, Any]:
if new_sub and not old_sub:
# Создаем подменю
submenu = SubMenu(
@ -183,7 +186,9 @@ async def submenus_updater(submenus: dict, session: AsyncSession) -> None:
await redis.set('ALL_SUBMENUS', pickle.dumps(submenus))
async def on_dish_change(new_dish: dict, old_dish, session: AsyncSession) -> dict:
async def on_dish_change(
new_dish: dict, old_dish, session: AsyncSession
) -> dict[str, Any]:
if new_dish and not old_dish:
dish = Dish(
title=new_dish['data']['title'],

View File

@ -55,8 +55,6 @@ services:
redis:
condition: service_healthy
restart: always
volumes:
- .:/usr/src/fastfood

View File

@ -1,13 +0,0 @@
{
"type": "service_account",
"project_id": "psyched-ceiling-413920",
"private_key_id": "d19492eea6a030092cf8ad767b62d7909734ccb1",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIB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mT15PJkbx0lMYEYzw\nPyB7doBHIQKBgGiJi7ZpYYRw1eLH0fOOk1if+uhUqHTrYx/M6MjGRHTryBgXCkzI\n8QIAO9/hqwOirpq2/9pDgXZR1uC90EkC2jlQvPvAUokg7T5ikYpd3Y4ZSkoUjoAS\ngTK20yFvuw4DgVUvJIO7a+14PgjU1MQYC52MEPuv6sbvItX1Oxq/FnRhAoGAHWYK\ncbBSvJzuKtY+CC3gPa0i5cfq07VIVU8Pm7OosM7Q0CR/y88ntgVsscC0qJFwr/EU\ny7aJyBY9TInYqDPzMTeJVXsUwQ5gJut4ngFWk6kitDsJwFqqNFKmeLOj4repY5ee\n79U6kEHJzkOE8VgsH5nW4sjzDEQ9hmhOJ3tFz0ECgYEA8N+7yq1tK/99S8ThYW1J\n9mvUXRhAcFamBYp+8bIBdnQlrM9bGd9j8gYzQj+RBcvfCpVHFM20z8CC8oN0bitk\nh5MEjLBkw1vaywFlA/hcnA8A3g+5/IgHl03Y1tPWnyAtB77vE2M2ThklZ5l4E8eT\nP1vYw9RUSAPjtd43XDTqPNQ=\n-----END PRIVATE KEY-----\n",
"client_email": "tester@psyched-ceiling-413920.iam.gserviceaccount.com",
"client_id": "100697987276606879445",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/tester%40psyched-ceiling-413920.iam.gserviceaccount.com",
"universe_domain": "googleapis.com"
}

View File

@ -13,7 +13,7 @@ class DishRepository:
def __init__(self, session: AsyncSession = Depends(get_async_session)) -> None:
self.db = session
async def get_dishes(self, menu_id: UUID, submenu_id: UUID) -> list[Dish]:
async def get_dishes(self, submenu_id: UUID) -> list[Dish]:
query = select(Dish).where(
Dish.parent_submenu == submenu_id,
)
@ -22,7 +22,6 @@ class DishRepository:
async def create_dish_item(
self,
menu_id: UUID,
submenu_id: UUID,
dish_data: Dish_db,
) -> Dish:
@ -35,8 +34,6 @@ class DishRepository:
async def get_dish_item(
self,
menu_id: UUID,
submenu_id: UUID,
dish_id: UUID,
) -> Dish | None:
query = select(Dish).where(Dish.id == dish_id)
@ -45,8 +42,6 @@ class DishRepository:
async def update_dish_item(
self,
menu_id: UUID,
submenu_id: UUID,
dish_id: UUID,
dish_data: Dish_db,
) -> Dish | None:
@ -59,8 +54,6 @@ class DishRepository:
async def delete_dish_item(
self,
menu_id: UUID,
submenu_id: UUID,
dish_id: UUID,
) -> None:
query = delete(Dish).where(Dish.id == dish_id)

View File

@ -32,14 +32,13 @@ class SubMenuRepository:
await self.db.commit()
await self.db.refresh(new_submenu)
full_sub = await self.get_submenu_item(menu_id, new_submenu.id)
full_sub = await self.get_submenu_item(new_submenu.id)
if full_sub is None:
raise TypeError
return full_sub
async def get_submenu_item(
self,
menu_id: UUID,
submenu_id: UUID,
) -> SubMenu | None:
s = aliased(SubMenu)
@ -56,7 +55,6 @@ class SubMenuRepository:
async def update_submenu_item(
self,
menu_id: UUID,
submenu_id: UUID,
submenu_data: MenuBase,
) -> SubMenu | None:
@ -71,7 +69,7 @@ class SubMenuRepository:
updated_submenu = await self.db.execute(qr)
return updated_submenu.scalar_one_or_none()
async def delete_submenu_item(self, menu_id: UUID, submenu_id: UUID) -> None:
async def delete_submenu_item(self, submenu_id: UUID) -> None:
query = delete(SubMenu).where(
SubMenu.id == submenu_id,
)

View File

@ -1,3 +1,5 @@
from typing import Any
from fastapi import Depends
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
@ -11,7 +13,7 @@ class SummaryRepository:
def __init__(self, session: AsyncSession = Depends(get_async_session)) -> None:
self.db = session
async def get_data(self):
async def get_data(self) -> list[Any]:
query = select(Menu).options(
selectinload(Menu.submenus).selectinload(SubMenu.dishes)
)

View File

@ -1,6 +1,6 @@
from uuid import UUID
from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException
from fastfood.schemas import Dish, DishBase
from fastfood.service.dish import DishService
@ -19,7 +19,6 @@ async def get_dishes(
menu_id: UUID,
submenu_id: UUID,
dish: DishService = Depends(),
background_tasks: BackgroundTasks = BackgroundTasks(),
) -> list[Dish]:
result = await dish.read_dishes(menu_id, submenu_id)
return result
@ -35,7 +34,6 @@ async def create_dish(
submenu_id: UUID,
dish_data: DishBase,
dish: DishService = Depends(),
background_tasks: BackgroundTasks = BackgroundTasks(),
) -> Dish:
return await dish.create_dish(
menu_id,
@ -53,7 +51,6 @@ async def get_dish(
submenu_id: UUID,
dish_id: UUID,
dish: DishService = Depends(),
background_tasks: BackgroundTasks = BackgroundTasks(),
) -> Dish | None:
result = await dish.read_dish(
menu_id,
@ -78,7 +75,6 @@ async def update_dish(
dish_id: UUID,
dish_data: DishBase,
dish: DishService = Depends(),
background_tasks: BackgroundTasks = BackgroundTasks(),
) -> Dish:
result = await dish.update_dish(
menu_id,
@ -102,6 +98,5 @@ async def delete_dish(
submenu_id: UUID,
dish_id: UUID,
dish: DishService = Depends(),
background_tasks: BackgroundTasks = BackgroundTasks(),
) -> None:
await dish.del_dish(menu_id, submenu_id, dish_id)
await dish.del_dish(menu_id, dish_id)

View File

@ -1,6 +1,6 @@
from uuid import UUID
from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException
from fastfood.schemas import MenuBase, MenuRead
from fastfood.service.menu import MenuService
@ -18,7 +18,6 @@ router = APIRouter(
)
async def get_menus(
menu: MenuService = Depends(),
background_tasks: BackgroundTasks = BackgroundTasks(),
) -> list[MenuRead]:
return await menu.read_menus()
@ -31,7 +30,6 @@ async def get_menus(
async def add_menu(
menu: MenuBase,
responce: MenuService = Depends(),
background_tasks: BackgroundTasks = BackgroundTasks(),
) -> MenuRead:
return await responce.create_menu(menu)
@ -43,7 +41,6 @@ async def add_menu(
async def get_menu(
menu_id: UUID,
responce: MenuService = Depends(),
background_tasks: BackgroundTasks = BackgroundTasks(),
) -> MenuRead:
result = await responce.read_menu(menu_id=menu_id)
@ -63,7 +60,6 @@ async def update_menu(
menu_id: UUID,
menu: MenuBase,
responce: MenuService = Depends(),
background_tasks: BackgroundTasks = BackgroundTasks(),
) -> MenuRead:
result = await responce.update_menu(
menu_id=menu_id,
@ -85,6 +81,5 @@ async def update_menu(
async def delete_menu(
menu_id: UUID,
menu: MenuService = Depends(),
background_tasks: BackgroundTasks = BackgroundTasks(),
) -> None:
await menu.del_menu(menu_id)

View File

@ -1,6 +1,6 @@
from uuid import UUID
from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException
from fastfood.schemas import MenuBase, SubMenuRead
from fastfood.service.submenu import SubmenuService
@ -18,7 +18,6 @@ router = APIRouter(
async def get_submenus(
menu_id: UUID,
submenu: SubmenuService = Depends(),
background_tasks: BackgroundTasks = BackgroundTasks(),
) -> list[SubMenuRead]:
result = await submenu.read_submenus(menu_id=menu_id)
return result
@ -33,7 +32,6 @@ async def create_submenu_item(
menu_id: UUID,
submenu_data: MenuBase,
submenu: SubmenuService = Depends(),
background_tasks: BackgroundTasks = BackgroundTasks(),
) -> SubMenuRead:
result = await submenu.create_submenu(
menu_id=menu_id,
@ -50,7 +48,6 @@ async def get_submenu(
menu_id: UUID,
submenu_id: UUID,
submenu: SubmenuService = Depends(),
background_tasks: BackgroundTasks = BackgroundTasks(),
) -> SubMenuRead:
result = await submenu.read_menu(
menu_id=menu_id,
@ -73,7 +70,6 @@ async def update_submenu(
submenu_id: UUID,
submenu_data: MenuBase,
submenu: SubmenuService = Depends(),
background_tasks: BackgroundTasks = BackgroundTasks(),
) -> SubMenuRead:
result = await submenu.update_submenu(
menu_id=menu_id,
@ -96,6 +92,5 @@ async def delete_submenu(
menu_id: UUID,
submenu_id: UUID,
submenu: SubmenuService = Depends(),
background_tasks: BackgroundTasks = BackgroundTasks(),
) -> None:
await submenu.del_menu(menu_id=menu_id, submenu_id=submenu_id)

View File

@ -1,4 +1,4 @@
from fastapi import APIRouter, BackgroundTasks, Depends
from fastapi import APIRouter, Depends
from fastfood.schemas import MenuSummary
from fastfood.service.summary import SummaryService
@ -12,6 +12,5 @@ router = APIRouter(
@router.get('/', response_model=list[MenuSummary])
async def get_summary(
sum: SummaryService = Depends(),
background_tasks: BackgroundTasks = BackgroundTasks(),
) -> list[MenuSummary]:
return await sum.read_data()

View File

@ -42,7 +42,7 @@ class DishService:
if cached_dishes is not None:
return cached_dishes
data = await self.dish_repo.get_dishes(menu_id, submenu_id)
data = await self.dish_repo.get_dishes(submenu_id)
response = []
for row in data:
dish = await self._convert_dish_to_dict(row)
@ -67,7 +67,6 @@ class DishService:
) -> Dish:
dish_db = Dish_db(**dish_data.model_dump())
data = await self.dish_repo.create_dish_item(
menu_id,
submenu_id,
dish_db,
)
@ -95,7 +94,7 @@ class DishService:
if cached_dish is not None:
return cached_dish
data = await self.dish_repo.get_dish_item(menu_id, submenu_id, dish_id)
data = await self.dish_repo.get_dish_item(dish_id)
if data is None:
return None
dish = await self._convert_dish_to_dict(data)
@ -116,9 +115,7 @@ class DishService:
self, menu_id: UUID, submenu_id: UUID, dish_id, dish_data: DishBase
) -> Dish | None:
dish_db = Dish_db(**dish_data.model_dump())
data = await self.dish_repo.update_dish_item(
menu_id, submenu_id, dish_id, dish_db
)
data = await self.dish_repo.update_dish_item(dish_id, dish_db)
if data is None:
return None
@ -139,10 +136,8 @@ class DishService:
return dish
async def del_dish(self, menu_id: UUID, submenu_id: UUID, dish_id: UUID) -> None:
async def del_dish(self, menu_id: UUID, dish_id: UUID) -> None:
await self.dish_repo.delete_dish_item(
menu_id,
submenu_id,
dish_id,
)
await self.cache.delete(key=str(menu_id), bg_task=self.bg_tasks)

View File

@ -33,7 +33,7 @@ class SubmenuService:
submenus = []
for r in data:
submenu = r.__dict__
subq = await self.submenu_repo.get_submenu_item(menu_id, r.id)
subq = await self.submenu_repo.get_submenu_item(r.id)
if subq is not None:
submenu['dishes_count'] = len(subq.dishes)
submenu = SubMenuRead(**submenu)
@ -73,7 +73,7 @@ class SubmenuService:
if cached_submenu is not None:
return cached_submenu
data = await self.submenu_repo.get_submenu_item(menu_id, submenu_id)
data = await self.submenu_repo.get_submenu_item(submenu_id)
if data is None:
return None
submenu = data.__dict__
@ -90,9 +90,7 @@ class SubmenuService:
async def update_submenu(
self, menu_id: UUID, submenu_id: UUID, submenu_data: MenuBase
) -> SubMenuRead | None:
data = await self.submenu_repo.update_submenu_item(
menu_id, submenu_id, submenu_data
)
data = await self.submenu_repo.update_submenu_item(submenu_id, submenu_data)
if data is None:
return None
@ -111,7 +109,7 @@ class SubmenuService:
return submenu
async def del_menu(self, menu_id: UUID, submenu_id: UUID) -> None:
await self.submenu_repo.delete_submenu_item(menu_id, submenu_id)
await self.submenu_repo.delete_submenu_item(submenu_id)
await self.cache.delete(
key=self.key(
'submenu',

View File

@ -19,7 +19,7 @@ class SummaryService:
self.key = get_key
self.bg_tasks = background_tasks
async def read_data(self):
async def read_data(self) -> list[MenuSummary]:
result = []