-
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 #10 from hrspace-request-builder/feature/micro-models
Feature/micro models
- Loading branch information
Showing
27 changed files
with
509 additions
and
282 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
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 |
---|---|---|
@@ -1,12 +1,11 @@ | ||
from starlette_admin.contrib.sqla import Admin | ||
from .views import City, CityView, Vacancy, VacancyView | ||
from app.core.dependencies import engine | ||
|
||
from .views import City, CityView | ||
|
||
admin = Admin( | ||
engine, | ||
"💾 База данных HRSpace", | ||
) | ||
|
||
admin.add_view(CityView(City)) | ||
admin.add_view(VacancyView(Vacancy)) | ||
# admin.add_view(VacancyView(VacancyName)) |
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,89 @@ | ||
from fastapi import APIRouter | ||
|
||
from app.core.business_logic import get_salary | ||
from app.core.config import settings | ||
from app.core.dependencies import async_session | ||
from app.models import models | ||
from app.repositories import crud | ||
from app.schemas import schemas | ||
|
||
from . import responses | ||
|
||
SUM_CITIES = "Города России" | ||
SUM_CATEGORIES = "Сферы деятельности (и их профессии)" | ||
SUM_CONDITIONS = "Условия труда" | ||
SUM_SPECIALIZATION = "Выбранная специализация (полный формат)" | ||
SUM_SPECIALIZATIONS = "Список профессий (сокращенный формат)" | ||
SUM_REQUIREMENTS = "Общий список требований" | ||
SUM_RESPONSIBILITIES = "Общий список обязанностей" | ||
SUM_ALL_VACANCY_NAMES = "Предлагаемые названия вакансий" | ||
SUM_VACANCY_NAME_DATA = "Данные для полей заявки" | ||
SUM_VACANCY = "Данные заполненной заявки" | ||
|
||
router = APIRouter(prefix=f"{settings.URL_PREFIX}hrspace", tags=["First_page"]) | ||
|
||
|
||
@router.get( | ||
"/cities", | ||
response_model=list[schemas.CityOut], | ||
summary=SUM_CITIES, | ||
description=(f"{settings.ALL_USERS} {SUM_CITIES}"), | ||
) | ||
async def get_all_cities(session: async_session): | ||
return await crud.get_all(session, models.City) | ||
|
||
|
||
@router.get( | ||
"/vacancy_names", | ||
response_model=list[schemas.ShortSpecialization], | ||
summary=SUM_ALL_VACANCY_NAMES, | ||
description=(f"{settings.ALL_USERS} {SUM_ALL_VACANCY_NAMES}"), | ||
) | ||
async def get_all_vacancies(session: async_session) -> list: | ||
return await crud.get_all(session, models.Specialization) | ||
|
||
|
||
@router.get( | ||
"/categories", | ||
response_model=list[schemas.CategoryOut], | ||
summary=SUM_CATEGORIES, | ||
description=(f"{settings.ALL_USERS} {SUM_CATEGORIES}"), | ||
) | ||
async def get_all_categories(session: async_session): | ||
return await crud.get_all(session, models.Category) | ||
|
||
|
||
@router.get( | ||
"/specializations/{vacancy_name_id}", | ||
response_model=schemas.FullSpecialization, | ||
responses={**responses.get_404("Specialization")}, | ||
summary=SUM_SPECIALIZATION, | ||
description=(f"{settings.ALL_USERS} {SUM_SPECIALIZATION}"), | ||
) | ||
async def get_spec(vacancy_name_id: int, session: async_session): | ||
return await crud.get_or_404(session, models.Specialization, vacancy_name_id) | ||
|
||
|
||
@router.get( | ||
"/data/", | ||
responses={**responses.get_404("City or specialization")}, | ||
summary=SUM_VACANCY_NAME_DATA, | ||
description=(f"{settings.ALL_USERS} {SUM_VACANCY_NAME_DATA}"), | ||
) | ||
async def get_data(vacancy_name_id: int, city_id: int, session: async_session): | ||
spec = await crud.get_or_404(session, models.Specialization, vacancy_name_id) | ||
salary = await get_salary(session, city_id) | ||
conditions = [c.asdict() for c in await crud.get_all(session, models.Condition)] | ||
return {**spec.__dict__, **{"salary": salary, "conditions": conditions}} | ||
|
||
|
||
@router.post( | ||
"/vacancy", | ||
status_code=201, | ||
# response_model=schemas.VacancyOut, | ||
# responses={**responses.get_400("Object")}, | ||
summary=SUM_VACANCY, | ||
description=(f"{settings.ALL_USERS} {SUM_VACANCY}"), | ||
) | ||
async def post_vacancy(payload: schemas.VacancyIn, session: async_session): | ||
pass |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
from fastapi import APIRouter | ||
|
||
from app.api.endpoints import example | ||
from app.api.endpoints import endpoints | ||
|
||
main_router = APIRouter() | ||
|
||
|
||
for router in (example.router,): | ||
for router in (endpoints.router,): | ||
main_router.include_router(router) |
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,12 @@ | ||
from decimal import Decimal | ||
|
||
from sqlalchemy.ext.asyncio import AsyncSession | ||
|
||
from app.models.models import City | ||
from app.repositories import crud | ||
|
||
|
||
async def get_salary(session: AsyncSession, city_id: int) -> dict[str, Decimal]: | ||
city = await crud.get_or_404(session, City, city_id) # noqa | ||
# TODO: calculate salary min/max as per city | ||
return {"min": Decimal(1000.00), "max": Decimal(2000.00)} |
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,4 @@ | ||
name | ||
Информационные технологии | ||
Экономика | ||
Юриспруденция |
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,9 @@ | ||
name | ||
Москва | ||
Санкт_Петербург | ||
Вологда | ||
Казань | ||
Владивосток | ||
Красноярск | ||
Воронеж | ||
Белгород |
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,4 @@ | ||
name | ||
оформление по ТК РФ | ||
обустроенный офис | ||
ДМС |
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,41 @@ | ||
import csv | ||
|
||
from sqlalchemy import insert | ||
|
||
from app.core.dependencies import AsyncSessionLocal | ||
from app.models import models as m | ||
|
||
DATA = ( | ||
(m.City, "app/data/cities.csv"), | ||
(m.Condition, "app/data/conditions.csv"), | ||
(m.Category, "app/data/categories.csv"), | ||
(m.Specialization, "app/data/specializations.csv"), | ||
(m.Requirement, "app/data/requirements.csv"), | ||
(m.Responsibility, "app/data/responsibilities.csv"), | ||
) | ||
|
||
|
||
def read_csvfile(file_name: str) -> list[dict[str, str | int]]: | ||
with open(file_name, newline="") as f: | ||
return [row for row in csv.DictReader(f)] | ||
|
||
|
||
def convert_to_int(rows: list[dict[str, str | int]]) -> None: | ||
for row in rows: | ||
for key in row: | ||
try: | ||
row[key] = int(row[key]) | ||
except (TypeError, ValueError): | ||
pass | ||
|
||
|
||
async def load_csv(model, file_name: str) -> None: | ||
rows = read_csvfile(file_name) | ||
convert_to_int(rows) | ||
async with AsyncSessionLocal.begin() as session: | ||
await session.execute(insert(model), rows) | ||
|
||
|
||
async def load_models_data(): | ||
for model, scv_file in DATA: | ||
await load_csv(model, scv_file) |
Oops, something went wrong.