feat(profile): delete photo

This commit is contained in:
Alex
2024-12-04 15:15:28 +03:00
parent 480a26fe78
commit cb1b480c42
5 changed files with 46 additions and 1 deletions

View File

@@ -92,4 +92,9 @@ class ProfileCubit extends Cubit<ProfileState> {
await profileRepository.uploadPhoto(await ImageCompressUtility.compressFile(file));
return await getMyProfile();
}
deletePhoto() async {
await profileRepository.deletePhoto();
return await getMyProfile();
}
}

View File

@@ -737,7 +737,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
child: Row(
children: [
PopupMenuButton(
onSelected: (value) {
onSelected: (value) async {
if (value == 'view') {
context.pushTransparentRoute(
rootNavigator: true,
@@ -797,6 +797,10 @@ class _ProfileScreenState extends State<ProfileScreen> {
),
);
}
if (value == 'delete') {
await profileCubit.deletePhoto();
await sl<ProfileAvatarCubit>().getMyProfile();
}
},
itemBuilder: (context) => [
PopupMenuItem(

View File

@@ -163,4 +163,12 @@ class ProfileRepository {
rethrow;
}
}
Future<void> deletePhoto() async {
try {
return await profileService.deletePhoto();
} catch (e) {
rethrow;
}
}
}

View File

@@ -96,4 +96,7 @@ abstract class ProfileService {
Future<void> uploadPhoto({
@Part(name: 'photo') required File photo,
});
@DELETE('/api/profile/photo/delete')
Future<void> deletePhoto();
}

View File

@@ -571,6 +571,31 @@ class _ProfileService implements ProfileService {
await _dio.fetch<void>(_options);
}
@override
Future<void> deletePhoto() async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
const Map<String, dynamic>? _data = null;
final _options = _setStreamType<void>(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<void>(_options);
}
RequestOptions _setStreamType<T>(RequestOptions requestOptions) {
if (T != dynamic &&
!(requestOptions.responseType == ResponseType.bytes ||