prof002313 / API_ENDPOINTS_VERIFICATION.md
Huzaifa1435's picture
Initial Commit: Clean backend without large files
e3fefe8
|
Raw History Blame Contribute Delete
9.7 kB
# 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)