Refactor file retrieval and annotation methods to simplify path generation and improve error handling

This commit is contained in:
Leon Bösche
2026-01-14 03:09:08 +01:00
parent 95b0ff51b6
commit 3382e5496e

View File

@@ -213,11 +213,14 @@ class FileService {
String orgId,
String fileId,
) async {
if (orgId.isEmpty || fileId.isEmpty) {
throw Exception('OrgId and fileId cannot be empty');
if (fileId.isEmpty) {
throw Exception('fileId cannot be empty');
}
final path = orgId.isEmpty
? '/user/files/$fileId/edit'
: '/orgs/$orgId/files/$fileId/edit';
return await _apiClient.get(
'/orgs/$orgId/files/$fileId/edit',
path,
fromJson: (data) => EditorSession.fromJson(data),
);
}
@@ -227,11 +230,14 @@ class FileService {
String fileId,
List<Annotation> annotations,
) async {
if (orgId.isEmpty || fileId.isEmpty) {
throw Exception('OrgId and fileId cannot be empty');
if (fileId.isEmpty) {
throw Exception('fileId cannot be empty');
}
final path = orgId.isEmpty
? '/user/files/$fileId/annotations'
: '/orgs/$orgId/files/$fileId/annotations';
await _apiClient.post(
'/orgs/$orgId/files/$fileId/annotations',
path,
data: {
'annotations': annotations.map((a) => a.toJson()).toList(),
'baseVersionId': '1', // mock