Category Service
Overview
Categories are used to organize products into logical hierarchies. They support parent-child relationships and are used for navigation, filtering, reporting and merchandising.
All category operations are tenant-aware and scoped to the current tenant.
Endpoints
GET
/api/v1/Category/GetCategoryById/{id}
Returns a single category by its numeric identifier.
Behavior:
- Looks up category by ID
- Returns
404if the category does not exist
Authorization:
- Requires Bearer Token
GET
/api/v1/Category/GetCategoryByCode/{code}
Returns a single category by its unique code.
Behavior:
- Looks up category by
Code - Category codes are unique per tenant
- Returns
404if no category matches the provided code
Authorization:
- Requires Bearer Token
GET
/api/v1/Category/GetAllCategories
Returns all categories filtered by parent and active status.
Query parameters:
parentId(int)0→ root categories (no parent)> 0→ child categories of the given parent
isActive(bool) - filter by active flag
Behavior:
- Returns categories matching
isActive - Filters by parent category using
parentId - Returns
404if no categories match the filter
Authorization:
- Requires Bearer Token
POST
/api/v1/Category/AddNewCategory
Creates a new category.
Request body:
Name(string, required)Code(string, required)ParentId(long, optional)0→ root category
IsActive(bool, optional)
Behavior:
- Validation is handled in the service layer
- Category code must be unique per tenant
- If
ParentIdis0, the category is treated as a root category - If
IsActiveis not provided, it is stored asfalse - Successful creation writes an audit log entry
Errors:
- Returns
400if validation - or category code already exists
Authorization:
- Requires Bearer Token
PUT
/api/v1/Category/UpdateCategoryById/{id}
Updates an existing category.
Request:
- Category ID is taken from the route
- Request body must include:
Name(string, required)Code(string, required)
- Optional fields:
ParentIdIsActive
Behavior:
- Partial updates are not supported
- If
ParentIdis0, the category becomes a root category - If
IsActiveis provided, it overwrites the existing value - Successful update writes an audit log entry
Errors:
- Returns
400if validation - or category does not exist
Authorization:
- Requires Bearer Token
DELETE
/api/v1/Category/DeleteCategoryById/{id}
Deletes a category by its identifier.
Behavior:
- Performs a hard delete
- Record is permanently removed from the database
- Successful deletion writes an audit log entry
Errors:
- Returns
400if category does not exist or deletion -
Authorization:
- Requires Bearer Token
Notes
- Validation is enforced in the service layer, not via model attributes
- Category hierarchy is managed using
ParentId ParentId = 0always represents a root category- All state-changing operations are audited
- Internal errors are logged but not exposed to clients