boxes-api/api_specification.md

490 lines
9.8 KiB
Markdown
Raw Normal View History

# Boxes API Specification
2024-10-05 03:03:50 +00:00
## Base URL
`/api/v1`
2024-10-05 03:03:50 +00:00
## Authentication
- All endpoints except `/login` require JWT authentication
- JWT token must be provided in the Authorization header as `Bearer <token>`
- Tokens expire after 24 hours
2024-10-05 03:03:50 +00:00
## Endpoints
2024-10-06 17:24:39 +00:00
### Authentication
#### Login
- **URL**: `/login`
- **Method**: `POST`
- **Auth Required**: No
- **Request Body**:
```json
{
"username": "string",
"password": "string"
}
```
- **Success Response**:
- **Code**: 200
- **Content**:
2024-10-05 03:03:50 +00:00
```json
{
"token": "string"
2024-10-05 03:03:50 +00:00
}
```
- **Error Responses**:
- **Code**: 401 UNAUTHORIZED
- **Content**: "Invalid username or password"
### Boxes
2024-10-06 17:24:39 +00:00
#### Get All Boxes
- **URL**: `/boxes`
- **Method**: `GET`
- **Auth Required**: Yes
- **Success Response**:
- **Code**: 200
- **Content**:
```json
[
{
"ID": "number",
"CreatedAt": "timestamp",
"UpdatedAt": "timestamp",
"DeletedAt": "timestamp|null",
"name": "string"
}
]
```
2024-10-06 17:24:39 +00:00
#### Create Box
- **URL**: `/boxes`
- **Method**: `POST`
- **Auth Required**: Yes
- **Request Body**:
```json
{
"name": "string"
}
```
- **Success Response**:
- **Code**: 200
- **Content**:
2024-10-05 03:03:50 +00:00
```json
{
"id": "number",
"name": "string"
2024-10-05 03:03:50 +00:00
}
```
#### Get Box
- **URL**: `/boxes/{id}`
- **Method**: `GET`
- **Auth Required**: Yes
- **Success Response**:
- **Code**: 200
- **Content**:
```json
{
"ID": "number",
"CreatedAt": "timestamp",
"UpdatedAt": "timestamp",
"DeletedAt": "timestamp|null",
"name": "string"
}
```
- **Error Response**:
- **Code**: 404 NOT FOUND
- **Content**: "Box not found"
2024-10-05 03:03:50 +00:00
#### Delete Box
- **URL**: `/boxes/{id}`
- **Method**: `DELETE`
- **Auth Required**: Yes
- **Success Response**:
- **Code**: 204 NO CONTENT
- **Error Response**:
- **Code**: 404 NOT FOUND
- **Content**: "Box not found"
2024-10-05 03:03:50 +00:00
### Items
2024-10-06 17:24:39 +00:00
#### Get All Items
- **URL**: `/items`
- **Method**: `GET`
- **Auth Required**: Yes
- **Success Response**:
- **Code**: 200
- **Content**:
2024-10-05 03:03:50 +00:00
```json
[
{
"ID": "number",
"CreatedAt": "timestamp",
"UpdatedAt": "timestamp",
"DeletedAt": "timestamp|null",
"name": "string",
"description": "string",
"box_id": "number",
"image_path": "string",
"tags": [
{
"ID": "number",
"name": "string",
"description": "string",
"color": "string"
}
]
2024-10-05 03:03:50 +00:00
}
]
```
2024-10-06 17:24:39 +00:00
#### Create Item
- **URL**: `/items`
- **Method**: `POST`
- **Auth Required**: Yes
- **Request Body**:
```json
{
"name": "string",
"description": "string",
"box_id": "number"
}
```
- **Success Response**:
- **Code**: 200
- **Content**:
```json
{
"id": "number",
"name": "string"
}
```
2024-10-06 17:24:39 +00:00
#### Get Item
- **URL**: `/items/{id}`
- **Method**: `GET`
- **Auth Required**: Yes
- **Success Response**:
- **Code**: 200
- **Content**:
2024-10-05 03:03:50 +00:00
```json
{
"ID": "number",
"CreatedAt": "timestamp",
"UpdatedAt": "timestamp",
"DeletedAt": "timestamp|null",
"name": "string",
"description": "string",
"box_id": "number",
"image_path": "string",
"tags": [
{
"ID": "number",
"name": "string",
"description": "string",
"color": "string"
}
]
2024-10-05 03:03:50 +00:00
}
```
- **Error Response**:
- **Code**: 404 NOT FOUND
- **Content**: "Item not found"
#### Update Item
- **URL**: `/items/{id}`
- **Method**: `PUT`
- **Auth Required**: Yes
- **Request Body**:
```json
{
"name": "string",
"description": "string",
"box_id": "number"
}
```
- **Success Response**:
- **Code**: 200
- **Content**: Updated item object
- **Error Response**:
- **Code**: 404 NOT FOUND
- **Content**: "Item not found"
#### Delete Item
- **URL**: `/items/{id}`
- **Method**: `DELETE`
- **Auth Required**: Yes
- **Success Response**:
- **Code**: 204 NO CONTENT
- **Error Response**:
- **Code**: 404 NOT FOUND
- **Content**: "Item not found"
#### Get Items in Box
- **URL**: `/boxes/{id}/items`
- **Method**: `GET`
- **Auth Required**: Yes
- **Success Response**:
- **Code**: 200
- **Content**: Array of item objects
- **Error Response**:
- **Code**: 404 NOT FOUND
- **Content**: "Items not found"
2024-10-06 17:24:39 +00:00
#### Search Items
- **URL**: `/search/items`
- **Method**: `GET`
- **Auth Required**: Yes
- **Query Parameters**:
- `q`: Search query string
- **Success Response**:
- **Code**: 200
- **Content**: Array of matching item objects
- **Error Response**:
- **Code**: 400 BAD REQUEST
- **Content**: "Search query is required"
2024-10-06 17:24:39 +00:00
### Item Images
#### Upload Item Image
- **URL**: `/items/{id}/upload`
- **Method**: `POST`
- **Auth Required**: Yes
- **Content-Type**: `multipart/form-data`
- **Form Parameters**:
- `image`: File upload
- **Success Response**:
- **Code**: 200
- **Content**:
2024-10-05 03:03:50 +00:00
```json
{
"imagePath": "string"
2024-10-05 03:03:50 +00:00
}
```
- **Error Responses**:
- **Code**: 404 NOT FOUND
- **Content**: "Item not found"
- **Code**: 400 BAD REQUEST
- **Content**: "Unable to parse form"
2024-10-06 17:24:39 +00:00
#### Get Item Image
- **URL**: `/items/{id}/image`
- **Method**: `GET`
- **Auth Required**: Yes
- **Success Response**:
- **Code**: 200
- **Content**: Image file
- **Note**: Returns default image if no image is found
2024-10-05 03:03:50 +00:00
### Tags
2024-10-06 17:24:39 +00:00
#### Get All Tags
- **URL**: `/tags`
- **Method**: `GET`
- **Auth Required**: Yes
- **Success Response**:
- **Code**: 200
- **Content**:
2024-10-05 03:03:50 +00:00
```json
[
{
"ID": "number",
"CreatedAt": "timestamp",
"UpdatedAt": "timestamp",
"DeletedAt": "timestamp|null",
"name": "string",
"description": "string",
"color": "string" // hex color code
2024-10-05 03:03:50 +00:00
}
]
```
2024-10-06 17:24:39 +00:00
#### Create Tag
- **URL**: `/tags`
- **Method**: `POST`
- **Auth Required**: Yes
- **Request Body**:
```json
{
"name": "string",
"description": "string",
"color": "string" // hex color code, optional
}
```
- **Success Response**:
- **Code**: 200
- **Content**: Created tag object
- **Error Responses**:
- **Code**: 400 BAD REQUEST
- **Content**: "Tag name is required"
- **Code**: 409 CONFLICT
- **Content**: "Tag name already exists"
#### Update Tag
- **URL**: `/tags/{id}`
- **Method**: `PUT`
- **Auth Required**: Yes
- **Request Body**:
```json
{
"name": "string",
"description": "string",
"color": "string"
}
```
- **Success Response**:
- **Code**: 200
- **Content**: Updated tag object
- **Error Responses**:
- **Code**: 404 NOT FOUND
- **Content**: "Tag not found"
- **Code**: 409 CONFLICT
- **Content**: "Tag name already exists"
#### Delete Tag
- **URL**: `/tags/{id}`
- **Method**: `DELETE`
- **Auth Required**: Yes
- **Success Response**:
- **Code**: 204 NO CONTENT
- **Error Response**:
- **Code**: 404 NOT FOUND
- **Content**: "Tag not found"
2024-10-06 17:24:39 +00:00
### Item Tags
#### Add Tags to Item
- **URL**: `/items/{id}/tags`
- **Method**: `POST`
- **Auth Required**: Yes
- **Request Body**:
```json
[1, 2, 3] // Array of tag IDs
```
- **Success Response**:
- **Code**: 200
- **Content**: Updated item object with tags
- **Error Responses**:
- **Code**: 404 NOT FOUND
- **Content**: "Item not found"
- **Code**: 400 BAD REQUEST
- **Content**: "Tag {id} not found"
#### Remove Tag from Item
- **URL**: `/items/{id}/tags/{tagId}`
- **Method**: `DELETE`
- **Auth Required**: Yes
- **Success Response**:
- **Code**: 204 NO CONTENT
- **Error Responses**:
- **Code**: 404 NOT FOUND
- **Content**: "Item not found" or "Tag not found"
#### Get Items by Tag
- **URL**: `/tags/{id}/items`
- **Method**: `GET`
- **Auth Required**: Yes
- **Success Response**:
- **Code**: 200
- **Content**:
2024-10-05 03:03:50 +00:00
```json
[
{
"ID": "number",
"CreatedAt": "timestamp",
"UpdatedAt": "timestamp",
"DeletedAt": "timestamp|null",
"name": "string",
"description": "string",
"box_id": "number",
"image_path": "string",
"tags": [
{
"ID": "number",
"name": "string",
"description": "string",
"color": "string"
}
]
}
]
2024-10-05 03:03:50 +00:00
```
- **Error Response**:
- **Code**: 404 NOT FOUND
- **Content**: "Tag not found"
### Admin Endpoints
#### Get All Users
- **URL**: `/admin/user`
- **Method**: `GET`
- **Auth Required**: Yes
- **Success Response**:
- **Code**: 200
- **Content**: Array of user objects
#### Create User
- **URL**: `/admin/user`
- **Method**: `POST`
- **Auth Required**: Yes
- **Request Body**:
```json
{
"username": "string",
"password": "string",
"email": "string"
}
```
- **Success Response**:
- **Code**: 200
- **Content**: Created user object
#### Get User
- **URL**: `/admin/user/{id}`
- **Method**: `GET`
- **Auth Required**: Yes
- **Success Response**:
- **Code**: 200
- **Content**: User object
- **Error Response**:
- **Code**: 404 NOT FOUND
- **Content**: "User not found"
#### Delete User
- **URL**: `/admin/user/{id}`
- **Method**: `DELETE`
- **Auth Required**: Yes
- **Success Response**:
- **Code**: 204 NO CONTENT
- **Error Response**:
- **Code**: 404 NOT FOUND
- **Content**: "User not found"
2024-10-06 17:24:39 +00:00
#### Backup Database
- **URL**: `/admin/db`
- **Method**: `GET`
- **Auth Required**: Yes
- **Success Response**:
- **Code**: 200
- **Content**: Database file
2024-10-06 17:24:39 +00:00
#### Restore Database
- **URL**: `/admin/db`
- **Method**: `POST`
- **Auth Required**: Yes
- **Content-Type**: `multipart/form-data`
- **Form Parameters**:
- `database`: Database file
- **Success Response**:
- **Code**: 200
- **Content**:
2024-10-05 03:03:50 +00:00
```json
{
"message": "Database restored successfully"
2024-10-05 03:03:50 +00:00
}
```
2024-10-06 17:24:39 +00:00
## Error Responses
All endpoints may return these common errors:
- **401 Unauthorized**: Missing or invalid authentication token
- **500 Internal Server Error**: Server-side error