Skip to content

Commit 4f6752b

Browse files
committed
add backend
1 parent ac60cae commit 4f6752b

52 files changed

Lines changed: 2615 additions & 2463 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.copier/.copier-answers.yml.jinja

Lines changed: 0 additions & 1 deletion
This file was deleted.

.copier/update_dotenv.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

.env renamed to .env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ PROJECT_NAME="Full Stack FastAPI Project"
1717
STACK_NAME=full-stack-fastapi-project
1818

1919
# Backend
20-
BACKEND_CORS_ORIGINS="http://localhost,http://localhost:5173,https://localhost,https://localhost:5173,http://localhost.tiangolo.com"
20+
BACKEND_CORS_ORIGINS="http://localhost,http://localhost:5173,https://localhost,https://localhost:5173,http://ar.anon.tiangolo.com"
2121
SECRET_KEY=changethis
2222
FIRST_SUPERUSER=admin@example.com
2323
FIRST_SUPERUSER_PASSWORD=changethis

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ node_modules/
44
/playwright-report/
55
/blob-report/
66
/playwright/.cache/
7+
8+
.env

LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
check:
2+
cd backend && \
3+
uv run ruff check . --fix && \
4+
uv run ruff format .

SECURITY.md

Lines changed: 0 additions & 29 deletions
This file was deleted.

backend/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
FROM python:3.10
1+
FROM --platform=linux/amd64 python:3.10
22

3-
ENV PYTHONUNBUFFERED=1
3+
ENV PYTHONUNBUFFERED=1 \
4+
UV_HTTP_TIMEOUT=3000
45

56
WORKDIR /app/
67

@@ -25,7 +26,7 @@ ENV UV_LINK_MODE=copy
2526
RUN --mount=type=cache,target=/root/.cache/uv \
2627
--mount=type=bind,source=uv.lock,target=uv.lock \
2728
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
28-
uv sync --frozen --no-install-project
29+
uv sync --frozen --no-install-project --no-dev
2930

3031
ENV PYTHONPATH=/app
3132

backend/app/api/deps.py

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
11
from collections.abc import Generator
22
from typing import Annotated
33

4-
import jwt
5-
from fastapi import Depends, HTTPException, status
6-
from fastapi.security import OAuth2PasswordBearer
7-
from jwt.exceptions import InvalidTokenError
8-
from pydantic import ValidationError
4+
from fastapi import Depends
95
from sqlmodel import Session
106

11-
from app.core import security
12-
from app.core.config import settings
137
from app.core.db import engine
14-
from app.models import TokenPayload, User
15-
16-
reusable_oauth2 = OAuth2PasswordBearer(
17-
tokenUrl=f"{settings.API_V1_STR}/login/access-token"
18-
)
198

209

2110
def get_db() -> Generator[Session, None, None]:
@@ -24,34 +13,3 @@ def get_db() -> Generator[Session, None, None]:
2413

2514

2615
SessionDep = Annotated[Session, Depends(get_db)]
27-
TokenDep = Annotated[str, Depends(reusable_oauth2)]
28-
29-
30-
def get_current_user(session: SessionDep, token: TokenDep) -> User:
31-
try:
32-
payload = jwt.decode(
33-
token, settings.SECRET_KEY, algorithms=[security.ALGORITHM]
34-
)
35-
token_data = TokenPayload(**payload)
36-
except (InvalidTokenError, ValidationError):
37-
raise HTTPException(
38-
status_code=status.HTTP_403_FORBIDDEN,
39-
detail="Could not validate credentials",
40-
)
41-
user = session.get(User, token_data.sub)
42-
if not user:
43-
raise HTTPException(status_code=404, detail="User not found")
44-
if not user.is_active:
45-
raise HTTPException(status_code=400, detail="Inactive user")
46-
return user
47-
48-
49-
CurrentUser = Annotated[User, Depends(get_current_user)]
50-
51-
52-
def get_current_active_superuser(current_user: CurrentUser) -> User:
53-
if not current_user.is_superuser:
54-
raise HTTPException(
55-
status_code=403, detail="The user doesn't have enough privileges"
56-
)
57-
return current_user

backend/app/api/main.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
from fastapi import APIRouter
22

3-
from app.api.routes import items, login, private, users, utils
3+
from app.api.routes import dashboard, private
44
from app.core.config import settings
55

66
api_router = APIRouter()
7-
api_router.include_router(login.router)
8-
api_router.include_router(users.router)
9-
api_router.include_router(utils.router)
10-
api_router.include_router(items.router)
7+
api_router.include_router(dashboard.router)
118

129

1310
if settings.ENVIRONMENT == "local":

0 commit comments

Comments
 (0)