# API Quick Reference - Hard Delete ## 🎯 En Hızlı Yöntem (Copy-Paste) ### Email ile Kullanıcı Sil ```bash # 1. Bu değişkenleri değiştir EMAIL_TO_DELETE="test@example.com" # 2. Komutu çalıştır (tek satır) TOKEN=$(curl -s -X POST http://localhost:8080/v1/auth/login -H "Content-Type: application/json" -d '{"email":"admin@gauth.local","password":"Admin@123"}' | jq -r '.access_token') && USER_ID=$(curl -s -X GET "http://localhost:8080/v1/admin/users/search?q=$EMAIL_TO_DELETE" -H "Authorization: Bearer $TOKEN" | jq -r '.users[0].id') && curl -X DELETE "http://localhost:8080/v1/admin/users/$USER_ID?hard=true" -H "Authorization: Bearer $TOKEN" | jq '.' ``` ### User ID ile Kullanıcı Sil ```bash # 1. Bu değişkenleri değiştir USER_ID_TO_DELETE="6df5465d-b8e6-44d2-970a-f682cb428e80" # 2. Komutu çalıştır (tek satır) TOKEN=$(curl -s -X POST http://localhost:8080/v1/auth/login -H "Content-Type: application/json" -d '{"email":"admin@gauth.local","password":"Admin@123"}' | jq -r '.access_token') && curl -X DELETE "http://localhost:8080/v1/admin/users/$USER_ID_TO_DELETE?hard=true" -H "Authorization: Bearer $TOKEN" | jq '.' ``` ## 📋 API Endpoints Tablosu | Endpoint | Method | Auth | Body/Params | Açıklama | |----------|--------|------|-------------|----------| | `/v1/auth/login` | POST | ❌ | `{"email":"admin@gauth.local","password":"Admin@123"}` | Admin login | | `/v1/admin/users/search` | GET | ✅ | `?q=email@test.com` | Email ile kullanıcı ara | | `/v1/admin/users` | GET | ✅ | `?page=1&limit=10` | Kullanıcıları listele | | `/v1/admin/users/{id}` | GET | ✅ | - | Kullanıcı detayı | | `/v1/admin/users/{id}` | DELETE | ✅ | - | Soft delete | | `/v1/admin/users/{id}?hard=true` | DELETE | ✅ | - | **Hard delete** | ## 📝 POST/PUT İçin Gerekli Veriler ### Yeni Kullanıcı Oluştur ```bash curl -X POST http://localhost:8080/v1/admin/users \ -H "Authorization: Bearer $TOKEN" \ -F "email=newuser@test.com" \ -F "password=password123" \ -F "user_name=New User" \ -F "email_verified=false" \ -F "roles=user" ``` **Gerekli Alanlar:** - `email` (string, required) - Email adresi - `password` (string, required) - Şifre (min 6 karakter) - `user_name` (string, required) - Kullanıcı adı (min 3 karakter) - `email_verified` (boolean, optional) - Email doğrulandı mı? (default: false) - `roles` (string, optional) - Roller (virgülle ayrılmış: "admin,user") - `avatar` (file, optional) - Profil resmi ### Kullanıcı Güncelle ```bash curl -X PUT http://localhost:8080/v1/admin/users/{user_id} \ -H "Authorization: Bearer $TOKEN" \ -F "email=updated@test.com" \ -F "user_name=Updated Name" \ -F "email_verified=true" \ -F "is_active=true" \ -F "roles=admin,user" ``` **Güncellenebilir Alanlar:** - `email` (string, optional) - `user_name` (string, optional) - `email_verified` (boolean, optional) - `is_active` (boolean, optional) - `roles` (string, optional) - `avatar` (file, optional) ### Rol Ata/Kaldır ```bash # Rol ata curl -X POST http://localhost:8080/v1/admin/users/{user_id}/roles \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"roles": ["admin", "user"]}' # Rol kaldır curl -X DELETE http://localhost:8080/v1/admin/users/{user_id}/roles/admin \ -H "Authorization: Bearer $TOKEN" ``` ## 🔄 Tam İş Akışı Örnekleri ### Örnek 1: Kullanıcı Oluştur → Kontrol Et → Hard Delete ```bash #!/bin/bash set -e echo "📝 Step 1: Admin Login" TOKEN=$(curl -s -X POST http://localhost:8080/v1/auth/login \ -H "Content-Type: application/json" \ -d '{"email":"admin@gauth.local","password":"Admin@123"}' | jq -r '.access_token') echo "✅ Token: ${TOKEN:0:30}..." echo "" echo "📝 Step 2: Create Test User" CREATE_RESULT=$(curl -s -X POST http://localhost:8080/v1/admin/users \ -H "Authorization: Bearer $TOKEN" \ -F "email=temp@test.com" \ -F "password=temp123" \ -F "user_name=Temp User" \ -F "email_verified=false" \ -F "roles=user") USER_ID=$(echo $CREATE_RESULT | jq -r '.id') echo "✅ Created User ID: $USER_ID" echo "" echo "📝 Step 3: Verify User Exists" GET_RESULT=$(curl -s -X GET "http://localhost:8080/v1/admin/users/$USER_ID" \ -H "Authorization: Bearer $TOKEN") echo "✅ User: $(echo $GET_RESULT | jq -r '.email')" echo "" echo "📝 Step 4: Hard Delete User" DELETE_RESULT=$(curl -s -X DELETE "http://localhost:8080/v1/admin/users/$USER_ID?hard=true" \ -H "Authorization: Bearer $TOKEN") echo "✅ $DELETE_RESULT" echo "" echo "📝 Step 5: Verify User Deleted" VERIFY=$(curl -s -X GET "http://localhost:8080/v1/admin/users/$USER_ID" \ -H "Authorization: Bearer $TOKEN") if echo $VERIFY | grep -q "error"; then echo "✅ User successfully deleted (not found)" else echo "❌ User still exists!" fi ``` ### Örnek 2: Toplu Test Kullanıcıları Temizleme ```bash #!/bin/bash echo "🧹 Cleaning test users..." TOKEN=$(curl -s -X POST http://localhost:8080/v1/auth/login \ -H "Content-Type: application/json" \ -d '{"email":"admin@gauth.local","password":"Admin@123"}' | jq -r '.access_token') # "test" içeren tüm kullanıcıları bul USERS=$(curl -s -X GET "http://localhost:8080/v1/admin/users/search?q=test" \ -H "Authorization: Bearer $TOKEN") # Her kullanıcıyı hard delete yap echo "$USERS" | jq -r '.users[] | .id' | while read USER_ID; do EMAIL=$(echo "$USERS" | jq -r ".users[] | select(.id==\"$USER_ID\") | .email") echo "Deleting: $EMAIL ($USER_ID)" curl -s -X DELETE "http://localhost:8080/v1/admin/users/$USER_ID?hard=true" \ -H "Authorization: Bearer $TOKEN" | jq '.' sleep 0.2 # Rate limiting done echo "✅ Cleanup completed!" ``` ## 💾 JSON Response Örnekleri ### Başarılı Hard Delete ```json { "message": "User deleted permanently successfully" } ``` ### Başarılı Soft Delete ```json { "message": "User deleted soft successfully" } ``` ### Kullanıcı Arama Sonucu ```json { "users": [ { "id": "abc-123", "username": "testuser", "email": "test@example.com", "email_verified": false, "created_at": "2026-02-04T20:00:00Z" } ] } ``` ### Kullanıcı Detay ```json { "id": "abc-123", "username": "testuser", "email": "test@example.com", "avatar": "", "email_verified": false, "created_at": "2026-02-04T20:00:00Z", "updated_at": "2026-02-04T20:00:00Z", "roles": [ { "id": 2, "name": "user", "description": "Default user role", "permissions": [ { "name": "user:read" } ] } ] } ``` ## ⚠️ Önemli Hatırlatmalar | ❌ YAPMAYIN | ✅ YAPIN | |------------|---------| | Üretimde hard delete kullanmadan test etmeden | Önce test ortamında deneyin | | Token'ı kodda hard-code etmeyin | Environment variable kullanın | | Kendi admin hesabınızı silmeye çalışmayın | Başka admin oluşturun | | Yedek almadan toplu silme | Önce yedek alın | ## 🔧 Troubleshooting ### Token hatası alıyorsam? ```bash # Token'ı kontrol et curl -X GET http://localhost:8080/v1/auth/validate \ -H "Authorization: Bearer $TOKEN" ``` ### Kullanıcı bulunamıyor? ```bash # Search ile kontrol et curl -X GET "http://localhost:8080/v1/admin/users/search?q=email@test.com" \ -H "Authorization: Bearer $TOKEN" | jq '.' ``` ### Hard delete çalışmıyor? ```bash # Önce soft delete dene curl -X DELETE "http://localhost:8080/v1/admin/users/$USER_ID" \ -H "Authorization: Bearer $TOKEN" # Sonra hard=true ile tekrar dene curl -X DELETE "http://localhost:8080/v1/admin/users/$USER_ID?hard=true" \ -H "Authorization: Bearer $TOKEN" ```