createComment method
Implementation
Future<CommentModel> createComment(String requestId, String text) async {
final userId = await userService.getUserId();
final response = await http.post(
Uri.parse('${apiUrl}requests/$requestId/comments'),
headers: {
'api-key': apiKey,
'user-id': userId,
"Content-Type": "application/json",
"Accept": "application/json",
},
body: json.encode({
'text': text,
'userId': userId,
}),
);
if (response.statusCode == 201) {
Map<String, dynamic> body = json.decode(response.body);
return CommentModel.fromJson(body);
} else {
throw Exception('Failed to create comment');
}
}