Skip to content

sixtis1/test-crud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

User API

A RESTful API service for managing users with the ability to select a repository (in-memory or database) during application initialization. The project is developed using FastAPI, PostgreSQL, SQLAlchemy, and Docker Compose. Tests are written using pytest.

Table of Contents

Requirements

  • Python 3.10 or higher
  • Docker and Docker Compose
  • PostgreSQL (if using the database repository)

Installation and Setup

Clone the Repository

git clone https://github.com/sixtis1/test-crud.git
cd test-crud

Install Dependencies

Install the dependencies from the requirements.txt file:

pip install -r requirements.txt

Start the Database

Start the PostgreSQL container using Docker Compose:

docker-compose up -d

Configure the Application

Configuration parameters are located in the app/.env file.

REPOSITORY_TYPE=memory # Change to "db" to use the database repository
DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/test_db

POSTGRES_USER=user
POSTGRES_PASSWORD=password
POSTGRES_DB=test_db

Run the Application

Start the application using Uvicorn:

python -m uvicorn app.main:app --reload

The application will be available at: http://localhost:8000

Upon startup, the application automatically creates the necessary tables in the database.

API Usage

Swagger Documentation

Interactive API documentation is available at http://localhost:8000/docs

Running Tests

Execute the following command to run all tests:

pytest

Project Structure

├── app
│   ├── __init__.py
│   ├── main.py                # Entry point of the FastAPI application
│   ├── models.py              # SQLAlchemy models
│   ├── schemas.py             # Pydantic schemas for validation
│   ├── routers
│   │   ├── __init__.py
│   │   └── users.py           # Endpoints for user operations
│   ├── repositories
│   │   ├── __init__.py
│   │   ├── base.py            # Abstract repository class
│   │   ├── memory_repository.py  # In-memory repository implementation
│   │   └── db_repository.py   # Database repository implementation
│   ├── dependencies.py        # Application dependencies
│   └── config.py              # Configuration file
├── tests
│   ├── __init__.py
│   └── test_users.py          # Tests for user endpoints
├── docker-compose.yml         # Docker Compose file for PostgreSQL
├── requirements.txt           # Project dependencies
└── README.md                  # Project documentation

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages