openapi: 3.0.3 info: title: Admin Management API description: RESTful API endpoints for admin management functionality including category and user CRUD operations version: 1.0.0 contact: name: Inventory System API servers: - url: http://localhost:3001/api/v1 description: Local development server tags: - name: Categories description: Category management operations (admin only) - name: Users description: User account management operations (admin only) - name: Admin Dashboard description: Admin dashboard overview and statistics paths: # ===== CATEGORIES ===== /admin/categories: get: tags: - Categories summary: List all categories with item counts description: Retrieves all categories sorted alphabetically with the count of items in each category (FR-006, FR-007) operationId: getCategories security: - adminAuth: [] responses: '200': description: Successful response content: application/json: schema: type: object properties: data: type: array items: $ref: '#/components/schemas/CategoryWithCount' message: type: string example: Categories retrieved successfully '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '500': $ref: '#/components/responses/ServerError' post: tags: - Categories summary: Create a new category description: Creates a new category with a unique name (FR-001, FR-005) operationId: createCategory security: - adminAuth: [] requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/CreateCategoryRequest' responses: '201': description: Category created successfully content: application/json: schema: type: object properties: data: $ref: '#/components/schemas/Category' message: type: string example: Category created successfully '400': description: Validation error (empty name, too long, duplicate name) content: application/json: schema: $ref: '#/components/schemas/Error' examples: duplicate: value: error: Category name already exists message: A category with this name already exists emptyName: value: error: Validation error message: Category name is required '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '500': $ref: '#/components/responses/ServerError' /admin/categories/{categoryId}: parameters: - $ref: '#/components/parameters/CategoryId' get: tags: - Categories summary: Get category by ID description: Retrieves a single category with its item count operationId: getCategoryById security: - adminAuth: [] responses: '200': description: Successful response content: application/json: schema: type: object properties: data: $ref: '#/components/schemas/CategoryWithCount' message: type: string example: Category retrieved successfully '404': $ref: '#/components/responses/NotFound' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' put: tags: - Categories summary: Update category name description: Updates an existing category's name (FR-002, FR-005 - must remain unique) operationId: updateCategory security: - adminAuth: [] requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/UpdateCategoryRequest' responses: '200': description: Category updated successfully content: application/json: schema: type: object properties: data: $ref: '#/components/schemas/Category' message: type: string example: Category updated successfully '400': description: Validation error (duplicate name, empty name) content: application/json: schema: $ref: '#/components/schemas/Error' '404': $ref: '#/components/responses/NotFound' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' delete: tags: - Categories summary: Delete category description: Deletes a category only if it has no items assigned (FR-003, FR-004) operationId: deleteCategory security: - adminAuth: [] responses: '200': description: Category deleted successfully content: application/json: schema: type: object properties: message: type: string example: Category deleted successfully '404': $ref: '#/components/responses/NotFound' '409': description: Cannot delete category with assigned items content: application/json: schema: type: object properties: error: type: string example: Cannot delete category message: type: string example: Cannot delete category "Electronics". It has 15 item(s) assigned. itemCount: type: integer example: 15 '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' # ===== USERS ===== /admin/users: get: tags: - Users summary: List all users description: Retrieves all users with their roles and account status (FR-015) operationId: getUsers security: - adminAuth: [] parameters: - name: role in: query description: Filter by role required: false schema: type: string enum: [administrator, standard user] responses: '200': description: Successful response content: application/json: schema: type: object properties: data: type: array items: $ref: '#/components/schemas/User' message: type: string example: Users retrieved successfully '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' post: tags: - Users summary: Create a new user account description: Creates a new user account and sends notification (FR-008, FR-009, FR-016) operationId: createUser security: - adminAuth: [] requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/CreateUserRequest' responses: '201': description: User created successfully content: application/json: schema: type: object properties: data: $ref: '#/components/schemas/User' message: type: string example: User created successfully. Notification sent to user@example.com '400': description: Validation error (invalid email, duplicate email, missing required fields) content: application/json: schema: $ref: '#/components/schemas/Error' examples: duplicateEmail: value: error: Validation error message: Email address already exists invalidEmail: value: error: Validation error message: Invalid email format '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' /admin/users/{userId}: parameters: - $ref: '#/components/parameters/UserId' get: tags: - Users summary: Get user by ID description: Retrieves a single user's details operationId: getUserById security: - adminAuth: [] responses: '200': description: Successful response content: application/json: schema: type: object properties: data: $ref: '#/components/schemas/User' message: type: string example: User retrieved successfully '404': $ref: '#/components/responses/NotFound' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' put: tags: - Users summary: Update user account description: Updates user information including name, email, and role (FR-010, FR-011) operationId: updateUser security: - adminAuth: [] requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/UpdateUserRequest' responses: '200': description: User updated successfully content: application/json: schema: type: object properties: data: $ref: '#/components/schemas/User' message: type: string example: User updated successfully '400': description: Validation error (invalid email, duplicate email) content: application/json: schema: $ref: '#/components/schemas/Error' '404': $ref: '#/components/responses/NotFound' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' delete: tags: - Users summary: Delete or deactivate user account description: Removes or deactivates a user account with safety checks (FR-011, FR-013, FR-014) operationId: deleteUser security: - adminAuth: [] responses: '200': description: User deleted successfully content: application/json: schema: type: object properties: message: type: string example: User account deleted successfully '403': description: Cannot delete user (self-deletion or last admin) content: application/json: schema: type: object properties: error: type: string example: Cannot delete user message: type: string examples: - Cannot delete your own account - Cannot delete the last administrator account '404': $ref: '#/components/responses/NotFound' '401': $ref: '#/components/responses/Unauthorized' # ===== ADMIN DASHBOARD ===== /admin/dashboard: get: tags: - Admin Dashboard summary: Get admin dashboard statistics description: Retrieves overview statistics for admin dashboard (FR-021) operationId: getAdminDashboard security: - adminAuth: [] responses: '200': description: Successful response content: application/json: schema: type: object properties: data: $ref: '#/components/schemas/AdminDashboard' message: type: string example: Dashboard statistics retrieved successfully '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' # ===== COMPONENTS ===== components: securitySchemes: adminAuth: type: http scheme: bearer description: JWT token with administrator role required parameters: CategoryId: name: categoryId in: path required: true description: Category UUID schema: type: string format: uuid UserId: name: userId in: path required: true description: User UUID schema: type: string format: uuid schemas: Category: type: object properties: id: type: string format: uuid example: 550e8400-e29b-41d4-a716-446655440000 name: type: string minLength: 1 maxLength: 50 example: Electronics createdAt: type: string format: date-time example: 2026-01-25T10:30:00Z updatedAt: type: string format: date-time example: 2026-01-25T10:30:00Z required: - id - name - createdAt - updatedAt CategoryWithCount: allOf: - $ref: '#/components/schemas/Category' - type: object properties: itemCount: type: integer minimum: 0 description: Number of items assigned to this category example: 15 CreateCategoryRequest: type: object properties: name: type: string minLength: 1 maxLength: 50 description: Unique category name (case-insensitive) example: Electronics required: - name UpdateCategoryRequest: type: object properties: name: type: string minLength: 1 maxLength: 50 description: Updated category name (must remain unique) example: Electronic Devices required: - name User: type: object properties: id: type: string format: uuid example: 660e8400-e29b-41d4-a716-446655440000 name: type: string minLength: 1 maxLength: 100 example: John Doe email: type: string format: email example: john.doe@example.com role: type: string enum: [administrator, standard user] example: standard user createdAt: type: string format: date-time example: 2026-01-25T10:30:00Z updatedAt: type: string format: date-time example: 2026-01-25T10:30:00Z required: - id - name - email - role - createdAt - updatedAt CreateUserRequest: type: object properties: name: type: string minLength: 1 maxLength: 100 example: John Doe email: type: string format: email example: john.doe@example.com role: type: string enum: [administrator, standard user] default: standard user example: standard user required: - name - email - role UpdateUserRequest: type: object properties: name: type: string minLength: 1 maxLength: 100 example: John Smith email: type: string format: email example: john.smith@example.com role: type: string enum: [administrator, standard user] example: administrator description: At least one field must be provided AdminDashboard: type: object properties: totalUsers: type: integer minimum: 0 example: 42 totalCategories: type: integer minimum: 0 example: 12 totalAdministrators: type: integer minimum: 1 example: 5 recentActions: type: array items: $ref: '#/components/schemas/AuditLogSummary' maxItems: 10 description: Last 10 administrative actions AuditLogSummary: type: object properties: id: type: string format: uuid adminName: type: string example: Alice Admin action: type: string enum: - CREATE_CATEGORY - UPDATE_CATEGORY - DELETE_CATEGORY - CREATE_USER - UPDATE_USER - DELETE_USER example: CREATE_USER entityType: type: string enum: [Category, User] example: User entityId: type: string format: uuid timestamp: type: string format: date-time example: 2026-01-25T10:30:00Z Error: type: object properties: error: type: string example: Validation error message: type: string example: Detailed error message required: - error - message responses: Unauthorized: description: Authentication required content: application/json: schema: $ref: '#/components/schemas/Error' example: error: Unauthorized message: Authentication required Forbidden: description: Administrator access required content: application/json: schema: $ref: '#/components/schemas/Error' example: error: Forbidden message: Administrator access required NotFound: description: Resource not found content: application/json: schema: $ref: '#/components/schemas/Error' example: error: Not found message: Resource not found ServerError: description: Internal server error content: application/json: schema: $ref: '#/components/schemas/Error' example: error: Server error message: An unexpected error occurred