add dleete image projects

This commit is contained in:
Phuoc Nguyen
2025-11-28 13:47:47 +07:00
parent 6e7e848ad6
commit ed6cc4cebc
6 changed files with 300 additions and 39 deletions

View File

@@ -43,6 +43,14 @@ abstract class SubmissionsRemoteDataSource {
required String projectName,
required String filePath,
});
/// Delete a file from a project submission
/// [fileId] is the file ID to delete
/// [projectName] is the project name (docname)
Future<void> deleteProjectFile({
required String fileId,
required String projectName,
});
}
/// Submissions Remote Data Source Implementation
@@ -303,4 +311,41 @@ class SubmissionsRemoteDataSourceImpl implements SubmissionsRemoteDataSource {
throw Exception('Failed to upload project file: $e');
}
}
/// Delete a file from a project submission
///
/// Calls: POST /api/method/frappe.desk.form.utils.remove_attach
/// Form-data: fid, dt, dn
@override
Future<void> deleteProjectFile({
required String fileId,
required String projectName,
}) async {
try {
final formData = FormData.fromMap({
'fid': fileId,
'dt': 'Architectural Project',
'dn': projectName,
});
final response = await _dioClient.post<Map<String, dynamic>>(
'${ApiConstants.frappeApiMethod}${ApiConstants.removeProjectFile}',
data: formData,
);
final data = response.data;
if (data == null) {
throw Exception('No data received from deleteProjectFile API');
}
// Check for error in response
if (data['exc_type'] != null || data['exception'] != null) {
final errorMessage =
data['_server_messages'] ?? data['exception'] ?? 'Unknown error';
throw Exception('API error: $errorMessage');
}
} catch (e) {
throw Exception('Failed to delete project file: $e');
}
}
}

View File

@@ -171,4 +171,19 @@ class SubmissionsRepositoryImpl implements SubmissionsRepository {
rethrow;
}
}
@override
Future<void> deleteProjectFile({
required String fileId,
required String projectName,
}) async {
try {
return await _remoteDataSource.deleteProjectFile(
fileId: fileId,
projectName: projectName,
);
} catch (e) {
rethrow;
}
}
}