Skip to content

Commit 81f8772

Browse files
committed
added editTag to tags.dart
1 parent 515fe5b commit 81f8772

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

lib/network/tags.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:dio/dio.dart';
44
import 'package:flutter/material.dart';
55
import 'package:piwigo_ng/models/tag_model.dart';
66
import 'package:piwigo_ng/network/api_error.dart';
7+
import 'package:piwigo_ng/services/preferences_service.dart';
78

89
import 'api_client.dart';
910

@@ -60,3 +61,34 @@ Future<ApiResponse<TagModel>> createTag(String name) async {
6061
}
6162
return ApiResponse(error: ApiErrors.error);
6263
}
64+
65+
Future<dynamic> editTag(int tagId, String tagName) async {
66+
Map<String, String> queries = {
67+
"format": "json",
68+
"method": "pwg.tags.rename",
69+
};
70+
FormData formData = FormData.fromMap({
71+
"tag_id": tagId,
72+
"new_name": tagName,
73+
'pwg_token': appPreferences.getString('PWG_TOKEN'),
74+
});
75+
Response response = await ApiClient.post(
76+
data: formData,
77+
queryParameters: queries
78+
);
79+
80+
try {
81+
if (response.statusCode == 200) {
82+
var data = json.decode(response.data);
83+
if (data['stat'] == 'fail') {
84+
return ApiResponse(error: ApiErrors.error);
85+
}
86+
return ApiResponse(data: true);
87+
}
88+
} on DioError catch (e) {
89+
debugPrint('Get tags: ${e.message}');
90+
} on Error catch (e) {
91+
debugPrint('Get tags: $e\n${e.stackTrace}');
92+
}
93+
return ApiResponse(error: ApiErrors.error);
94+
}

0 commit comments

Comments
 (0)