Skip to content

Commit

Permalink
Merge branch 'upgrade-docker' of https://github.com/javadzarezadeh/fu…
Browse files Browse the repository at this point in the history
…ll-stack-fastapi-template into upgrade-docker
  • Loading branch information
javadzarezadeh committed Dec 29, 2024
2 parents e39fcf4 + 87f8030 commit 5d76b9a
Show file tree
Hide file tree
Showing 31 changed files with 1,867 additions and 655 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/generate-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
with:
python-version: "3.10"
- name: Install uv
uses: astral-sh/setup-uv@v3
uses: astral-sh/setup-uv@v5
with:
version: "0.4.15"
enable-cache: true
Expand All @@ -39,6 +39,10 @@ jobs:
- run: uv run bash scripts/generate-client.sh
env:
VIRTUAL_ENV: backend/.venv
ENVIRONMENT: production
SECRET_KEY: just-for-generating-client
POSTGRES_PASSWORD: just-for-generating-client
FIRST_SUPERUSER_PASSWORD: just-for-generating-client
- name: Add changes to git
run: |
git config --local user.email "[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/latest-changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
with:
# To allow latest-changes to commit to the main branch
token: ${{ secrets.LATEST_CHANGES }}
- uses: tiangolo/[email protected].1
- uses: tiangolo/[email protected].2
with:
token: ${{ secrets.GITHUB_TOKEN }}
latest_changes_file: ./release-notes.md
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
with:
python-version: "3.10"
- name: Install uv
uses: astral-sh/setup-uv@v3
uses: astral-sh/setup-uv@v5
with:
version: "0.4.15"
enable-cache: true
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ jobs:
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled == 'true' }}
with:
limit-access-to-actor: true
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: "0.4.15"
enable-cache: true
- run: uv sync
working-directory: backend
- run: npm ci
working-directory: frontend
- run: uv run bash scripts/generate-client.sh
env:
VIRTUAL_ENV: backend/.venv
- run: docker compose build
- run: docker compose down -v --remove-orphans
- name: Run Playwright tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
with:
python-version: "3.10"
- name: Install uv
uses: astral-sh/setup-uv@v3
uses: astral-sh/setup-uv@v5
with:
version: "0.4.15"
enable-cache: true
Expand Down
15 changes: 10 additions & 5 deletions backend/app/api/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from fastapi import APIRouter

from app.api.routes import items, login, users, utils
from app.api.routes import items, login, private, users, utils
from app.core.config import settings

api_router = APIRouter()
api_router.include_router(login.router, tags=["login"])
api_router.include_router(users.router, prefix="/users", tags=["users"])
api_router.include_router(utils.router, prefix="/utils", tags=["utils"])
api_router.include_router(items.router, prefix="/items", tags=["items"])
api_router.include_router(login.router)
api_router.include_router(users.router)
api_router.include_router(utils.router)
api_router.include_router(items.router)


if settings.ENVIRONMENT == "local":
api_router.include_router(private.router)
2 changes: 1 addition & 1 deletion backend/app/api/routes/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from app.api.deps import CurrentUser, SessionDep
from app.models import Item, ItemCreate, ItemPublic, ItemsPublic, ItemUpdate, Message

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


@router.get("/", response_model=ItemsPublic)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/api/routes/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
verify_password_reset_token,
)

router = APIRouter()
router = APIRouter(tags=["login"])


@router.post("/login/access-token")
Expand Down
38 changes: 38 additions & 0 deletions backend/app/api/routes/private.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from typing import Any

from fastapi import APIRouter
from pydantic import BaseModel

from app.api.deps import SessionDep
from app.core.security import get_password_hash
from app.models import (
User,
UserPublic,
)

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


class PrivateUserCreate(BaseModel):
email: str
password: str
full_name: str
is_verified: bool = False


@router.post("/users/", response_model=UserPublic)
def create_user(user_in: PrivateUserCreate, session: SessionDep) -> Any:
"""
Create a new user.
"""

user = User(
email=user_in.email,
full_name=user_in.full_name,
hashed_password=get_password_hash(user_in.password),
)

session.add(user)
session.commit()

return user
2 changes: 1 addition & 1 deletion backend/app/api/routes/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
)
from app.utils import generate_new_account_email, send_email

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


@router.get(
Expand Down
2 changes: 1 addition & 1 deletion backend/app/api/routes/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from app.models import Message
from app.utils import generate_test_email, send_email

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


@router.post(
Expand Down
26 changes: 26 additions & 0 deletions backend/app/tests/api/routes/test_private.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from fastapi.testclient import TestClient
from sqlmodel import Session, select

from app.core.config import settings
from app.models import User


def test_create_user(client: TestClient, db: Session) -> None:
r = client.post(
f"{settings.API_V1_STR}/private/users/",
json={
"email": "[email protected]",
"password": "password123",
"full_name": "Pollo Listo",
},
)

assert r.status_code == 200

data = r.json()

user = db.exec(select(User).where(User.id == data["id"])).first()

assert user
assert user.email == "[email protected]"
assert user.full_name == "Pollo Listo"
2 changes: 1 addition & 1 deletion frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ If you are developing an API-only app and want to remove the frontend, you can d

* In the `docker-compose.yml` file, remove the whole service / section `frontend`.

* In the `docker-compose.override.yml` file, remove the whole service / section `frontend`.
* In the `docker-compose.override.yml` file, remove the whole service / section `frontend` and `playwright`.

Done, you have a frontend-less (api-only) app. 🤓

Expand Down
36 changes: 0 additions & 36 deletions frontend/modify-openapi-operationids.js

This file was deleted.

28 changes: 28 additions & 0 deletions frontend/openapi-ts.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { defineConfig } from "@hey-api/openapi-ts"

export default defineConfig({
client: "legacy/axios",
input: "./openapi.json",
output: "./src/client",
// exportSchemas: true,
plugins: [
{
name: "@hey-api/sdk",
// NOTE: this doesn't allow tree-shaking
asClass: true,
operationId: true,
methodNameBuilder: (operation) => {
// @ts-ignore
let name: string = operation.name
// @ts-ignore
let service: string = operation.service

if (service && name.toLowerCase().startsWith(service.toLowerCase())) {
name = name.slice(service.length)
}

return name.charAt(0).toLowerCase() + name.slice(1)
},
},
],
})
Loading

0 comments on commit 5d76b9a

Please sign in to comment.