improvements are done
This commit is contained in:
47
API.md
47
API.md
@@ -107,30 +107,41 @@ Response:
|
||||
"priority": 1,
|
||||
"img": "https://...",
|
||||
"categoryId": "cat1",
|
||||
"itemCount": 15
|
||||
"itemCount": 15,
|
||||
"hasItems": true,
|
||||
"subcategories": []
|
||||
}
|
||||
]
|
||||
|
||||
Note:
|
||||
- Subcategories can have nested subcategories (recursive)
|
||||
- If hasItems is true, cannot create child subcategories
|
||||
```
|
||||
|
||||
### Get Single Subcategory
|
||||
```
|
||||
GET /api/subcategories/:subcategoryId
|
||||
|
||||
Response: (subcategory object)
|
||||
Response: (subcategory object with nested subcategories if any)
|
||||
```
|
||||
|
||||
### Create Subcategory
|
||||
```
|
||||
POST /api/categories/:categoryId/subcategories
|
||||
|
||||
Note: categoryId can be either a category ID or a parent subcategory ID for nested structure
|
||||
|
||||
Body:
|
||||
{
|
||||
"id": "custom-id", // Optional, auto-generated if not provided
|
||||
"name": "New Subcategory",
|
||||
"visible": true,
|
||||
"priority": 10
|
||||
}
|
||||
|
||||
Response: (created subcategory object)
|
||||
|
||||
Error: Returns 400 if parent subcategory already has items
|
||||
```
|
||||
|
||||
### Update Subcategory
|
||||
@@ -139,6 +150,7 @@ PATCH /api/subcategories/:subcategoryId
|
||||
|
||||
Body: (any field)
|
||||
{
|
||||
"id": "new-id", // ID is now editable (used for routing)
|
||||
"name": "Updated Name",
|
||||
"visible": false
|
||||
}
|
||||
@@ -185,7 +197,15 @@ Response:
|
||||
{ "key": "Storage", "value": "256GB" }
|
||||
],
|
||||
"subcategoryId": "sub1",
|
||||
"comments": [...]
|
||||
"comments": [
|
||||
{
|
||||
"id": "c1",
|
||||
"text": "Great product!",
|
||||
"author": "John Doe",
|
||||
"stars": 5,
|
||||
"createdAt": "2024-01-10T10:30:00Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"total": 150,
|
||||
@@ -299,3 +319,24 @@ Response:
|
||||
- Images: array of URLs
|
||||
- Description: array of key-value pairs
|
||||
- Auto-save triggers PATCH with single field every 500ms
|
||||
### Business Rules
|
||||
|
||||
1. **Nested Subcategories**
|
||||
- Subcategories can have unlimited nesting levels
|
||||
- A subcategory with items (`hasItems: true`) cannot have child subcategories
|
||||
- Creating a subcategory under a parent with items will fail
|
||||
|
||||
2. **Item Management**
|
||||
- When first item is created in a subcategory, `hasItems` is set to true
|
||||
- When last item is deleted, `hasItems` is set to false
|
||||
- Items belong to the deepest subcategory in the hierarchy
|
||||
|
||||
3. **Comments**
|
||||
- Stars field is optional (1-5 rating)
|
||||
- createdAt is ISO 8601 timestamp
|
||||
- author is optional (can be anonymous)
|
||||
|
||||
4. **URL Structure for Marketplace**
|
||||
- Items: `/{categoryId}/{subcategoryId}/.../{itemId}`
|
||||
- Example: `/electronics/smartphones/iphone-15`
|
||||
- Example nested: `/electronics/smartphones/apple/iphone-15`
|
||||
Reference in New Issue
Block a user