first commit

This commit is contained in:
Beyhan Oğur
2026-04-26 21:35:24 +03:00
commit bbbf76b184
592 changed files with 246870 additions and 0 deletions

View File

@@ -0,0 +1,193 @@
# Hard Delete Hızlı Referans
## Tek Komutla Hard Delete
### 1. Kullanıcı ID ile Hard Delete
```bash
# Admin token al ve kullanıcıyı sil
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_BURAYA?hard=true" \
-H "Authorization: Bearer $TOKEN"
```
**USER_ID_BURAYA** yerine gerçek UUID'yi yazın.
### 2. Email ile Bul ve Hard Delete
```bash
# Token al
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')
# Email ile kullanıcı bul
USER_ID=$(curl -s -X GET "http://localhost:8080/v1/admin/users/search?q=test@example.com" \
-H "Authorization: Bearer $TOKEN" | jq -r '.users[0].id')
# Hard delete
curl -X DELETE "http://localhost:8080/v1/admin/users/$USER_ID?hard=true" \
-H "Authorization: Bearer $TOKEN"
```
### 3. One-Liner (Tek Satırda)
```bash
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_BURAYA" -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"
```
**EMAIL_BURAYA** yerine silinecek email'i yazın.
## API Endpoint'leri
| İşlem | Method | Endpoint | Query Param |
|-------|--------|----------|-------------|
| Aktif Kullanıcılar | GET | `/v1/admin/users` | `?page=1&limit=10` |
| **Silinen Kullanıcılar** | GET | `/v1/admin/users/deleted` | `?page=1&limit=10` |
| Soft Delete | DELETE | `/v1/admin/users/{id}` | - |
| Hard Delete | DELETE | `/v1/admin/users/{id}` | `?hard=true` |
| **Restore User** | POST | `/v1/admin/users/{id}/restore` | - |
| Kullanıcı Ara | GET | `/v1/admin/users/search` | `?q=email` |
## Örnek Yanıtlar
### Başarılı Hard Delete
```json
{
"message": "User deleted permanently successfully"
}
```
### Başarılı Soft Delete
```json
{
"message": "User deleted soft successfully"
}
```
### Hata (Kullanıcı Bulunamadı)
```json
{
"error": "Failed to delete user"
}
```
### Hata (Kendi Hesabını Silmeye Çalışma)
```json
{
"error": "Cannot delete your own account"
}
```
## cURL ile POST Örnekleri
### Yeni Kullanıcı Oluştur (Hard Delete için)
```bash
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')
# Form data ile (avatar ile)
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"
# Yanıt - User ID'yi not edin
# {
# "id": "abc-123-def-456",
# "email": "newuser@test.com",
# ...
# }
# Hard delete
curl -X DELETE "http://localhost:8080/v1/admin/users/abc-123-def-456?hard=true" \
-H "Authorization: Bearer $TOKEN"
```
## Pratik Scriptler
### test-hard-delete.sh
```bash
#!/bin/bash
# Test kullanıcısı oluştur ve hemen hard delete yap
echo "Creating admin token..."
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 "Creating test user..."
CREATE_RESPONSE=$(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_RESPONSE | jq -r '.id')
echo "Created user: $USER_ID"
echo "Hard deleting user..."
DELETE_RESPONSE=$(curl -s -X DELETE "http://localhost:8080/v1/admin/users/$USER_ID?hard=true" \
-H "Authorization: Bearer $TOKEN")
echo "Result: $DELETE_RESPONSE"
```
### bulk-hard-delete.sh
```bash
#!/bin/bash
# Belirli email pattern'e uyan tüm kullanıcıları hard delete yap
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 emailler
SEARCH_QUERY="test"
echo "Searching users with pattern: $SEARCH_QUERY"
USER_IDS=$(curl -s -X GET "http://localhost:8080/v1/admin/users/search?q=$SEARCH_QUERY" \
-H "Authorization: Bearer $TOKEN" | jq -r '.users[].id')
for USER_ID in $USER_IDS; do
echo "Hard deleting: $USER_ID"
curl -s -X DELETE "http://localhost:8080/v1/admin/users/$USER_ID?hard=true" \
-H "Authorization: Bearer $TOKEN" | jq '.'
sleep 0.5 # Rate limiting için
done
echo "Bulk hard delete completed!"
```
## Önemli Notlar
**Kullanım Öncesi:**
- Admin token'ınızın geçerli olduğundan emin olun
- Silinecek kullanıcının ID'sini doğrulayın
- Soft delete yerine hard delete kullanmak istediğinizden emin olun
⚠️ **Dikkat:**
- Hard delete **GERİ ALINAMAZ**
- Kendi hesabınızı silemezsiniz
- Üretim ortamında dikkatli kullanın
- Yedek almadan hard delete yapmayın
🔧 **Debug:**
```bash
# Token geçerli mi kontrol et
curl -X GET http://localhost:8080/v1/auth/validate \
-H "Authorization: Bearer $TOKEN"
# Kullanıcı var mı kontrol et
curl -X GET "http://localhost:8080/v1/admin/users/$USER_ID" \
-H "Authorization: Bearer $TOKEN"
```