Java Spring Boot ile geliştirilmiş, hem REST API sunan hem de Thymeleaf ile Server-Side Rendering (SSR) yaparak HTML arayüz sağlayan temiz ve genişletilebilir bir blog uygulaması.
- Java 21 + Spring Boot 3.3.6
- Spring Data JPA + PostgreSQL
- Spring Security + JWT Authentication
- Thymeleaf - HTML Template Engine
- Flyway - Database Migration & Versioning
- Lombok + Hibernate Validator
src/main/java/com/raptiye/blog/
├── BlogApplication.java # Ana uygulama
├── domain/ # Entity'ler (Post, Comment, Tag)
├── repository/ # Data Access Layer
├── service/ # Business Logic
├── controller/ # REST API & Web Controllers
├── dto/ # Request/Response DTOs
├── mapper/ # Entity ↔ DTO
└── exception/ # Error Handling
POST ||--o{ COMMENT : has
POST }o--o{ TAG : has
POST: id, title, slug, summary, content, published, created_at, updated_at
COMMENT: id, author_name, author_email, content, approved, post_id, created_at
TAG: id, name, slug, created_at
Uygulamanın CSS dosyaları src/main/resources/static/css/ altında bulunur ve bakımı kolaylaştırmak için yarı-modüler bir yapıda organize edilmiştir:
blog.css: Ana giriş noktası.@importkullanarak diğer modülleri birleştirir.modules/base.css: İskelet ve Temel Ayarlar.- Bootstrap override'ları (renkler, butonlar).
- Genel tipografi (fontlar, başlık stilleri).
- Global elementler (scrollbar, temel layout sınıfları).
modules/main.css: Görsel Tasarım ve Sayfa Detayları.- UI Bileşenleri (kartlar, etiketler, ikonlar).
- Sayfa özel stilleri (Ana sayfa listeleme düzeni, yazı detay sayfası içerik formatlaması).
Uygulama, JSON API'nin yanı sıra son kullanıcılar için basit bir web arayüzü de sunar.
- Ana Sayfa: http://localhost:8080/ - Blog yazılarını listeler
- Post Detay: http://localhost:8080/post/{slug} - Yazı detayını ve yorumları gösterir
API dokümantasyonuna ve test arayüzüne aşağıdaki adresten erişebilirsiniz:
- Swagger UI: http://localhost:8080/swagger-ui/index.html
- OpenAPI JSON: http://localhost:8080/v3/api-docs
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /api/auth/register |
Kullanıcı kaydı | No |
| POST | /api/auth/login |
Kullanıcı girişi | No |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /api/posts |
Tüm postları listele | No |
| GET | /api/posts/{slug} |
Slug ile post detayı | No |
| GET | /api/posts/id/{id} |
ID ile post detayı | No |
| GET | /api/posts/tag/{tagSlug} |
Tag'e göre postlar | No |
| POST | /api/posts |
Yeni post oluştur | ✅ ADMIN |
| PUT | /api/posts/{id} |
Post güncelle | ✅ ADMIN |
| DELETE | /api/posts/{id} |
Post sil | ✅ ADMIN |
| POST | /api/posts/{postId}/tags/{tagId} |
Tag ekle | ✅ ADMIN |
| DELETE | /api/posts/{postId}/tags/{tagId} |
Tag çıkar | ✅ ADMIN |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /api/posts/{postId}/comments |
Yorumları listele | No |
| POST | /api/posts/{postId}/comments |
Yorum ekle | No |
| GET | /api/comments/pending |
Onay bekleyen yorumlar | ✅ ADMIN |
| PUT | /api/comments/{id}/approve |
Yorumu onayla | ✅ ADMIN |
| DELETE | /api/comments/{id} |
Yorum sil | ✅ ADMIN |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /api/tags |
Tüm tag'leri listele | No |
| GET | /api/tags/{slug} |
Tag detayı | No |
| POST | /api/tags |
Yeni tag oluştur | ✅ ADMIN |
| DELETE | /api/tags/{id} |
Tag sil | ✅ ADMIN |
-
PostgreSQL veritabanı oluştur:
CREATE DATABASE blog_db;
-
Environment variables ayarla (opsiyonel):
export DB_USERNAME=postgres export DB_PASSWORD=postgres export JWT_SECRET=your-secret-key-here
-
Java 21 kullanılıyor olduğundan emin ol:
export JAVA_HOME=/path/to/java-21 -
Uygulamayı çalıştır:
mvn spring-boot:run
-
Default Kullanıcılar:
- Admin:
username: admin,password: admin123 - User:
username: user,password: user123
- Admin:
# Kullanıcı kaydı
curl -X POST http://localhost:8080/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"username": "johndoe",
"email": "john@example.com",
"password": "password123"
}'
# Kullanıcı girişi
curl -X POST http://localhost:8080/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"username": "admin",
"password": "admin123"
}'
# Response:
# {
# "token": "eyJhbGciOiJIUzI1NiJ9...",
# "type": "Bearer",
# "username": "admin",
# "email": "admin@blog.com",
# "role": "ADMIN"
# }# JWT token'ı değişkene kaydet
TOKEN="your-jwt-token-here"
# Tag oluştur (ADMIN gerekli)
curl -X POST http://localhost:8080/api/tags \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{"name": "Java"}'
# Post oluştur (ADMIN gerekli)
curl -X POST http://localhost:8080/api/posts \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{"title": "İlk Post", "summary": "Özet", "content": "İçerik", "published": true}'
# Postları listele
curl http://localhost:8080/api/posts
# Yorum ekle
curl -X POST http://localhost:8080/api/posts/1/comments \
-H "Content-Type: application/json" \
-d '{"authorName": "Ali", "authorEmail": "ali@test.com", "content": "Güzel yazı!"}'MIT