forked from eatvio/eatvio_app
feat(app): refactoring of sentry using, feat(become_consultant): fixed possible infinite loading, feat(push_notifications): fixed push navigation from paid plan push
This commit is contained in:
@@ -3,6 +3,7 @@ import 'dart:developer';
|
||||
import 'package:eatvio_app/features/plans/repositories/plans_repository.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/bloc/plans_cubit/plans_state.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:eatvio_app/core/error_reporting/report_from.dart';
|
||||
|
||||
class PlansCubit extends Cubit<PlansState> {
|
||||
final PlansRepository plansRepository;
|
||||
@@ -15,7 +16,8 @@ class PlansCubit extends Cubit<PlansState> {
|
||||
emit(const PlansState.loading());
|
||||
try {
|
||||
emit(PlansState.loaded(plansList: await plansRepository.getPlansBySlug(slug)));
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
log(e.toString());
|
||||
emit(PlansState.error(errorMessage: e.toString()));
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import 'package:eatvio_app/features/feed/models/feed_blog_post_model.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_state.dart';
|
||||
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:eatvio_app/core/error_reporting/report_from.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
class ProfileCubit extends Cubit<ProfileState> {
|
||||
@@ -41,9 +42,9 @@ class ProfileCubit extends Cubit<ProfileState> {
|
||||
certPhotos: certPhotos,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
emit(ProfileState.error(errorMessage: e.toString()));
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +68,7 @@ class ProfileCubit extends Cubit<ProfileState> {
|
||||
),
|
||||
);
|
||||
} catch (e, stackTrace) {
|
||||
await reportFrom(e, stackTrace, this);
|
||||
log(e.toString(), stackTrace: stackTrace);
|
||||
emit(ProfileState.error(errorMessage: e.toString()));
|
||||
}
|
||||
@@ -101,7 +103,8 @@ class ProfileCubit extends Cubit<ProfileState> {
|
||||
hipCircumference: hipCircumference,
|
||||
);
|
||||
await getMyProfile(period: _currentPeriod);
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
emit(ProfileState.error(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
@@ -110,7 +113,8 @@ class ProfileCubit extends Cubit<ProfileState> {
|
||||
try {
|
||||
await profileRepository.addWeight(weight: weight);
|
||||
await getMyProfile(period: _currentPeriod);
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
emit(ProfileState.error(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
@@ -121,27 +125,37 @@ class ProfileCubit extends Cubit<ProfileState> {
|
||||
final userProfile = await profileRepository.getProfileBySlug(slug);
|
||||
if (chatIdOrError == '404') {
|
||||
AppRouter.navigatorKey.currentContext?.pushNamed('emptyChatScreen', extra: userProfile);
|
||||
} else if (chatIdOrError == 'error') {
|
||||
showErrorToast('Ошибка создания чата');
|
||||
} else {
|
||||
AppRouter.navigatorKey.currentContext?.pushNamed('chatScreen', extra: {'uuid': chatIdOrError});
|
||||
return chatIdOrError;
|
||||
}
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
log(e.toString(), stackTrace: st);
|
||||
showErrorToast('Ошибка создания чата');
|
||||
return '';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> uploadPhoto(File file) async {
|
||||
await profileRepository.uploadPhoto(await ImageCompressUtility.compressFile(file));
|
||||
return await getMyProfile();
|
||||
try {
|
||||
await profileRepository.uploadPhoto(await ImageCompressUtility.compressFile(file));
|
||||
await getMyProfile();
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
emit(ProfileState.error(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deletePhoto() async {
|
||||
await profileRepository.deletePhoto();
|
||||
return await getMyProfile();
|
||||
try {
|
||||
await profileRepository.deletePhoto();
|
||||
await getMyProfile();
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
emit(ProfileState.error(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> hideCertPhoto(int id) async {
|
||||
@@ -153,7 +167,8 @@ class ProfileCubit extends Cubit<ProfileState> {
|
||||
if (currentState is ProfileStateLoaded) {
|
||||
emit(currentState.copyWith(certPhotos: certPhotos));
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
log(e.toString());
|
||||
}
|
||||
}
|
||||
@@ -167,7 +182,8 @@ class ProfileCubit extends Cubit<ProfileState> {
|
||||
if (currentState is ProfileStateLoaded) {
|
||||
emit(currentState.copyWith(certPhotos: certPhotos));
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
log(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:eatvio_app/features/profile/presentation/bloc/sub_cubit/sub_state.dart';
|
||||
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:eatvio_app/core/error_reporting/report_from.dart';
|
||||
|
||||
class SubCubit extends Cubit<SubState> {
|
||||
final ProfileRepository profileRepository;
|
||||
@@ -16,7 +17,8 @@ class SubCubit extends Cubit<SubState> {
|
||||
return;
|
||||
}
|
||||
emit(SubState.loaded(subList: await profileRepository.getSubscriptionsBySlug(slug, query)));
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
emit(SubState.error(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
@@ -30,16 +32,25 @@ class SubCubit extends Cubit<SubState> {
|
||||
return;
|
||||
}
|
||||
emit(SubState.loaded(subList: await profileRepository.getSubscribersBySlug(slug, query)));
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
emit(SubState.error(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> subscribe(String slug) async {
|
||||
return await profileRepository.subscribe(slug);
|
||||
try {
|
||||
await profileRepository.subscribe(slug);
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> unsubscribe(String slug) async {
|
||||
return await profileRepository.unsubscribe(slug);
|
||||
try {
|
||||
await profileRepository.unsubscribe(slug);
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ 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';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
class ProfileRepository {
|
||||
final ProfileService profileService;
|
||||
@@ -17,210 +16,101 @@ class ProfileRepository {
|
||||
ProfileRepository({required this.profileService});
|
||||
|
||||
Future<ProfileModel> getProfileBySlug(String slug) async {
|
||||
try {
|
||||
return await profileService.getProfileBySlug(slug: slug);
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
return profileService.getProfileBySlug(slug: slug);
|
||||
}
|
||||
|
||||
Future<ProfileDetailsModel> getProfileDetailsBySlug(String slug) async {
|
||||
try {
|
||||
return await profileService.getProfileDetailsBySlug(slug: slug);
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
return profileService.getProfileDetailsBySlug(slug: slug);
|
||||
}
|
||||
|
||||
Future<ProfileModel> getMyProfile() async {
|
||||
try {
|
||||
return await profileService.getMyProfile();
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
return profileService.getMyProfile();
|
||||
}
|
||||
|
||||
Future<ProfileDetailsModel> getMyProfileDetails() async {
|
||||
try {
|
||||
return await profileService.getMyProfileDetails();
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
return profileService.getMyProfileDetails();
|
||||
}
|
||||
|
||||
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, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
return profileService.addCircumference(
|
||||
chestCircumference: chestCircumference,
|
||||
waistCircumference: waistCircumference,
|
||||
hipCircumference: hipCircumference,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> addWeight({required double weight}) async {
|
||||
try {
|
||||
return (await profileService.addWeight(weight: weight));
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
return profileService.addWeight(weight: weight);
|
||||
}
|
||||
|
||||
Future<List<FeedBlogPostModel>> getBlogPostsByAuthorSlug({required String slug}) async {
|
||||
try {
|
||||
return (await profileService.getBlogPostByAuthorSlug(slug: slug));
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
return profileService.getBlogPostByAuthorSlug(slug: slug);
|
||||
}
|
||||
|
||||
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, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
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 {
|
||||
try {
|
||||
if (slug != null) {
|
||||
return (await profileService.getCircumferencesBySlug(period: period, slug: slug));
|
||||
} else {
|
||||
return (await profileService.getCircumferences(period: period));
|
||||
}
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
if (slug != null) {
|
||||
return profileService.getCircumferencesBySlug(period: period, slug: slug);
|
||||
}
|
||||
return profileService.getCircumferences(period: period);
|
||||
}
|
||||
|
||||
Future<List<SubModel>> getSubscribersBySlug(String slug, [String? query]) async {
|
||||
try {
|
||||
return (await profileService.getSubscribers(slug: slug, query: query)).data;
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
return (await profileService.getSubscribers(slug: slug, query: query)).data;
|
||||
}
|
||||
|
||||
Future<List<SubModel>> getSubscriptionsBySlug(String slug, [String? query]) async {
|
||||
try {
|
||||
return (await profileService.getSubscriptions(slug: slug, query: query)).data;
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
return (await profileService.getSubscriptions(slug: slug, query: query)).data;
|
||||
}
|
||||
|
||||
Future<void> subscribe(String slug) async {
|
||||
try {
|
||||
return await profileService.subscribe(slug: slug);
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
return profileService.subscribe(slug: slug);
|
||||
}
|
||||
|
||||
Future<void> unsubscribe(String slug) async {
|
||||
try {
|
||||
return await profileService.unsubscribe(slug: slug);
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
return profileService.unsubscribe(slug: slug);
|
||||
}
|
||||
|
||||
Future<void> uploadPhoto(File file) async {
|
||||
try {
|
||||
return await profileService.uploadPhoto(photo: file);
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
return profileService.uploadPhoto(photo: file);
|
||||
}
|
||||
|
||||
Future<void> deletePhoto() async {
|
||||
try {
|
||||
return await profileService.deletePhoto();
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
return profileService.deletePhoto();
|
||||
}
|
||||
|
||||
Future<List<ChosenDietModel>> getChosenDiets() async {
|
||||
try {
|
||||
return (await profileService.getChosenDiets()).diets;
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
return (await profileService.getChosenDiets()).diets;
|
||||
}
|
||||
|
||||
Future<String> getPassKey({required String routeName, Map<String, dynamic>? routeParams}) async {
|
||||
try {
|
||||
return (await profileService.getPassKey(
|
||||
json: PassKeyParams(routeName: routeName, routeParams: routeParams),
|
||||
)).data['key_is']!;
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
return (await profileService.getPassKey(
|
||||
json: PassKeyParams(routeName: routeName, routeParams: routeParams),
|
||||
)).data['key_is']!;
|
||||
}
|
||||
|
||||
Future<String> getMyPhone() async {
|
||||
try {
|
||||
return (jsonDecode(await profileService.getMyPhone())['phone']);
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
return (jsonDecode(await profileService.getMyPhone())['phone']);
|
||||
}
|
||||
|
||||
Future<void> sendEmailCode({String? newEmail}) async {
|
||||
try {
|
||||
if (newEmail != null) {
|
||||
return await profileService.sendEmailCode(data: {'new_email': newEmail});
|
||||
} else {
|
||||
return await profileService.sendEmailCode();
|
||||
}
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
if (newEmail != null) {
|
||||
return profileService.sendEmailCode(data: {'new_email': newEmail});
|
||||
}
|
||||
return profileService.sendEmailCode();
|
||||
}
|
||||
|
||||
Future<bool> tryVerifyEmailByCode(String code) async {
|
||||
try {
|
||||
await profileService.tryVerifyEmailByCode(code: "{\"code\": \"$code\"}");
|
||||
return true;
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
return false;
|
||||
}
|
||||
Future<void> tryVerifyEmailByCode(String code) async {
|
||||
await profileService.tryVerifyEmailByCode(code: "{\"code\": \"$code\"}");
|
||||
}
|
||||
|
||||
Future<void> deleteAccount() async {
|
||||
try {
|
||||
await profileService.deleteAccount();
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
await profileService.deleteAccount();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user