mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-11 18:39:45 +00:00
fix(volume): Change raw int to DiskSize object in volume endpoints
We already have an abstraction for size, there is no need to pass size value as raw numeric variables
This commit is contained in:
parent
aa1c04fdb8
commit
59d186a8af
|
@ -252,7 +252,10 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> resizeVolume(final ServerVolume volume, final int sizeGb) async {
|
Future<bool> resizeVolume(
|
||||||
|
final ServerVolume volume,
|
||||||
|
final DiskSize size,
|
||||||
|
) async {
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
final Response dbPostResponse;
|
final Response dbPostResponse;
|
||||||
|
@ -263,7 +266,7 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
data: {
|
data: {
|
||||||
'type': 'resize',
|
'type': 'resize',
|
||||||
'volume_name': volume.name,
|
'volume_name': volume.name,
|
||||||
'size_gigabytes': sizeGb,
|
'size_gigabytes': size.gibibyte,
|
||||||
'region': region,
|
'region': region,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -281,7 +281,10 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> resizeVolume(final ServerVolume volume, final int sizeGb) async {
|
Future<bool> resizeVolume(
|
||||||
|
final ServerVolume volume,
|
||||||
|
final DiskSize size,
|
||||||
|
) async {
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
final Response dbPostResponse;
|
final Response dbPostResponse;
|
||||||
|
@ -290,7 +293,7 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
dbPostResponse = await client.post(
|
dbPostResponse = await client.post(
|
||||||
'/volumes/$volume.id/actions/resize',
|
'/volumes/$volume.id/actions/resize',
|
||||||
data: {
|
data: {
|
||||||
'size': sizeGb,
|
'size': size.gibibyte,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
success = dbPostResponse.data['action']['status'].toString() != 'error';
|
success = dbPostResponse.data['action']['status'].toString() != 'error';
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_map.dart';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/api_map.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/disk_size.dart';
|
||||||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||||
import 'package:selfprivacy/logic/models/price.dart';
|
import 'package:selfprivacy/logic/models/price.dart';
|
||||||
|
|
||||||
|
@ -7,7 +8,7 @@ mixin VolumeProviderApi on ApiMap {
|
||||||
Future<List<ServerVolume>> getVolumes({final String? status});
|
Future<List<ServerVolume>> getVolumes({final String? status});
|
||||||
Future<bool> attachVolume(final ServerVolume volume, final int serverId);
|
Future<bool> attachVolume(final ServerVolume volume, final int serverId);
|
||||||
Future<bool> detachVolume(final ServerVolume volume);
|
Future<bool> detachVolume(final ServerVolume volume);
|
||||||
Future<bool> resizeVolume(final ServerVolume volume, final int sizeGb);
|
Future<bool> resizeVolume(final ServerVolume volume, final DiskSize size);
|
||||||
Future<void> deleteVolume(final ServerVolume volume);
|
Future<void> deleteVolume(final ServerVolume volume);
|
||||||
Future<Price?> getPricePerGb();
|
Future<Price?> getPricePerGb();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_settings.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/server_provider_factory.dart';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/server_provider_factory.dart';
|
||||||
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/disk_size.dart';
|
||||||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||||
import 'package:selfprivacy/logic/models/disk_status.dart';
|
import 'package:selfprivacy/logic/models/disk_status.dart';
|
||||||
import 'package:selfprivacy/logic/models/price.dart';
|
import 'package:selfprivacy/logic/models/price.dart';
|
||||||
|
@ -76,7 +77,7 @@ class ApiProviderVolumeCubit
|
||||||
|
|
||||||
Future<bool> resizeVolume(
|
Future<bool> resizeVolume(
|
||||||
final DiskVolume volume,
|
final DiskVolume volume,
|
||||||
final int newSizeGb,
|
final DiskSize newSize,
|
||||||
final Function() callback,
|
final Function() callback,
|
||||||
) async {
|
) async {
|
||||||
getIt<NavigationService>().showSnackBar(
|
getIt<NavigationService>().showSnackBar(
|
||||||
|
@ -85,7 +86,7 @@ class ApiProviderVolumeCubit
|
||||||
emit(state.copyWith(isResizing: true));
|
emit(state.copyWith(isResizing: true));
|
||||||
final bool resized = await providerApi!.getVolumeProvider().resizeVolume(
|
final bool resized = await providerApi!.getVolumeProvider().resizeVolume(
|
||||||
volume.providerVolume!,
|
volume.providerVolume!,
|
||||||
newSizeGb,
|
newSize,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!resized) {
|
if (!resized) {
|
||||||
|
|
|
@ -153,7 +153,7 @@ class _ExtendingVolumePageState extends State<ExtendingVolumePage> {
|
||||||
: () {
|
: () {
|
||||||
context.read<ApiProviderVolumeCubit>().resizeVolume(
|
context.read<ApiProviderVolumeCubit>().resizeVolume(
|
||||||
widget.diskVolumeToResize,
|
widget.diskVolumeToResize,
|
||||||
_currentSliderGbValue.round(),
|
DiskSize.fromGibibyte(_currentSliderGbValue),
|
||||||
context.read<ApiServerVolumeCubit>().reload,
|
context.read<ApiServerVolumeCubit>().reload,
|
||||||
);
|
);
|
||||||
Navigator.of(context).pushAndRemoveUntil(
|
Navigator.of(context).pushAndRemoveUntil(
|
||||||
|
|
Loading…
Reference in a new issue