forked from eatvio/eatvio_app
122 lines
2.2 KiB
Dart
122 lines
2.2 KiB
Dart
import 'package:eatvio_app/features/diary/models/diary_model.dart';
|
|
import 'package:eatvio_app/features/diary/models/product.dart';
|
|
import 'package:eatvio_app/features/diary/services/diary_service.dart';
|
|
|
|
class DiaryRepository {
|
|
final DiaryService diaryService;
|
|
|
|
DiaryRepository({required this.diaryService});
|
|
|
|
Future<Map<String, int>> getDiaryID() async {
|
|
try {
|
|
return await diaryService.getDiaryID();
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<DiaryModel> getDiary(int diaryID) async {
|
|
try {
|
|
return (await diaryService.getDiary(diaryID))['diary']!;
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<Map<String, List<Product>>> inputProduct(String name) async {
|
|
try {
|
|
return await diaryService.getInputProduct(name);
|
|
} catch (e) {
|
|
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;
|
|
}
|
|
}
|
|
|
|
Future<void> changeWakeup(
|
|
int diaryID,
|
|
String wakeup,
|
|
) async {
|
|
try {
|
|
await diaryService.sendWakeupData(
|
|
diaryID,
|
|
wakeup,
|
|
);
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<void> changeRetire(
|
|
int diaryID,
|
|
String retire,
|
|
) async {
|
|
try {
|
|
await diaryService.sendWakeupData(
|
|
diaryID,
|
|
retire,
|
|
);
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<void> addPortion(
|
|
int diaryID,
|
|
int mealID,
|
|
String name,
|
|
String product,
|
|
int quantity,
|
|
) async {
|
|
try {
|
|
await diaryService.sendPortionData(
|
|
diaryID,
|
|
mealID,
|
|
name,
|
|
product,
|
|
quantity,
|
|
);
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<void> removePortion(
|
|
int diaryID,
|
|
int mealID,
|
|
int portionID,
|
|
) async {
|
|
try {
|
|
await diaryService.sendRemovePortionData(
|
|
diaryID,
|
|
mealID,
|
|
portionID,
|
|
);
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
}
|