Skip to content

[RSDK-10127] Add get and update metadata functions #360

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

Merged
merged 3 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions lib/src/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -729,4 +729,76 @@ 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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor/nit) can we rename to organizationId or orgId? it's more specific and more consistent with similar calls elsewhere in the SDK.

Same comment applies to below methods.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great catch, thanks for calling this out

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<void> updateOrganizationMetadata(String id, Map<String, dynamic> data) async {
final request = UpdateOrganizationMetadataRequest()
..organizationId = id
..data = _mapToStruct(data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_mapToStruct is undefined, which is causing errors. I think what you're looking for is data.toStruct().

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<void> updateLocationMetadata(String id, Map<String, dynamic> data) async {
final request = UpdateLocationMetadataRequest()
..locationId = id
..data = _mapToStruct(data);
await _client.updateLocationMetadata(request);
}

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

/// Updates user-defined [Metadata] for a robot.
///
/// For more information, see [Fleet Management API](https://docs.viam.com/appendix/apis/fleet/).
Future<void> updateRobotMetadata(String id, Map<String, dynamic> data) async {
final request = UpdateRobotMetadataRequest()
..id = id
..data = _mapToStruct(data);
await _client.updateRobotMetadata(request);
}

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

/// Updates user-defined [Metadata] for a robot part.
///
/// For more information, see [Fleet Management API](https://docs.viam.com/appendix/apis/fleet/).
Future<void> updateRobotPartMetadata(String id, Map<String, dynamic> data) async {
final request = UpdateRobotPartMetadataRequest()
..id = id
..data = _mapToStruct(data);
await _client.updateRobotPartMetadata(request);
}
}
7 changes: 7 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,12 @@ void main() {
final response = await appClient.createKeyFromExistingKeyAuthorizations('id');
expect(response, equals(expected));
});

test('getOrganizationMetadata', () async {
final expected = GetOrganizationMetadataResponse()..data = (Struct()..fields['key'] = (Value()..stringValue = 'value'));
when(serviceClient.getOrganizationMetadata(any)).thenAnswer((_) => MockResponseFuture.value(expected));
final response = await appClient.getOrganizationMetadata('orgId');
expect(response, equals(expected));
});
Comment on lines +758 to +763
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test looks good, but we should probably add tests for all the other methods you implemented as well!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Naveed and I were just debugging before I put all of the tests up - thanks for calling this out!

});
}
Loading