Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RSDK-10123] User defined metadata crud apis #345

Closed
wants to merge 11 commits into from
77 changes: 77 additions & 0 deletions lib/src/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import '../gen/app/v1/app.pbgrpc.dart';
import '../gen/common/v1/common.pb.dart';
import '../utils.dart';
import 'permissions.dart';
import 'package:google_protobuf/google/protobuf/struct.pb.dart';

typedef RobotPartLogPage = GetRobotPartLogsResponse;

Expand Down Expand Up @@ -729,4 +730,80 @@ class AppClient {
final request = CreateKeyFromExistingKeyAuthorizationsRequest()..id = id;
return await _client.createKeyFromExistingKeyAuthorizations(request);
}

/// Retrieves user-defined [Metadata] for an organization.
///
/// For more information, see [Fleet Management API](https://docs.viam.com/appendix/apis/fleet/).
Future<GetOrganizationMetadataResponse> getOrganizationMetadata(String id) async {
final request = GetOrganizationMetadataRequest()..organizationId = id;
return await _client.getOrganizationMetadata(request);
}

/// Updates user-defined [Metadata] for an organization.
///
/// For more information, see [Fleet Management API](https://docs.viam.com/appendix/apis/fleet/).
Future<UpdateOrganizationMetadataResponse> updateOrganizationMetadata(
String id, Map<String, dynamic> data) async {
final request = UpdateOrganizationMetadataRequest()
..organizationId = id
..data = Struct()..fields.addAll(data.map((key, value) => MapEntry(key, Value()..stringValue = value.toString())));
return await _client.updateOrganizationMetadata(request);
}

/// Retrieves user-defined [Metadata] for a location.
///
/// For more information, see [Fleet Management API](https://docs.viam.com/appendix/apis/fleet/).
Future<GetLocationMetadataResponse> getLocationMetadata(String id) async {
final request = GetLocationMetadataRequest()..locationId = id;
return await _client.getLocationMetadata(request);
}

/// Updates user-defined [Metadata] for a location.
///
/// For more information, see [Fleet Management API](https://docs.viam.com/appendix/apis/fleet/).
Future<UpdateLocationMetadataResponse> updateLocationMetadata(
String id, Map<String, dynamic> data) async {
final request = UpdateLocationMetadataRequest()
..locationId = id
..data = Struct()..fields.addAll(data.map((key, value) => MapEntry(key, Value()..stringValue = value.toString())));
return await _client.updateLocationMetadata(request);
}

/// Retrieves user-defined [Metadata] for a machine.
///
/// For more information, see [Fleet Management API](https://docs.viam.com/appendix/apis/fleet/).
Future<GetRobotMetadataResponse> getMachineMetadata(String id) async {
final request = GetRobotMetadataRequest()..id = id;
return await _client.getRobotMetadata(request);
}

/// Updates user-defined [Metadata] for a machine.
///
/// For more information, see [Fleet Management API](https://docs.viam.com/appendix/apis/fleet/).
Future<UpdateRobotMetadataResponse> updateMachineMetadata(
String id, Map<String, dynamic> data) async {
final request = UpdateRobotMetadataRequest()
..id = id
..data = Struct()..fields.addAll(data.map((key, value) => MapEntry(key, Value()..stringValue = value.toString())));
return await _client.updateRobotMetadata(request);
}

/// Retrieves user-defined [Metadata] for a machine part.
///
/// For more information, see [Fleet Management API](https://docs.viam.com/appendix/apis/fleet/).
Future<GetRobotPartMetadataResponse> getMachinePartMetadata(String id) async {
final request = GetRobotPartMetadataRequest()..id = id;
return await _client.getRobotPartMetadata(request);
}

/// Updates user-defined [Metadata] for a machine part.
///
/// For more information, see [Fleet Management API](https://docs.viam.com/appendix/apis/fleet/).
Future<UpdateRobotPartMetadataResponse> updateMachinePartMetadata(
String id, Map<String, dynamic> data) async {
final request = UpdateRobotPartMetadataRequest()
..id = id
..data = Struct()..fields.addAll(data.map((key, value) => MapEntry(key, Value()..stringValue = value.toString())));
return await _client.updateRobotPartMetadata(request);
}
}
64 changes: 64 additions & 0 deletions test/unit_test/app/app_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -754,5 +754,69 @@ void main() {
final response = await appClient.createKeyFromExistingKeyAuthorizations('id');
expect(response, equals(expected));
});

test('getOrganizationMetadata', () async {
final expected = GetOrganizationMetadataResponse()
..metadata = (Struct()..fields['key'] = (Value()..stringValue = 'value'));
when(serviceClient.getOrganizationMetadata(any)).thenAnswer((_) => MockResponseFuture.value(expected));
final response = await appClient.getOrganizationMetadata('orgId');
expect(response, equals(expected));
});

test('updateOrganizationMetadata', () async {
final expected = UpdateOrganizationMetadataResponse()
..metadata = (Struct()..fields['key'] = (Value()..stringValue = 'newValue'));
when(serviceClient.updateOrganizationMetadata(any)).thenAnswer((_) => MockResponseFuture.value(expected));
final response = await appClient.updateOrganizationMetadata('orgId', {'key': 'newValue'});
expect(response, equals(expected));
});

test('getLocationMetadata', () async {
final expected = GetLocationMetadataResponse()
..metadata = (Struct()..fields['locationKey'] = (Value()..stringValue = 'locationValue'));
when(serviceClient.getLocationMetadata(any)).thenAnswer((_) => MockResponseFuture.value(expected));
final response = await appClient.getLocationMetadata('locationId');
expect(response, equals(expected));
});

test('updateLocationMetadata', () async {
final expected = UpdateLocationMetadataResponse()
..metadata = (Struct()..fields['locationKey'] = (Value()..stringValue = 'newLocationValue'));
when(serviceClient.updateLocationMetadata(any)).thenAnswer((_) => MockResponseFuture.value(expected));
final response = await appClient.updateLocationMetadata('locationId', {'locationKey': 'newLocationValue'});
expect(response, equals(expected));
});

test('getMachineMetadata', () async {
final expected = GetRobotMetadataResponse()
..metadata = (Struct()..fields['robotKey'] = (Value()..stringValue = 'robotValue'));
when(serviceClient.getMachineMetadata(any)).thenAnswer((_) => MockResponseFuture.value(expected));
final response = await appClient.getMachineMetadata('robotId');
expect(response, equals(expected));
});

test('updateMachineMetadata', () async {
final expected = UpdateRobotMetadataResponse()
..metadata = (Struct()..fields['robotKey'] = (Value()..stringValue = 'newRobotValue'));
when(serviceClient.updateMachineMetadata(any)).thenAnswer((_) => MockResponseFuture.value(expected));
final response = await appClient.updateMachineMetadata('robotId', {'robotKey': 'newRobotValue'});
expect(response, equals(expected));
});

test('getMachinePartMetadata', () async {
final expected = GetRobotPartMetadataResponse()
..metadata = (Struct()..fields['partKey'] = (Value()..stringValue = 'partValue'));
when(serviceClient.getMachinePartMetadata(any)).thenAnswer((_) => MockResponseFuture.value(expected));
final response = await appClient.getMachinePartMetadata('partId');
expect(response, equals(expected));
});

test('updateMachinePartMetadata', () async {
final expected = UpdateRobotPartMetadataResponse()
..metadata = (Struct()..fields['partKey'] = (Value()..stringValue = 'newPartValue'));
when(serviceClient.updateMachinePartMetadata(any)).thenAnswer((_) => MockResponseFuture.value(expected));
final response = await appClient.updateMachinePartMetadata('partId', {'partKey': 'newPartValue'});
expect(response, equals(expected));
});
});
}
Loading