-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 error ImportError: cannot import name 'FilmService' from partially initialized module 'src.services.film' (most likely due to a circular import) (/Users/ershov/Desktop/practicum-async-api/async_api/src/services/film.py)
- Loading branch information
Showing
19 changed files
with
55 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
содержит исходный код приложения |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
содержит разные конфигурационные файлы. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,14 @@ | ||
from fastapi import APIRouter | ||
from pydantic import BaseModel | ||
|
||
# Объект router, в котором регистрируем обработчики | ||
router = APIRouter() | ||
|
||
# FastAPI в качестве моделей использует библиотеку pydantic | ||
# https://pydantic-docs.helpmanual.io | ||
# У неё есть встроенные механизмы валидации, сериализации и десериализации | ||
# Также она основана на дата-классах | ||
|
||
|
||
# Модель ответа API | ||
class Film(BaseModel): | ||
id: str | ||
title: str | ||
|
||
|
||
# С помощью декоратора регистрируем обработчик film_details | ||
# На обработку запросов по адресу <some_prefix>/some_id | ||
# Позже подключим роутер к корневому роутеру | ||
# И адрес запроса будет выглядеть так — /api/v1/film/some_id | ||
# В сигнатуре функции указываем тип данных, получаемый из адреса запроса (film_id: str) | ||
# И указываем тип возвращаемого объекта — Film | ||
@router.get("/{film_id}", response_model=Film) | ||
async def film_details(film_id: str) -> Film: | ||
return Film(id="some_id", title="some_title") | ||
async def film_details(film_id: str = "0") -> Film: | ||
return Film(id=film_id, title="some_title") |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
import os | ||
|
||
from logging import config as logging_config | ||
from pathlib import Path | ||
|
||
from core.logger import LOGGING | ||
|
||
# Применяем настройки логирования | ||
logging_config.dictConfig(LOGGING) | ||
|
||
# Название проекта. Используется в Swagger-документации | ||
PROJECT_NAME = os.getenv("PROJECT_NAME", "movies") | ||
|
||
# Настройки Redis | ||
REDIS_HOST = os.getenv("REDIS_HOST", "127.0.0.1") | ||
REDIS_PORT = int(os.getenv("REDIS_PORT", 6379)) | ||
REDIS_PORT = int(os.getenv("REDIS_PORT", "6379")) | ||
|
||
# Настройки Elasticsearch | ||
ELASTIC_HOST = os.getenv("ELASTIC_HOST", "127.0.0.1") | ||
ELASTIC_PORT = int(os.getenv("ELASTIC_PORT", 9200)) | ||
ELASTIC_PORT = int(os.getenv("ELASTIC_PORT", "9200")) | ||
|
||
# Корень проекта | ||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
BASE_DIR = Path(__file__).resolve().parent.parent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
предоставляет объекты баз данных (Redis, Elasticsearch) и провайдеры для внедрения зависимостей. Redis будет использоваться для кеширования, чтобы не нагружать лишний раз Elasticsearch. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
from typing import Optional | ||
# nfrom typing import Optional | ||
|
||
from elasticsearch import AsyncElasticsearch | ||
|
||
es: AsyncElasticsearch | None = None | ||
|
||
|
||
# Функция понадобится при внедрении зависимостей | ||
class GetElasticError(Exception): | ||
def __init__(self, message: str = "Ellastic not found"): | ||
self.message = message | ||
|
||
|
||
async def get_elastic() -> AsyncElasticsearch: | ||
es: AsyncElasticsearch | None = None | ||
if es is None: | ||
raise GetElasticError | ||
return es |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
from typing import Optional | ||
# nfrom typing import Optional | ||
|
||
from redis.asyncio import Redis | ||
|
||
redis: Redis | None = None | ||
|
||
|
||
# Функция понадобится при внедрении зависимостей | ||
class GetRedisError(Exception): | ||
def __init__(self, message: str = "Redis not found"): | ||
self.message = message | ||
|
||
|
||
async def get_redis() -> Redis: | ||
if redis is None: | ||
raise GetRedisError | ||
return redis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
содержит классы, описывающие бизнес-сущности, например, фильмы, жанры, актёров. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
главное в сервисе. В этом модуле находится реализация всей бизнес-логики. Таким образом она отделена от транспорта. Благодаря такому разделению, вам будет легче добавлять новые типы транспортов в сервис. Например, легко добавить RPC протокол поверх AMQP или Websockets. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters