-
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.
Merge pull request #1 from hrspace-request-builder/feature/initial
Feature/initial
- Loading branch information
Showing
29 changed files
with
632 additions
and
0 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,31 @@ | ||
name: Test Suite | ||
|
||
on: | ||
push: | ||
branches: ["main", "develop"] | ||
pull_request: | ||
branches: ["main", "develop"] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
|
||
tests: | ||
name: Tests Ruff and pytest | ||
runs-on: ubuntu-latest | ||
strategy: | ||
max-parallel: 3 | ||
matrix: | ||
python-version: ["3.10", "3.11", "3.12"] | ||
steps: | ||
- name: Checkout the repo | ||
uses: actions/checkout@v4 | ||
- name: Setup Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Ruff check | ||
uses: chartboost/ruff-action@v1 | ||
- name: Install Dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements/test.requirements.txt |
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,173 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
.pybuilder/ | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
fastapi.db | ||
test.db | ||
_main.yml | ||
_test* | ||
=GARB= | ||
infra/local/admin | ||
.~lock.*.xlsx# | ||
|
||
# pyenv | ||
# For a library or package, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# .python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# poetry | ||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. | ||
# This is especially recommended for binary packages to ensure reproducibility, and is more | ||
# commonly ignored for libraries. | ||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control | ||
#poetry.lock | ||
|
||
# pdm | ||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. | ||
#pdm.lock | ||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it | ||
# in version control. | ||
# https://pdm.fming.dev/#use-with-ide | ||
.pdm.toml | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# pytype static type analyzer | ||
.pytype/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ | ||
|
||
# PyCharm | ||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can | ||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore | ||
# and can be added to the global gitignore or merged into this file. For a more nuclear | ||
# option (not recommended) you can uncomment the following to ignore the entire idea folder. | ||
.idea | ||
.vscode | ||
.ruff* | ||
fastapi.db | ||
test.db | ||
=GARB= |
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,60 @@ | ||
repos: | ||
|
||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.2.0 | ||
hooks: | ||
- id: trailing-whitespace # убирает лишние пробелы | ||
- id: check-added-large-files # проверяет тяжелые файлы на изменения | ||
- id: check-yaml # проверяет синтаксис .yaml файлов | ||
- id: check-json # проверяет синтаксис .json файлов | ||
exclude: launch.json | ||
- id: check-case-conflict # проверяет файлы, которые могут конфликтовать в файловых системах без учета регистра. | ||
- id: check-merge-conflict # проверяет файлы, содержащие конфликтные строки слияния. | ||
- id: end-of-file-fixer # добавляет пустую строку в конце файла | ||
|
||
# Отсортировывает импорты в проекте | ||
- repo: https://github.com/pycqa/isort | ||
rev: 5.12.0 | ||
hooks: | ||
- id: isort | ||
exclude: __init__.py | ||
args: [ --profile, black, --filter-files ] | ||
|
||
# Обновляет синтаксис Python кода в соответствии с последними версиями | ||
- repo: https://github.com/asottile/pyupgrade | ||
rev: v2.31.1 | ||
hooks: | ||
- id: pyupgrade | ||
args: [--py310-plus] | ||
|
||
# Форматирует код под PEP8 | ||
- repo: https://github.com/pre-commit/mirrors-autopep8 | ||
rev: v2.0.4 | ||
hooks: | ||
- id: autopep8 | ||
args: [--max-line-length=120, --in-place] | ||
|
||
# Сканер стилистических ошибок, нарушающие договоренности PEP8 | ||
- repo: https://github.com/PyCQA/flake8 | ||
rev: 6.0.0 | ||
hooks: | ||
- id: flake8 | ||
exclude: "__init__.py" | ||
args: ["--ignore=F821,F403,F405"] | ||
|
||
# Проверка статических типов с помощью mypy | ||
- repo: https://github.com/pre-commit/mirrors-mypy | ||
rev: v0.991 | ||
hooks: | ||
- id: mypy | ||
exclude: 'alembic' | ||
|
||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
# Ruff version. | ||
rev: v0.3.2 | ||
hooks: | ||
# Run the linter. | ||
- id: ruff | ||
args: [ --fix ] | ||
# Run the formatter. | ||
- id: ruff-format |
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,2 +1,60 @@ | ||
# hrspace-request-builder-backend | ||
|
||
|
||
Backend for hrspace-requst-builder | ||
|
||
## Установка приложения: | ||
|
||
<details><summary>Предварительные условия</summary> | ||
|
||
Предполагается, что пользователь установил [Docker](https://docs.docker.com/engine/install/) и [Docker Compose](https://docs.docker.com/compose/install/) на локальной машине. Проверить наличие можно выполнив команды: | ||
|
||
```bash | ||
docker --version && docker-compose --version | ||
``` | ||
</details> | ||
|
||
<br> | ||
|
||
Клонируйте репозиторий с GitHub и введите данные для переменных окружения (значения даны для примера, но их можно оставить): | ||
|
||
```bash | ||
git clone https://github.com/hrspace-request-builder/hrspace-request-builder-backend.git | ||
cd hrspace-request-builder-backend | ||
cp env_example .env | ||
nano .env | ||
``` | ||
|
||
<br> | ||
|
||
## Запуск приложения: | ||
|
||
1. Из корневой директории проекта выполните команду: | ||
```bash | ||
docker compose -f docker/docker-compose.yml --env-file .env up -d --build | ||
``` | ||
Проект будет развернут в docker-контейнерах по адресу http://127.0.0.1:8000. | ||
|
||
Администрирование приложения может быть осуществлено: | ||
- через Swagger доступный по адресу http://127.0.0.1:8000/docs | ||
- через админ панель по адресу http://127.0.0.1:8000/admin | ||
|
||
<br> | ||
2. Остановить docker и удалить контейнеры можно командой из корневой директории проекта: | ||
|
||
```bash | ||
docker compose -f docker/docker-compose.yml --env-file .env down | ||
``` | ||
|
||
Если также необходимо удалить том базы данных: | ||
```bash | ||
docker compose -f docker/docker-compose.yml --env-file .env down -v | ||
``` | ||
|
||
<br> | ||
|
||
## Удаление приложения: | ||
Из корневой директории проекта выполните команду: | ||
```bash | ||
cd .. && rm -fr hrspace-request-builder-backend | ||
``` |
File renamed without changes.
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,10 @@ | ||
from starlette_admin.contrib.sqla import Admin | ||
from .views import VacancyView, Vacancy | ||
from app.core.dependencies import engine | ||
|
||
|
||
admin = Admin( | ||
engine, | ||
"💾 База данных HRSpace", | ||
) | ||
admin.add_view(VacancyView(Vacancy)) |
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,15 @@ | ||
from starlette_admin import TextAreaField | ||
from starlette_admin.contrib.sqla import ModelView | ||
|
||
from app.models.models import Vacancy | ||
|
||
|
||
class VacancyView(ModelView): | ||
model = Vacancy | ||
fields = ( | ||
"id", | ||
"title", | ||
TextAreaField( | ||
"description", | ||
), | ||
) |
File renamed without changes.
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,26 @@ | ||
from fastapi import APIRouter | ||
|
||
from app.core.config import settings | ||
from app.core.dependencies import async_session | ||
from app.models.models import Vacancy | ||
from app.schemas import schemas | ||
|
||
from .responses import get_400, get_404 | ||
|
||
SUM_ALL_ITEMS = "ALL_ITEMS" | ||
|
||
router = APIRouter(prefix=f"{settings.URL_PREFIX}items", tags=["Items"]) | ||
|
||
|
||
@router.get( | ||
"/", | ||
response_model=list[schemas.VacancyOut], | ||
responses={**get_400("Item"), **get_404("Item")}, | ||
summary=SUM_ALL_ITEMS, | ||
description=(f"{settings.ALL_USERS} {SUM_ALL_ITEMS}"), | ||
) | ||
async def get_all_vacancies(session: async_session) -> list: | ||
from sqlalchemy import select | ||
|
||
stmt = select(Vacancy) | ||
return await session.scalars(stmt) |
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,17 @@ | ||
from typing import Any | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
def get_400(name: str) -> dict[int, dict[str, Any]]: | ||
class Message(BaseModel): | ||
detail: str = f"{name} already exists" | ||
|
||
return {400: {"model": Message, "description": "The item already exists"}} | ||
|
||
|
||
def get_404(name: str) -> dict[int, dict[str, Any]]: | ||
class Message(BaseModel): | ||
detail: str = f"{name} not found" | ||
|
||
return {404: {"model": Message, "description": "The item was not found"}} |
Oops, something went wrong.