Spaces:
Running
Running
File size: 6,602 Bytes
68a2738 | 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 | # Service Catalogue API - Quick Reference (SPA-MS)
## Overview
Customer-facing API for listing and viewing service catalogue in SPA microservice.
**Data Source**: `scm_service_catalogue` (MongoDB)
**Base Path**: `/customer/services`
**Authentication**: Optional (depends on deployment)
## Endpoints
### 1. List Services (with Projection Support)
```http
POST /customer/services/list
```
**Request Body**:
```json
{
"category": "Hair Services",
"status": "active",
"limit": 20,
"offset": 0,
"projection_list": ["service_id", "name", "price", "duration_mins"]
}
```
**Response (with projection)**:
```json
[
{
"service_id": "uuid",
"name": "Hair Cut",
"price": 500.00,
"duration_mins": 30
}
]
```
**Response (without projection)**:
```json
{
"services": [
{
"service_id": "uuid",
"merchant_id": "merchant_123",
"name": "Hair Cut",
"code": "SVC001",
"category": {
"id": "cat_hair",
"name": "Hair Services"
},
"description": "Professional hair cutting service",
"duration_mins": 30,
"price": 500.00,
"currency": "INR",
"gst_rate": 18.0,
"status": "active"
}
],
"pagination": {
"limit": 20,
"offset": 0,
"total": 15
}
}
```
**Projection Fields**:
- `service_id` - Service UUID
- `merchant_id` - Merchant UUID
- `name` - Service name
- `code` - Service code
- `category` - Category object
- `description` - Service description
- `duration_mins` - Duration in minutes
- `price` - Service price
- `currency` - Currency code
- `gst_rate` - GST rate percentage
- `status` - Service status
---
### 2. Get Service by ID
```http
GET /customer/services/{service_id}
```
**Response**: `CustomerServiceResponse`
---
### 3. Legacy GET List (Deprecated)
```http
GET /customer/services?category=Hair%20Services&status=active&limit=20&offset=0
```
**Note**: Use POST /list instead for projection support.
---
## Request Schema
### ServiceListRequest
```json
{
"category": "string (optional)",
"status": "active|inactive|archived (optional)",
"limit": 20,
"offset": 0,
"projection_list": ["field1", "field2"]
}
```
---
## Response Schema
### CustomerServiceResponse
```json
{
"service_id": "uuid",
"merchant_id": "uuid",
"name": "Hair Cut",
"code": "SVC001",
"category": {
"id": "cat_123",
"name": "Hair Services"
},
"description": "Professional hair cutting service",
"duration_mins": 30,
"price": 500.00,
"currency": "INR",
"gst_rate": 18.0,
"status": "active"
}
```
---
## Example Usage
### List All Active Services
```bash
curl -X POST "http://localhost:8000/customer/services/list" \
-H "Content-Type: application/json" \
-d '{
"status": "active",
"limit": 20,
"offset": 0
}'
```
### List Services by Category
```bash
curl -X POST "http://localhost:8000/customer/services/list" \
-H "Content-Type: application/json" \
-d '{
"category": "Hair Services",
"status": "active",
"limit": 20,
"offset": 0
}'
```
### List Services with Projection (Performance Optimized)
```bash
curl -X POST "http://localhost:8000/customer/services/list" \
-H "Content-Type: application/json" \
-d '{
"category": "Hair Services",
"status": "active",
"limit": 20,
"offset": 0,
"projection_list": ["service_id", "name", "price", "duration_mins"]
}'
```
### Get Service Details
```bash
curl -X GET "http://localhost:8000/customer/services/{service_id}"
```
---
## Filters
### category
Filter services by category name (case-insensitive).
**Example**:
```json
{
"category": "Hair Services"
}
```
### status
Filter services by status.
**Valid Values**: `active`, `inactive`, `archived`
**Example**:
```json
{
"status": "active"
}
```
---
## Pagination
Use `limit` and `offset` for pagination:
```json
{
"limit": 20,
"offset": 0
}
```
**Rules**:
- `limit`: 1-100 (default: 20)
- `offset`: >= 0 (default: 0)
---
## Projection List Benefits
Using `projection_list` reduces payload size significantly:
**Without Projection** (Full Response):
```json
{
"service_id": "uuid",
"merchant_id": "merchant_123",
"name": "Hair Cut",
"code": "SVC001",
"category": {"id": "cat_hair", "name": "Hair Services"},
"description": "Professional hair cutting service",
"duration_mins": 30,
"price": 500.00,
"currency": "INR",
"gst_rate": 18.0,
"status": "active"
}
```
**With Projection** (Minimal Response):
```json
{
"service_id": "uuid",
"name": "Hair Cut",
"price": 500.00,
"duration_mins": 30
}
```
**Payload Reduction**: ~70% smaller
---
## Error Responses
### 404 Not Found
```json
{
"detail": "Service with ID 'xyz' not found"
}
```
### 422 Validation Error
```json
{
"detail": [
{
"loc": ["body", "status"],
"msg": "Status must be one of: active, inactive, archived",
"type": "value_error"
}
]
}
```
### 500 Internal Server Error
```json
{
"detail": "Failed to list services"
}
```
---
## Integration with Client Apps
### Mobile App Example (React Native)
```javascript
// List services with projection
const response = await fetch('http://api.example.com/customer/services/list', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
category: 'Hair Services',
status: 'active',
limit: 20,
offset: 0,
projection_list: ['service_id', 'name', 'price', 'duration_mins']
})
});
const services = await response.json();
```
### Web App Example (JavaScript)
```javascript
// Get service details
const response = await fetch(`http://api.example.com/customer/services/${serviceId}`);
const service = await response.json();
```
---
## Performance Tips
1. **Use Projection**: Always use `projection_list` to request only needed fields
2. **Pagination**: Use appropriate `limit` values (20-50 recommended)
3. **Caching**: Cache service lists on client side with TTL
4. **Filters**: Apply filters server-side rather than client-side filtering
---
## Data Flow
```
Client App
β
SPA-MS (/customer/services/list)
β
MongoDB (scm_service_catalogue collection)
β
Transform to customer-safe format
β
Apply projection (if requested)
β
Return to client
```
---
## Notes
- All services are read from `scm_service_catalogue` MongoDB collection
- No authentication required (configure as needed)
- Customer-safe data only (no internal audit fields exposed)
- Projection support for performance optimization
- Follows API List Endpoint Standard
- Compatible with mobile and web client apps
|