diff --git a/lib/Presentation/home_page/home_page.dart b/lib/Presentation/home_page/home_page.dart index 0d093f4..8263b92 100644 --- a/lib/Presentation/home_page/home_page.dart +++ b/lib/Presentation/home_page/home_page.dart @@ -2,7 +2,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:labs_petrushin/repositories/mock_repository.dart'; import '../../Presentation/detailPage.dart'; -import '../../repositories/bread_repository.dart'; +import '../../repositories/food_repository.dart'; part '../../domain/models/card.dart'; class MyHomePage extends StatefulWidget { @@ -44,7 +44,7 @@ class _BodyState extends State { final TextEditingController searchController = TextEditingController(); late Future?> data; - final repo = BreadRepository(); + final repo = FoodRepository(); @override void initState() { @@ -95,7 +95,7 @@ class _BodyState extends State { WidgetsBinding.instance.addPostFrameCallback((_){ ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: Text( - 'Bread liked!', + 'Food liked!', style: Theme.of(context).textTheme.bodyLarge, ), backgroundColor: Colors.red, diff --git a/lib/data/dtos/breads_dto.dart b/lib/data/dtos/breads_dto.dart deleted file mode 100644 index 34965af..0000000 --- a/lib/data/dtos/breads_dto.dart +++ /dev/null @@ -1,28 +0,0 @@ -import 'dart:convert'; -import 'dart:ffi'; - -import 'package:json_annotation/json_annotation.dart'; - -part 'breads_dto.g.dart'; - -@JsonSerializable(createToJson: false) -class BreadsDto { - final List? foods; - - const BreadsDto({this.foods}); - - factory BreadsDto.fromJson(Map json) => _$BreadsDtoFromJson(json); - -} - -@JsonSerializable(createToJson: false) -class BreadDataDto { - final int? fdcId; - final String? brandName; - final String? description; - final String? image; - - const BreadDataDto({this.fdcId, this.brandName, this.description, this.image}); - - factory BreadDataDto.fromJson(Map json) => _$BreadDataDtoFromJson(json); -} \ No newline at end of file diff --git a/lib/data/dtos/foods_dto.dart b/lib/data/dtos/foods_dto.dart new file mode 100644 index 0000000..9ff2837 --- /dev/null +++ b/lib/data/dtos/foods_dto.dart @@ -0,0 +1,28 @@ +import 'dart:convert'; +import 'dart:ffi'; + +import 'package:json_annotation/json_annotation.dart'; + +part 'Foods_dto.g.dart'; + +@JsonSerializable(createToJson: false) +class FoodsDto { + final List? foods; + + const FoodsDto({this.foods}); + + factory FoodsDto.fromJson(Map json) => _$FoodsDtoFromJson(json); + +} + +@JsonSerializable(createToJson: false) +class FoodDataDto { + final int? fdcId; + final String? brandName; + final String? description; + final String? image; + + const FoodDataDto({this.fdcId, this.brandName, this.description, this.image}); + + factory FoodDataDto.fromJson(Map json) => _$FoodDataDtoFromJson(json); +} \ No newline at end of file diff --git a/lib/data/dtos/breads_dto.g.dart b/lib/data/dtos/foods_dto.g.dart similarity index 66% rename from lib/data/dtos/breads_dto.g.dart rename to lib/data/dtos/foods_dto.g.dart index 6d01075..3eb2e09 100644 --- a/lib/data/dtos/breads_dto.g.dart +++ b/lib/data/dtos/foods_dto.g.dart @@ -1,18 +1,18 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'breads_dto.dart'; +part of 'foods_dto.dart'; // ************************************************************************** // JsonSerializableGenerator // ************************************************************************** -BreadsDto _$BreadsDtoFromJson(Map json) => BreadsDto( +FoodsDto _$FoodsDtoFromJson(Map json) => FoodsDto( foods: (json['foods'] as List?) - ?.map((e) => BreadDataDto.fromJson(e as Map)) + ?.map((e) => FoodDataDto.fromJson(e as Map)) .toList(), ); -BreadDataDto _$BreadDataDtoFromJson(Map json) => BreadDataDto( +FoodDataDto _$FoodDataDtoFromJson(Map json) => FoodDataDto( fdcId: (json['fdcId'] as num?)?.toInt(), brandName: json['brandName'] as String?, description: json['description'] as String?, diff --git a/lib/data/mappers/bread_mapper.dart b/lib/data/mappers/food_mapper.dart similarity index 67% rename from lib/data/mappers/bread_mapper.dart rename to lib/data/mappers/food_mapper.dart index e02521b..f7f68ca 100644 --- a/lib/data/mappers/bread_mapper.dart +++ b/lib/data/mappers/food_mapper.dart @@ -1,8 +1,8 @@ import 'package:labs_petrushin/Presentation/home_page/home_page.dart'; -import 'package:labs_petrushin/data/dtos/breads_dto.dart'; +import 'package:labs_petrushin/data/dtos/foods_dto.dart'; -extension CharacterDataDtoToModel on BreadDataDto { +extension CharacterDataDtoToModel on FoodDataDto { CardData toDomain() => CardData( text: brandName ?? "Просто хлэп", info: description ?? "Очень кусьна", diff --git a/lib/repositories/bread_repository.dart b/lib/repositories/food_repository.dart similarity index 71% rename from lib/repositories/bread_repository.dart rename to lib/repositories/food_repository.dart index b44913e..abdd8d5 100644 --- a/lib/repositories/bread_repository.dart +++ b/lib/repositories/food_repository.dart @@ -1,12 +1,12 @@ import 'package:dio/dio.dart'; import 'package:labs_petrushin/Presentation/home_page/home_page.dart'; -import 'package:labs_petrushin/data/dtos/breads_dto.dart'; -import 'package:labs_petrushin/data/mappers/bread_mapper.dart'; +import 'package:labs_petrushin/data/dtos/foods_dto.dart'; +import 'package:labs_petrushin/data/mappers/food_mapper.dart'; import 'package:labs_petrushin/repositories/api_interface.dart'; import 'package:pretty_dio_logger/pretty_dio_logger.dart'; -class BreadRepository extends ApiInterface { +class FoodRepository extends ApiInterface { static final Dio _dio = Dio() ..interceptors.add( PrettyDioLogger( @@ -20,12 +20,12 @@ class BreadRepository extends ApiInterface { @override Future?> loadData({String? q}) async { try { - final String searchQuery = q ?? 'Bread'; // Используем 'Bread' как значение по умолчанию + final String searchQuery = q ?? 'food'; // Используем 'food' как значение по умолчанию final String url = '$_baseUrl/fdc/v1/foods/search?api_key=91xPcWwfSGljSRMuoS8IH0GP4hM9QqwwtgSzqJMw&query=$searchQuery&pageSize=10'; final Response response = await _dio.get>(url); - final BreadsDto dto = BreadsDto.fromJson(response.data as Map); + final FoodsDto dto = FoodsDto.fromJson(response.data as Map); final List? data = dto.foods?.map((e) => e.toDomain()).toList(); return data; } on DioException catch (e) {