Refactor file retrieval and annotation methods to simplify path generation and improve error handling
This commit is contained in:
@@ -213,11 +213,14 @@ class FileService {
|
|||||||
String orgId,
|
String orgId,
|
||||||
String fileId,
|
String fileId,
|
||||||
) async {
|
) async {
|
||||||
if (orgId.isEmpty || fileId.isEmpty) {
|
if (fileId.isEmpty) {
|
||||||
throw Exception('OrgId and fileId cannot be empty');
|
throw Exception('fileId cannot be empty');
|
||||||
}
|
}
|
||||||
|
final path = orgId.isEmpty
|
||||||
|
? '/user/files/$fileId/edit'
|
||||||
|
: '/orgs/$orgId/files/$fileId/edit';
|
||||||
return await _apiClient.get(
|
return await _apiClient.get(
|
||||||
'/orgs/$orgId/files/$fileId/edit',
|
path,
|
||||||
fromJson: (data) => EditorSession.fromJson(data),
|
fromJson: (data) => EditorSession.fromJson(data),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -227,11 +230,14 @@ class FileService {
|
|||||||
String fileId,
|
String fileId,
|
||||||
List<Annotation> annotations,
|
List<Annotation> annotations,
|
||||||
) async {
|
) async {
|
||||||
if (orgId.isEmpty || fileId.isEmpty) {
|
if (fileId.isEmpty) {
|
||||||
throw Exception('OrgId and fileId cannot be empty');
|
throw Exception('fileId cannot be empty');
|
||||||
}
|
}
|
||||||
|
final path = orgId.isEmpty
|
||||||
|
? '/user/files/$fileId/annotations'
|
||||||
|
: '/orgs/$orgId/files/$fileId/annotations';
|
||||||
await _apiClient.post(
|
await _apiClient.post(
|
||||||
'/orgs/$orgId/files/$fileId/annotations',
|
path,
|
||||||
data: {
|
data: {
|
||||||
'annotations': annotations.map((a) => a.toJson()).toList(),
|
'annotations': annotations.map((a) => a.toJson()).toList(),
|
||||||
'baseVersionId': '1', // mock
|
'baseVersionId': '1', // mock
|
||||||
|
|||||||
Reference in New Issue
Block a user