Files
eatvio_app/lib/features/profile/repositories/profile_repository.dart

117 lines
3.9 KiB
Dart

import 'dart:convert';
import 'dart:io';
import 'package:eatvio_app/features/feed/models/feed_blog_post_model.dart';
import 'package:eatvio_app/features/profile/models/chosen_diets_pagination_model.dart';
import 'package:eatvio_app/features/profile/models/circumference_model.dart';
import 'package:eatvio_app/features/profile/models/pass_key_params.dart';
import 'package:eatvio_app/features/profile/models/profile_model.dart';
import 'package:eatvio_app/features/profile/models/sub_model.dart';
import 'package:eatvio_app/features/profile/models/weight_model.dart';
import 'package:eatvio_app/features/profile/services/profile_service.dart';
class ProfileRepository {
final ProfileService profileService;
ProfileRepository({required this.profileService});
Future<ProfileModel> getProfileBySlug(String slug) async {
return profileService.getProfileBySlug(slug: slug);
}
Future<ProfileDetailsModel> getProfileDetailsBySlug(String slug) async {
return profileService.getProfileDetailsBySlug(slug: slug);
}
Future<ProfileModel> getMyProfile() async {
return profileService.getMyProfile();
}
Future<ProfileDetailsModel> getMyProfileDetails() async {
return profileService.getMyProfileDetails();
}
Future<void> addCircumference({required int chestCircumference, required int waistCircumference, required int hipCircumference}) async {
return profileService.addCircumference(
chestCircumference: chestCircumference,
waistCircumference: waistCircumference,
hipCircumference: hipCircumference,
);
}
Future<void> addWeight({required double weight}) async {
return profileService.addWeight(weight: weight);
}
Future<List<FeedBlogPostModel>> getBlogPostsByAuthorSlug({required String slug}) async {
return profileService.getBlogPostByAuthorSlug(slug: slug);
}
Future<List<WeightModel>> getWeight({required String period, String? slug}) async {
if (slug != null) {
return profileService.getWeightBySlug(period: period, slug: slug);
}
return profileService.getWeight(period: period);
}
Future<List<CircumferenceModel>> getCircumferences({required String period, String? slug}) async {
if (slug != null) {
return profileService.getCircumferencesBySlug(period: period, slug: slug);
}
return profileService.getCircumferences(period: period);
}
Future<List<SubModel>> getSubscribersBySlug(String slug, [String? query]) async {
return (await profileService.getSubscribers(slug: slug, query: query)).data;
}
Future<List<SubModel>> getSubscriptionsBySlug(String slug, [String? query]) async {
return (await profileService.getSubscriptions(slug: slug, query: query)).data;
}
Future<void> subscribe(String slug) async {
return profileService.subscribe(slug: slug);
}
Future<void> unsubscribe(String slug) async {
return profileService.unsubscribe(slug: slug);
}
Future<void> uploadPhoto(File file) async {
return profileService.uploadPhoto(photo: file);
}
Future<void> deletePhoto() async {
return profileService.deletePhoto();
}
Future<List<ChosenDietModel>> getChosenDiets() async {
return (await profileService.getChosenDiets()).diets;
}
Future<String> getPassKey({required String routeName, Map<String, dynamic>? routeParams}) async {
return (await profileService.getPassKey(
json: PassKeyParams(routeName: routeName, routeParams: routeParams),
)).data['key_is']!;
}
Future<String> getMyPhone() async {
return (jsonDecode(await profileService.getMyPhone())['phone']);
}
Future<void> sendEmailCode({String? newEmail}) async {
if (newEmail != null) {
return profileService.sendEmailCode(data: {'new_email': newEmail});
}
return profileService.sendEmailCode();
}
Future<void> tryVerifyEmailByCode(String code) async {
await profileService.tryVerifyEmailByCode(code: "{\"code\": \"$code\"}");
}
Future<void> deleteAccount() async {
await profileService.deleteAccount();
}
}