This commit is contained in:
Phuoc Nguyen
2025-11-10 14:21:27 +07:00
parent 2a71c65577
commit 36bdf6613b
33 changed files with 2206 additions and 252 deletions

View File

@@ -10,23 +10,11 @@ class ApiConstants {
// Base URLs
// ============================================================================
/// Base URL for development environment
static const String devBaseUrl = 'https://dev-api.worker.example.com';
/// Base URL for all APIs (Frappe/ERPNext)
static const String baseUrl = 'https://land.dbiz.com';
/// Base URL for staging environment
static const String stagingBaseUrl = 'https://staging-api.worker.example.com';
/// Base URL for production environment
static const String prodBaseUrl = 'https://api.worker.example.com';
/// Current base URL (should be configured based on build flavor)
static const String baseUrl = devBaseUrl; // TODO: Configure with flavors
/// API version prefix
static const String apiVersion = '/v1';
/// Full API base URL with version
static String get apiBaseUrl => '$baseUrl$apiVersion';
/// Full API base URL (no version prefix, using Frappe endpoints)
static String get apiBaseUrl => baseUrl;
// ============================================================================
// Timeout Configurations
@@ -347,6 +335,35 @@ class ApiConstants {
/// POST /promotions/{promotionId}/claim
static const String claimPromotion = '/promotions';
// ============================================================================
// Frappe/ERPNext API Endpoints
// ============================================================================
/// Frappe API method prefix
static const String frappeApiMethod = '/api/method';
/// Get Frappe session (public API, no auth required)
/// POST /api/method/dbiz_common.dbiz_common.api.auth.get_session
/// Returns: { "message": { "data": { "sid": "...", "csrf_token": "..." } }, "full_name": "..." }
static const String frappeGetSession = '/dbiz_common.dbiz_common.api.auth.get_session';
/// Login with phone (requires session sid and csrf_token)
/// POST /api/method/building_material.building_material.api.auth.login
/// Body: { "username": "phone", "googleid": null, "facebookid": null, "zaloid": null }
/// Returns: { "message": { "data": { "sid": "...", "csrf_token": "..." } }, "full_name": "..." }
static const String frappeLogin = '/building_material.building_material.api.auth.login';
/// Frappe client get_list (requires sid and csrf_token)
/// POST /api/method/frappe.client.get_list
static const String frappeGetList = '/frappe.client.get_list';
/// Register user (requires session sid and csrf_token)
/// POST /api/method/building_material.building_material.api.user.register
static const String frappeRegister = '/building_material.building_material.api.user.register';
/// Frappe public API user ID
static const String frappePublicUserId = 'public_api@dbiz.com';
// ============================================================================
// Notification Endpoints
// ============================================================================
@@ -380,8 +397,8 @@ class ApiConstants {
///
/// Example:
/// ```dart
/// final url = ApiConstants.buildUrl('/products', {'page': '1', 'limit': '20'});
/// // Returns: https://api.worker.example.com/v1/products?page=1&limit=20
/// final url = ApiConstants.buildUrl('/api/method/frappe.client.get_list', {'doctype': 'Item'});
/// // Returns: https://land.dbiz.com/api/method/frappe.client.get_list?doctype=Item
/// ```
static String buildUrl(String endpoint, [Map<String, String>? queryParams]) {
final uri = Uri.parse('$apiBaseUrl$endpoint');
@@ -395,8 +412,8 @@ class ApiConstants {
///
/// Example:
/// ```dart
/// final url = ApiConstants.buildUrlWithParams('/products/{id}', {'id': '123'});
/// // Returns: https://api.worker.example.com/v1/products/123
/// final url = ApiConstants.buildUrlWithParams('/api/resource/Item/{id}', {'id': '123'});
/// // Returns: https://land.dbiz.com/api/resource/Item/123
/// ```
static String buildUrlWithParams(
String endpoint,