forked from eatvio/eatvio_app
192 lines
4.9 KiB
Dart
192 lines
4.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/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 {
|
|
try {
|
|
return await profileService.getProfileBySlug(slug: slug);
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<ProfileDetailsModel> getProfileDetailsBySlug(String slug) async {
|
|
try {
|
|
return await profileService.getProfileDetailsBySlug(slug: slug);
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<ProfileModel> getMyProfile() async {
|
|
try {
|
|
return await profileService.getMyProfile();
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<ProfileDetailsModel> getMyProfileDetails() async {
|
|
try {
|
|
return await profileService.getMyProfileDetails();
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<void> addCircumference({required int chestCircumference, required int waistCircumference, required int hipCircumference}) async {
|
|
try {
|
|
return (await profileService.addCircumference(
|
|
chestCircumference: chestCircumference,
|
|
waistCircumference: waistCircumference,
|
|
hipCircumference: hipCircumference,
|
|
));
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<void> addWeight({required double weight}) async {
|
|
try {
|
|
return (await profileService.addWeight(weight: weight));
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<List<FeedBlogPostModel>> getBlogPostsByAuthorSlug({required String slug}) async {
|
|
try {
|
|
return (await profileService.getBlogPostByAuthorSlug(slug: slug));
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<List<WeightModel>> getWeight({required String period, String? slug}) async {
|
|
try {
|
|
if (slug != null) {
|
|
return (await profileService.getWeightBySlug(period: period, slug: slug));
|
|
} else {
|
|
return (await profileService.getWeight(period: period));
|
|
}
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<List<CircumferenceModel>> getCircumferences({required String period, String? slug}) async {
|
|
try {
|
|
if (slug != null) {
|
|
return (await profileService.getCircumferencesBySlug(period: period, slug: slug));
|
|
} else {
|
|
return (await profileService.getCircumferences(period: period));
|
|
}
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<List<SubModel>> getSubscribersBySlug(String slug, [String? query]) async {
|
|
try {
|
|
return (await profileService.getSubscribers(slug: slug, query: query)).data;
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<List<SubModel>> getSubscriptionsBySlug(String slug, [String? query]) async {
|
|
try {
|
|
return (await profileService.getSubscriptions(slug: slug, query: query)).data;
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<void> subscribe(String slug) async {
|
|
try {
|
|
return await profileService.subscribe(slug: slug);
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<void> unsubscribe(String slug) async {
|
|
try {
|
|
return await profileService.unsubscribe(slug: slug);
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<void> uploadPhoto(File file) async {
|
|
try {
|
|
return await profileService.uploadPhoto(photo: file);
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<void> deletePhoto() async {
|
|
try {
|
|
return await profileService.deletePhoto();
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<List<ChosenDietModel>> getChosenDiets() async {
|
|
try {
|
|
return (await profileService.getChosenDiets()).diets;
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<String> getPassKey(String phone) async {
|
|
return (jsonDecode(
|
|
(await profileService.getPassKey(json: '{"route_name": "user_detailz.change-phone-verify", "route_params": {"phone": "$phone"}}')),
|
|
))['key_is']!;
|
|
}
|
|
|
|
Future<String> getMyPhone() async {
|
|
return (jsonDecode(await profileService.getMyPhone())['phone']);
|
|
}
|
|
|
|
Future<void> sendEmailCode({String? newEmail}) async {
|
|
if (newEmail != null) {
|
|
return await profileService.sendEmailCode(data: {'new_email': newEmail});
|
|
} else {
|
|
return await profileService.sendEmailCode();
|
|
}
|
|
}
|
|
|
|
Future<bool> tryVerifyEmailByCode(String code) async {
|
|
try {
|
|
await profileService.tryVerifyEmailByCode(code: "{\"code\": \"$code\"}");
|
|
return true;
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
Future<void> deleteAccount() async {
|
|
try {
|
|
await profileService.deleteAccount();
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
}
|