fill
This commit is contained in:
178
lib/core/constants/api_endpoints.dart
Normal file
178
lib/core/constants/api_endpoints.dart
Normal file
@@ -0,0 +1,178 @@
|
||||
/// API endpoint constants for the warehouse management application
|
||||
///
|
||||
/// This class contains all API endpoint paths used throughout the app.
|
||||
/// Endpoints are organized by feature for better maintainability.
|
||||
class ApiEndpoints {
|
||||
// Private constructor to prevent instantiation
|
||||
ApiEndpoints._();
|
||||
|
||||
// ==================== Base Configuration ====================
|
||||
|
||||
/// Base API URL - should be configured based on environment
|
||||
static const String baseUrl = 'https://api.warehouse.example.com';
|
||||
|
||||
/// API version prefix
|
||||
static const String apiVersion = '/api/v1';
|
||||
|
||||
// ==================== Authentication Endpoints ====================
|
||||
|
||||
/// Login endpoint
|
||||
/// POST: { "EmailPhone": string, "Password": string }
|
||||
/// Response: User with access token
|
||||
static const String login = '/PortalAuth/Login';
|
||||
|
||||
/// Logout endpoint
|
||||
/// POST: Empty body (requires auth token)
|
||||
static const String logout = '$apiVersion/auth/logout';
|
||||
|
||||
/// Refresh token endpoint
|
||||
/// POST: { "refreshToken": string }
|
||||
/// Response: New access token
|
||||
static const String refreshToken = '$apiVersion/auth/refresh';
|
||||
|
||||
/// Get current user profile
|
||||
/// GET: (requires auth token)
|
||||
static const String profile = '$apiVersion/auth/profile';
|
||||
|
||||
// ==================== Warehouse Endpoints ====================
|
||||
|
||||
/// Get all warehouses
|
||||
/// POST: /portalWareHouse/search (requires auth token)
|
||||
/// Response: List of warehouses
|
||||
static const String warehouses = '/portalWareHouse/search';
|
||||
|
||||
/// Get warehouse by ID
|
||||
/// GET: (requires auth token)
|
||||
/// Parameter: warehouseId
|
||||
static String warehouseById(int id) => '$apiVersion/warehouses/$id';
|
||||
|
||||
/// Get warehouse statistics
|
||||
/// GET: (requires auth token)
|
||||
/// Parameter: warehouseId
|
||||
static String warehouseStats(int id) => '$apiVersion/warehouses/$id/stats';
|
||||
|
||||
// ==================== Product Endpoints ====================
|
||||
|
||||
/// Get products for a warehouse
|
||||
/// GET: /portalProduct/getAllProduct (requires auth token)
|
||||
/// Response: List of products
|
||||
static const String products = '/portalProduct/getAllProduct';
|
||||
|
||||
/// Get product by ID
|
||||
/// GET: (requires auth token)
|
||||
/// Parameter: productId
|
||||
static String productById(int id) => '$apiVersion/products/$id';
|
||||
|
||||
/// Search products
|
||||
/// GET: (requires auth token)
|
||||
/// Query params: query (string), warehouseId (int, optional)
|
||||
static const String searchProducts = '$apiVersion/products/search';
|
||||
|
||||
/// Get products by barcode
|
||||
/// GET: (requires auth token)
|
||||
/// Query params: barcode (string), warehouseId (int, optional)
|
||||
static const String productsByBarcode = '$apiVersion/products/by-barcode';
|
||||
|
||||
// ==================== Import/Export Operations ====================
|
||||
|
||||
/// Create import operation
|
||||
/// POST: { warehouseId, productId, quantity, ... }
|
||||
/// Response: Import operation details
|
||||
static const String importOperation = '$apiVersion/operations/import';
|
||||
|
||||
/// Create export operation
|
||||
/// POST: { warehouseId, productId, quantity, ... }
|
||||
/// Response: Export operation details
|
||||
static const String exportOperation = '$apiVersion/operations/export';
|
||||
|
||||
/// Get operation history
|
||||
/// GET: (requires auth token)
|
||||
/// Query params: warehouseId (int), type (string, optional), page (int), limit (int)
|
||||
static const String operationHistory = '$apiVersion/operations/history';
|
||||
|
||||
/// Get operation by ID
|
||||
/// GET: (requires auth token)
|
||||
/// Parameter: operationId
|
||||
static String operationById(String id) => '$apiVersion/operations/$id';
|
||||
|
||||
/// Cancel operation
|
||||
/// POST: (requires auth token)
|
||||
/// Parameter: operationId
|
||||
static String cancelOperation(String id) => '$apiVersion/operations/$id/cancel';
|
||||
|
||||
/// Confirm operation
|
||||
/// POST: (requires auth token)
|
||||
/// Parameter: operationId
|
||||
static String confirmOperation(String id) => '$apiVersion/operations/$id/confirm';
|
||||
|
||||
// ==================== Inventory Endpoints ====================
|
||||
|
||||
/// Get inventory for warehouse
|
||||
/// GET: (requires auth token)
|
||||
/// Parameter: warehouseId
|
||||
/// Query params: page (int), limit (int)
|
||||
static String warehouseInventory(int warehouseId) =>
|
||||
'$apiVersion/inventory/warehouse/$warehouseId';
|
||||
|
||||
/// Get product inventory across all warehouses
|
||||
/// GET: (requires auth token)
|
||||
/// Parameter: productId
|
||||
static String productInventory(int productId) =>
|
||||
'$apiVersion/inventory/product/$productId';
|
||||
|
||||
/// Update inventory
|
||||
/// PUT: { warehouseId, productId, quantity, reason, ... }
|
||||
static const String updateInventory = '$apiVersion/inventory/update';
|
||||
|
||||
// ==================== Report Endpoints ====================
|
||||
|
||||
/// Generate warehouse report
|
||||
/// GET: (requires auth token)
|
||||
/// Query params: warehouseId (int), startDate (string), endDate (string), format (string)
|
||||
static const String warehouseReport = '$apiVersion/reports/warehouse';
|
||||
|
||||
/// Generate product movement report
|
||||
/// GET: (requires auth token)
|
||||
/// Query params: productId (int, optional), startDate (string), endDate (string)
|
||||
static const String movementReport = '$apiVersion/reports/movements';
|
||||
|
||||
/// Generate inventory summary
|
||||
/// GET: (requires auth token)
|
||||
/// Query params: warehouseId (int, optional)
|
||||
static const String inventorySummary = '$apiVersion/reports/inventory-summary';
|
||||
|
||||
// ==================== Utility Endpoints ====================
|
||||
|
||||
/// Health check endpoint
|
||||
/// GET: No authentication required
|
||||
static const String health = '$apiVersion/health';
|
||||
|
||||
/// Get app configuration
|
||||
/// GET: (requires auth token)
|
||||
static const String config = '$apiVersion/config';
|
||||
|
||||
// ==================== Helper Methods ====================
|
||||
|
||||
/// Build full URL with base URL
|
||||
static String fullUrl(String endpoint) => baseUrl + endpoint;
|
||||
|
||||
/// Build URL with query parameters
|
||||
static String withQueryParams(String endpoint, Map<String, dynamic> params) {
|
||||
if (params.isEmpty) return endpoint;
|
||||
|
||||
final queryString = params.entries
|
||||
.where((e) => e.value != null)
|
||||
.map((e) => '${e.key}=${Uri.encodeComponent(e.value.toString())}')
|
||||
.join('&');
|
||||
|
||||
return '$endpoint?$queryString';
|
||||
}
|
||||
|
||||
/// Build paginated URL
|
||||
static String withPagination(String endpoint, int page, int limit) {
|
||||
return withQueryParams(endpoint, {
|
||||
'page': page,
|
||||
'limit': limit,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user