Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Students CRUD API

Backend web application for managing students with Django.

Features

  • CRUD API for students
  • PostgreSQL database
  • Docker Compose setup
  • Correlation-ID middleware for logging
  • Request counter middleware (total, 2xx, 4xx, 5xx)
  • Latency measurement decorator with histogram storage
  • Health check endpoint
  • Integration tests
  • Ruff linting configuration

Requirements

  • Docker and Docker Compose
  • Python 3.11+ (for local development)

Quick Start

  1. Copy .env.example to .env and adjust settings if needed:

    cp .env.example .env
  2. Build and start containers:

    docker-compose up --build
  3. The API will be available at http://localhost

API Endpoints

Health Check

  • GET /health - Health check endpoint (returns 200)

Students

  • POST /students - Create a new student
  • GET /students - Get all students
  • GET /students/{id} - Get student by id
  • PUT /students/{id} - Update student

API Examples

Create Student

curl -X POST http://localhost/students \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Иван Иванов",
    "age": 20,
    "email": "ivan@example.com"
  }'

Get All Students

curl http://localhost/students

Get Student by ID

curl http://localhost/students/1

Update Student

curl -X PUT http://localhost/students/1 \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Иван Иванович",
    "age": 21,
    "email": "ivan_updated@example.com"
  }'

Running Tests

docker-compose exec web python manage.py test

Linting

docker-compose exec web ruff check .

Project Structure

.
├── exam/              # Django project settings
│   ├── config.py      # Configuration module for environment variables
│   ├── settings.py    # Django settings
│   └── urls.py        # URL configuration
├── myapp/             # Main application
│   ├── models.py      # Student model and monitoring models
│   ├── views.py       # API views
│   ├── serializers.py # Data validation
│   ├── middleware/    # Custom middleware
│   │   ├── correlation_id.py
│   │   ├── request_counter.py
│   │   └── latency.py
│   └── tests.py      # Integration tests
├── nginx/             # Nginx configuration
├── Dockerfile         # Web container definition
├── docker-compose.yml # Docker Compose configuration
└── requirements.txt   # Python dependencies

Docker Containers

  • db: PostgreSQL database
  • web: Django application (Gunicorn)
  • nginx: Reverse proxy (port 80)

All containers run health checks and do not run as root user.

fix commands

Остановите системный nginx

sudo systemctl stop nginx

Или если systemctl не работает:

sudo service nginx stop

Проверьте, что порт 80 свободен

sudo lsof -i :80
wsl -e bash -c "cd /mnt/m/prep_kval/EXAM && docker-compose exec web python manage.py createsuperuser"

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages