FFFF GitHub - fskalkan/BookNest: Katmanlı mimari ile geliştirilmiş; JWT auth, rol bazlı yetkilendirme, Redis Cache, Unit & Integration test altyapısı içeren kitap yönetim API projesi. · GitHub
[go: up one dir, main page]

Skip to content
fskalkanPublic

About

Katmanlı mimari ile geliştirilmiş; JWT auth, rol bazlı yetkilendirme, Redis Cache, Unit & Integration test altyapısı içeren kitap yönetim API projesi.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

BookNest API

BookNest, ASP.NET Core Web API ile geliştirilmiş, katmanlı mimariye sahip bir kitap yönetim API projesidir.

Bu projede authentication, role-based authorization, CRUD işlemleri, review/favorite yönetimi, pagination-filtering-sorting, Redis cache, global exception handling, validation, logging, unit test ve integration test yapıları uygulanmıştır.

Kullanılan Teknolojiler

  • ASP.NET Core Web API ve C#
  • .NET 8
  • Entity Framework Core
  • MSSQL
  • JWT Authentication
  • AutoMapper
  • FluentValidation
  • Serilog
  • Redis
  • Docker Compose
  • xUnit
  • Moq
  • FluentAssertions
  • Swagger / OpenAPI

Proje Yapısı

BookNest
├── BookNest.API
├── BookNest.Application
├── BookNest.Domain
├── BookNest.Infrastructure
├── BookNest.UnitTests
├── BookNest.IntegrationTests
└── docker-compose.yml

Mimari

Proje katmanlı mimari prensibine göre geliştirilmiştir.

Katman Sorumluluk
BookNest.API Controller, middleware, authentication, authorization, Swagger ve uygulama başlangıç ayarları
BookNest.Application DTO, service, interface, validator, mapping ve iş kuralları
BookNest.Domain Entity ve enum yapıları
BookNest.Infrastructure EF Core DbContext, repository implementasyonları, JWT service ve Redis cache implementasyonu
BookNest.UnitTests Service ve validator unit testleri
BookNest.IntegrationTests Controller integration testleri

Özellikler

  • Kullanıcı kayıt ve giriş işlemleri
  • Admin / Member rol bazlı yetkilendirme
  • Book, Author ve Category yönetimi
  • Review ve favorite book yönetimi
  • Pagination, filtering ve sorting
  • Average rating hesaplama
  • Soft delete
  • Global exception handling
  • Redis cache kullanımı
  • Unit ve integration test yapısı

Redis Cache Stratejisi

Redis cache, sık okunan ve nadiren değişen veriler için kullanılmıştır.

Cache uygulanan endpointler:

GET /api/authors
GET /api/categories

Cache temizleme işlemleri:

  • Author create/update/delete sonrası author list cache temizlenir.
  • Category create/update/delete sonrası category list cache temizlenir.

Book endpointleri bilinçli olarak cache kapsamına alınmamıştır. Çünkü kitapların average rating değeri review işlemleriyle sık değişebilir. Bu nedenle gereksiz cache invalidation karmaşıklığından kaçınılmıştır.

API Endpointleri

Auth

POST /api/auth/register
POST /api/auth/login

Books

GET    /api/books
GET    /api/books/{id}
POST   /api/books
PUT    /api/books/{id}
DELETE /api/books/{id}

Authors

GET    /api/authors
GET    /api/authors/{id}
POST   /api/authors
PUT    /api/authors/{id}
DELETE /api/authors/{id}

Categories

GET    /api/categories
GET    /api/categories/{id}
POST   /api/categories
PUT    /api/categories/{id}
DELETE /api/categories/{id}

Reviews

GET    /api/books/{bookId}/reviews
POST   /api/books/{bookId}/reviews
GET    /api/reviews/my
PUT    /api/reviews/{reviewId}
DELETE /api/reviews/{reviewId}

Favorites

GET    /api/favorites/my
POST   /api/books/{bookId}/favorites
DELETE /api/books/{bookId}/favorites

Test Yapısı

Projede unit test ve integration test olmak üzere iki ayrı test projesi bulunmaktadır.

Unit Tests

Unit testlerde service katmanındaki iş kuralları ve validator kuralları test edilmiştir.

Test edilen alanlar:

  • UserService
  • BookService
  • AuthorService
  • CategoryService
  • ReviewService
  • FavoriteBookService
  • Auth validators
  • Book validators
  • Author validators
  • Category validators
  • Review validators

Kullanılan araçlar:

  • xUnit
  • Moq
  • FluentAssertions
  • FluentValidation TestHelper

Integration Tests

Integration testlerde API endpointleri gerçek HTTP request mantığıyla test edilmiştir.

Test edilen controllerlar:

  • AuthController
  • BooksController
  • AuthorsController
  • CategoriesController
  • ReviewsController
  • FavoriteBooksController

Integration testlerde gerçek MSSQL yerine EF Core InMemory Database kullanılmıştır. Böylece testler izole ve tekrar çalıştırılabilir yapıdadır.

Tüm testleri çalıştırmak için:

dotnet test

Docker & Redis

Redis, Docker Compose ile yönetilmektedir.

Redis container’ını başlatmak için:

docker compose up -d

Redis bağlantısını test etmek için:

docker exec -it booknest-redis redis-cli ping

Beklenen çıktı:

PONG

Redis container’ını durdurmak için:

docker compose down

Projeyi Çalıştırma

Repository’yi klonla:

git clone https://github.com/fskalkan/BookNest.git
cd BookNest

Redis’i başlat:

docker compose up -d

BookNest.API projesinde appsettings.Development.json dosyası oluştur ve aşağıdaki örneği kendi ortamına göre düzenle:

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=YOUR_SERVER_NAME;Database=BookNestDB;Trusted_Connection=True;TrustServerCertificate=True;MultipleActiveResultSets=true"
  },
  "Jwt": {
    "Key": "YOUR_SECRET_KEY_MINIMUM_32_CHARACTERS",
    "Issuer": "BookNestAPI",
    "Audience": "BookNestClient",
    "ExpireMinutes": 60
  },
  "Redis": {
    "ConnectionString": "localhost:6379"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  }
}

Migrationları uygula:

dotnet ef database update --project BookNest.Infrastructure --startup-project BookNest.API

API’yi çalıştır:

dotnet run --project BookNest.API

API çalıştıktan sonra Swagger arayüzüne development ortamında erişilebilir.

Geliştirici

Ferhat Samet Kalkan

About

Katmanlı mimari ile geliştirilmiş; JWT auth, rol bazlı yetkilendirme, Redis Cache, Unit & Integration test altyapısı içeren kitap yönetim API projesi.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0