Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
update logging
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewKorchemniy committed Dec 7, 2023
1 parent c6e9f29 commit 809cc4d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
1 change: 1 addition & 0 deletions AddInventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public async Task<IActionResult> Run(
var result = await _inventoryService.AddInventoryAsync(newInventory, client, log);

string responseMessage = $"Added inventory \"{newInventory.name}\" to company \"{companyName}\" ";
log.LogInformation(responseMessage);

if (result) {
return new OkObjectResult(responseMessage);
Expand Down
1 change: 1 addition & 0 deletions AddItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public async Task<IActionResult> Run(
var result = await _inventoryService.AddItemAsync(newItem, client, log);

string responseMessage = $"Added item \"{newItem.name}\" to \"{companyName}\"/\"{inventoryName}\"";
log.LogInformation(responseMessage);

if (result) {
return new OkObjectResult(responseMessage);
Expand Down
1 change: 1 addition & 0 deletions AddUsername.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public async Task<IActionResult> Run(
var result = await _inventoryService.AddUserAsync(newUser, client, log);

string responseMessage = $"Added username \"{newUser.name}\" to \"{companyName}\"/\"{inventoryName}\"";
log.LogInformation(responseMessage);

if (result) {
return new OkObjectResult(responseMessage);
Expand Down
8 changes: 2 additions & 6 deletions InventoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public InventoryService(ILogger logger)
public async Task<bool> AddInventoryAsync(Inventory inventory, CosmosClient client, ILogger log)
{
Container container = client.GetDatabase("IMS").GetContainer("Inventories");
log.LogInformation($"Add inventory {inventory.name} in {inventory.companyName}");
var result = await container.CreateItemAsync(inventory);

if (result.StatusCode == System.Net.HttpStatusCode.Created)
Expand All @@ -40,7 +39,6 @@ public async Task<bool> AddInventoryAsync(Inventory inventory, CosmosClient clie
public async Task<IEnumerable<Inventory>> GetInventoriesAsync(string companyName, CosmosClient client, ILogger log)
{
Container container = client.GetDatabase("IMS").GetContainer("Inventories");
log.LogInformation($"Searching for Pending Jokes");
QueryDefinition queryDefinition = new QueryDefinition(
$"SELECT * FROM Inventories i WHERE i.companyName = @companyName")
.WithParameter("@companyName", companyName);
Expand All @@ -60,7 +58,6 @@ public async Task<IEnumerable<Inventory>> GetInventoriesAsync(string companyName
public async Task<bool> AddUserAsync(User user, CosmosClient client, ILogger log)
{
Container container = client.GetDatabase("IMS").GetContainer("Usernames");
log.LogInformation($"Add user {user.name} in {user.companyName}/{user.inventoryName}");
var result = await container.CreateItemAsync(user);

if (result.StatusCode == System.Net.HttpStatusCode.Created)
Expand All @@ -76,7 +73,7 @@ public async Task<bool> AddUserAsync(User user, CosmosClient client, ILogger log
public async Task<IEnumerable<User>> GetUsersAsync(string companyName, string inventoryName, CosmosClient client, ILogger log)
{
Container container = client.GetDatabase("IMS").GetContainer("Usernames");
log.LogInformation($"Searching for Usernames");
log.LogInformation($"Searching for username in {companyName}/{inventoryName}");
QueryDefinition queryDefinition = new QueryDefinition(
$"SELECT * FROM Usernames i WHERE i.companyName = @companyName AND i.inventoryName = @inventoryName")
.WithParameter("@companyName", companyName)
Expand Down Expand Up @@ -113,7 +110,7 @@ public async Task<bool> AddItemAsync(Item item, CosmosClient client, ILogger log
public async Task<IEnumerable<Item>> GetItemsAsync(string companyName, string inventoryName, CosmosClient client, ILogger log)
{
Container container = client.GetDatabase("IMS").GetContainer("Items");
log.LogInformation($"Searching for Items");
log.LogInformation($"Searching for items in {companyName}/{inventoryName}");
QueryDefinition queryDefinition = new QueryDefinition(
$"SELECT * FROM Items i WHERE i.companyName = @companyName AND i.inventoryName = @inventoryName")
.WithParameter("@companyName", companyName)
Expand All @@ -136,7 +133,6 @@ public async Task<IEnumerable<Item>> GetItemsAsync(string companyName, string in
public async Task<ActionResult> DeleteItemAsync(string itemId, string companyName, string inventoryName, CosmosClient client, ILogger log)
{
Container container = client.GetDatabase("IMS").GetContainer("Items");
log.LogInformation($"Delete item {itemId} in {companyName}/{inventoryName}");
var result = await container.DeleteItemAsync<Item>(itemId, new PartitionKey(companyName));

if (result.StatusCode == System.Net.HttpStatusCode.NoContent)
Expand Down

0 comments on commit 809cc4d

Please sign in to comment.