pmu_kursach/lib/data/repositories/hiphop_repository.dart

44 lines
1.3 KiB
Dart
Raw Permalink Normal View History

2024-12-16 19:00:34 +04:00
import 'dart:developer';
import 'package:dio/dio.dart';
import 'package:kursach/data/dtos/artists_dto.dart';
import 'package:kursach/data/mappers/characters_mapper.dart';
import 'package:kursach/data/repositories/api_interface.dart';
import 'package:kursach/domain/models/home_data.dart';
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
class HipHopRepository extends ApiInterface {
static final Dio _dio = Dio(
BaseOptions(connectTimeout: const Duration(seconds: 10)))
..interceptors.add(
PrettyDioLogger(request: true, requestHeader: true, requestBody: true));
static const String _baseUrl = "http://10.0.2.2:8080";
@override
Future<HomeData?> loadData(
{OnErrorCallback? onError,
String? q,
int page = 1,
int pageSize = 10}) async {
try {
const String url = '$_baseUrl/artist/get';
final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>(
url,
queryParameters: {'filter': q, 'pageNum': page, 'pageSize': pageSize},
);
final ArtistsDto dto =
ArtistsDto.fromJson(response.data as Map<String, dynamic>);
return dto.toDomain();
} on DioException catch (e) {
log("DioException: $e");
onError?.call(e.error?.toString());
return null;
} catch (e) {
log('Unknown error: $e');
return null;
}
}
}