Skip to content

Repository files navigation

PC Components Store API

A RESTful API built with .NET 8.0 for managing PC components inventory, categories, orders, and user authentication.

🚀 Quick Start

Prerequisites

  • Docker and Docker Compose installed
  • .NET 8.0 SDK (for local development)

Running with Docker (Recommended)

# Navigate to project directory
cd pc-components-api

# Build and start all services
docker-compose up --build

# API will be available at: http://localhost:8080
# Swagger UI: http://localhost:8080/swagger

Running Locally (Without Docker)

# 1. Start PostgreSQL database
docker run -d \
  --name pccomponents-postgres \
  -e POSTGRES_DB=pccomponentsdb \
  -e POSTGRES_USER=postgres \
  -e POSTGRES_PASSWORD=postgres \
  -p 5432:5432 \
  postgres:15

# 2. Update appsettings.json with your connection string if needed

# 3. Run the API
cd PCComponentsApi
dotnet run

📚 Documentation

API Reference

Interactive Documentation

  • Swagger UI - Interactive API documentation (available when running the API)

🔐 Authentication Flow

1. Register an Admin User

curl -X POST http://localhost:8080/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "email": "admin@pccomponents.com",
    "fullName": "Admin User",
    "password": "AdminPass123!",
    "role": "admin"
  }'

2. Login and Get Token

curl -X POST http://localhost:8080/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "admin@pccomponents.com",
    "password": "AdminPass123!"
  }'

3. Use Token for Protected Endpoints

curl http://localhost:8080/api/products \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

🛠️ Development

Build Project

cd PCComponentsApi
dotnet build

Run Tests (if added)

dotnet test

Create Migration

dotnet ef migrations add InitialCreate
dotnet ef database update

🔒 Security Features

  • ✅ BCrypt password hashing
  • ✅ JWT token authentication
  • ✅ Role-based authorization (admin/customer)
  • ✅ Input validation with DataAnnotations
  • ✅ Secure connection strings
  • ✅ HTTPS support (configure for production)

📝 Configuration

appsettings.json

{
  "ConnectionStrings": {
    "DefaultConnection": "Host=db;Port=5432;Database=pccomponentsdb;Username=postgres;Password=postgres"
  },
  "Jwt": {
    "Key": "your-secret-key-here",
    "Issuer": "PCComponentsApi",
    "Audience": "PCComponentsApi",
    "ExpirationInMinutes": 60
  }
}

🐳 Docker Compose Commands

# Start services
docker-compose up -d

# View logs
docker-compose logs -f

# Stop services
docker-compose down

# Rebuild
docker-compose up --build

# Clean up volumes
docker-compose down -v

📦 Dependencies

  • .NET 8.0
  • Entity Framework Core
  • PostgreSQL (via Npgsql)
  • JWT Bearer Authentication
  • BCrypt.Net-Next
  • Swagger/OpenAPI

🚨 Production Checklist

  • Change JWT secret key
  • Configure HTTPS
  • Set up proper logging
  • Add database migrations
  • Configure environment variables
  • Set up monitoring and health checks
  • Configure rate limiting
  • Add input sanitization
  • Enable CORS if needed

📞 Support

For issues or questions, please refer to the API Reference or the Swagger UI at /swagger when running the application.

About

Small api to run locally and create api test suites against

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages