Get All Categories
Get all categories with product count.Authentication Required: YesRoles: admin, manager, cashier
Query Parameters
Number of categories to return
Response
Number of products in this category
Example
curl -X GET "https://localhost:8080/api/v1/categories?limit=10&offset=0" \
-H "Cookie: access_token=YOUR_TOKEN"
{
"message": "Categories retrieved successfully",
"data": [
{
"id": 1,
"name": "Beverages",
"product_count": 25,
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-02-15T10:30:00Z"
},
{
"id": 2,
"name": "Food",
"product_count": 18,
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-02-20T14:20:00Z"
}
]
}
Get Category by ID
Get a specific category by its ID.Authentication Required: YesRoles: admin, manager
Path Parameters
Response
Example
curl -X GET https://localhost:8080/api/v1/categories/1 \
-H "Cookie: access_token=YOUR_TOKEN"
{
"message": "Category retrieved successfully",
"data": {
"id": 1,
"name": "Beverages",
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-02-15T10:30:00Z"
}
}
Create Category
Create a new category.Authentication Required: YesRoles: admin, manager
Request Body
Category name (3-100 characters)
Response
Created category information
Example
curl -X POST https://localhost:8080/api/v1/categories \
-H "Content-Type: application/json" \
-H "Cookie: access_token=YOUR_TOKEN" \
-d '{
"name": "Desserts"
}'
{
"message": "Category created successfully",
"data": {
"id": 3,
"name": "Desserts",
"created_at": "2024-03-03T12:00:00Z",
"updated_at": "2024-03-03T12:00:00Z"
}
}
Update Category
Update a category by its ID.Authentication Required: YesRoles: admin, manager
Path Parameters
Request Body
Category name (3-100 characters)
Response
Updated category information
Example
curl -X PUT https://localhost:8080/api/v1/categories/3 \
-H "Content-Type: application/json" \
-H "Cookie: access_token=YOUR_TOKEN" \
-d '{
"name": "Sweet Treats"
}'
{
"message": "Category updated successfully",
"data": {
"id": 3,
"name": "Sweet Treats",
"created_at": "2024-03-03T12:00:00Z",
"updated_at": "2024-03-03T14:30:00Z"
}
}
Delete Category
Delete a category by its ID.Authentication Required: YesRoles: admin, managerNote: Category cannot be deleted if it has products assigned to it.
Path Parameters
Response
Example
curl -X DELETE https://localhost:8080/api/v1/categories/3 \
-H "Cookie: access_token=YOUR_TOKEN"
{
"message": "Category deleted successfully"
}
Get Category Count
Get total number of categories with products.Authentication Required: YesRoles: admin, manager, cashier
Response
Array of category objects with product counts
Example
curl -X GET https://localhost:8080/api/v1/categories/count \
-H "Cookie: access_token=YOUR_TOKEN"
{
"message": "Category count retrieved successfully",
"data": [
{
"id": 1,
"name": "Beverages",
"product_count": 25
},
{
"id": 2,
"name": "Food",
"product_count": 18
}
]
}