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

Get entity api #5456

Merged
merged 22 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6e0e7c2
mroe quotes
gearama Jan 16, 2024
cd9c1ec
dssf
gearama Jan 16, 2024
3533f8b
Merge branch 'main' of https://github.com/gearama/azure-sdk-for-cpp
gearama Feb 12, 2024
166d493
Merge branch 'main' of https://github.com/gearama/azure-sdk-for-cpp
gearama Feb 15, 2024
1505804
Merge branch 'main' of https://github.com/gearama/azure-sdk-for-cpp
gearama Feb 21, 2024
735ec09
Merge branch 'main' of https://github.com/gearama/azure-sdk-for-cpp
gearama Feb 23, 2024
5f7bab8
Merge branch 'main' of https://github.com/gearama/azure-sdk-for-cpp
gearama Feb 27, 2024
bdd6871
Merge branch 'main' of https://github.com/gearama/azure-sdk-for-cpp
gearama Feb 28, 2024
7db0a2e
Merge branch 'main' of https://github.com/gearama/azure-sdk-for-cpp
gearama Mar 5, 2024
1114279
Merge branch 'main' of https://github.com/gearama/azure-sdk-for-cpp
gearama Mar 7, 2024
d01d911
Merge branch 'main' of https://github.com/gearama/azure-sdk-for-cpp
gearama Mar 12, 2024
15f57ae
Merge branch 'main' of https://github.com/gearama/azure-sdk-for-cpp
gearama Mar 14, 2024
f24d203
getentity
gearama Mar 18, 2024
30d8ffc
Merge branch 'main' of https://github.com/gearama/azure-sdk-for-cpp
gearama Mar 18, 2024
596e50f
ewe
gearama Mar 18, 2024
c4372b9
tests
gearama Mar 18, 2024
576ad30
re
gearama Mar 18, 2024
c3d215d
assets working now
gearama Mar 18, 2024
3e644f5
re
gearama Mar 18, 2024
fd7e64d
fgf
gearama Mar 18, 2024
c702052
clang
gearama Mar 18, 2024
bf445f4
url encode
gearama Mar 19, 2024
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
2 changes: 1 addition & 1 deletion sdk/tables/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "cpp",
"TagPrefix": "cpp/tables",
"Tag": "cpp/tables_ca30219607"
"Tag": "cpp/tables_69657814a3"
}
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,19 @@ namespace Azure { namespace Data { namespace Tables {
Models::QueryEntitiesOptions const& options = {},
Core::Context const& context = {});

/**
* @brief Get one table entity.
*
* @param partitionKey The partition key of the entity.
* @param rowKey The row key of the entity.
* @param context for canceling long running operations.
* @return Entity list paged response.
*/
Response<Models::TableEntity> GetEntity(
Comment on lines +310 to +312
Copy link
Member

Choose a reason for hiding this comment

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

The comment doesn't match the Response<T>. It isn't a paged response.

const std::string& partitionKey,
const std::string& rowKey,
Core::Context const& context = {});

/**
* @brief Creates a new transaction.
*
Expand Down
53 changes: 43 additions & 10 deletions sdk/tables/azure-data-tables/src/tables_clients.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,8 @@ Azure::Response<Models::UpdateEntityResult> TableClient::UpdateEntity(
(void)options;
auto url = m_url;
url.AppendPath(
m_tableName + "(PartitionKey='" + tableEntity.PartitionKey + "',RowKey='" + tableEntity.RowKey
+ "')");
m_tableName + "(PartitionKey='" + Azure::Core::Url::Encode(tableEntity.PartitionKey)
+ "',RowKey='" + Azure::Core::Url::Encode(tableEntity.RowKey) + "')");

std::string jsonBody = Serializers::UpdateEntity(tableEntity);

Expand Down Expand Up @@ -716,8 +716,8 @@ Azure::Response<Models::MergeEntityResult> TableClient::MergeEntity(
(void)options;
auto url = m_url;
url.AppendPath(
m_tableName + "(PartitionKey='" + tableEntity.PartitionKey + "',RowKey='" + tableEntity.RowKey
+ "')");
m_tableName + "(PartitionKey='" + Azure::Core::Url::Encode(tableEntity.PartitionKey)
+ "',RowKey='" + Azure::Core::Url::Encode(tableEntity.RowKey) + "')");

std::string jsonBody = Serializers::MergeEntity(tableEntity);

Expand Down Expand Up @@ -758,8 +758,8 @@ Azure::Response<Models::DeleteEntityResult> TableClient::DeleteEntity(
{
auto url = m_url;
url.AppendPath(
m_tableName + "(PartitionKey='" + tableEntity.PartitionKey + "',RowKey='" + tableEntity.RowKey
+ "')");
m_tableName + "(PartitionKey='" + Azure::Core::Url::Encode(tableEntity.PartitionKey)
+ "',RowKey='" + Azure::Core::Url::Encode(tableEntity.RowKey) + "')");

Core::Http::Request request(Core::Http::HttpMethod::Delete, url);

Expand Down Expand Up @@ -820,6 +820,39 @@ void Models::QueryEntitiesPagedResponse::OnNextPage(const Azure::Core::Context&
*this = m_tableClient->QueryEntities(m_operationOptions, context);
}

Azure::Response<Models::TableEntity> TableClient::GetEntity(
const std::string& partitionKey,
const std::string& rowKey,
Core::Context const& context)
{
auto url = m_url;
url.AppendPath(
m_tableName + "(PartitionKey='" + Azure::Core::Url::Encode(partitionKey) + "',RowKey='"
+ Azure::Core::Url::Encode(rowKey) + "')");

Core::Http::Request request(Core::Http::HttpMethod::Get, url);
request.SetHeader("Accept", "application/json;odata=fullmetadata");

auto rawResponse = m_pipeline->Send(request, context);
auto const httpStatusCode = rawResponse->GetStatusCode();
if (httpStatusCode != Core::Http::HttpStatusCode::Ok)
{
throw Core::RequestFailedException(rawResponse);
}
Comment on lines +837 to +841
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a test for the non-happy error path here?


Models::TableEntity response{};
{
const auto& responseBody = rawResponse->GetBody();
std::string responseString = std::string(responseBody.begin(), responseBody.end());

auto const jsonRoot
= Azure::Core::Json::_internal::json::parse(responseBody.begin(), responseBody.end());

response = Serializers::DeserializeEntity(jsonRoot);
}
return Response<Models::TableEntity>(std::move(response), std::move(rawResponse));
}

Models::QueryEntitiesPagedResponse TableClient::QueryEntities(
Models::QueryEntitiesOptions const& options,
Core::Context const& context)
Expand All @@ -828,23 +861,23 @@ Models::QueryEntitiesPagedResponse TableClient::QueryEntities(
std::string appendPath = m_tableName + "(";
if (!options.PartitionKey.empty())
{
appendPath += "PartitionKey='" + options.PartitionKey + "'";
appendPath += "PartitionKey='" + Azure::Core::Url::Encode(options.PartitionKey) + "'";
}
if (!options.RowKey.empty())
{
appendPath += ",RowKey='" + options.RowKey + "'";
appendPath += ",RowKey='" + Azure::Core::Url::Encode(options.RowKey) + "'";
}
appendPath += ")";

url.AppendPath(appendPath);

if (options.Filter.HasValue())
{
url.AppendQueryParameter("$filter", options.Filter.Value());
url.AppendQueryParameter("$filter", Azure::Core::Url::Encode(options.Filter.Value()));
}
if (!options.SelectColumns.empty())
{
url.AppendQueryParameter("$select", options.SelectColumns);
url.AppendQueryParameter("$select", Azure::Core::Url::Encode(options.SelectColumns));
}

Core::Http::Request request(Core::Http::HttpMethod::Get, url);
Expand Down
35 changes: 35 additions & 0 deletions sdk/tables/azure-data-tables/test/ut/table_client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,41 @@ namespace Azure { namespace Data { namespace Test {
EXPECT_EQ(responseQuery.TableEntities.size(), 1);
}

TEST_P(TablesClientTest, EntityGet)
{
if (GetParam() == AuthType::Key)
{
EXPECT_TRUE(true);
return;
}
Comment on lines +474 to +478
Copy link
Member

Choose a reason for hiding this comment

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

Why do we have this type of parameterized test if it doesn't make sense here? Deserves a comment.

Azure::Data::Tables::Models::TableEntity entity;

entity.PartitionKey = "P1";
entity.RowKey = "R1";
entity.Properties["Name"] = "Azure";
entity.Properties["Product"] = "Tables";
auto createResponse = m_tableServiceClient->CreateTable(m_tableName);
auto response = m_tableClient->CreateEntity(entity);
EXPECT_EQ(response.RawResponse->GetStatusCode(), Azure::Core::Http::HttpStatusCode::NoContent);
EXPECT_FALSE(response.Value.ETag.empty());

entity.Properties["Product"] = "Tables2";
entity.RowKey = "R2";
m_tableClient->CreateEntity(entity);

entity.Properties["Product"] = "Tables3";
entity.RowKey = "R3";
m_tableClient->CreateEntity(entity);

std::string partitionKey = "P1";
std::string rowKey = "R1";
auto responseQuery = m_tableClient->GetEntity(partitionKey, rowKey);
EXPECT_EQ(responseQuery.Value.PartitionKey, "P1");
EXPECT_EQ(responseQuery.Value.RowKey, "R1");
EXPECT_EQ(responseQuery.Value.Properties["Name"], "Azure");
EXPECT_EQ(responseQuery.Value.Properties["Product"], "Tables");
}

TEST_P(TablesClientTest, TransactionCreateFail_LIVEONLY_)
{
Azure::Data::Tables::Models::TableEntity entity;
Expand Down