File size: 6,260 Bytes
4e33b5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# API Request Examples for `/submit` Endpoint

This document provides working examples for the `/submit` endpoint that accepts multipart/form-data.

## Endpoint Details

- **URL**: `POST /submit`
- **Content-Type**: `multipart/form-data`
- **Required fields**: `report_id`, `description`
- **Optional fields**: `user_id`, `latitude`, `longitude`, `image`

## Example 1: Basic Request (No Image)

### cURL

```bash
curl -X POST "http://localhost:8000/submit" \
  -F "report_id=test-123" \
  -F "description=Pothole on Main Street near the intersection with Oak Avenue. It's quite large and dangerous for vehicles."
```

### Python (requests)

```python
import requests

url = "http://localhost:8000/submit"
data = {
    "report_id": "test-123",
    "description": "Pothole on Main Street near the intersection with Oak Avenue. It's quite large and dangerous for vehicles."
}

response = requests.post(url, data=data)
print(response.status_code)
print(response.json())
```

## Example 2: Request with All Optional Fields (No Image)

### cURL

```bash
curl -X POST "http://localhost:8000/submit" \
  -F "report_id=test-456" \
  -F "description=Overflowing garbage bin on Park Avenue causing bad smell" \
  -F "user_id=user-789" \
  -F "latitude=37.7749" \
  -F "longitude=-122.4194"
```

### Python (requests)

```python
import requests

url = "http://localhost:8000/submit"
data = {
    "report_id": "test-456",
    "description": "Overflowing garbage bin on Park Avenue causing bad smell",
    "user_id": "user-789",
    "latitude": "37.7749",
    "longitude": "-122.4194"
}

response = requests.post(url, data=data)
print(response.status_code)
print(response.json())
```

## Example 3: Request with Image File

### cURL

```bash
curl -X POST "http://localhost:8000/submit" \
  -F "report_id=test-789" \
  -F "description=Damaged streetlight on Elm Street not working at night" \
  -F "user_id=user-123" \
  -F "latitude=40.7128" \
  -F "longitude=-74.0060" \
  -F "image=@/path/to/your/image.jpg"
```

### Python (requests)

```python
import requests

url = "http://localhost:8000/submit"

# Prepare form data
data = {
    "report_id": "test-789",
    "description": "Damaged streetlight on Elm Street not working at night",
    "user_id": "user-123",
    "latitude": "40.7128",
    "longitude": "-74.0060"
}

# Add image file
files = {
    "image": ("image.jpg", open("/path/to/your/image.jpg", "rb"), "image/jpeg")
}

response = requests.post(url, data=data, files=files)
print(response.status_code)
print(response.json())

# Don't forget to close the file
files["image"][1].close()
```

### Python (with context manager)

```python
import requests

url = "http://localhost:8000/submit"

data = {
    "report_id": "test-789",
    "description": "Damaged streetlight on Elm Street not working at night",
    "user_id": "user-123",
    "latitude": "40.7128",
    "longitude": "-74.0060"
}

# Using context manager for automatic file handling
with open("/path/to/your/image.jpg", "rb") as img_file:
    files = {
        "image": ("image.jpg", img_file, "image/jpeg")
    }
    response = requests.post(url, data=data, files=files)
    print(response.status_code)
    print(response.json())
```

## Example 4: Request with Image Only (Minimal Fields)

### cURL

```bash
curl -X POST "http://localhost:8000/submit" \
  -F "report_id=test-999" \
  -F "description=Broken traffic signal at downtown intersection" \
  -F "image=@/path/to/your/image.png"
```

### Python (requests)

```python
import requests

url = "http://localhost:8000/submit"

data = {
    "report_id": "test-999",
    "description": "Broken traffic signal at downtown intersection"
}

with open("/path/to/your/image.png", "rb") as img_file:
    files = {"image": ("image.png", img_file, "image/png")}
    response = requests.post(url, data=data, files=files)
    print(response.status_code)
    print(response.json())
```

## Example 5: Using FastAPI Test Client (for testing)

```python
from fastapi.testclient import TestClient
from app.main import app

client = TestClient(app)

# Test without image
response = client.post(
    "/submit",
    data={
        "report_id": "test-001",
        "description": "Waterlogging in residential area after heavy rain"
    }
)
print(response.status_code)
print(response.json())

# Test with image
with open("/path/to/your/image.jpg", "rb") as img_file:
    response = client.post(
        "/submit",
        data={
            "report_id": "test-002",
            "description": "Pothole on highway",
            "latitude": "40.7128",
            "longitude": "-74.0060"
        },
        files={"image": ("image.jpg", img_file, "image/jpeg")}
    )
    print(response.status_code)
    print(response.json())
```

## Expected Response Format

### Success Response

```json
{
  "report_id": "test-123",
  "accept": true,
  "status": "accepted",
  "category": "Road & Traffic",
  "confidence": 0.85,
  "urgency": "medium",
  "reason": "Report accepted successfully"
}
```

### Rejection Response

```json
{
  "report_id": "test-123",
  "accept": false,
  "status": "rejected",
  "category": "Other",
  "confidence": 0.15,
  "reason": "Unable to determine issue category. Please provide more details."
}
```

## Error Responses

### 422 Validation Error Examples

```json
{
  "detail": "Validation error: 'report_id' is required and cannot be empty"
}
```

```json
{
  "detail": "Validation error: 'latitude' must be between -90 and 90, got 95.5"
}
```

```json
{
  "detail": "Validation error: Image file too large. Maximum size is 10.0MB, got 15.5MB"
}
```

## Notes

1. **Content-Type**: Do NOT manually set `Content-Type: multipart/form-data` header. The HTTP client/library will automatically set it with the correct boundary.

2. **Image Formats**: Supported image formats include JPEG, JPG, PNG, GIF, and WebP.

3. **Image Size Limit**: Maximum image size is 10MB.

4. **Latitude/Longitude**: 
   - Must be valid numbers (strings that can be converted to float)
   - Latitude: -90 to 90
   - Longitude: -180 to 180

5. **Required Fields**: 
   - `report_id`: Cannot be empty
   - `description`: Cannot be empty

6. **Base URL**: Replace `http://localhost:8000` with your actual API base URL (e.g., `https://your-api.render.com` for production).