# Quick Swagger Test Guide

## 🚀 Test Flight Search in 3 Minutes

### Step 1: Open Swagger UI
Open your browser and go to:
```
http://localhost:8081/swagger-ui.html
```

### Step 2: Find the Flight Search Endpoint
1. Scroll down to **"Flight Search"** section
2. Click on **`POST /api/v1/flights/search`**
3. Click **"Try it out"** button

### Step 3: Fill in the Test Data

#### agencyId (Query Parameter):
```
123e4567-e89b-12d3-a456-426614174000
```

#### Request Body (Copy and paste this):
```json
{
  "origin": "MAD",
  "destination": "JFK",
  "departureDate": "2026-03-15",
  "returnDate": "2026-03-22",
  "adults": 1,
  "children": 0,
  "infants": 0,
  "cabinClass": "ECONOMY"
}
```

### Step 4: Handle Authentication

⚠️ **Important**: This endpoint requires authentication!

You have 2 options:

#### Option A: Setup Keycloak (Recommended)
```bash
cd keycloak
./setup-keycloak.sh
```

Then get a token and authorize in Swagger UI.

#### Option B: Temporarily Disable Auth (Testing Only)

For quick testing, you can temporarily allow public access. See below.

---

## 📝 More Example Requests

### Example 1: Madrid to New York (One-Way)
```json
{
  "origin": "MAD",
  "destination": "JFK",
  "departureDate": "2026-03-15",
  "adults": 1,
  "children": 0,
  "infants": 0,
  "cabinClass": "ECONOMY"
}
```

### Example 2: London to Dubai (Business Class)
```json
{
  "origin": "LHR",
  "destination": "DXB",
  "departureDate": "2026-04-10",
  "returnDate": "2026-04-20",
  "adults": 2,
  "children": 0,
  "infants": 0,
  "cabinClass": "BUSINESS"
}
```

### Example 3: Paris to Barcelona (Family Trip)
```json
{
  "origin": "CDG",
  "destination": "BCN",
  "departureDate": "2026-05-01",
  "returnDate": "2026-05-08",
  "adults": 2,
  "children": 2,
  "infants": 1,
  "cabinClass": "ECONOMY"
}
```

---

## 🔓 Temporary: Disable Authentication for Testing

**WARNING**: Only for local testing! Never do this in production!

Edit `src/main/java/com/flightticket/config/SecurityConfig.java`:

Find this line (around line 55):
```java
.requestMatchers("/api/v1/flights/**").hasAnyRole("SUPER_ADMIN", "AGENT")
```

Change it to:
```java
.requestMatchers("/api/v1/flights/**").permitAll()
```

Then rebuild and restart:
```bash
mvn clean package -DskipTests
docker-compose restart app
```

Now you can test without authentication!

**Remember to revert this change after testing!**

---

## ✅ Expected Response

When successful, you'll see something like:

```json
{
  "searchId": "search-abc123",
  "offers": [
    {
      "offerId": "offer-xyz789",
      "validatingCarrier": "AV",
      "price": {
        "baseFare": 266.66,
        "taxes": 50.00,
        "markup": 15.83,
        "total": 332.49,
        "currency": "EUR"
      },
      "outboundSegments": [
        {
          "departureAirport": "MAD",
          "arrivalAirport": "BOG",
          "departureTime": "2026-03-15T10:50:00",
          "arrivalTime": "2026-03-15T15:05:00",
          "carrierCode": "AV",
          "flightNumber": "183",
          "cabinClass": "ECONOMY"
        }
      ]
    }
  ]
}
```

---

## 🎯 Popular Airport Codes

| Code | City | Country |
|------|------|---------|
| MAD | Madrid | Spain |
| BCN | Barcelona | Spain |
| JFK | New York | USA |
| LAX | Los Angeles | USA |
| LHR | London | UK |
| CDG | Paris | France |
| DXB | Dubai | UAE |
| NRT | Tokyo | Japan |
| SIN | Singapore | Singapore |
| SYD | Sydney | Australia |

---

## 🐛 Troubleshooting

### Error: "Full authentication is required"
- You need to authorize with a JWT token
- Or temporarily disable auth (see above)

### Error: "Departure date must be in the future"
- Use a date like `2026-03-15` or later

### Error: "Origin airport code is required"
- Make sure all required fields are filled

### No response / Timeout
- Check if app is running: `docker-compose ps`
- Check Amadeus API health: `curl http://localhost:8081/actuator/health`

---

## 📚 Full Documentation

For complete details, see:
- **SWAGGER_TESTING_GUIDE.md** - Complete Swagger testing guide
- **AMADEUS_INTEGRATION_COMPLETE.md** - Full integration documentation

---

## 🎉 Quick Commands

```bash
# View Swagger UI
open http://localhost:8081/swagger-ui.html

# Test Amadeus API directly
./test-amadeus-simple.sh

# Setup test data
./setup-test-data.sh

# Check application health
curl http://localhost:8081/actuator/health
```

---

**Happy Testing! 🚀**
