runable
This commit is contained in:
141
lib/core/constants/api_constants.dart
Normal file
141
lib/core/constants/api_constants.dart
Normal file
@@ -0,0 +1,141 @@
|
||||
/// API configuration constants for the Retail POS application
|
||||
class ApiConstants {
|
||||
// Private constructor to prevent instantiation
|
||||
ApiConstants._();
|
||||
|
||||
// ===== Base URL Configuration =====
|
||||
/// Base URL for the API
|
||||
/// TODO: Replace with actual production URL
|
||||
static const String baseUrl = 'https://api.retailpos.example.com';
|
||||
|
||||
/// API version prefix
|
||||
static const String apiVersion = '/api/v1';
|
||||
|
||||
/// Full base URL with version
|
||||
static String get fullBaseUrl => '$baseUrl$apiVersion';
|
||||
|
||||
// ===== Timeout Configuration =====
|
||||
/// Connection timeout in milliseconds (30 seconds)
|
||||
static const int connectTimeout = 30000;
|
||||
|
||||
/// Receive timeout in milliseconds (30 seconds)
|
||||
static const int receiveTimeout = 30000;
|
||||
|
||||
/// Send timeout in milliseconds (30 seconds)
|
||||
static const int sendTimeout = 30000;
|
||||
|
||||
// ===== Retry Configuration =====
|
||||
/// Maximum number of retry attempts for failed requests
|
||||
static const int maxRetries = 3;
|
||||
|
||||
/// Delay between retry attempts in milliseconds (1 second)
|
||||
static const int retryDelay = 1000;
|
||||
|
||||
// ===== Endpoint Paths =====
|
||||
|
||||
// Products Endpoints
|
||||
/// GET - Fetch all products
|
||||
static const String products = '/products';
|
||||
|
||||
/// GET - Fetch single product by ID
|
||||
/// Use: '${ApiConstants.products}/:id'
|
||||
static String productById(String id) => '$products/$id';
|
||||
|
||||
/// GET - Fetch products by category
|
||||
/// Use: '${ApiConstants.products}/category/:categoryId'
|
||||
static String productsByCategory(String categoryId) =>
|
||||
'$products/category/$categoryId';
|
||||
|
||||
/// GET - Search products
|
||||
/// Query params: ?q=searchTerm
|
||||
static const String searchProducts = '$products/search';
|
||||
|
||||
/// POST - Sync products (bulk update/create)
|
||||
static const String syncProducts = '$products/sync';
|
||||
|
||||
// Categories Endpoints
|
||||
/// GET - Fetch all categories
|
||||
static const String categories = '/categories';
|
||||
|
||||
/// GET - Fetch single category by ID
|
||||
/// Use: '${ApiConstants.categories}/:id'
|
||||
static String categoryById(String id) => '$categories/$id';
|
||||
|
||||
/// POST - Sync categories (bulk update/create)
|
||||
static const String syncCategories = '$categories/sync';
|
||||
|
||||
// Transactions Endpoints (for future use)
|
||||
/// POST - Create new transaction
|
||||
static const String transactions = '/transactions';
|
||||
|
||||
/// GET - Fetch transaction history
|
||||
static const String transactionHistory = '$transactions/history';
|
||||
|
||||
// Settings Endpoints (for future use)
|
||||
/// GET - Fetch app settings
|
||||
static const String settings = '/settings';
|
||||
|
||||
/// PUT - Update app settings
|
||||
static const String updateSettings = settings;
|
||||
|
||||
// ===== Request Headers =====
|
||||
/// Content-Type header key
|
||||
static const String contentType = 'Content-Type';
|
||||
|
||||
/// Content-Type value for JSON
|
||||
static const String applicationJson = 'application/json';
|
||||
|
||||
/// Authorization header key
|
||||
static const String authorization = 'Authorization';
|
||||
|
||||
/// Accept header key
|
||||
static const String accept = 'Accept';
|
||||
|
||||
// ===== API Keys and Authentication =====
|
||||
/// API key header name (if using API key authentication)
|
||||
static const String apiKeyHeader = 'X-API-Key';
|
||||
|
||||
/// TODO: Store API key securely (use flutter_secure_storage in production)
|
||||
static const String apiKey = 'your-api-key-here';
|
||||
|
||||
// ===== Status Codes =====
|
||||
/// Success status codes
|
||||
static const int statusOk = 200;
|
||||
static const int statusCreated = 201;
|
||||
static const int statusNoContent = 204;
|
||||
|
||||
/// Client error status codes
|
||||
static const int statusBadRequest = 400;
|
||||
static const int statusUnauthorized = 401;
|
||||
static const int statusForbidden = 403;
|
||||
static const int statusNotFound = 404;
|
||||
static const int statusUnprocessableEntity = 422;
|
||||
static const int statusTooManyRequests = 429;
|
||||
|
||||
/// Server error status codes
|
||||
static const int statusInternalServerError = 500;
|
||||
static const int statusBadGateway = 502;
|
||||
static const int statusServiceUnavailable = 503;
|
||||
static const int statusGatewayTimeout = 504;
|
||||
|
||||
// ===== Cache Configuration =====
|
||||
/// Cache duration for products (in hours)
|
||||
static const int productsCacheDuration = 24;
|
||||
|
||||
/// Cache duration for categories (in hours)
|
||||
static const int categoriesCacheDuration = 24;
|
||||
|
||||
// ===== Pagination =====
|
||||
/// Default page size for paginated requests
|
||||
static const int defaultPageSize = 20;
|
||||
|
||||
/// Maximum page size
|
||||
static const int maxPageSize = 100;
|
||||
|
||||
// ===== Mock/Development Configuration =====
|
||||
/// Use mock data instead of real API (for development/testing)
|
||||
static const bool useMockData = false;
|
||||
|
||||
/// Mock API delay in milliseconds
|
||||
static const int mockApiDelay = 500;
|
||||
}
|
||||
Reference in New Issue
Block a user