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 loadData( {OnErrorCallback? onError, String? q, int page = 1, int pageSize = 10}) async { try { const String url = '$_baseUrl/artist/get'; final Response response = await _dio.get>( url, queryParameters: {'filter': q, 'pageNum': page, 'pageSize': pageSize}, ); final ArtistsDto dto = ArtistsDto.fromJson(response.data as Map); 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; } } }