mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-08-21 20:41:50 +00:00
- Separate response success from business logic operation success - Remove ApiResponse, replace with GenericResult - Make GenericMutationResult inherit GenericResult - Add generic error message for when a response couldn't be sent or received
48 lines
1.4 KiB
Dart
48 lines
1.4 KiB
Dart
part of 'server.dart';
|
|
|
|
mixin JobsApi on ApiMap {
|
|
Future<List<ServerJob>> getServerJobs() async {
|
|
QueryResult<Query$GetApiJobs> response;
|
|
List<ServerJob> jobsList = [];
|
|
|
|
try {
|
|
final GraphQLClient client = await getClient();
|
|
response = await client.query$GetApiJobs();
|
|
if (response.hasException) {
|
|
print(response.exception.toString());
|
|
}
|
|
jobsList = jobsList = response.parsedData?.jobs.getJobs
|
|
.map<ServerJob>((final job) => ServerJob.fromGraphQL(job))
|
|
.toList() ??
|
|
[];
|
|
} catch (e) {
|
|
print(e);
|
|
}
|
|
|
|
return jobsList;
|
|
}
|
|
|
|
Future<GenericMutationResult<bool>> removeApiJob(final String uid) async {
|
|
try {
|
|
final GraphQLClient client = await getClient();
|
|
final variables = Variables$Mutation$RemoveJob(jobId: uid);
|
|
final mutation = Options$Mutation$RemoveJob(variables: variables);
|
|
final response = await client.mutate$RemoveJob(mutation);
|
|
return GenericMutationResult(
|
|
data: response.parsedData?.removeJob.success ?? false,
|
|
success: true,
|
|
code: response.parsedData?.removeJob.code ?? 0,
|
|
message: response.parsedData?.removeJob.message,
|
|
);
|
|
} catch (e) {
|
|
print(e);
|
|
return GenericMutationResult(
|
|
data: false,
|
|
success: false,
|
|
code: 0,
|
|
message: e.toString(),
|
|
);
|
|
}
|
|
}
|
|
}
|