getAllBlogs method
Get all published blogs with pagination and sorting
Implementation
Future<BlogResponse> getAllBlogs({
int page = 1,
int perPage = 15,
String sortBy = 'published_at',
String sort = 'desc',
}) async {
try {
final response = await _dio.get(
'$baseUrl/blogs',
queryParameters: {
'page': page,
'per_page': perPage,
'sort_by': sortBy,
'sort': sort,
},
);
if (response.statusCode == 200) {
return BlogResponse.fromJson(response.data as Map<String, dynamic>);
} else {
throw Exception('Failed to load blogs');
}
} on DioException catch (e) {
throw Exception('Error fetching blogs: ${e.message}');
} catch (e) {
throw Exception('Error: $e');
}
}