mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-09-19 01:47:51 +00:00
NaiJi
0234278c2c
Because the class is called ServerApi, not just Server, it's totally not consistent with all other apis
178 lines
5.6 KiB
Dart
178 lines
5.6 KiB
Dart
part of 'server_api.dart';
|
|
|
|
mixin ServicesApi on ApiMap {
|
|
Future<List<Service>> getAllServices() async {
|
|
QueryResult<Query$AllServices> response;
|
|
List<Service> services = [];
|
|
try {
|
|
final GraphQLClient client = await getClient();
|
|
response = await client.query$AllServices();
|
|
if (response.hasException) {
|
|
print(response.exception.toString());
|
|
}
|
|
services = response.parsedData?.services.allServices
|
|
.map<Service>((final service) => Service.fromGraphQL(service))
|
|
.toList() ??
|
|
[];
|
|
} catch (e) {
|
|
print(e);
|
|
}
|
|
return services;
|
|
}
|
|
|
|
Future<GenericMutationResult<bool>> enableService(
|
|
final String serviceId,
|
|
) async {
|
|
try {
|
|
final GraphQLClient client = await getClient();
|
|
final variables = Variables$Mutation$EnableService(serviceId: serviceId);
|
|
final mutation = Options$Mutation$EnableService(variables: variables);
|
|
final response = await client.mutate$EnableService(mutation);
|
|
return GenericMutationResult(
|
|
data: response.parsedData?.enableService.success ?? false,
|
|
success: true,
|
|
code: response.parsedData?.enableService.code ?? 0,
|
|
message: response.parsedData?.enableService.message,
|
|
);
|
|
} catch (e) {
|
|
print(e);
|
|
return GenericMutationResult(
|
|
data: false,
|
|
success: false,
|
|
code: 0,
|
|
message: e.toString(),
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<GenericMutationResult<void>> disableService(
|
|
final String serviceId,
|
|
) async {
|
|
try {
|
|
final GraphQLClient client = await getClient();
|
|
final variables = Variables$Mutation$DisableService(serviceId: serviceId);
|
|
final mutation = Options$Mutation$DisableService(variables: variables);
|
|
final response = await client.mutate$DisableService(mutation);
|
|
return GenericMutationResult(
|
|
data: null,
|
|
success: response.parsedData?.disableService.success ?? false,
|
|
code: response.parsedData?.disableService.code ?? 0,
|
|
message: response.parsedData?.disableService.message,
|
|
);
|
|
} catch (e) {
|
|
print(e);
|
|
return GenericMutationResult(
|
|
data: null,
|
|
success: false,
|
|
code: 0,
|
|
message: e.toString(),
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<GenericMutationResult<bool>> stopService(
|
|
final String serviceId,
|
|
) async {
|
|
try {
|
|
final GraphQLClient client = await getClient();
|
|
final variables = Variables$Mutation$StopService(serviceId: serviceId);
|
|
final mutation = Options$Mutation$StopService(variables: variables);
|
|
final response = await client.mutate$StopService(mutation);
|
|
return GenericMutationResult(
|
|
data: response.parsedData?.stopService.success ?? false,
|
|
success: true,
|
|
code: response.parsedData?.stopService.code ?? 0,
|
|
message: response.parsedData?.stopService.message,
|
|
);
|
|
} catch (e) {
|
|
print(e);
|
|
return GenericMutationResult(
|
|
data: false,
|
|
success: false,
|
|
code: 0,
|
|
message: e.toString(),
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<GenericMutationResult> startService(final String serviceId) async {
|
|
try {
|
|
final GraphQLClient client = await getClient();
|
|
final variables = Variables$Mutation$StartService(serviceId: serviceId);
|
|
final mutation = Options$Mutation$StartService(variables: variables);
|
|
final response = await client.mutate$StartService(mutation);
|
|
return GenericMutationResult(
|
|
data: null,
|
|
success: response.parsedData?.startService.success ?? false,
|
|
code: response.parsedData?.startService.code ?? 0,
|
|
message: response.parsedData?.startService.message,
|
|
);
|
|
} catch (e) {
|
|
print(e);
|
|
return GenericMutationResult(
|
|
data: null,
|
|
success: false,
|
|
code: 0,
|
|
message: e.toString(),
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<GenericMutationResult<bool>> restartService(
|
|
final String serviceId,
|
|
) async {
|
|
try {
|
|
final GraphQLClient client = await getClient();
|
|
final variables = Variables$Mutation$RestartService(serviceId: serviceId);
|
|
final mutation = Options$Mutation$RestartService(variables: variables);
|
|
final response = await client.mutate$RestartService(mutation);
|
|
return GenericMutationResult(
|
|
data: response.parsedData?.restartService.success ?? false,
|
|
success: true,
|
|
code: response.parsedData?.restartService.code ?? 0,
|
|
message: response.parsedData?.restartService.message,
|
|
);
|
|
} catch (e) {
|
|
print(e);
|
|
return GenericMutationResult(
|
|
data: false,
|
|
success: false,
|
|
code: 0,
|
|
message: e.toString(),
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<GenericMutationResult<ServerJob?>> moveService(
|
|
final String serviceId,
|
|
final String destination,
|
|
) async {
|
|
try {
|
|
final GraphQLClient client = await getClient();
|
|
final variables = Variables$Mutation$MoveService(
|
|
input: Input$MoveServiceInput(
|
|
serviceId: serviceId,
|
|
location: destination,
|
|
),
|
|
);
|
|
final mutation = Options$Mutation$MoveService(variables: variables);
|
|
final response = await client.mutate$MoveService(mutation);
|
|
final jobJson = response.parsedData?.moveService.job?.toJson();
|
|
return GenericMutationResult(
|
|
success: true,
|
|
code: response.parsedData?.moveService.code ?? 0,
|
|
message: response.parsedData?.moveService.message,
|
|
data: jobJson != null ? ServerJob.fromJson(jobJson) : null,
|
|
);
|
|
} catch (e) {
|
|
print(e);
|
|
return GenericMutationResult(
|
|
success: false,
|
|
code: 0,
|
|
message: e.toString(),
|
|
data: null,
|
|
);
|
|
}
|
|
}
|
|
}
|