Skip to content

Commit 154f327

Browse files
committed
refactor: replace module comments with docstrings
1 parent cc26d37 commit 154f327

File tree

13 files changed

+101
-34
lines changed

13 files changed

+101
-34
lines changed

.codacy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exclude_paths:
44
- "assets/**/*"
5-
- "database/**/*"
5+
- "databases/**/*"
66
- "models/**/*"
77
- "postman_collections/**/*"
88
- "schemas/**/*"

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ COPY README.md ./
3838
COPY assets ./assets
3939

4040
# Copy pre-built wheels from builder
41-
COPY --from=builder /app/wheelhouse /app/wheelhouse
41+
COPY --from=builder /app/wheelhouse /app/wheelhouse
4242

4343
# Install dependencies
4444
COPY requirements.txt .
@@ -53,9 +53,12 @@ COPY routes ./routes
5353
COPY schemas ./schemas
5454
COPY services ./services
5555

56-
# Copy entrypoint script and image-bundled, pre-seeded SQLite database
56+
# https://rules.sonarsource.com/docker/RSPEC-6504/
57+
58+
# Copy entrypoint and healthcheck scripts
5759
COPY --chmod=755 scripts/entrypoint.sh ./entrypoint.sh
5860
COPY --chmod=755 scripts/healthcheck.sh ./healthcheck.sh
61+
# Copy pre-seeded SQLite database as init bundle
5962
COPY --chmod=755 storage ./docker-compose
6063

6164
# Add non-root user and make volume mount point writable

codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ comment:
4040
# https://docs.codecov.com/docs/ignoring-paths
4141
ignore:
4242
- "^assets/.*"
43-
- "^database/.*"
43+
- "^databases/.*"
4444
- "^models/.*"
4545
- "^postman_collections/.*"
4646
- "^schemas/.*"

databases/__init__.py

Whitespace-only changes.
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
# ------------------------------------------------------------------------------
2-
# Database
3-
# ------------------------------------------------------------------------------
1+
"""
2+
Database setup and session management for async SQLAlchemy with SQLite.
43
4+
- Configures the async database engine using `aiosqlite` driver.
5+
- Creates an async sessionmaker for ORM operations.
6+
- Defines the declarative base class for model definitions.
7+
- Provides an async generator dependency to yield database sessions.
8+
9+
The `STORAGE_PATH` environment variable controls the SQLite file location.
10+
"""
511
import logging
612
import os
713
from typing import AsyncGenerator

main.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
# ------------------------------------------------------------------------------
2-
# Main
3-
# ------------------------------------------------------------------------------
1+
"""
2+
Main application module for the FastAPI RESTful API.
43
4+
- Sets up the FastAPI app with metadata (title, description, version).
5+
- Defines the lifespan event handler for app startup/shutdown logging.
6+
- Includes API routers for player and health endpoints.
7+
8+
This serves as the entry point for running the API server.
9+
"""
510
from contextlib import asynccontextmanager
611
import logging
712
from typing import AsyncIterator

models/player_model.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
# ------------------------------------------------------------------------------
2-
# Model
3-
# ------------------------------------------------------------------------------
1+
"""
2+
Pydantic models defining the data schema for football players.
43
4+
- `MainModel`: Base model with common config for camelCase aliasing.
5+
- `PlayerModel`: Represents a football player with personal and team details.
6+
7+
These models are used for data validation and serialization in the API.
8+
"""
59
from typing import Optional
610
from pydantic import BaseModel, ConfigDict
711
from pydantic.alias_generators import to_camel

routes/health_route.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# ------------------------------------------------------------------------------
2-
# Route
3-
# ------------------------------------------------------------------------------
1+
"""
2+
Health check API route.
43
4+
Defines a simple endpoint to verify that the service is up and running.
5+
Returns a JSON response with a "status" key set to "ok".
6+
"""
57
from fastapi import APIRouter
68

7-
89
api_router = APIRouter()
910

1011
@api_router.get("/health", tags=["Health"])

routes/player_route.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1-
# ------------------------------------------------------------------------------
2-
# Route
3-
# ------------------------------------------------------------------------------
4-
1+
"""
2+
API routes for managing Player resources.
3+
4+
Provides CRUD endpoints to create, read, update, and delete Player entities.
5+
6+
Features:
7+
- Caching with in-memory cache to optimize retrieval performance.
8+
- Async database session dependency injection.
9+
- Standard HTTP status codes and error handling.
10+
11+
Endpoints:
12+
- POST /players/ : Create a new Player.
13+
- GET /players/ : Retrieve all Players.
14+
- GET /players/{player_id} : Retrieve Player by ID.
15+
- GET /players/squadnumber/{squad_number} : Retrieve Player by Squad Number.
16+
- PUT /players/{player_id} : Update an existing Player.
17+
- DELETE /players/{player_id} : Delete an existing Player.
18+
"""
519
from typing import List
620
from fastapi import APIRouter, Body, Depends, HTTPException, status, Path, Response
721
from sqlalchemy.ext.asyncio import AsyncSession
822
from aiocache import SimpleMemoryCache
923

10-
from database.player_database import generate_async_session
24+
from databases.player_database import generate_async_session
1125
from models.player_model import PlayerModel
1226
from services import player_service
1327

schemas/player_schema.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
# ------------------------------------------------------------------------------
2-
# Schema
3-
# ------------------------------------------------------------------------------
1+
"""
2+
SQLAlchemy ORM model for the Player database table.
43
4+
Defines the schema and columns corresponding to football player attributes.
5+
6+
Used for async database CRUD operations in the application.
7+
"""
58
from sqlalchemy import Column, String, Integer, Boolean
6-
from database.player_database import Base
9+
from databases.player_database import Base
710

811

912
class Player(Base):

0 commit comments

Comments
 (0)