Spaces:
Paused
Paused
File size: 9,698 Bytes
e3fefe8 | 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 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | # Service Connect Backend - API Endpoints Verification
## Backend URL
- **Local**: http://localhost:5000
- **LAN**: http://192.168.1.10:5000
## β
AUTHENTICATION ENDPOINTS
### 1. POST /api/auth/google
**Purpose**: Google Sign-In
**Input**: `{ idToken, fcmToken? }`
**Process**:
- Verify Firebase ID token (or Google token)
- Get/create user in Realtime Database at `/users/{uid}`
- Generate Firebase customToken using `admin.auth().createCustomToken(uid)`
- Return customToken + JWT token
**Response** (201 for new user, 200 for existing):
```json
{
"success": true,
"data": {
"user": {
"uid": "xxx",
"email": "user@gmail.com",
"displayName": "User Name",
"photoURL": "url",
"phoneNumber": "",
"role": null,
"profileCompleted": false
},
"customToken": "firebase_custom_token",
"token": "jwt_session_token",
"expiresIn": "7d"
}
}
```
**Status**: β
IMPLEMENTED
---
### 2. POST /api/auth/signup
**Purpose**: Phone Number Registration
**Input**: `{ phone, password, name, fcmToken? }`
**Process**:
- Convert phone to email: `03001234567@serviceconnect.pk`
- Create Firebase Auth user with email/password
- Save to `/users/{uid}` with `role = null`, `profileCompleted = false`
- Generate customToken
- Return same format as /auth/google
**Status**: β
IMPLEMENTED
---
### 3. POST /api/auth/signin
**Purpose**: Phone Number Login
**Input**: `{ phone, password, fcmToken? }` OR `{ email, password }`
**Process**:
- Convert phone to email if needed
- Verify with Firebase REST API
- Get user from `/users/{uid}`
- Generate customToken
- Return user + tokens
**Status**: β
IMPLEMENTED
---
### 4. GET /api/auth/me
**Purpose**: Get Current User Profile
**Auth**: Required (JWT or customToken)
**Response**:
```json
{
"success": true,
"data": {
"user": {
"uid": "xxx",
"email": "xxx",
"displayName": "xxx",
"phoneNumber": "03001234567",
"role": "customer/professional/null",
"profileCompleted": true/false,
"location": { "lat": 31.5, "lng": 74.3 }
}
}
}
```
**Status**: β
IMPLEMENTED
---
### 5. POST /api/auth/set-role
**Purpose**: Set Customer or Professional Role
**Auth**: Required
**Input**: `{ role: "customer" | "professional" }`
**Process**:
- Update `/users/{uid}/role`
- If role == "professional", create `/professionals/{uid}` with `walletBalance = 5000`
- Set `/users/{uid}/profileCompleted = true` (for professional only)
- Return updated user
**Status**: β
IMPLEMENTED
---
## β
PROFESSIONAL ENDPOINTS
### 1. GET /api/professionals/nearby
**Purpose**: Get Nearby Professionals
**Query Params**:
- `lat` (required)
- `lng` (required)
- `radius` (default: 10 km)
- `service` or `serviceType` (optional)
- `minRating` (optional)
- `maxPrice` (optional)
**Response**:
```json
{
"success": true,
"data": {
"professionals": [
{
"uid": "xxx",
"displayName": "Ali Raza",
"phoneNumber": "03001234567",
"serviceTypes": ["plumber", "electrician"],
"description": "10 years experience",
"hourlyRate": 500,
"distance": 0.5,
"rating": 4.5,
"totalRatings": 20,
"isAvailableNow": true,
"photoURL": "url",
"completedJobs": 15
}
],
"count": 1
}
}
```
**Status**: β
IMPLEMENTED (returns phoneNumber directly)
---
### 2. GET /api/professionals/:uid
**Purpose**: Get Professional Profile
**Response**:
```json
{
"success": true,
"data": {
"professional": {
"uid": "xxx",
"serviceTypes": ["plumber"],
"description": "10 years experience",
"isAvailableNow": true,
"walletBalance": 5000,
"rating": 4.5,
"profileCreated": true,
"userInfo": {
"uid": "xxx",
"displayName": "Ali",
"phoneNumber": "03001234567",
"rating": 4.5,
"address": "Karachi"
}
},
"isAvailable": true
}
}
```
**Status**: β
IMPLEMENTED
---
### 3. POST /api/professionals/profile
**Purpose**: Create Professional Profile (One-Time)
**Auth**: Required
**Input**:
```json
{
"serviceTypes": ["plumber", "electrician"],
"description": "10 years experience",
"hourlyRate": 500,
"experienceYears": 10,
"location": { "lat": 31.5, "lng": 74.3, "address": "Karachi" }
}
```
**Process**:
- Check if profile already exists
- If exists β return 400 error
- If not exists β save to `/professionals/{uid}`
- Set `/users/{uid}/profileCompleted = true`
**Response** (201):
```json
{
"success": true,
"message": "Professional profile created successfully.",
"data": {
"profile": { ... }
}
}
```
**Status**: β
IMPLEMENTED (one-time only)
---
### 4. POST /api/professionals/availability
**Purpose**: Toggle Online/Offline
**Auth**: Required
**Input**: `{ isAvailableNow: true/false }`
**Response**:
```json
{
"success": true,
"data": { "isAvailableNow": true }
}
```
**Status**: β
IMPLEMENTED
---
## β
BOOKING ENDPOINTS
### 1. POST /api/bookings
**Purpose**: Create Booking (No Payment Required)
**Auth**: Required
**Input**:
```json
{
"professionalId": "xxx",
"serviceType": "plumbing",
"address": "123 Main St",
"description": "Leaking tap",
"proposedPrice": 500,
"scheduledTime": "2024-05-22 10:00"
}
```
**Process**:
- Create booking with status = "confirmed"
- Return professional's phone number and location immediately
**Response** (201):
```json
{
"success": true,
"message": "Booking confirmed. Professional contact details are now available.",
"data": {
"bookingId": "xxx",
"status": "confirmed",
"proposedPrice": 500,
"professionalPhone": "03001234567",
"professionalName": "Ali Raza",
"professionalLocation": { "lat": 31.5, "lng": 74.3 },
"professionalPhotoURL": "url",
"phoneRevealed": true
}
}
```
**Status**: β
IMPLEMENTED
---
### 2. POST /api/bookings/:id/accept
**Purpose**: Professional Accept Booking
**Auth**: Required
**Status Update**: pending_acceptance β confirmed (or similar)
**Status**: β
IMPLEMENTED
---
### 3. POST /api/bookings/:id/reject
**Purpose**: Professional Reject Booking
**Auth**: Required
**Status Update**: confirmed β rejected
**Status**: β
IMPLEMENTED
---
### 4. GET /api/bookings/my
**Purpose**: Get User's Bookings (Both Customer & Professional)
**Auth**: Required
**Response**:
```json
{
"success": true,
"data": {
"bookings": [
{
"bookingId": "xxx",
"customerId": "xxx",
"professionalId": "xxx",
"status": "confirmed",
"proposedPrice": 500,
"contactInfo": {
"name": "Ali Raza",
"phone": "03001234567",
"address": "Karachi"
},
"phoneRevealed": true
}
]
}
}
```
**Status**: β
IMPLEMENTED
---
### 5. GET /api/bookings/active
**Purpose**: Get Active Bookings
**Auth**: Required
**Response**: Same as /bookings/my but only active statuses
**Status**: β
IMPLEMENTED
---
## β
ADMIN ENDPOINTS
### 1. POST /api/admin/login
**Input**: `{ username }` (username = "Huzaifa")
**Response**:
```json
{
"success": true,
"data": {
"token": "admin_jwt_token",
"expiresIn": "8h"
}
}
```
**Status**: β
IMPLEMENTED
---
### 2. GET /api/admin/stats
**Auth**: Admin
**Response**:
```json
{
"success": true,
"data": {
"totalProfessionals": 10,
"totalCustomers": 50,
"totalBookings": 100,
"totalCompletedJobs": 80,
"totalCommission": 5000
}
}
```
**Status**: β
IMPLEMENTED
---
## DATABASE STRUCTURE
### /users/{uid}
```
{
"uid": "string",
"email": "user@gmail.com",
"displayName": "User Name",
"photoURL": "url",
"phoneNumber": "03001234567",
"role": "customer/professional/null",
"profileCompleted": true/false,
"location": { "lat": 31.5, "lng": 74.3 },
"address": "Karachi",
"rating": 4.5,
"totalRatings": 20,
"_createdAt": 1234567890,
"_updatedAt": 1234567890
}
```
### /professionals/{uid}
```
{
"uid": "string",
"serviceTypes": ["plumber"],
"description": "10 years experience",
"isAvailableNow": true,
"location": { "lat": 31.5, "lng": 74.3 },
"walletBalance": 5000,
"rating": 4.5,
"completedJobs": 15,
"profileCreated": true,
"hourlyRate": 500,
"_createdAt": 1234567890,
"_updatedAt": 1234567890
}
```
### /bookings/{bookingId}
```
{
"bookingId": "uuid",
"customerId": "uid",
"professionalId": "uid",
"status": "confirmed/in_progress/completed/rejected",
"proposedPrice": 500,
"address": "123 Main St",
"createdAt": 1234567890,
"_updatedAt": 1234567890
}
```
---
## TESTING CHECKLIST
- [ ] POST /api/auth/google returns customToken
- [ ] POST /api/auth/signup creates user in RTDB
- [ ] POST /api/auth/signin returns customToken
- [ ] GET /api/auth/me retrieves user correctly
- [ ] POST /api/auth/set-role updates role and creates professional entry
- [ ] GET /api/professionals/nearby returns list with phoneNumbers
- [ ] POST /api/professionals/profile rejects if already exists
- [ ] POST /api/bookings returns professional phone + location
- [ ] Role persists in RTDB after /auth/set-role
- [ ] User profileCompleted flag updates correctly
---
## KEY FIXES APPLIED
1. β
customToken generation in all auth endpoints
2. β
Phone number exposure in /professionals/nearby
3. β
Professional phone + location in /api/bookings response
4. β
One-time profile creation (rejects if exists)
5. β
Role persistence in Realtime Database
6. β
Proper user data upsert with all fields
7. β
JWT token generation for session management
8. β
Booking status set to "confirmed" on creation (no payment flow)
|