forked from eatvio/eatvio_app
fix(diary): Satiety and mood change API method call fix
This commit is contained in:
@@ -18,8 +18,7 @@ part 'diary_event.dart';
|
||||
class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
final DiaryRepository diaryRepository;
|
||||
|
||||
DiaryBloc({required this.diaryRepository})
|
||||
: super(const DiaryState.loading()) {
|
||||
DiaryBloc({required this.diaryRepository}) : super(const DiaryState.loading()) {
|
||||
on<LoadDiary>(loadDiary);
|
||||
on<ChangeSatiety>(_changeSatiety); // пользователь нажимает на шкалу сытости
|
||||
on<ChangeMood>(_changeMood); // пользователь нажимает на шкалу настроения
|
||||
@@ -58,10 +57,7 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
final int? diaryID = data['id'];
|
||||
final DiaryModel diary = await diaryRepository.getDiary(diaryID ?? 45);
|
||||
final Meal currentMeal = diary.meals[0];
|
||||
List<SelectionPopupModel> portions = [
|
||||
SelectionPopupModel(title: "gr"),
|
||||
SelectionPopupModel(title: "pcs")
|
||||
];
|
||||
List<SelectionPopupModel> portions = [SelectionPopupModel(title: "gr"), SelectionPopupModel(title: "pcs")];
|
||||
emit(DiaryState.loaded(
|
||||
diary: diary,
|
||||
currentMeal: currentMeal,
|
||||
@@ -69,8 +65,8 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
photos: currentMeal.photos,
|
||||
portionList: portions,
|
||||
portionController: portions[0],
|
||||
selectedMood: 3,
|
||||
selectedSatiety: 3,
|
||||
selectedMood: currentMeal.mood,
|
||||
selectedSatiety: currentMeal.satiety,
|
||||
commentController: TextEditingController(),
|
||||
productNameController: TextEditingController(),
|
||||
productQuantityController: TextEditingController(),
|
||||
@@ -88,7 +84,6 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
consumedChartValues: [1, 1, 1, 1]));
|
||||
} catch (e) {
|
||||
emit(DiaryState.error(errorMessage: e.toString()));
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,22 +105,14 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
if (responseChart.statusCode == 200) {
|
||||
final responseBody = jsonDecode(responseChart.body);
|
||||
|
||||
final recommendedChartValues =
|
||||
responseBody['dailyNutritionRecommendation']
|
||||
.values
|
||||
.map<int>((value) => convertToInt(value))
|
||||
.toList();
|
||||
final recommendedChartValues = responseBody['dailyNutritionRecommendation'].values.map<int>((value) => convertToInt(value)).toList();
|
||||
|
||||
final consumedChartValues = responseBody['dailyNutritionIntake']
|
||||
.values
|
||||
.map<int>((value) => convertToInt(value))
|
||||
.toList();
|
||||
final consumedChartValues = responseBody['dailyNutritionIntake'].values.map<int>((value) => convertToInt(value)).toList();
|
||||
|
||||
print([recommendedChartValues, consumedChartValues]);
|
||||
return [recommendedChartValues, consumedChartValues];
|
||||
} else {
|
||||
emit(DiaryStateError(
|
||||
errorMessage: 'Ошибка при декодировании данных КБЖУ'));
|
||||
emit(DiaryStateError(errorMessage: 'Ошибка при декодировании данных КБЖУ'));
|
||||
print('fail');
|
||||
return [[], []]; // Return empty lists instead of -1
|
||||
}
|
||||
@@ -152,69 +139,23 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
) async {
|
||||
if (state is DiaryStateLoaded) {
|
||||
var currentState = state as DiaryStateLoaded;
|
||||
var updatedState =
|
||||
currentState.copyWith(selectedMood: event.selectedElement);
|
||||
|
||||
// Отправляем данные по HTTP маршруту и ждем ответ
|
||||
var response = await sendSatietyData(
|
||||
event.selectedElement,
|
||||
currentState.currentMeal.id,
|
||||
currentState.diary.id,
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
print(
|
||||
'Satiety change success! meal_id: ${currentState.currentMeal.id}, mood: ${event.selectedElement}',
|
||||
);
|
||||
emit(updatedState); // Передаем обновленное состояние в emit
|
||||
} else
|
||||
print("dad");
|
||||
var updatedState = currentState.copyWith(selectedSatiety: event.selectedElement);
|
||||
diaryRepository.changeSatiety(event.selectedElement, currentState.currentMeal.id, currentState.diary.id);
|
||||
emit(updatedState);
|
||||
}
|
||||
}
|
||||
|
||||
Future<http.Response> sendSatietyData(
|
||||
int selectedSatiety,
|
||||
int? mealID,
|
||||
int diaryID,
|
||||
) async {
|
||||
String url = dotenv.env['SERVER_ROOT']! +
|
||||
'/diary/$diaryID/meal/$mealID/satiety/fill';
|
||||
final Map<String, dynamic> credentials = {
|
||||
'satiety': selectedSatiety,
|
||||
};
|
||||
var response = await http.post(
|
||||
Uri.parse(url),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: json.encode(credentials),
|
||||
encoding: utf8,
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
Future<void> _changeMood(
|
||||
ChangeMood event,
|
||||
Emitter<DiaryState> emit,
|
||||
) async {
|
||||
if (state is DiaryStateLoaded) {
|
||||
var currentState = state as DiaryStateLoaded;
|
||||
var updatedState =
|
||||
currentState.copyWith(selectedMood: event.selectedElement);
|
||||
var updatedState = currentState.copyWith(selectedMood: event.selectedElement);
|
||||
|
||||
// Отправляем данные по HTTP маршруту и ждем ответ
|
||||
var response = await sendMoodData(
|
||||
event.selectedElement,
|
||||
currentState.currentMeal.id,
|
||||
currentState.diary.id,
|
||||
);
|
||||
diaryRepository.changeMood(event.selectedElement, currentState.currentMeal.id, currentState.diary.id);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
print(
|
||||
'Mood change success! meal_id: ${currentState.currentMeal.id}, mood: ${event.selectedElement}',
|
||||
);
|
||||
emit(updatedState); // Передаем обновленное состояние в emit
|
||||
}
|
||||
emit(updatedState); // Передаем обновленное состояние в emit
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,8 +164,7 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
int? mealID,
|
||||
int diaryID,
|
||||
) async {
|
||||
String url =
|
||||
dotenv.env['SERVER_ROOT']! + '/diary/$diaryID/meal/$mealID/mood/fill';
|
||||
String url = dotenv.env['SERVER_ROOT']! + '/diary/$diaryID/meal/$mealID/mood/fill';
|
||||
final Map<String, dynamic> credentials = {
|
||||
'mood': selectedMood,
|
||||
};
|
||||
@@ -253,8 +193,7 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
await reloadScreen(event, emit);
|
||||
var updatedState =
|
||||
currentState.copyWith(wakeupController: event.selectedTime);
|
||||
var updatedState = currentState.copyWith(wakeupController: event.selectedTime);
|
||||
print("Wakeup time changed to ${event.selectedTime}");
|
||||
emit(updatedState); // Передаем обновленное состояние в emit
|
||||
} else
|
||||
@@ -274,8 +213,7 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
await reloadScreen(event, emit);
|
||||
var updatedState =
|
||||
currentState.copyWith(retireController: event.selectedTime);
|
||||
var updatedState = currentState.copyWith(retireController: event.selectedTime);
|
||||
print("Retire time changed to ${event.selectedTime}");
|
||||
emit(updatedState); // Передаем обновленное состояние в emit
|
||||
} else
|
||||
@@ -289,8 +227,7 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
) async {
|
||||
String url = dotenv.env['SERVER_ROOT']! + '/diary/$diaryID/wakeUp/fill';
|
||||
final formatter = DateFormat('HH:mm');
|
||||
final wakeupString =
|
||||
formatter.format(DateTime(2022, 1, 1, wakeup.hour, wakeup.minute));
|
||||
final wakeupString = formatter.format(DateTime(2022, 1, 1, wakeup.hour, wakeup.minute));
|
||||
final Map<String, dynamic> credentials = {
|
||||
'wakeUp': wakeupString,
|
||||
};
|
||||
@@ -313,8 +250,7 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
) async {
|
||||
String url = dotenv.env['SERVER_ROOT']! + '/diary/$diaryID/retire/fill';
|
||||
final formatter = DateFormat('HH:mm');
|
||||
final retireString =
|
||||
formatter.format(DateTime(2022, 1, 1, retire.hour, retire.minute));
|
||||
final retireString = formatter.format(DateTime(2022, 1, 1, retire.hour, retire.minute));
|
||||
final Map<String, dynamic> credentials = {
|
||||
'retire': retireString,
|
||||
};
|
||||
@@ -375,8 +311,7 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
) async {
|
||||
if (state is DiaryStateLoaded) {
|
||||
var currentState = state as DiaryStateLoaded;
|
||||
Meal? meal =
|
||||
currentState.diary.meals.firstWhere((meal) => meal.id == event.value);
|
||||
Meal? meal = currentState.diary.meals.firstWhere((meal) => meal.id == event.value);
|
||||
|
||||
DiaryStateLoaded updatedState = currentState.copyWith(
|
||||
currentMeal: event.value,
|
||||
@@ -469,8 +404,7 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
int? mealID,
|
||||
int diaryID,
|
||||
) async {
|
||||
String url =
|
||||
'${dotenv.env['SERVER_ROOT']!}/diary/$diaryID/meal/$mealID/portions/create';
|
||||
String url = '${dotenv.env['SERVER_ROOT']!}/diary/$diaryID/meal/$mealID/portions/create';
|
||||
|
||||
final Map<String, dynamic> credentials = {
|
||||
'product_name': name,
|
||||
@@ -509,16 +443,13 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
},
|
||||
);
|
||||
|
||||
final productNutritionalValues =
|
||||
jsonDecode(response.body)['product_nutritional_value'];
|
||||
final productNutritionalValues = jsonDecode(response.body)['product_nutritional_value'];
|
||||
|
||||
if (productNutritionalValues is List<dynamic>) {
|
||||
// Create a new controller with the input text and update the autocomplete list
|
||||
var updatedState = currentState.copyWith(
|
||||
productNameController: TextEditingController(text: event.input),
|
||||
autocompleteList: productNutritionalValues
|
||||
.map((product) => product['name'])
|
||||
.toList(),
|
||||
autocompleteList: productNutritionalValues.map((product) => product['name']).toList(),
|
||||
);
|
||||
if (event.input.length > 3) {
|
||||
updatedState = updatedState.copyWith(moderationExpanded: true);
|
||||
@@ -538,8 +469,7 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
if (state is DiaryStateLoaded) {
|
||||
var currentState = state as DiaryStateLoaded;
|
||||
|
||||
int? mealId =
|
||||
currentState.currentMeal.id; // Rename id to mealId for clarity
|
||||
int? mealId = currentState.currentMeal.id; // Rename id to mealId for clarity
|
||||
|
||||
var response = await sendRemovePortion(
|
||||
event.portionId,
|
||||
@@ -562,8 +492,7 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
int? mealID,
|
||||
int diaryID,
|
||||
) async {
|
||||
String url =
|
||||
'${dotenv.env['SERVER_ROOT']!}/diary/$diaryID/meal/$mealID/portions/$portionID/delete';
|
||||
String url = '${dotenv.env['SERVER_ROOT']!}/diary/$diaryID/meal/$mealID/portions/$portionID/delete';
|
||||
|
||||
var response = await http.delete(
|
||||
Uri.parse(url),
|
||||
@@ -606,8 +535,7 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
int? mealID,
|
||||
int diaryID,
|
||||
) async {
|
||||
String url =
|
||||
'${dotenv.env['SERVER_ROOT']!}/diary/$diaryID/meal/$mealID/photo/delete';
|
||||
String url = '${dotenv.env['SERVER_ROOT']!}/diary/$diaryID/meal/$mealID/photo/delete';
|
||||
final Map<String, dynamic> credentials = {
|
||||
'id': photoID,
|
||||
'path': path,
|
||||
@@ -648,10 +576,8 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
String? comment,
|
||||
) async {
|
||||
final formatter = DateFormat('HH:mm');
|
||||
final wakeupString =
|
||||
formatter.format(DateTime(2022, 1, 1, wakeup!.hour, wakeup.minute));
|
||||
final retireString =
|
||||
formatter.format(DateTime(2022, 1, 1, retire!.hour, retire.minute));
|
||||
final wakeupString = formatter.format(DateTime(2022, 1, 1, wakeup!.hour, wakeup.minute));
|
||||
final retireString = formatter.format(DateTime(2022, 1, 1, retire!.hour, retire.minute));
|
||||
|
||||
final Map<String, dynamic> credentials = {
|
||||
'wakeup': wakeupString,
|
||||
@@ -695,8 +621,7 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
int diaryID,
|
||||
int mealId,
|
||||
) async {
|
||||
String url =
|
||||
'${dotenv.env['SERVER_ROOT']!}/diary/$diaryID/meal/$mealId/photo/upload';
|
||||
String url = '${dotenv.env['SERVER_ROOT']!}/diary/$diaryID/meal/$mealId/photo/upload';
|
||||
|
||||
var request = http.MultipartRequest('POST', Uri.parse(url));
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ mixin _$DiaryState {
|
||||
TextEditingController fatsController,
|
||||
TextEditingController proteinsController,
|
||||
TextEditingController carbsController,
|
||||
int? selectedMood,
|
||||
int? selectedSatiety,
|
||||
int selectedMood,
|
||||
int selectedSatiety,
|
||||
bool wakeupExpanded,
|
||||
bool moderationExpanded,
|
||||
bool moodExpanded,
|
||||
@@ -77,8 +77,8 @@ mixin _$DiaryState {
|
||||
TextEditingController fatsController,
|
||||
TextEditingController proteinsController,
|
||||
TextEditingController carbsController,
|
||||
int? selectedMood,
|
||||
int? selectedSatiety,
|
||||
int selectedMood,
|
||||
int selectedSatiety,
|
||||
bool wakeupExpanded,
|
||||
bool moderationExpanded,
|
||||
bool moodExpanded,
|
||||
@@ -113,8 +113,8 @@ mixin _$DiaryState {
|
||||
TextEditingController fatsController,
|
||||
TextEditingController proteinsController,
|
||||
TextEditingController carbsController,
|
||||
int? selectedMood,
|
||||
int? selectedSatiety,
|
||||
int selectedMood,
|
||||
int selectedSatiety,
|
||||
bool wakeupExpanded,
|
||||
bool moderationExpanded,
|
||||
bool moodExpanded,
|
||||
@@ -231,8 +231,8 @@ class _$DiaryStateImpl implements _DiaryState {
|
||||
TextEditingController fatsController,
|
||||
TextEditingController proteinsController,
|
||||
TextEditingController carbsController,
|
||||
int? selectedMood,
|
||||
int? selectedSatiety,
|
||||
int selectedMood,
|
||||
int selectedSatiety,
|
||||
bool wakeupExpanded,
|
||||
bool moderationExpanded,
|
||||
bool moodExpanded,
|
||||
@@ -270,8 +270,8 @@ class _$DiaryStateImpl implements _DiaryState {
|
||||
TextEditingController fatsController,
|
||||
TextEditingController proteinsController,
|
||||
TextEditingController carbsController,
|
||||
int? selectedMood,
|
||||
int? selectedSatiety,
|
||||
int selectedMood,
|
||||
int selectedSatiety,
|
||||
bool wakeupExpanded,
|
||||
bool moderationExpanded,
|
||||
bool moodExpanded,
|
||||
@@ -309,8 +309,8 @@ class _$DiaryStateImpl implements _DiaryState {
|
||||
TextEditingController fatsController,
|
||||
TextEditingController proteinsController,
|
||||
TextEditingController carbsController,
|
||||
int? selectedMood,
|
||||
int? selectedSatiety,
|
||||
int selectedMood,
|
||||
int selectedSatiety,
|
||||
bool wakeupExpanded,
|
||||
bool moderationExpanded,
|
||||
bool moodExpanded,
|
||||
@@ -429,8 +429,8 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
|
||||
TextEditingController fatsController,
|
||||
TextEditingController proteinsController,
|
||||
TextEditingController carbsController,
|
||||
int? selectedMood,
|
||||
int? selectedSatiety,
|
||||
int selectedMood,
|
||||
int selectedSatiety,
|
||||
bool wakeupExpanded,
|
||||
bool moderationExpanded,
|
||||
bool moodExpanded,
|
||||
@@ -468,8 +468,8 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
|
||||
TextEditingController fatsController,
|
||||
TextEditingController proteinsController,
|
||||
TextEditingController carbsController,
|
||||
int? selectedMood,
|
||||
int? selectedSatiety,
|
||||
int selectedMood,
|
||||
int selectedSatiety,
|
||||
bool wakeupExpanded,
|
||||
bool moderationExpanded,
|
||||
bool moodExpanded,
|
||||
@@ -507,8 +507,8 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
|
||||
TextEditingController fatsController,
|
||||
TextEditingController proteinsController,
|
||||
TextEditingController carbsController,
|
||||
int? selectedMood,
|
||||
int? selectedSatiety,
|
||||
int selectedMood,
|
||||
int selectedSatiety,
|
||||
bool wakeupExpanded,
|
||||
bool moderationExpanded,
|
||||
bool moodExpanded,
|
||||
@@ -593,8 +593,8 @@ abstract class _$$DiaryStateLoadedImplCopyWith<$Res> {
|
||||
TextEditingController fatsController,
|
||||
TextEditingController proteinsController,
|
||||
TextEditingController carbsController,
|
||||
int? selectedMood,
|
||||
int? selectedSatiety,
|
||||
int selectedMood,
|
||||
int selectedSatiety,
|
||||
bool wakeupExpanded,
|
||||
bool moderationExpanded,
|
||||
bool moodExpanded,
|
||||
@@ -636,8 +636,8 @@ class __$$DiaryStateLoadedImplCopyWithImpl<$Res>
|
||||
Object? fatsController = null,
|
||||
Object? proteinsController = null,
|
||||
Object? carbsController = null,
|
||||
Object? selectedMood = freezed,
|
||||
Object? selectedSatiety = freezed,
|
||||
Object? selectedMood = null,
|
||||
Object? selectedSatiety = null,
|
||||
Object? wakeupExpanded = null,
|
||||
Object? moderationExpanded = null,
|
||||
Object? moodExpanded = null,
|
||||
@@ -725,14 +725,14 @@ class __$$DiaryStateLoadedImplCopyWithImpl<$Res>
|
||||
? _value.carbsController
|
||||
: carbsController // ignore: cast_nullable_to_non_nullable
|
||||
as TextEditingController,
|
||||
selectedMood: freezed == selectedMood
|
||||
selectedMood: null == selectedMood
|
||||
? _value.selectedMood
|
||||
: selectedMood // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
selectedSatiety: freezed == selectedSatiety
|
||||
as int,
|
||||
selectedSatiety: null == selectedSatiety
|
||||
? _value.selectedSatiety
|
||||
: selectedSatiety // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
as int,
|
||||
wakeupExpanded: null == wakeupExpanded
|
||||
? _value.wakeupExpanded
|
||||
: wakeupExpanded // ignore: cast_nullable_to_non_nullable
|
||||
@@ -797,8 +797,8 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
required this.fatsController,
|
||||
required this.proteinsController,
|
||||
required this.carbsController,
|
||||
this.selectedMood,
|
||||
this.selectedSatiety,
|
||||
required this.selectedMood,
|
||||
required this.selectedSatiety,
|
||||
required this.wakeupExpanded,
|
||||
required this.moderationExpanded,
|
||||
required this.moodExpanded,
|
||||
@@ -891,9 +891,9 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
@override
|
||||
final TextEditingController carbsController;
|
||||
@override
|
||||
final int? selectedMood;
|
||||
final int selectedMood;
|
||||
@override
|
||||
final int? selectedSatiety;
|
||||
final int selectedSatiety;
|
||||
@override
|
||||
final bool wakeupExpanded;
|
||||
@override
|
||||
@@ -1033,8 +1033,8 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
TextEditingController fatsController,
|
||||
TextEditingController proteinsController,
|
||||
TextEditingController carbsController,
|
||||
int? selectedMood,
|
||||
int? selectedSatiety,
|
||||
int selectedMood,
|
||||
int selectedSatiety,
|
||||
bool wakeupExpanded,
|
||||
bool moderationExpanded,
|
||||
bool moodExpanded,
|
||||
@@ -1099,8 +1099,8 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
TextEditingController fatsController,
|
||||
TextEditingController proteinsController,
|
||||
TextEditingController carbsController,
|
||||
int? selectedMood,
|
||||
int? selectedSatiety,
|
||||
int selectedMood,
|
||||
int selectedSatiety,
|
||||
bool wakeupExpanded,
|
||||
bool moderationExpanded,
|
||||
bool moodExpanded,
|
||||
@@ -1165,8 +1165,8 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
|
||||
TextEditingController fatsController,
|
||||
TextEditingController proteinsController,
|
||||
TextEditingController carbsController,
|
||||
int? selectedMood,
|
||||
int? selectedSatiety,
|
||||
int selectedMood,
|
||||
int selectedSatiety,
|
||||
bool wakeupExpanded,
|
||||
bool moderationExpanded,
|
||||
bool moodExpanded,
|
||||
@@ -1269,8 +1269,8 @@ abstract class DiaryStateLoaded implements DiaryState {
|
||||
required final TextEditingController fatsController,
|
||||
required final TextEditingController proteinsController,
|
||||
required final TextEditingController carbsController,
|
||||
final int? selectedMood,
|
||||
final int? selectedSatiety,
|
||||
required final int selectedMood,
|
||||
required final int selectedSatiety,
|
||||
required final bool wakeupExpanded,
|
||||
required final bool moderationExpanded,
|
||||
required final bool moodExpanded,
|
||||
@@ -1297,8 +1297,8 @@ abstract class DiaryStateLoaded implements DiaryState {
|
||||
TextEditingController get fatsController;
|
||||
TextEditingController get proteinsController;
|
||||
TextEditingController get carbsController;
|
||||
int? get selectedMood;
|
||||
int? get selectedSatiety;
|
||||
int get selectedMood;
|
||||
int get selectedSatiety;
|
||||
bool get wakeupExpanded;
|
||||
bool get moderationExpanded;
|
||||
bool get moodExpanded;
|
||||
@@ -1398,8 +1398,8 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
|
||||
TextEditingController fatsController,
|
||||
TextEditingController proteinsController,
|
||||
TextEditingController carbsController,
|
||||
int? selectedMood,
|
||||
int? selectedSatiety,
|
||||
int selectedMood,
|
||||
int selectedSatiety,
|
||||
bool wakeupExpanded,
|
||||
bool moderationExpanded,
|
||||
bool moodExpanded,
|
||||
@@ -1437,8 +1437,8 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
|
||||
TextEditingController fatsController,
|
||||
TextEditingController proteinsController,
|
||||
TextEditingController carbsController,
|
||||
int? selectedMood,
|
||||
int? selectedSatiety,
|
||||
int selectedMood,
|
||||
int selectedSatiety,
|
||||
bool wakeupExpanded,
|
||||
bool moderationExpanded,
|
||||
bool moodExpanded,
|
||||
@@ -1476,8 +1476,8 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
|
||||
TextEditingController fatsController,
|
||||
TextEditingController proteinsController,
|
||||
TextEditingController carbsController,
|
||||
int? selectedMood,
|
||||
int? selectedSatiety,
|
||||
int selectedMood,
|
||||
int selectedSatiety,
|
||||
bool wakeupExpanded,
|
||||
bool moderationExpanded,
|
||||
bool moodExpanded,
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import 'package:eatvio_app/core/app_export.dart';
|
||||
import 'package:eatvio_app/features/diary/models/diary_model.dart';
|
||||
import 'package:eatvio_app/features/diary/models/meal.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/bloc/diary_bloc.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart';
|
||||
import 'package:eatvio_app/features/diary/services/diary_service.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
class DiaryRepository {
|
||||
final DiaryService diaryService;
|
||||
@@ -21,4 +26,28 @@ class DiaryRepository {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> changeSatiety(int satiety, int mealID, int diaryID) async {
|
||||
try {
|
||||
await diaryService.sendSatietyData(
|
||||
diaryID,
|
||||
mealID,
|
||||
satiety,
|
||||
);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> changeMood(int mood, int mealID, int diaryID) async {
|
||||
try {
|
||||
await diaryService.sendMoodData(
|
||||
diaryID,
|
||||
mealID,
|
||||
mood,
|
||||
);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,18 +18,18 @@ abstract class DiaryService {
|
||||
@GET('/diary/{id}/dailyNutritionData/')
|
||||
Future<DiaryModel> getChart(@Path() String id);
|
||||
|
||||
@POST('/diary/{diaryID}/meal/{mealID}/satiety/fill')
|
||||
Future<DiaryModel> sendSatiety(
|
||||
@Path() String diaryID,
|
||||
String mealID,
|
||||
int satiety,
|
||||
@POST('/diary/{diary_id}/meal/{meal_id}/satiety/fill')
|
||||
Future<Map<String, int>> sendSatietyData(
|
||||
@Path() int diary_id,
|
||||
@Path() int meal_id,
|
||||
@Query('satiety') int satiety,
|
||||
);
|
||||
|
||||
@POST('/diary/{diaryID}/meal/{mealID}/mood/fill')
|
||||
Future<DiaryModel> sendMood(
|
||||
@Path() String diaryID,
|
||||
String mealID,
|
||||
int mood,
|
||||
@POST('/diary/{diary_id}/meal/{meal_id}/mood/fill')
|
||||
Future<Map<String, int>> sendMoodData(
|
||||
@Path() int diary_id,
|
||||
@Path() int meal_id,
|
||||
@Query('mood') int mood,
|
||||
);
|
||||
|
||||
@POST('/diary/{diaryID}/wakeup/fill')
|
||||
|
||||
@@ -101,24 +101,24 @@ class _DiaryService implements DiaryService {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DiaryModel> sendSatiety(
|
||||
String diaryID,
|
||||
String mealID,
|
||||
Future<Map<String, int>> sendSatietyData(
|
||||
int diary_id,
|
||||
int meal_id,
|
||||
int satiety,
|
||||
) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{r'satiety': satiety};
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _result = await _dio
|
||||
.fetch<Map<String, dynamic>>(_setStreamType<DiaryModel>(Options(
|
||||
.fetch<Map<String, dynamic>>(_setStreamType<Map<String, int>>(Options(
|
||||
method: 'POST',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/diary/${diaryID}/meal/{mealID}/satiety/fill',
|
||||
'/diary/${diary_id}/meal/${meal_id}/satiety/fill',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
@@ -127,29 +127,29 @@ class _DiaryService implements DiaryService {
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
))));
|
||||
final _value = DiaryModel.fromJson(_result.data!);
|
||||
final _value = _result.data!.cast<String, int>();
|
||||
return _value;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DiaryModel> sendMood(
|
||||
String diaryID,
|
||||
String mealID,
|
||||
Future<Map<String, int>> sendMoodData(
|
||||
int diary_id,
|
||||
int meal_id,
|
||||
int mood,
|
||||
) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{r'mood': mood};
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _result = await _dio
|
||||
.fetch<Map<String, dynamic>>(_setStreamType<DiaryModel>(Options(
|
||||
.fetch<Map<String, dynamic>>(_setStreamType<Map<String, int>>(Options(
|
||||
method: 'POST',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/diary/${diaryID}/meal/{mealID}/mood/fill',
|
||||
'/diary/${diary_id}/meal/${meal_id}/mood/fill',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
@@ -158,7 +158,7 @@ class _DiaryService implements DiaryService {
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
))));
|
||||
final _value = DiaryModel.fromJson(_result.data!);
|
||||
final _value = _result.data!.cast<String, int>();
|
||||
return _value;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user