diff --git a/lib/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart b/lib/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart index 5a322425..ad975da2 100644 --- a/lib/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart +++ b/lib/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart @@ -92,4 +92,9 @@ class ProfileCubit extends Cubit { await profileRepository.uploadPhoto(await ImageCompressUtility.compressFile(file)); return await getMyProfile(); } + + deletePhoto() async { + await profileRepository.deletePhoto(); + return await getMyProfile(); + } } diff --git a/lib/features/profile/presentation/pages/profile_screen.dart b/lib/features/profile/presentation/pages/profile_screen.dart index 81a7cc7a..2647b989 100644 --- a/lib/features/profile/presentation/pages/profile_screen.dart +++ b/lib/features/profile/presentation/pages/profile_screen.dart @@ -737,7 +737,7 @@ class _ProfileScreenState extends State { child: Row( children: [ PopupMenuButton( - onSelected: (value) { + onSelected: (value) async { if (value == 'view') { context.pushTransparentRoute( rootNavigator: true, @@ -797,6 +797,10 @@ class _ProfileScreenState extends State { ), ); } + if (value == 'delete') { + await profileCubit.deletePhoto(); + await sl().getMyProfile(); + } }, itemBuilder: (context) => [ PopupMenuItem( diff --git a/lib/features/profile/repositories/profile_repository.dart b/lib/features/profile/repositories/profile_repository.dart index 96825109..21f5e7b3 100644 --- a/lib/features/profile/repositories/profile_repository.dart +++ b/lib/features/profile/repositories/profile_repository.dart @@ -163,4 +163,12 @@ class ProfileRepository { rethrow; } } + + Future deletePhoto() async { + try { + return await profileService.deletePhoto(); + } catch (e) { + rethrow; + } + } } diff --git a/lib/features/profile/services/profile_service.dart b/lib/features/profile/services/profile_service.dart index 8cab7056..d357ea3a 100644 --- a/lib/features/profile/services/profile_service.dart +++ b/lib/features/profile/services/profile_service.dart @@ -96,4 +96,7 @@ abstract class ProfileService { Future uploadPhoto({ @Part(name: 'photo') required File photo, }); + + @DELETE('/api/profile/photo/delete') + Future deletePhoto(); } diff --git a/lib/features/profile/services/profile_service.g.dart b/lib/features/profile/services/profile_service.g.dart index a0e72b67..e8214593 100644 --- a/lib/features/profile/services/profile_service.g.dart +++ b/lib/features/profile/services/profile_service.g.dart @@ -571,6 +571,31 @@ class _ProfileService implements ProfileService { await _dio.fetch(_options); } + @override + Future deletePhoto() async { + final _extra = {}; + final queryParameters = {}; + final _headers = {}; + const Map? _data = null; + final _options = _setStreamType(Options( + method: 'DELETE', + headers: _headers, + extra: _extra, + ) + .compose( + _dio.options, + '/api/profile/photo/delete', + queryParameters: queryParameters, + data: _data, + ) + .copyWith( + baseUrl: _combineBaseUrls( + _dio.options.baseUrl, + baseUrl, + ))); + await _dio.fetch(_options); + } + RequestOptions _setStreamType(RequestOptions requestOptions) { if (T != dynamic && !(requestOptions.responseType == ResponseType.bytes ||