Skip to content

Commit

Permalink
huge refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
michael7nightingale committed Apr 12, 2024
1 parent 60e4085 commit 4cfebeb
Show file tree
Hide file tree
Showing 81 changed files with 5,513 additions and 1,439 deletions.
11 changes: 0 additions & 11 deletions backend/.flake8

This file was deleted.

6 changes: 3 additions & 3 deletions backend/.test.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ SUPERUSER_USERNAME=admin
SUPERUSER_PASSWORD=password
SUPERUSER_EMAIL=admin@gmail.com

EMAIL_USER=suslanchikmopl@gmail.com
EMAIL_PASSWORD=12345678
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=465
EMAIL_HOST=smtp.gmail.com
EMAIL_USER=suslanchikmopl@gmail.com
EMAIL_PASSWORD=fjyndurcxgzfgcjo

ALGORITHM=HS256
SECRET_KEY=asdf0-aofjklasjmfg;algk
Expand Down
2 changes: 1 addition & 1 deletion backend/aioredis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def parse_georadius_generic(response, **options):
# with other command arguments.
return response

if type(response) != list:
if not isinstance(response, list):
response_list = [response]
else:
response_list = response
Expand Down
70 changes: 70 additions & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
[tool.ruff]
# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
"migrations",
"aioredis",
"tests",

]

# Same as Black.
line-length = 120
indent-width = 4

# Assume Python 3.8
target-version = "py311"

[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
select = ["E", "F", "W"]
ignore = []

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"


[tool.mypy]
exclude = [
"venv",
"src.aioredis"
]
explicit_package_bases = true
mypy_path = "src"
62 changes: 24 additions & 38 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,66 +1,52 @@
aiosqlite==0.17.0
amqp==5.2.0
annotated-types==0.6.0
anyio==4.2.0
asgiref==3.7.2
anyio==4.3.0
async-timeout==4.0.3
asyncpg==0.29.0
billiard==4.2.0
celery==5.3.6
certifi==2024.2.2
charset-normalizer==3.3.2
click==8.1.7
click-didyoumean==0.3.0
click-didyoumean==0.3.1
click-plugins==1.1.1
click-repl==0.3.0
contourpy==1.2.0
contourpy==1.2.1
cycler==0.12.1
dnspython==2.5.0
ecdsa==0.18.0
email-validator==2.1.0.post1
fastapi==0.109.2
dnspython==2.6.1
ecdsa==0.19.0
email_validator==2.1.1
fastapi==0.110.1
fastapi-authtools==0.6.2
fonttools==4.48.1
gunicorn==21.2.0
h11==0.14.0
httpcore==1.0.2
httpx==0.26.0
fonttools==4.51.0
idna==3.6
iso8601==1.1.0
kiwisolver==1.4.5
kombu==5.3.5
matplotlib==3.8.2
motor==3.3.2
mpmath==1.3.0
nest-asyncio==1.6.0
kombu==5.3.6
matplotlib==3.8.4
numpy==1.26.4
packaging==23.2
pandas==2.2.0
packaging==24.0
pandas==2.2.1
passlib==1.7.4
pillow==10.2.0
pillow==10.3.0
prompt-toolkit==3.0.43
pyasn1==0.5.1
pydantic==2.6.1
pydantic-settings==2.1.0
pydantic_core==2.16.2
pymongo==4.6.1
pyparsing==3.1.1
pyasn1==0.6.0
pydantic==2.0.2
pydantic-settings==2.2.1
pydantic_core==2.1.2
pyparsing==3.1.2
pypika-tortoise==0.1.6
python-dateutil==2.8.2
python-dateutil==2.9.0.post0
python-dotenv==1.0.1
python-jose==3.3.0
pytz==2024.1
redis==5.0.1
requests==2.31.0
redis==5.0.3
rsa==4.9
ruff==0.3.5
six==1.16.0
sniffio==1.3.0
starlette==0.36.3
sympy==1.12
sniffio==1.3.1
starlette==0.37.2
tortoise-orm==0.20.0
typing_extensions==4.9.0
typing_extensions==4.11.0
tzdata==2024.1
urllib3==2.2.0
uvicorn==0.27.1
vine==5.1.0
wcwidth==0.2.13
22 changes: 15 additions & 7 deletions backend/src/apps/cabinets/routes.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
from fastapi import APIRouter, Request, Depends
from fastapi.responses import FileResponse, RedirectResponse
from fastapi_authtools import login_required

from .dependencies import HistoryParser
from .models import History
from .schemas import HistoryListSchema
from .services import delete_history
from ..users.permissions import login_required

router = APIRouter(prefix="/cabinet", tags=["Cabinets"])


@router.get('/history')
@router.get('/history', response_model=list[HistoryListSchema])
@login_required
async def history(request: Request):
async def history_list_view(request: Request):
"""History view."""
history_list = await History.filter(user__id=request.user.id)
return history_list
history_list = await History.filter(user__id=request.user.id).select_related("formula", "formula__category")
return [
{
**history.as_dict(),
"formula": history.formula.as_dict(),
"category": history.formula.category.as_dict(),
}
for history in history_list
]


@router.post('/history/download')
@login_required
async def history(request: Request, filedata: str = Depends(HistoryParser())):
async def history_download_view(request: Request, filedata: str = Depends(HistoryParser())):
if filedata is not None:
filepath, filename = filedata
return FileResponse(path=filepath, filename=filename)
Expand All @@ -29,6 +37,6 @@ async def history(request: Request, filedata: str = Depends(HistoryParser())):

@router.delete('/history')
@login_required
async def history(request: Request):
async def history_delete_view(request: Request):
await delete_history(request.user)
return {"detail": "History deletes successfully"}
12 changes: 12 additions & 0 deletions backend/src/apps/cabinets/schemas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
from datetime import datetime

from pydantic import BaseModel

from src.apps.sciences.schemas import FormulaListSchema, CategoryListSchema


class DownloadFile(BaseModel):
filename: str
extension: str


class HistoryListSchema(BaseModel):
id: str
result: float | str
date_time: datetime
formula: FormulaListSchema
category: CategoryListSchema
10 changes: 0 additions & 10 deletions backend/src/apps/main/routes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from fastapi import APIRouter, Request
from fastapi.responses import RedirectResponse


router = APIRouter(prefix='', tags=["Main"])
Expand All @@ -9,12 +8,3 @@
async def homepage(request: Request):
"""Main page."""
return {"detail": "Application is started."}


@router.get("/github")
async def github_redirect(request: Request):
"""Redirect to the GitHub project repository."""
return RedirectResponse(
url="https://github.com/michael7nightingale/Calculations-FastAPI-Fullstack",
status_code=303,
)
3 changes: 2 additions & 1 deletion backend/src/apps/sciences/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ async def get_mongodb_db(request: Request):
def get_mongodb_repository(repository_class):
def inner(db=Depends(get_mongodb_db)):
return repository_class(db)

return inner


Expand All @@ -37,7 +38,7 @@ async def get_science_dependency(science_slug: str) -> Science:


async def get_category_dependency(category_slug: str) -> Category:
category = await Formula.get_or_none(slug=category_slug)
category = await Category.get_or_none(slug=category_slug)
if category is None:
raise HTTPException(status_code=404, detail="Category is not found.")
return category
7 changes: 7 additions & 0 deletions backend/src/apps/sciences/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class Science(TortoiseModel):
image_path = fields.CharField(max_length=255, null=True)
slug = fields.CharField(max_length=40, unique=True, index=True)

class Meta:
ordering = ["title"]

def __str__(self):
return self.title

Expand All @@ -32,6 +35,9 @@ class Category(TortoiseModel):
slug = fields.CharField(max_length=40, unique=True, index=True)
is_special = fields.BooleanField(default=False)

class Meta:
ordering = ["title"]

def __str__(self):
return self.title

Expand All @@ -55,6 +61,7 @@ class Formula(TortoiseModel):
related_name="formulas"
)
slug = fields.CharField(max_length=40, unique=True, index=True)
data = fields.JSONField(null=True)

def __str__(self):
return self.title
Expand Down
Loading

0 comments on commit 4cfebeb

Please sign in to comment.