Skip to content
kaanchinarPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

PetPet API

A comprehensive backend API for an online pet shop and pet adoption platform built with ASP.NET Core 9, PostgreSQL, and Docker.

Business logic is in BUSINESS.md

πŸš€ Features

Shop Logic

  • Product Management: Complete CRUD operations for pet products
  • Categories: Support for Cats, Dogs, and Other animals
  • Product Filtering: Filter by price range, category (toys, food, litters, medicines), and more
  • Shopping Cart: Add, update, remove items from cart
  • Order Management: Create orders, track order status
  • Inventory Management: Stock tracking with low stock alerts

Admin Panel

  • Dashboard: Total products, inventory value, low stock alerts, recent products
  • Product Management: Add, edit, delete products with image support
  • Order Management: View and update order statuses (waiting, processing, completed, withdrawn, rejected)
  • Inventory Tracking: Monitor stock levels and get low stock alerts

Authentication & Authorization

  • JWT Authentication: Secure token-based authentication
  • Role-based Authorization: Admin and User roles
  • Refresh Tokens: Secure token refresh mechanism
  • User Management: Registration, login, logout functionality

πŸ›  Tech Stack

  • Framework: ASP.NET Core 9 Web API
  • Database: PostgreSQL with Entity Framework Core
  • Authentication: JWT Bearer tokens
  • Documentation: OpenAPI/Swagger with Scalar UI
  • Containerization: Docker & Docker Compose
  • ORM: Entity Framework Core with Npgsql

πŸ“‹ Prerequisites

  • .NET 9 SDK
  • Docker and Docker Compose
  • Git

πŸš€ Quick Start

1. Clone the Repository

git clone https://github.com/yourusername/PetpetAPI.git
cd PetpetAPI

2. Environment Setup

The application uses Docker Compose for easy setup. All necessary configuration is already included.

3. Run with Docker Compose

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

# Or run in detached mode
docker-compose up -d --build

This will start:

  • PostgreSQL database on port 5432
  • PetPet API on port 8080

4. Access the API

5. Default Admin Account

πŸ“š API Documentation

The API includes comprehensive OpenAPI documentation accessible at:

πŸ—‚ Project Structure

PetpetAPI/
β”œβ”€β”€ src/
β”‚   └── PetpetAPI/
β”‚       β”œβ”€β”€ Controllers/           # API Controllers
β”‚       β”œβ”€β”€ Data/                 # Database Context
β”‚       β”œβ”€β”€ DTOs/                 # Data Transfer Objects
β”‚       β”‚   β”œβ”€β”€ Auth/
β”‚       β”‚   β”œβ”€β”€ Products/
β”‚       β”‚   β”œβ”€β”€ Cart/
β”‚       β”‚   β”œβ”€β”€ Orders/
β”‚       β”‚   β”œβ”€β”€ Admin/
β”‚       β”‚   └── Common/
β”‚       β”œβ”€β”€ Models/               # Entity Models
β”‚       β”œβ”€β”€ Services/             # Business Logic
β”‚       └── Program.cs            # Application Entry Point
β”œβ”€β”€ Dockerfile                   # Docker configuration
β”œβ”€β”€ docker-compose.yml          # Docker Compose configuration
└── README.md

πŸ”‘ Authentication

Registration

POST /api/auth/register
Content-Type: application/json

{
  "email": "[email protected]",
  "password": "Password123!",
  "firstName": "John",
  "lastName": "Doe"
}

Login

POST /api/auth/login
Content-Type: application/json

{
  "email": "[email protected]",
  "password": "Password123!"
}

Using JWT Token

Include the JWT token in the Authorization header:

Authorization: Bearer <your-jwt-token>

πŸ“¦ Main API Endpoints

Products

  • GET /api/products - Get products with filtering
  • GET /api/products/{id} - Get specific product
  • POST /api/products - Create product (Admin)
  • PUT /api/products/{id} - Update product (Admin)
  • DELETE /api/products/{id} - Delete product (Admin)

Cart

  • GET /api/cart - Get user's cart
  • POST /api/cart/items - Add item to cart
  • PUT /api/cart/items/{id} - Update cart item
  • DELETE /api/cart/items/{id} - Remove cart item

Orders

  • POST /api/orders - Create order from cart
  • GET /api/orders/my-orders - Get user's orders
  • GET /api/orders - Get all orders (Admin)
  • PUT /api/orders/{id}/status - Update order status (Admin)

Admin

  • GET /api/admin/dashboard/stats - Dashboard statistics
  • GET /api/admin/products/low-stock - Low stock products

πŸ”§ Configuration

Database Connection

The connection string is configured in appsettings.Development.json:

{
  "ConnectionStrings": {
    "DefaultConnection": "Host=db;Database=petpetdb;Username=postgres;Password=postgres"
  }
}

JWT Settings

JWT configuration in appsettings.json:

{
  "JwtSettings": {
    "SecretKey": "your-secret-key-here-minimum-32-characters-long",
    "Issuer": "PetpetAPI",
    "Audience": "PetpetAPI-Users",
    "ExpirationInMinutes": 60,
    "RefreshTokenExpirationInDays": 7
  }
}

πŸ› Development

Local Development (without Docker)

  1. Install PostgreSQL locally

  2. Update connection string in appsettings.json

  3. Run migrations:

    cd src/PetpetAPI
    dotnet ef database update
  4. Run the application:

    dotnet run

Database Migrations

# Add new migration
dotnet ef migrations add MigrationName

# Update database
dotnet ef database update

# Remove last migration
dotnet ef migrations remove

πŸ“ Sample Data

The application automatically seeds sample data including:

  • Default admin user
  • Sample products (cat food, dog toys, cat litter)
  • Product images
  • User and Admin roles

🚒 Deployment

Docker Production Deployment

# Build production image
docker build -t petpetapi:latest .

# Run with external database
docker run -d \
  -p 8080:8080 \
  -e ConnectionStrings__DefaultConnection="Host=your-db-host;Database=petpetdb;Username=user;Password=pass" \
  petpetapi:latest

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

πŸ“„ License

This project is licensed under the MIT License.

πŸ†˜ Support

For support, email [email protected] or create an issue in the repository.


PetPet API - Making pet care accessible and convenient! 🐾

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages