Skip to content

Commit

Permalink
Merge pull request #11 from yorek/main
Browse files Browse the repository at this point in the history
Other fixes
  • Loading branch information
JetterMcTedder authored Sep 30, 2024
2 parents 139fd14 + aa76a99 commit 0afc4b3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/1-Getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ swa --version
* [git](https://git-scm.com/downloads)
* [Azure Data Studio](https://learn.microsoft.com/sql/azure-data-studio/download-azure-data-studio)
* [Azure Functions Core Tools](https://learn.microsoft.com/azure/azure-functions/functions-run-local?tabs=v4%2Cwindows%2Ccsharp%2Cportal%2Cbash#install-the-azure-functions-core-tools)
* [.NET SDK 6+](https://dotnet.microsoft.com/download/dotnet/7.0)
* [.NET SDK 8+](https://dotnet.microsoft.com/download/dotnet/8.0)
* [Go-sqlcmd](https://github.com/microsoft/go-sqlcmd)
* [SqlPackage](https://learn.microsoft.com/sql/tools/sqlpackage/sqlpackage-download)
* [Data API Builder](https://github.com/Azure/data-api-builder)
Expand Down
8 changes: 7 additions & 1 deletion docs/11-sql-bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ In this section, you will create a change data stream using Change Tracking, the

1. If you didn't already, **save the file**.
1. In the terminal run the following code:
```C#
dotnet add package Newtonsoft.Json
```
to make sure the needed Newtonsoft.Json is installed.
### Testing the trigger
1. Now that the function code is done, we need to provide it a value for the `connection-string` Azure Function setting. If you remember, back in the `.env` in the root directory,
Expand Down Expand Up @@ -254,4 +260,4 @@ In this section, you will create a change data stream using Change Tracking, the

## Continue to chapter 12

Click [here](./12-github-actions.md) to continue to chapter 12, GitHub Actions!
Click [here](./12-github-actions.md) to continue to chapter 12, GitHub Actions!
22 changes: 18 additions & 4 deletions workshop-assets/func/HttpTriggerFunctionSQL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,33 @@
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Text.Json;

namespace func
{
public class Payload
{
public string? currency { get; set; }
}

public class HttpTriggerFunctionSQL(ILogger<HttpTriggerFunctionSQL> logger)
{
private readonly ILogger<HttpTriggerFunctionSQL> _logger = logger;

[Function(nameof(ConvertCurrency))]
public IActionResult ConvertCurrency([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req, [FromBody] dynamic data)
public async Task<IActionResult> ConvertCurrency([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req)
{
string? currency = req.Query["currency"];
currency ??= data?.currency ?? "USD";


string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
if (!string.IsNullOrEmpty(requestBody))
{
Payload? data = JsonSerializer.Deserialize<Payload>(requestBody);
Console.WriteLine(JsonSerializer.Serialize(data));
currency ??= data?.currency;
}
currency ??= "USD";

double conversion = currency switch
{
"JPY" => 147.81,
Expand All @@ -26,7 +40,7 @@ public IActionResult ConvertCurrency([HttpTrigger(AuthorizationLevel.Anonymous,
}

[Function(nameof(GetKeys))]
public IActionResult GetKeys([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req, [FromBody] dynamic data)
public IActionResult GetKeys([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req)
{
string openAIKey = Environment.GetEnvironmentVariable("OPENAI_KEY") ?? "N/A";
string languageServiceKey = Environment.GetEnvironmentVariable("LANGUAGE_SERVICE_KEY") ?? "N/A";
Expand Down

0 comments on commit 0afc4b3

Please sign in to comment.