Skip to content

Code2Work/fullstack-backend-project-14

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blog API — Bitirme Projesi (Capstone)

Amaç

Backend programında öğrendiğin her şeyi tek bir uygulamada birleştiriyorsun: REST API + JPA (veritabanı) + Spring Security (kimlik & yetki) + birim testleri. Küçük bir blog/forum servisi: kullanıcılar kayıt olur, ADMIN gönderi yazıp siler, giriş yapan herkes yorum yapabilir, okuma herkese açıktır. Süre: ~10-14 saat.

Bu, haftalık projelerden daha büyük ve entegre bir projedir — bitirince elinde portföye koyabileceğin tam bir Spring Boot API olur.

Mimari (hazır verilenler)

Controller ──> Service ──> Repository (JpaRepository) ──> H2
     ▲
SecurityFilterChain  (yazma=ADMIN, yorum=giriş yapan, okuma=herkes)
CustomUserDetailsService + BCryptPasswordEncoder

Veri modeli

  • User (username, hash'li password, role: ADMIN / MEMBER)
  • Post (title, content, authorUsername)
  • Comment (postId, text, authorUsername) — gönderiye postId ile bağlı

HAZIR — dokunma

  • entity/, repository/ (JpaRepository + türetilmiş sorgular: findByAuthorUsername, findByPostId)
  • dto/ (RegisterRequest, UserResponse, PostRequest, CommentRequest@Valid hazır)
  • security/ (SecurityConfig, CustomUserDetailsService), controller/GlobalExceptionHandler, application.properties

SEN YAZACAKSIN — service/ ve controller/ (// TODO 1-16)

  1. AuthService (1-3): kayıt — dup kontrol, şifre hash, kaydet.
  2. PostService (4-7): create, findAll, findByAuthor, delete.
  3. CommentService (8-9): addToPost (postId ile), findByPost.
  4. AuthController (10): POST /registerUserResponse (şifre dönmez), 201.
  5. PostController (11-14): GET /posts, GET /posts/author/{username}, POST /posts (201), DELETE /posts/{id} (200).
  6. CommentController (15-16): GET ve POST /posts/{postId}/comments.

💡 Yetki kuralları SecurityConfig'de hazır — controller'da rol kontrolü yazma. Spring Security isteği daha controller'a gelmeden 401 (kimlik yok) / 403 (yetki yok) ile reddeder.

Uç Noktalar (özet)

Method Yol Erişim
POST /register herkes
GET /posts, /posts/author/{username} herkes
GET /posts/{postId}/comments herkes
POST /posts ADMIN
DELETE /posts/{id} ADMIN
POST /posts/{postId}/comments giriş yapan herkes
mvn spring-boot:run
curl -i -X POST localhost:8080/register -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"sifre123","role":"ADMIN"}'
curl -i -u admin:sifre123 -X POST localhost:8080/posts -H "Content-Type: application/json" \
  -d '{"title":"İlk Yazı","content":"Merhaba dünya","authorUsername":"admin"}'
curl -i localhost:8080/posts
curl -i -u admin:sifre123 -X POST localhost:8080/posts/1/comments -H "Content-Type: application/json" \
  -d '{"text":"Güzel yazı","authorUsername":"admin"}'

Öğrenme Hedefleri (entegre)

  • REST: CRUD, path variable (/{id}, /author/{username}), iç içe kaynak (/posts/{id}/comments), ResponseEntity + durum kodları
  • JPA: @Entity, JpaRepository, türetilmiş sorgular, deleteById
  • Security: SecurityFilterChain, BCrypt, rol bazlı yetki (hasRole) + authenticated
  • DTO + validation: @Valid, hassas alanı gizleme (UserResponse)
  • Test: Mockito (servis) + MockMvc (@WithMockUser, 401/403/201)

Testler ve Skor

21 test: AuthServiceTest, PostServiceTest, CommentServiceTest (Mockito) + SecurityTest (MockMvc — rol/erişim). 1. student_id.txt'ye Kaizu numaranı yaz. 2. mvn test. 3. 21/21 → panelde yeşil tik.

Kısmi çalıştırmada skor gönderilmez — tik için tüm testleri koştur.

Çözüm

Takılırsan "Çözümü Göster" (3 gün sonra). Test çıktısındaki "beklenen/gelen" en iyi ipucudur.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages