Skip to content

Commit f34c505

Browse files
committed
Updated to MsSql.RestApi 0.4
1 parent 8074591 commit f34c505

10 files changed

Lines changed: 475 additions & 164 deletions

File tree

samples/databases/wide-world-importers/wwi-app/Controllers/ODataController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public ODataController(ICommand sqlCommandService)
2020
}
2121

2222

23-
TableSpec salesorders = new TableSpec("WebApi","SalesOrders", "OrderID,OrderDate,CustomerPurchaseOrderNumber,ExpectedDeliveryDate,PickingCompletedWhen,CustomerID,CustomerName,PhoneNumber,FaxNumber,WebsiteURL,DeliveryLocation,SalesPerson,SalesPersonPhone,SalesPersonEmail");
23+
TableSpec salesorders = new TableSpec(schema: "WebApi", table: "SalesOrders", columns: "OrderID,OrderDate,CustomerPurchaseOrderNumber,ExpectedDeliveryDate,PickingCompletedWhen,CustomerID,CustomerName,PhoneNumber,FaxNumber,WebsiteURL,DeliveryLocation,SalesPerson,SalesPersonPhone,SalesPersonEmail");
2424

2525
[HttpGet]
2626
public async Task SalesOrders(int? id)

samples/databases/wide-world-importers/wwi-app/wwi-app.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.1" />
2828
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.2" />
2929
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.3" />
30-
<PackageReference Include="MsSql.RestApi" Version="0.3.1" />
30+
<PackageReference Include="MsSql.RestApi" Version="0.4.0" />
3131
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
3232
</ItemGroup>
3333
<ItemGroup>

samples/databases/wide-world-importers/wwi-azure-functions/Customers.cs

Lines changed: 0 additions & 32 deletions
This file was deleted.

samples/databases/wide-world-importers/wwi-azure-functions/Invoices.cs

Lines changed: 0 additions & 32 deletions
This file was deleted.

samples/databases/wide-world-importers/wwi-azure-functions/ODataFunctions.cs

Lines changed: 406 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<#@ output extension=".cs"#>
2+
<#@ assembly name="Newtonsoft.Json" #>
3+
<#@ template language="C#" hostspecific="True" #>
4+
<#
5+
var o = Newtonsoft.Json.Linq.JObject.Parse(System.IO.File.ReadAllText(this.Host.ResolvePath(".") + "\\local.settings.json"));
6+
var json = o["ApiModel"].ToString();
7+
TableDef[] config = Newtonsoft.Json.JsonConvert.DeserializeObject<TableDef[]>(json);
8+
#>
9+
using Microsoft.AspNetCore.Http;
10+
using Microsoft.AspNetCore.Mvc;
11+
using Microsoft.Azure.WebJobs;
12+
using Microsoft.Azure.WebJobs.Extensions.Http;
13+
using Microsoft.Extensions.Logging;
14+
using MsSql.RestApi;
15+
using System;
16+
using System.Threading.Tasks;
17+
18+
namespace WideWorldImportersFunctions
19+
{
20+
public static class OData
21+
{
22+
<# foreach(var t in config) {#>
23+
<# if(string.IsNullOrEmpty(t.ODataColumns)) continue; #>
24+
[FunctionName("<#= t.Table #>")]
25+
public static async Task<IActionResult> <#= t.Table #>(
26+
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log)
27+
{
28+
log.LogInformation("C# HTTP trigger function processed a request.");
29+
try
30+
{
31+
TableSpec <#= t.Table.ToLower() #> = new TableSpec(schema: "<#= t.Schema #>", table: "<#= t.Table #>", columns: "<#= t.ODataColumns #>");
32+
return await req.OData(<#= t.Table.ToLower() #>).GetResult(Environment.GetEnvironmentVariable("SqlDb"));
33+
}
34+
catch (Exception ex)
35+
{
36+
log.LogError($"C# Http trigger function exception: {ex.Message}");
37+
return new StatusCodeResult(500);
38+
}
39+
}
40+
41+
<# } #>
42+
}
43+
}
44+
<#+
45+
public class TableDef {
46+
public string Schema {get; set;}
47+
public string Table {get; set;}
48+
public string ODataColumns {get; set;}
49+
public bool IsReadOnly {get; set;}
50+
}
51+
#>

samples/databases/wide-world-importers/wwi-azure-functions/SalesOrders.cs

Lines changed: 0 additions & 32 deletions
This file was deleted.

samples/databases/wide-world-importers/wwi-azure-functions/StockItems.cs

Lines changed: 0 additions & 32 deletions
This file was deleted.

samples/databases/wide-world-importers/wwi-azure-functions/Suppliers.cs

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFramework>netstandard2.0</TargetFramework>
44
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
55
<RootNamespace>wwi_azure_functions</RootNamespace>
66
</PropertyGroup>
77
<ItemGroup>
88
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.22" />
9-
<PackageReference Include="MsSql.RestApi" Version="0.3.1" />
9+
<PackageReference Include="MsSql.RestApi" Version="0.4.0" />
1010
</ItemGroup>
1111
<ItemGroup>
1212
<None Update="host.json">
@@ -16,5 +16,19 @@
1616
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1717
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
1818
</None>
19+
<None Update="ODataFunctions.tt">
20+
<Generator>TextTemplatingFileGenerator</Generator>
21+
<LastGenOutput>ODataFunctions.cs</LastGenOutput>
22+
</None>
23+
</ItemGroup>
24+
<ItemGroup>
25+
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
26+
</ItemGroup>
27+
<ItemGroup>
28+
<Compile Update="ODataFunctions.cs">
29+
<DesignTime>True</DesignTime>
30+
<AutoGen>True</AutoGen>
31+
<DependentUpon>ODataFunctions.tt</DependentUpon>
32+
</Compile>
1933
</ItemGroup>
2034
</Project>

0 commit comments

Comments
 (0)