File size: 5,479 Bytes
3bfd535
 
 
f295dd5
3bfd535
 
 
 
 
 
b88612a
e4d981c
3bfd535
b88612a
 
 
 
 
 
 
 
 
3bfd535
f295dd5
b88612a
f295dd5
3bfd535
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b88612a
 
 
 
 
 
 
3bfd535
 
 
 
 
 
 
 
b88612a
 
 
f295dd5
3bfd535
f295dd5
3bfd535
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b88612a
3bfd535
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Service Professionals API - Quick Reference

## Overview
API for service professionals to view and update their own profile. Authentication via JWT token with staff_id. Admin operations (create/delete/list) are handled separately.

## Base URL
```
/service-professionals
```

## Authentication
All endpoints require JWT authentication with `partner_id` in the token payload (which contains the staff_id for service professionals).

**Header:**
```
Authorization: Bearer <jwt_token>
```

## Available Endpoints

### 1. Get My Profile
**GET** `/service-professionals/me`

Retrieves the authenticated service professional's profile based on staff_id from JWT token.

**Authentication:** Required (JWT with staff_id)

**Response:** `200 OK`
```json
{
  "staff_id": "550e8400-e29b-41d4-a716-446655440001",
  "staff_code": "SP001",
  "name": "Priya Sharma",
  "designation": "Senior Beautician",
  "role": "beautician",
  "phone": "+919876543210",
  "email": "priya.sharma@example.com",
  "status": "active",
  "category": "beauty",
  "skills": ["facial", "makeup", "hair_styling"],
  "working_hours": [...],
  "photo_url": "https://example.com/photo.jpg",
  "address": {
    "street": "123 Main St",
    "city": "Mumbai",
    "state": "Maharashtra",
    "postal_code": "400001",
    "country": "India"
  },
  "notes": "Specialist in bridal makeup",
  "is_deleted": false,
  "meta": {...}
}
```

---

### 2. Update My Profile
**PUT** `/service-professionals/me`

Updates the authenticated service professional's profile. Staff ID is extracted from JWT token.

**Authentication:** Required (JWT with staff_id)

**Supports updating:**
- Basic info (name, designation, role, phone, email)
- Status and category
- Skills and working hours
- Address (add new or change existing)
- Photo URL and notes

**Request Body (all fields optional):**
```json
{
  "email": "priya.new@example.com",
  "status": "on_leave",
  "address": {
    "street": "456 New Street",
    "city": "Delhi"
  },
  "notes": "Updated notes"
}
```

**Response:** `200 OK`
```json
{
  "staff_id": "550e8400-e29b-41d4-a716-446655440001",
  "staff_code": "SP001",
  "name": "Priya Sharma",
  "email": "priya.new@example.com",
  "status": "on_leave",
  "address": {
    "street": "456 New Street",
    "city": "Delhi",
    "state": "Maharashtra",
    "postal_code": "400001",
    "country": "India"
  },
  ...
}
```

---

## Admin-Only Operations

The following operations are restricted to admin users and are not available through this API:

- **Create Service Professional** - Handled by admin interface
- **Delete Service Professional** - Handled by admin interface
- **List Service Professionals** - Handled by admin interface

---

## Field Definitions

### Updatable Fields (PUT endpoint)
- `staff_code`: Unique staff code (1-20 chars)
- `name`: Full name (1-100 chars)
- `designation`: Job designation (1-100 chars)
- `role`: Role category (1-50 chars)
- `phone`: Contact phone (10-20 chars, unique)
- `email`: Email address (valid email format)
- `status`: Status
- `category`: Service category
- `skills`: Array of skill strings
- `working_hours`: Array of schedule objects
- `photo_url`: Profile photo URL
- `address`: Address object with street, city, state, postal_code, country
- `notes`: Additional notes (max 500 chars)

### Valid Status Values
- `active`
- `inactive`
- `on_leave`
- `suspended`
- `terminated`

### Valid Category Values
- `beauty`
- `spa`
- `salon`
- `fitness`
- `wellness`

---

## Projection List Support

The `/list` endpoint supports projection to reduce payload size:

**Without projection** (returns full objects):
```json
{
  "filters": {"status": "active"},
  "skip": 0,
  "limit": 10
}
```

**With projection** (returns only specified fields):
```json
{
  "filters": {"status": "active"},
  "skip": 0,
  "limit": 10,
  "projection_list": ["staff_id", "name", "phone"]
}
```

Benefits:
- 50-90% payload reduction
- Better performance
- Less network bandwidth

---

## Error Responses

### 400 Bad Request
```json
{
  "detail": "Staff code SP001 already exists"
}
```

### 404 Not Found
```json
{
  "detail": "Service professional 550e8400-e29b-41d4-a716-446655440001 not found"
}
```

### 500 Internal Server Error
```json
{
  "detail": "Failed to create service professional"
}
```

---

## MongoDB Collection
- Collection: `spa_service_professionals`
- Indexes: `staff_code`, `phone`, `is_deleted`

---

## Example Use Cases

### 1. Add New Address
```json
PUT /service-professionals/{staff_id}
{
  "address": {
    "street": "789 Park Avenue",
    "city": "Bangalore",
    "state": "Karnataka",
    "postal_code": "560001",
    "country": "India"
  }
}
```

### 2. Change Email
```json
PUT /service-professionals/{staff_id}
{
  "email": "new.email@example.com"
}
```

### 3. Update Status to On Leave
```json
PUT /service-professionals/{staff_id}
{
  "status": "on_leave"
}
```

### 4. Add New Skills
```json
PUT /service-professionals/{staff_id}
{
  "skills": ["facial", "makeup", "hair_styling", "nail_art"]
}
```

### 5. List Active Beauty Professionals
```json
POST /service-professionals/list
{
  "filters": {
    "status": "active",
    "category": "beauty"
  },
  "projection_list": ["staff_id", "name", "phone", "skills"]
}
```

---

## Testing

Use the provided endpoints to test the API. All endpoints follow standard REST conventions and return appropriate HTTP status codes.

**Collection:** `spa_service_professionals`
**Module Path:** `app/service_professionals/`