request detail
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
/// Design Request Remote Data Source
|
||||
///
|
||||
/// Handles remote API calls for design requests.
|
||||
library;
|
||||
|
||||
import 'package:worker/core/constants/api_constants.dart';
|
||||
import 'package:worker/core/network/dio_client.dart';
|
||||
import 'package:worker/features/showrooms/data/models/design_request_model.dart';
|
||||
|
||||
/// Design Request Remote Data Source Interface
|
||||
abstract class DesignRequestRemoteDataSource {
|
||||
/// Fetch list of design requests from API
|
||||
Future<List<DesignRequestModel>> getDesignRequests({
|
||||
int limitStart = 0,
|
||||
int limitPageLength = 0,
|
||||
});
|
||||
|
||||
/// Fetch detail of a design request by name
|
||||
Future<DesignRequestModel> getDesignRequestDetail(String name);
|
||||
}
|
||||
|
||||
/// Design Request Remote Data Source Implementation
|
||||
class DesignRequestRemoteDataSourceImpl implements DesignRequestRemoteDataSource {
|
||||
const DesignRequestRemoteDataSourceImpl(this._dioClient);
|
||||
|
||||
final DioClient _dioClient;
|
||||
|
||||
/// Get list of design requests
|
||||
///
|
||||
/// Calls: POST /api/method/building_material.building_material.api.design_request.get_list
|
||||
/// Body: { "limit_start": 0, "limit_page_length": 0 }
|
||||
/// Returns: List of design requests
|
||||
@override
|
||||
Future<List<DesignRequestModel>> getDesignRequests({
|
||||
int limitStart = 0,
|
||||
int limitPageLength = 0,
|
||||
}) async {
|
||||
try {
|
||||
final response = await _dioClient.post<Map<String, dynamic>>(
|
||||
'${ApiConstants.frappeApiMethod}${ApiConstants.getDesignRequestList}',
|
||||
data: {
|
||||
'limit_start': limitStart,
|
||||
'limit_page_length': limitPageLength,
|
||||
},
|
||||
);
|
||||
|
||||
final data = response.data;
|
||||
if (data == null) {
|
||||
throw Exception('No data received from getDesignRequestList API');
|
||||
}
|
||||
|
||||
// API returns: { "message": [...] }
|
||||
final message = data['message'];
|
||||
if (message == null) {
|
||||
throw Exception('No message field in getDesignRequestList response');
|
||||
}
|
||||
|
||||
final List<dynamic> requestsList = message as List<dynamic>;
|
||||
return requestsList
|
||||
.map((json) => DesignRequestModel.fromJson(json as Map<String, dynamic>))
|
||||
.toList();
|
||||
} catch (e) {
|
||||
throw Exception('Failed to get design requests: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Get detail of a design request by name
|
||||
///
|
||||
/// Calls: POST /api/method/building_material.building_material.api.design_request.get_detail
|
||||
/// Body: { "name": "ISS-2025-00005" }
|
||||
/// Returns: Full design request detail with files_list
|
||||
@override
|
||||
Future<DesignRequestModel> getDesignRequestDetail(String name) async {
|
||||
try {
|
||||
final response = await _dioClient.post<Map<String, dynamic>>(
|
||||
'${ApiConstants.frappeApiMethod}${ApiConstants.getDesignRequestDetail}',
|
||||
data: {'name': name},
|
||||
);
|
||||
|
||||
final data = response.data;
|
||||
if (data == null) {
|
||||
throw Exception('No data received from getDesignRequestDetail API');
|
||||
}
|
||||
|
||||
// API returns: { "message": {...} }
|
||||
final message = data['message'];
|
||||
if (message == null) {
|
||||
throw Exception('No message field in getDesignRequestDetail response');
|
||||
}
|
||||
|
||||
return DesignRequestModel.fromJson(message as Map<String, dynamic>);
|
||||
} catch (e) {
|
||||
throw Exception('Failed to get design request detail: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user