/// Submissions Remote Data Source /// /// Handles remote API calls for project submissions. library; import 'package:worker/core/constants/api_constants.dart'; import 'package:worker/core/network/dio_client.dart'; import 'package:worker/features/projects/data/models/project_status_model.dart'; import 'package:worker/features/projects/data/models/project_submission_model.dart'; /// Submissions Remote Data Source /// /// Interface for remote project submission operations. abstract class SubmissionsRemoteDataSource { /// Fetch project status list from API Future> getProjectStatusList(); /// Fetch all submissions from remote API Future> getSubmissions({ int limitStart = 0, int limitPageLength = 0, }); } /// Submissions Remote Data Source Implementation /// /// Uses Frappe API endpoints for project submissions. class SubmissionsRemoteDataSourceImpl implements SubmissionsRemoteDataSource { const SubmissionsRemoteDataSourceImpl(this._dioClient); final DioClient _dioClient; /// Get project status list /// /// Calls: POST /api/method/building_material.building_material.api.project.get_project_status_list /// Body: { "limit_start": 0, "limit_page_length": 0 } /// Returns: List of project statuses with labels and colors @override Future> getProjectStatusList() async { try { final response = await _dioClient.post>( '${ApiConstants.frappeApiMethod}${ApiConstants.getProjectStatusList}', data: { 'limit_start': 0, 'limit_page_length': 0, }, ); final data = response.data; if (data == null) { throw Exception('No data received from getProjectStatusList API'); } // API returns: { "message": [...] } final message = data['message']; if (message == null) { throw Exception('No message field in getProjectStatusList response'); } final List statusList = message as List; return statusList .map((json) => ProjectStatusModel.fromJson(json as Map)) .toList(); } catch (e) { throw Exception('Failed to get project status list: $e'); } } /// Get list of project submissions /// /// Calls: POST /api/method/building_material.building_material.api.project.get_list /// Body: { "limit_start": 0, "limit_page_length": 0 } /// Returns: List of project submissions @override Future> getSubmissions({ int limitStart = 0, int limitPageLength = 0, }) async { try { final response = await _dioClient.post>( '${ApiConstants.frappeApiMethod}${ApiConstants.getProjectList}', data: { 'limit_start': limitStart, 'limit_page_length': limitPageLength, }, ); final data = response.data; if (data == null) { throw Exception('No data received from getProjectList API'); } // API returns: { "message": [...] } final message = data['message']; if (message == null) { throw Exception('No message field in getProjectList response'); } final List submissionsList = message as List; return submissionsList .map((json) => ProjectSubmissionModel.fromJson(json as Map)) .toList(); } catch (e) { throw Exception('Failed to get project submissions: $e'); } } }