Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RUN apt-get update && apt-get install -y \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*

COPY ./requirements.txt ./setup.cfg ./black.toml ./.pylintrc /
COPY ./requirements.txt ./setup.cfg ./black.toml ./.pylintrc ./pytest.ini /

RUN --mount=type=cache,target=/root/.cache/pip \
pip install --upgrade pip -r /requirements.txt
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ lint:
test:
docker compose run favorite-places-app pytest --cov=/src --cov-report html:htmlcov --cov-report term --cov-config=/src/tests/.coveragerc -vv

database:
docker compose up -d favorite-places-db

migrate:
docker compose run favorite-places-app alembic upgrade head

# запуск всех функций поддержки качества кода
all: format lint test
Empty file modified docs/Makefile
100644 → 100755
Empty file.
Binary file added docs/img/2023-03-05_00-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/2023-03-05_13-31.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/pagination.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified docs/make.bat
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion docs/source/conf.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
version = settings.project.release_version
# the full project version, including alpha/beta/rc tags
release = settings.project.release_version
author = "Michael"
author = "Roman"
copyright = f"{date.today().year}, {author}"

# -- General configuration ---------------------------------------------------
Expand Down
185 changes: 185 additions & 0 deletions docs/source/index.rst
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,56 @@
Зависимости
===========

Install the appropriate software:

1. [Docker Desktop](https://www.docker.com).
2. [Git](https://github.com/git-guides/install-git).
3. [PyCharm](https://www.jetbrains.com/ru-ru/pycharm/download) (optional).


Установка
=========

Clone the repository to your computer:

.. code-block::console

git clone https://github.com/mnv/python-course-favorite-places.git

1. To configure the application copy `.env.sample` into `.env` file:

.. code-block::console

cp .env.sample .env


This file contains environment variables that will share their values across the application.
The sample file (`.env.sample`) contains a set of variables with default values.
So it can be configured depending on the environment.

2. Build the container using Docker Compose:

.. code-block::console

docker compose build

This command should be run from the root directory where `Dockerfile` is located.
You also need to build the docker container again in case if you have updated `requirements.txt`.

3. To run application correctly set up the database.
Apply migrations to create tables in the database:

.. code-block::console

docker compose run favorite-places-app alembic upgrade head

4. Now it is possible to run the project inside the Docker container:

.. code-block::console

docker compose up

When containers are up server starts at [http://0.0.0.0:8010/docs](http://0.0.0.0:8010/docs). You can open it in your browser.


Использование
Expand All @@ -20,15 +65,155 @@

Работа с базой данных
---------------------
To first initialize migration functionality run:

.. code-block::console

docker compose exec favorite-places-app alembic init -t async migrations

This command will create a directory with configuration files to set up asynchronous migrations' functionality.

To create new migrations that will update database tables according updated models run this command:

.. code-block::console

docker compose run favorite-places-app alembic revision --autogenerate -m "your description"

To apply created migrations run:

.. code-block::console

docker compose run favorite-places-app alembic upgrade head


Автоматизация
=============
The project contains a special `Makefile` that provides shortcuts for a set of commands:

1. Build the Docker container:

.. code-block::console

make build


2. Generate Sphinx documentation run:

.. code-block::console

make docs-html


3. Autoformat source code:

.. code-block::console

make format


4. Static analysis (linters):

.. code-block::console

make lint


5. Autotests:

.. code-block::console

make test


The test coverage report will be located at `src/htmlcov/index.html`.
So you can estimate the quality of automated test coverage.

6. Run autoformat, linters and tests in one command:

.. code-block::console

make all


Run these commands from the source directory where `Makefile` is located.



Тестирование
============
To run tests use the following command:

.. code-block::console

make all

Документация
============

Клиенты
=======
Базовый
--------
.. automodule:: clients.base.base
:members:

Geo
---
.. automodule:: clients.geo
:members:

Schemas
-------
.. automodule:: clients.base.base
:members:

Integrations
============
Database
--------
.. automodule:: integrations.db.session
:members:
Events
------
.. automodule:: integrations.events.events
:members:
.. automodule:: integrations.events.schemas
:members:

Models
======
.. automodule:: models.mixins
:members:
.. automodule:: models.places
:members:
Repositories
============
.. automodule:: repositories.base_repository
:members:
.. automodule:: repositories.places_repository
:members:


Settings
========
.. automodule:: settings
:members:

Schemas
=======
.. automodule:: schemas.base
:members:
.. automodule:: schemas.places
:members:
.. automodule:: schemas.routes
:members:

Services
========
.. automodule:: services.places_service
:members:

Transport
=========
.. automodule:: transport.handlers.places
:members:
31 changes: 31 additions & 0 deletions report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

# Table of Contents

1. [Определение по ip](#org33cd135)
2. [Пагинация](#org395fab9)
3. [Результаты `make all`](#orgd4362b8)



<a id="org33cd135"></a>

# Определение по ip

![img](docs/img/Screenshot 2023-03-05 at 00-01-14 API системы Favorite Places Service - Swagger UI.png)
![img](docs/img/Screenshot 2023-03-05 at 00-00-01 API системы Favorite Places Service - Swagger UI.png)
![img](docs/img/2023-03-05_00-01.png)


<a id="org395fab9"></a>

# Пагинация

![img](docs/img/pagination.png)


<a id="orgd4362b8"></a>

# Результаты `make all`

![img](docs/img/2023-03-05_13-31.png)

11 changes: 11 additions & 0 deletions report.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#+title: Report

* Определение по ip
[[file:docs/img/Screenshot 2023-03-05 at 00-01-14 API системы Favorite Places Service - Swagger UI.png]]
[[file:docs/img/Screenshot 2023-03-05 at 00-00-01 API системы Favorite Places Service - Swagger UI.png]]
[[file:docs/img/2023-03-05_00-01.png]]

* Пагинация
[[file:docs/img/pagination.png]]
* Результаты =make all=
[[file:docs/img/2023-03-05_13-31.png]]
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ asyncpg>=0.26.0,<1.0.0
pika>=1.3.1,<1.4.0
# работа с HTTP-запросами
httpx>=0.23.0,<0.24.0
sqlalchemy-utils==0.40.0
psycopg2-binary==2.9.5

# автоматические тесты
pytest>=7.1.3,<7.2.0
Expand Down
Empty file modified src/__init__.py
100644 → 100755
Empty file.
Empty file modified src/alembic.ini
100644 → 100755
Empty file.
2 changes: 2 additions & 0 deletions src/bootstrap.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fastapi import FastAPI
from fastapi_pagination import add_pagination

from exceptions import setup_exception_handlers
from routes import metadata_tags, setup_routes
Expand All @@ -19,5 +20,6 @@ def build_app() -> FastAPI:

setup_routes(app)
setup_exception_handlers(app)
add_pagination(app)

return app
Empty file modified src/clients/__init__.py
100644 → 100755
Empty file.
Empty file modified src/clients/base/__init__.py
100644 → 100755
Empty file.
Empty file modified src/clients/base/base.py
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion src/clients/geo.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import httpx

from clients.base.base import BaseClient
from clients.shemas import LocalityDTO
from clients.schemas import LocalityDTO


class LocationClient(BaseClient):
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/exceptions.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ApiHTTPException(HTTPException):
"""Обработка ошибок API."""

status_code: int
code: str
code: str = "None"
detail: str

def __init__(
Expand Down
Empty file modified src/integrations/__init__.py
100644 → 100755
Empty file.
Empty file modified src/integrations/db/__init__.py
100644 → 100755
Empty file.
Empty file modified src/integrations/db/session.py
100644 → 100755
Empty file.
Empty file modified src/integrations/events/__init__.py
100644 → 100755
Empty file.
Empty file modified src/integrations/events/producer.py
100644 → 100755
Empty file.
Empty file modified src/integrations/events/schemas.py
100644 → 100755
Empty file.
3 changes: 2 additions & 1 deletion src/logging.conf
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[loggers]
keys=root


[handlers]
keys=fileHandler

Expand All @@ -15,7 +16,7 @@ handlers=fileHandler
class=FileHandler
level=DEBUG
formatter=commonFormatter
args=('/logs/actions.log', 'a',)
args=('../logs/actions.log', 'a',)

[formatter_commonFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
Empty file modified src/main.py
100644 → 100755
Empty file.
Empty file modified src/migrations/README
100644 → 100755
Empty file.
Empty file modified src/migrations/env.py
100644 → 100755
Empty file.
Empty file modified src/migrations/script.py.mako
100644 → 100755
Empty file.
Empty file modified src/migrations/versions/9e96afce0c9e_init.py
100644 → 100755
Empty file.
Empty file modified src/models/__init__.py
100644 → 100755
Empty file.
Empty file modified src/models/mixins.py
100644 → 100755
Empty file.
Empty file modified src/models/places.py
100644 → 100755
Empty file.
Empty file modified src/repositories/__init__.py
100644 → 100755
Empty file.
Empty file modified src/repositories/base_repository.py
100644 → 100755
Empty file.
Empty file modified src/repositories/places_repository.py
100644 → 100755
Empty file.
Empty file modified src/routes.py
100644 → 100755
Empty file.
Empty file modified src/schemas/__init__.py
100644 → 100755
Empty file.
Empty file modified src/schemas/base.py
100644 → 100755
Empty file.
Empty file modified src/schemas/places.py
100644 → 100755
Empty file.
8 changes: 7 additions & 1 deletion src/schemas/routes.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional

from pydantic import BaseModel
from pydantic import BaseModel, Field


class MetadataTag(BaseModel):
Expand All @@ -11,3 +11,9 @@ class MetadataTag(BaseModel):

class Config:
allow_population_by_field_name = True


class Description(BaseModel):
"""Модель для описания"""

description: str = Field(None, min_length=3, max_length=255)
Empty file modified src/services/__init__.py
100644 → 100755
Empty file.
Loading