Skip to content

🛒 Modern E-Commerce Web API with JWT Authentication, Entity Framework Core, and Swagger documentation - Complete shopping cart and order management

License

Notifications You must be signed in to change notification settings

alknbugra/ECommerceAPI

Repository files navigation

🛒 E-Commerce Web API

License: MIT .NET Entity Framework JWT Swagger SQL Server

Modern, ölçeklenebilir ve güvenli bir e-ticaret backend API'si. .NET 8, Entity Framework Core ve JWT Authentication kullanılarak geliştirilmiştir.

✨ Özellikler

🔐 Kimlik Doğrulama ✅

  • JWT Token tabanlı authentication
  • Kullanıcı kaydı ve giriş sistemi
  • Rol tabanlı yetkilendirme (Customer, Admin)
  • Güvenli şifre hash'leme (BCrypt)

📦 Ürün Yönetimi ✅

  • CRUD işlemleri (Create, Read, Update, Delete)
  • Kategori bazlı filtreleme
  • Arama fonksiyonu (isim ve açıklama)
  • Sayfalama (pagination) desteği
  • Stok takibi

🛒 Alışveriş Sepeti ✅

  • Sepete ürün ekleme/çıkarma
  • Miktar güncelleme
  • Sepet görüntüleme (ürün detayları ile)
  • Kullanıcı bazlı sepet yönetimi
  • Sepet temizleme

📋 Sipariş Yönetimi ✅

  • Sipariş oluşturma (sepetten)
  • Sipariş geçmişi görüntüleme
  • Sipariş detayı görüntüleme
  • Sipariş durumu takibi
  • Adres yönetimi

🏷️ Kategori Yönetimi ✅

  • Kategori CRUD işlemleri
  • Ürün-kategori ilişkilendirmesi
  • Admin yetkisi gerektiren işlemler

🛠️ Teknolojiler

  • .NET 8 - Modern C# framework
  • Entity Framework Core - ORM
  • SQL Server LocalDB - Veritabanı
  • JWT Bearer - Authentication
  • Swagger/OpenAPI - API dokümantasyonu
  • BCrypt - Şifre hash'leme
  • CORS - Cross-origin desteği

🚀 Kurulum

Gereksinimler

Adımlar

  1. Repository'yi klonlayın:
git clone https://github.com/alknbugra/ECommerceAPI.git
cd ECommerceAPI
  1. NuGet paketlerini yükleyin:
dotnet restore
  1. Veritabanını oluşturun:
dotnet ef database update
  1. Uygulamayı çalıştırın:
dotnet run
  1. API'yi test edin:
  • Swagger UI: https://localhost:7000/swagger
  • HTTP API: http://localhost:5280

📚 API Endpoints

🔐 Authentication

POST /api/auth/register    - Kullanıcı kaydı
POST /api/auth/login       - Kullanıcı girişi

📦 Products

GET    /api/products              - Tüm ürünleri listele
GET    /api/products/{id}         - Ürün detayı
POST   /api/products              - Yeni ürün ekle (Admin)
PUT    /api/products/{id}         - Ürün güncelle (Admin)
DELETE /api/products/{id}         - Ürün sil (Admin)

Query Parameters:

  • categoryId - Kategori filtresi
  • search - Arama terimi
  • page - Sayfa numarası
  • pageSize - Sayfa boyutu

🏷️ Categories

GET    /api/categories            - Tüm kategorileri listele
GET    /api/categories/{id}       - Kategori detayı
POST   /api/categories            - Yeni kategori ekle (Admin)
PUT    /api/categories/{id}       - Kategori güncelle (Admin)
DELETE /api/categories/{id}       - Kategori sil (Admin)

🛒 Cart

GET    /api/cart                  - Sepet içeriği
POST   /api/cart/add              - Sepete ürün ekle
PUT    /api/cart/update/{productId} - Ürün miktarını güncelle
DELETE /api/cart/remove/{productId} - Sepetten ürün çıkar

📋 Orders

GET    /api/orders                - Sipariş geçmişi
GET    /api/orders/{id}           - Sipariş detayı
POST   /api/orders                - Yeni sipariş oluştur
GET    /api/orders/all            - Tüm siparişler (Admin)

🔧 Konfigürasyon

appsettings.json

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=ECommerceDB;Trusted_Connection=true;MultipleActiveResultSets=true"
  },
  "JwtSettings": {
    "SecretKey": "YourSuperSecretKeyThatIsAtLeast32CharactersLong!",
    "Issuer": "ECommerceAPI",
    "Audience": "ECommerceAPIUsers",
    "ExpiryInHours": 24
  }
}

🧪 Test Etme

Swagger UI ile Test

  1. https://localhost:7000/swagger adresine gidin
  2. Authorize butonuna tıklayın
  3. JWT token'ı girin
  4. Endpoint'leri test edin

cURL ile Test

# Kullanıcı kaydı
curl -X POST "http://localhost:5280/api/auth/register" \
  -H "Content-Type: application/json" \
  -d '{"email":"test@example.com","password":"123456","firstName":"Test","lastName":"User"}'

# Giriş yap
curl -X POST "http://localhost:5280/api/auth/login" \
  -H "Content-Type: application/json" \
  -d '{"email":"test@example.com","password":"123456"}'

# Ürünleri listele
curl -X GET "http://localhost:5280/api/products"

📊 Veritabanı Şeması

Tablolar

  • Users - Kullanıcı bilgileri
  • Categories - Ürün kategorileri
  • Products - Ürün bilgileri
  • CartItems - Sepet öğeleri
  • Orders - Sipariş bilgileri
  • OrderItems - Sipariş detayları

İlişkiler

  • User → CartItems (1:N)
  • User → Orders (1:N)
  • Category → Products (1:N)
  • Product → CartItems (1:N)
  • Product → OrderItems (1:N)
  • Order → OrderItems (1:N)

🔒 Güvenlik

  • JWT Token authentication
  • BCrypt şifre hash'leme
  • CORS politikaları
  • Rol tabanlı yetkilendirme
  • SQL Injection koruması (EF Core)
  • HTTPS desteği

🚀 Deployment

Docker ile

FROM mcr.microsoft.com/dotnet/aspnet:8.0
COPY . /app
WORKDIR /app
EXPOSE 80
ENTRYPOINT ["dotnet", "ECommerceAPI.dll"]

Azure ile

  1. Azure App Service oluşturun
  2. SQL Database bağlantısı yapılandırın
  3. Application Settings'i güncelleyin
  4. Deploy edin

✅ Test Sonuçları

🧪 API Test Durumu

Tüm endpoint'ler başarıyla test edilmiştir:

  • Authentication: ✅ Çalışıyor
  • Ürün Yönetimi: ✅ Çalışıyor
  • Kategori Yönetimi: ✅ Çalışıyor
  • Alışveriş Sepeti: ✅ Çalışıyor
  • Sipariş Yönetimi: ✅ Çalışıyor

📊 Test Örneği

# Kullanıcı girişi
POST /api/auth/login
Response: JWT Token

# Sepete ürün ekleme
POST /api/cart/add
Response: CartItem with product details

# Sipariş oluşturma
POST /api/orders
Response: Order with total amount

# Sipariş geçmişi
GET /api/orders
Response: User's order history

🤝 Katkıda Bulunma

  1. Fork edin
  2. Feature branch oluşturun (git checkout -b feature/AmazingFeature)
  3. Commit edin (git commit -m 'Add some AmazingFeature')
  4. Push edin (git push origin feature/AmazingFeature)
  5. Pull Request oluşturun

📝 Lisans

Bu proje MIT lisansı altında lisanslanmıştır. Detaylar için LICENSE dosyasına bakın.

👨‍💻 Geliştirici

Buğra Alkın - @alknbugra

📞 İletişim

  • GitHub: @alknbugra
  • Email: [İletişim için GitHub üzerinden mesaj atın]

Bu projeyi beğendiyseniz yıldız vermeyi unutmayın!

About

🛒 Modern E-Commerce Web API with JWT Authentication, Entity Framework Core, and Swagger documentation - Complete shopping cart and order management

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published