Skip to content
This repository was archived by the owner on Jan 1, 2026. It is now read-only.

Commit 8aa7b57

Browse files
authored
Reorganize routes and add register endpoint (#5)
* Reorganize routes and add register endpoint * Remove obsolete test script for database connection * Format branches section in suggest-version-bump.yml for consistency * Refactor Super Linter workflow to use slim version and add fix-lint job for automatic linting corrections * Update version detection pattern to include app/ prefix in changed files * Bump API version to 1.1.0 * Update application version to 0.2.0
1 parent e0c86f9 commit 8aa7b57

19 files changed

Lines changed: 213 additions & 9 deletions

.github/workflows/detect-changed-versions.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
git fetch origin main
3232
BASE_SHA=$(git merge-base HEAD origin/main)
3333
34-
CHANGED=$(git diff --name-only "$BASE_SHA"...HEAD | grep '^routes/v[0-9]\+/.*\.py$' | grep -v 'test' || true)
35-
VERSIONS=$(echo "$CHANGED" | sed -n 's|^routes/\(v[0-9]\+\)/.*|\1|p' | sort -u | tr '\n' ' ')
34+
# Updated pattern to match app/routes/v*/ files
35+
CHANGED=$(git diff --name-status "$BASE_SHA"...HEAD | grep -E '^[AMD]' | awk '{print $2}' | grep '^app/routes/v[0-9]\+/.*\.py$' | grep -v 'test' || true)
36+
VERSIONS=$(echo "$CHANGED" | sed -n 's|^app/routes/\(v[0-9]\+\)/.*|\1|p' | sort -u | tr '\n' ' ')
3637
echo "versions=$VERSIONS" >> "$GITHUB_OUTPUT"

.github/workflows/suggest-version-bump.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ permissions:
88

99
on:
1010
pull_request:
11-
branches: [main]
11+
branches:
12+
- main
1213
paths:
1314
- '**/*.py'
1415
- '!**/tests/**'

.github/workflows/super-linter.yml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,43 @@ jobs:
2424
fetch-depth: 0
2525

2626
- name: Run Super Linter
27-
uses: super-linter/super-linter@v7
27+
uses: super-linter/super-linter/slim@v7
2828
env:
2929
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3030
VALIDATE_ALL_CODEBASE: false
3131
FILTER_REGEX_EXCLUDE: '(.devcontainer/Dockerfile|.github/pull_request_template.md|.github/ISSUE_TEMPLATE/*.md)'
3232
VALIDATE_PYTHON_ISORT: false
3333
VALIDATE_PYTHON_MYPY: false
34+
35+
fix-lint:
36+
name: Fix Lint
37+
runs-on: ubuntu-latest
38+
39+
steps:
40+
- name: Checkout code
41+
uses: actions/checkout@v4
42+
with:
43+
fetch-depth: 0
44+
45+
- name: Super-linter
46+
uses: super-linter/super-linter/slim@v7
47+
env:
48+
VALIDATE_ALL_CODEBASE: false
49+
FILTER_REGEX_EXCLUDE: '(.github/pull_request_template.md|.github/ISSUE_TEMPLATE/*.md)'
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
FIX_JSON_PRETTIER: true
52+
FIX_MARKDOWN: true
53+
FIX_MARKDOWN_PRETTIER: true
54+
FIX_YAML_PRETTIER: true
55+
VALIDATE_DOCKERFILE_HADOLINT: false
56+
57+
- name: Commit and push linting fixes
58+
if: >
59+
github.event_name == 'pull_request' &&
60+
github.event.pull_request.head.ref != github.event.repository.default_branch
61+
uses: stefanzweifel/git-auto-commit-action@v5
62+
with:
63+
branch: ${{ github.event.pull_request.head.ref }}
64+
commit_message: 'Super-Linter: Fix linting issues'
65+
commit_user_name: super-linter
66+
commit_user_email: super-linter@super-linter.dev

.vscode/tasks.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@
4343
"group": {
4444
"kind": "test"
4545
},
46+
"presentation": {
47+
"close": true
48+
},
4649
"problemMatcher": [],
4750
"runOptions": {
48-
"runOn": "default"
51+
"runOn": "default",
4952
}
5053
},
5154
{

app/models/__init__.py

Whitespace-only changes.

app/models/user.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import uuid
2+
from datetime import datetime
3+
4+
from sqlalchemy import Boolean, Column, DateTime, Integer, String, Text
5+
from sqlalchemy.dialects.postgresql import UUID
6+
from sqlalchemy.orm import declarative_base
7+
8+
Base = declarative_base()
9+
10+
11+
class User(Base):
12+
__tablename__ = "users"
13+
14+
user_id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
15+
16+
username = Column(String(50), unique=True, nullable=False)
17+
18+
email_encrypted = Column(Text, nullable=False)
19+
email_hash = Column(Text, unique=True, nullable=False)
20+
is_email_verified = Column(Boolean, default=False)
21+
22+
password_hash = Column(Text, nullable=False)
23+
24+
phone_encrypted = Column(Text)
25+
phone_hash = Column(Text, unique=True)
26+
27+
language_id = Column(Integer, nullable=True)
28+
29+
created_at = Column(DateTime(timezone=True), default=datetime.utcnow)
30+
updated_at = Column(DateTime(timezone=True), default=datetime.utcnow)
31+
last_login_at = Column(DateTime(timezone=True))
32+
deleted_at = Column(DateTime(timezone=True))

app/routes/v1/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
from fastapi import FastAPI
66

7-
from .orders import router as order_router
8-
from .products import router as product_router
7+
from .endpoints.authentication import router as auth_router
8+
from .endpoints.orders import router as order_router
9+
from .endpoints.products import router as product_router
910

10-
__version__ = "1.0.0"
11+
__version__ = "1.1.0"
1112

1213
api = FastAPI(title="ChocoMax Shop API", version=__version__)
1314

15+
api.include_router(auth_router, prefix="/auth", tags=["Authentication"])
1416
api.include_router(product_router, prefix="/products", tags=["Products"])
1517
api.include_router(order_router, prefix="/orders", tags=["Orders"])

app/routes/v1/endpoints/__init__.py

Whitespace-only changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from fastapi import APIRouter, Depends
2+
from sqlalchemy.ext.asyncio import AsyncSession
3+
4+
from app.models.user import User
5+
from app.routes.v1.schemas.user.create import UserCreate
6+
from app.utility.database import get_db
7+
from app.utility.security import (
8+
encrypt_email,
9+
encrypt_phone,
10+
hash_email,
11+
hash_password,
12+
hash_phone,
13+
)
14+
15+
router = APIRouter()
16+
17+
18+
@router.post("/register")
19+
async def register(data: UserCreate, db: AsyncSession = Depends(get_db)):
20+
"""Endpoint for user registration."""
21+
user = User(
22+
username=data.username,
23+
email_encrypted=encrypt_email(data.email),
24+
email_hash=hash_email(data.email),
25+
password_hash=hash_password(data.password),
26+
phone_encrypted=encrypt_phone(data.phone) if data.phone else None,
27+
phone_hash=hash_phone(data.phone) if data.phone else None,
28+
language_id=data.language_id,
29+
)
30+
db.add(user)
31+
await db.commit()
32+
await db.refresh(user)
33+
return {"message": "User registered successfully", "user_id": str(user.user_id)}

0 commit comments

Comments
 (0)