Skip to content

Commit ec9873f

Browse files
committed
Added partition keys to Cosmos DB get single item and delete item methods
1 parent 0bbe445 commit ec9873f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

dotnet/ServerlessMicroservices.Shared/Services/CosmosPersistenceService.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public async Task<DriverItem> RetrieveDriver(string code)
5858
// NOTE: ReadDocumentAsync is really fast in Cosmos as it bypasses all indexing...but it requires the doc ID
5959
var docId = $"{code.ToUpper()}-{ItemCollectionTypes.Driver}";
6060
RequestOptions options = new RequestOptions() { PartitionKey = new Microsoft.Azure.Documents.PartitionKey(code.ToUpper()) };
61-
var request = (await GetDocDBClient(_settingService)).ReadDocumentAsync<DriverItem>(UriFactory.CreateDocumentUri(_docDbDatabaseName, _docDbDigitalMainCollectionName, docId)/*, options*/);
61+
var request = (await GetDocDBClient(_settingService)).ReadDocumentAsync<DriverItem>(UriFactory.CreateDocumentUri(_docDbDatabaseName, _docDbDigitalMainCollectionName, docId), options);
6262
cost = request.Result.RequestCharge;
6363
return request.Result;
6464
}
@@ -346,8 +346,8 @@ public async Task DeleteDriver(string code)
346346
throw new Exception($"Unable to locate a driver with code {code}");
347347

348348
var link = (string)driver.Self;
349-
//RequestOptions requestOptions = new RequestOptions { PartitionKey = new Microsoft.Azure.Documents.PartitionKey(driver.Code.ToUpper()) };
350-
var response = await(await GetDocDBClient(_settingService)).DeleteDocumentAsync(link /*,requestOptions*/);
349+
RequestOptions requestOptions = new RequestOptions { PartitionKey = new Microsoft.Azure.Documents.PartitionKey(code.ToUpper()) };
350+
var response = await(await GetDocDBClient(_settingService)).DeleteDocumentAsync(link, requestOptions);
351351
cost += response.RequestCharge;
352352

353353
//TODO: Also delete the associated driver location items
@@ -380,7 +380,7 @@ public async Task<TripItem> RetrieveTrip(string code)
380380
// NOTE: ReadDocumentAsync is really fast in Cosmos as it bypasses all indexing...but it requires the doc ID
381381
var docId = $"{code.ToUpper()}-{ItemCollectionTypes.Trip}";
382382
RequestOptions options = new RequestOptions() { PartitionKey = new Microsoft.Azure.Documents.PartitionKey(code.ToUpper()) };
383-
var request = (await GetDocDBClient(_settingService)).ReadDocumentAsync<TripItem>(UriFactory.CreateDocumentUri(_docDbDatabaseName, _docDbDigitalMainCollectionName, docId)/*, options*/);
383+
var request = (await GetDocDBClient(_settingService)).ReadDocumentAsync<TripItem>(UriFactory.CreateDocumentUri(_docDbDatabaseName, _docDbDigitalMainCollectionName, docId), options);
384384
cost = request.Result.RequestCharge;
385385
return request.Result;
386386
}
@@ -612,8 +612,8 @@ public async Task DeleteTrip(string code)
612612
throw new Exception($"Unable to locate a trip with code {code}");
613613

614614
var link = (string)trip.Self;
615-
//RequestOptions requestOptions = new RequestOptions { PartitionKey = new Microsoft.Azure.Documents.PartitionKey(driver.Code.ToUpper()) };
616-
var response = await (await GetDocDBClient(_settingService)).DeleteDocumentAsync(link /*,requestOptions*/);
615+
RequestOptions requestOptions = new RequestOptions { PartitionKey = new Microsoft.Azure.Documents.PartitionKey(code.ToUpper()) };
616+
var response = await (await GetDocDBClient(_settingService)).DeleteDocumentAsync(link, requestOptions);
617617
cost += response.RequestCharge;
618618

619619
await _changeNotifierService.TripDeleted(trip);

0 commit comments

Comments
 (0)