Skip to content

Commit 9cd4497

Browse files
author
Samuel Abraham
committed
v9.1.2
1 parent 55540ea commit 9cd4497

4 files changed

Lines changed: 71 additions & 69 deletions

File tree

src/TypeCache.Web/Extensions/EndpointRouteBuilderExtensions.API.cs

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.Extensions.DependencyInjection;
88
using TypeCache.Web.Filters;
99
using TypeCache.Web.Handlers;
10+
using static Microsoft.AspNetCore.Http.StatusCodes;
1011
using static System.Net.Mime.MediaTypeNames;
1112

1213
namespace TypeCache.Web.Extensions;
@@ -24,14 +25,14 @@ public static partial class EndpointRouteBuilderExtensions
2425
/// Maps endpoints that execute SQL commands either atomically or in a single local transaction.<br/>
2526
/// These calls are all POSTs for webhook compatibility. Do <b>NOT</b> expose these publicly.
2627
/// <code>
27-
/// POST /api/execute/{dataSource}/{database}/{schema}/{procedure}<br/>
28-
/// POST /api/delete/{dataSource}/{database}/{schema}/{table}<br/>
29-
/// POST /api/delete-values/{dataSource}/{database}/{schema}/{table}<br/>
30-
/// POST /api/insert/{dataSource}/{database}/{schema}/{table}<br/>
31-
/// POST /api/insert-values/{dataSource}/{database}/{schema}/{table}<br/>
32-
/// POST /api/select/{dataSource}/{database}/{schema}/{table}<br/>
33-
/// POST /api/update/{dataSource}/{database}/{schema}/{table}<br/>
34-
/// POST /api/update-values/{dataSource}/{database}/{schema}/{table}<br/>
28+
/// POST /api/execute/{source}/{database}/{schema}/{procedure}<br/>
29+
/// POST /api/delete/{source}/{database}/{schema}/{table}<br/>
30+
/// POST /api/delete-values/{source}/{database}/{schema}/{table}<br/>
31+
/// POST /api/insert/{source}/{database}/{schema}/{table}<br/>
32+
/// POST /api/insert-values/{source}/{database}/{schema}/{table}<br/>
33+
/// POST /api/select/{source}/{database}/{schema}/{table}<br/>
34+
/// POST /api/update/{source}/{database}/{schema}/{table}<br/>
35+
/// POST /api/update-values/{source}/{database}/{schema}/{table}<br/>
3536
/// </code>
3637
/// </summary>
3738
public static RouteGroupBuilder MapSqlApi(this IEndpointRouteBuilder @this, string route = Route.API)
@@ -55,7 +56,7 @@ public static RouteGroupBuilder MapSqlApi(this IEndpointRouteBuilder @this, stri
5556
}
5657

5758
/// <summary>
58-
/// <c>POST /api/execute/{dataSource}/{database}/{schema}/{procedure}</c><br/><br/>
59+
/// <c>POST /api/execute/{source}/{database}/{schema}/{procedure}</c><br/><br/>
5960
/// <i><b>Requires calls to:</b></i>
6061
/// <code>
6162
/// MapGroup("/api")<br/>
@@ -70,12 +71,12 @@ public static RouteHandlerBuilder MapSqlApiExecuteProcedure(this IEndpointRouteB
7071
.WithDescription("Executes a stored procedure returning any result(s).")
7172
.WithHttpLogging(HTTP_LOGGING)
7273
.AddEndpointFilter<SqlApiProcedureEndpointFilter>()
73-
.Produces(StatusCodes.Status200OK, contentType: Application.Json)
74-
.Produces(StatusCodes.Status204NoContent)
75-
.Produces(StatusCodes.Status404NotFound, contentType: Text.Plain);
74+
.Produces(Status200OK, contentType: Application.Json)
75+
.Produces(Status204NoContent)
76+
.Produces(Status404NotFound, contentType: Text.Plain);
7677

7778
/// <summary>
78-
/// <c>POST /api/delete/{dataSource}/{database}/{schema}/{table}</c><br/><br/>
79+
/// <c>POST /api/delete/{source}/{database}/{schema}/{table}</c><br/><br/>
7980
/// <i><b>Requires calls to:</b></i>
8081
/// <code>
8182
/// MapGroup("/api")<br/>
@@ -90,12 +91,12 @@ public static RouteHandlerBuilder MapSqlApiDelete(this IEndpointRouteBuilder @th
9091
.WithDescription("Executes an atomic SQL DELETE command against a table.")
9192
.WithHttpLogging(HTTP_LOGGING)
9293
.AddEndpointFilter<SqlApiTableEndpointFilter>()
93-
.Produces(StatusCodes.Status200OK, contentType: Application.Json)
94-
.Produces(StatusCodes.Status204NoContent)
95-
.Produces(StatusCodes.Status404NotFound, contentType: Text.Plain);
94+
.Produces(Status200OK, contentType: Application.Json)
95+
.Produces(Status204NoContent)
96+
.Produces(Status404NotFound, contentType: Text.Plain);
9697

9798
/// <summary>
98-
/// <c>POST /api/delete-values/{dataSource}/{database}/{schema}/{table}</c><br/><br/>
99+
/// <c>POST /api/delete-values/{source}/{database}/{schema}/{table}</c><br/><br/>
99100
/// Body is an array of data whose property names match the primary keys of the table to delete from.<br/><br/>
100101
/// <i><b>Requires calls to:</b></i>
101102
/// <code>
@@ -111,12 +112,12 @@ public static RouteHandlerBuilder MapSqlApiDeleteValues(this IEndpointRouteBuild
111112
.WithDescription("Executes a batch of SQL DELETE commands against a table.")
112113
.WithHttpLogging(HTTP_LOGGING)
113114
.AddEndpointFilter<SqlApiTableEndpointFilter>()
114-
.Produces(StatusCodes.Status200OK, contentType: Application.Json)
115-
.Produces(StatusCodes.Status204NoContent)
116-
.Produces(StatusCodes.Status404NotFound, contentType: Text.Plain);
115+
.Produces(Status200OK, contentType: Application.Json)
116+
.Produces(Status204NoContent)
117+
.Produces(Status404NotFound, contentType: Text.Plain);
117118

118119
/// <summary>
119-
/// <c>POST /api/insert/{dataSource}/{database}/{schema}/{table}</c><br/><br/>
120+
/// <c>POST /api/insert/{source}/{database}/{schema}/{table}</c><br/><br/>
120121
/// <i><b>Requires calls to:</b></i>
121122
/// <code>
122123
/// MapGroup("/api")<br/>
@@ -131,12 +132,12 @@ public static RouteHandlerBuilder MapSqlApiInsert(this IEndpointRouteBuilder @th
131132
.WithDescription("Executes an atomic SQL INSERT command against a table.")
132133
.WithHttpLogging(HTTP_LOGGING)
133134
.AddEndpointFilter<SqlApiTableEndpointFilter>()
134-
.Produces(StatusCodes.Status200OK, contentType: Application.Json)
135-
.Produces(StatusCodes.Status204NoContent)
136-
.Produces(StatusCodes.Status404NotFound, contentType: Text.Plain);
135+
.Produces(Status200OK, contentType: Application.Json)
136+
.Produces(Status204NoContent)
137+
.Produces(Status404NotFound, contentType: Text.Plain);
137138

138139
/// <summary>
139-
/// <c>POST /api/insert-values/{dataSource}/{database}/{schema}/{table}</c><br/><br/>
140+
/// <c>POST /api/insert-values/{source}/{database}/{schema}/{table}</c><br/><br/>
140141
/// Body is an array of data whose property names match the primary keys of the table to delete from.<br/><br/>
141142
/// <i><b>Requires calls to:</b></i>
142143
/// <code>
@@ -152,12 +153,12 @@ public static RouteHandlerBuilder MapSqlApiInsertValues(this IEndpointRouteBuild
152153
.WithDescription("Executes batch of SQL INSERT commands against a table.")
153154
.WithHttpLogging(HTTP_LOGGING)
154155
.AddEndpointFilter<SqlApiTableEndpointFilter>()
155-
.Produces(StatusCodes.Status200OK, contentType: Application.Json)
156-
.Produces(StatusCodes.Status204NoContent)
157-
.Produces(StatusCodes.Status404NotFound, contentType: Text.Plain);
156+
.Produces(Status200OK, contentType: Application.Json)
157+
.Produces(Status204NoContent)
158+
.Produces(Status404NotFound, contentType: Text.Plain);
158159

159160
/// <summary>
160-
/// <c>POST /api/select/{dataSource}/{database}/{schema}/{table}</c><br/><br/>
161+
/// <c>POST /api/select/{source}/{database}/{schema}/{table}</c><br/><br/>
161162
/// Selects, filters, sorts and pages data from a view.<br/><br/>
162163
/// <i><b>Requires calls to:</b></i>
163164
/// <code>
@@ -173,12 +174,12 @@ public static RouteHandlerBuilder MapSqlApiSelect(this IEndpointRouteBuilder @th
173174
.WithDescription("Retrieves data from a table or view via a SELECT SQL command.")
174175
.WithHttpLogging(HTTP_LOGGING)
175176
.AddEndpointFilter<SqlApiTableEndpointFilter>()
176-
.Produces(StatusCodes.Status200OK, contentType: Application.Json)
177-
.Produces(StatusCodes.Status204NoContent)
178-
.Produces(StatusCodes.Status404NotFound, contentType: Text.Plain);
177+
.Produces(Status200OK, contentType: Application.Json)
178+
.Produces(Status204NoContent)
179+
.Produces(Status404NotFound, contentType: Text.Plain);
179180

180181
/// <summary>
181-
/// <c>POST /api/update/{dataSource}/{database}/{schema}/{table}</c><br/><br/>
182+
/// <c>POST /api/update/{source}/{database}/{schema}/{table}</c><br/><br/>
182183
/// Updates table data.<br/><br/>
183184
/// <i><b>Requires calls to:</b></i>
184185
/// <code>
@@ -194,12 +195,12 @@ public static RouteHandlerBuilder MapSqlApiUpdate(this IEndpointRouteBuilder @th
194195
.WithDescription("Executes an atomic SQL UPDATE command against a table.")
195196
.WithHttpLogging(HTTP_LOGGING)
196197
.AddEndpointFilter<SqlApiTableEndpointFilter>()
197-
.Produces(StatusCodes.Status200OK, contentType: Application.Json)
198-
.Produces(StatusCodes.Status204NoContent)
199-
.Produces(StatusCodes.Status404NotFound, contentType: Text.Plain);
198+
.Produces(Status200OK, contentType: Application.Json)
199+
.Produces(Status204NoContent)
200+
.Produces(Status404NotFound, contentType: Text.Plain);
200201

201202
/// <summary>
202-
/// <c>POST /api/update-values/{dataSource}/{database}/{schema}/{table}</c><br/><br/>
203+
/// <c>POST /api/update-values/{source}/{database}/{schema}/{table}</c><br/><br/>
203204
/// Updates table data.<br/><br/>
204205
/// Body is an array of data that contains values to update in the table.<br/><br/>
205206
/// <i><b>Requires calls to:</b></i>
@@ -216,7 +217,7 @@ public static RouteHandlerBuilder MapSqlApiUpdateValues(this IEndpointRouteBuild
216217
.WithDescription("Executes an atomic SQL UPDATE command against a table.")
217218
.WithHttpLogging(HTTP_LOGGING)
218219
.AddEndpointFilter<SqlApiTableEndpointFilter>()
219-
.Produces(StatusCodes.Status200OK, contentType: Application.Json)
220-
.Produces(StatusCodes.Status204NoContent)
221-
.Produces(StatusCodes.Status404NotFound, contentType: Text.Plain);
220+
.Produces(Status200OK, contentType: Application.Json)
221+
.Produces(Status204NoContent)
222+
.Produces(Status404NotFound, contentType: Text.Plain);
222223
}

src/TypeCache.Web/Extensions/EndpointRouteBuilderExtensions.SQL.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ public static partial class EndpointRouteBuilderExtensions
1515
/// <summary>
1616
/// Maps SQL API endpoints that return composed SQL <b><i>(for testing purposes only).</i></b>
1717
/// <code>
18-
/// GET /sql/schema/{dataSource}/{database}/{collection}<br/>
19-
/// GET /sql/delete/{dataSource}/{database}/{schema}/{table}<br/>
20-
/// GET /sql/delete-values/{dataSource}/{database}/{schema}/{table}<br/>
21-
/// GET /sql/insert/{dataSource}/{database}/{schema}/{table}<br/>
22-
/// GET /sql/insert-values/{dataSource}/{database}/{schema}/{table}<br/>
23-
/// GET /sql/select/{dataSource}/{database}/{schema}/{table}<br/>
24-
/// GET /sql/update/{dataSource}/{database}/{schema}/{table}<br/>
25-
/// GET /sql/update-values/{dataSource}/{database}/{schema}/{table}<br/>
18+
/// GET /sql/schema/{source}/{database}/{collection}<br/>
19+
/// GET /sql/delete/{source}/{database}/{schema}/{table}<br/>
20+
/// GET /sql/delete-values/{source}/{database}/{schema}/{table}<br/>
21+
/// GET /sql/insert/{source}/{database}/{schema}/{table}<br/>
22+
/// GET /sql/insert-values/{source}/{database}/{schema}/{table}<br/>
23+
/// GET /sql/select/{source}/{database}/{schema}/{table}<br/>
24+
/// GET /sql/update/{source}/{database}/{schema}/{table}<br/>
25+
/// GET /sql/update-values/{source}/{database}/{schema}/{table}<br/>
2626
/// </code>
2727
/// </summary>
2828
public static RouteGroupBuilder MapSqlGet(this IEndpointRouteBuilder @this, string route = Route.SQL)
@@ -45,7 +45,7 @@ public static RouteGroupBuilder MapSqlGet(this IEndpointRouteBuilder @this, stri
4545
}
4646

4747
/// <summary>
48-
/// <c>GET /sql/schema/{dataSource}/{database}/{collection}</c><br/><br/>
48+
/// <c>GET /sql/schema/{source}/{database}/{collection}</c><br/><br/>
4949
/// Gets database schema data.
5050
/// <i><b>Requires calls to:</b></i>
5151
/// <code>
@@ -66,7 +66,7 @@ public static RouteHandlerBuilder MapGetDatabaseSchema(this IEndpointRouteBuilde
6666
.Produces(StatusCodes.Status404NotFound, contentType: Text.Plain);
6767

6868
/// <summary>
69-
/// <c>GET /sql/delete/{dataSource}/{database}/{schema}/{table}</c><br/><br/>
69+
/// <c>GET /sql/delete/{source}/{database}/{schema}/{table}</c><br/><br/>
7070
/// Returns generated SQL statement.<br/><br/>
7171
/// <i><b>Requires calls to:</b></i>
7272
/// <code>
@@ -88,7 +88,7 @@ public static RouteHandlerBuilder MapGetDeleteSQL(this IEndpointRouteBuilder @th
8888
.Produces(StatusCodes.Status404NotFound, contentType: Text.Plain);
8989

9090
/// <summary>
91-
/// <c>POST /sql/delete-values/{dataSource}/{database}/{schema}/{table}</c><br/><br/>
91+
/// <c>POST /sql/delete-values/{source}/{database}/{schema}/{table}</c><br/><br/>
9292
/// Body is an array of data whose property names match the primary keys of the table to delete from.<br/><br/>
9393
/// Returns generated SQL statement.<br/><br/>
9494
/// <i><b>Requires calls to:</b></i>
@@ -110,7 +110,7 @@ public static RouteHandlerBuilder MapGetDeleteValuesSQL(this IEndpointRouteBuild
110110
.Produces(StatusCodes.Status404NotFound, contentType: Text.Plain);
111111

112112
/// <summary>
113-
/// <c>GET /sql/insert/{dataSource}/{database}/{schema}/{table}</c><br/><br/>
113+
/// <c>GET /sql/insert/{source}/{database}/{schema}/{table}</c><br/><br/>
114114
/// Returns generated SQL statement.<br/><br/>
115115
/// <i><b>Requires calls to:</b></i>
116116
/// <code>
@@ -131,7 +131,7 @@ public static RouteHandlerBuilder MapGetInsertSQL(this IEndpointRouteBuilder @th
131131
.Produces(StatusCodes.Status404NotFound, contentType: Text.Plain);
132132

133133
/// <summary>
134-
/// <c>POST /sql/insert-values/{dataSource}/{database}/{schema}/{table}</c><br/><br/>
134+
/// <c>POST /sql/insert-values/{source}/{database}/{schema}/{table}</c><br/><br/>
135135
/// Body is an array of data that would be inserted.<br/><br/>
136136
/// Returns generated SQL statement.<br/><br/>
137137
/// <i><b>Requires calls to:</b></i>
@@ -153,7 +153,7 @@ public static RouteHandlerBuilder MapGetInsertValuesSQL(this IEndpointRouteBuild
153153
.Produces(StatusCodes.Status404NotFound, contentType: Text.Plain);
154154

155155
/// <summary>
156-
/// <c>GET /sql/select/{dataSource}/{database}/{schema}/{table}</c><br/><br/>
156+
/// <c>GET /sql/select/{source}/{database}/{schema}/{table}</c><br/><br/>
157157
/// Returns generated SQL statement.<br/><br/>
158158
/// <i><b>Requires calls to:</b></i>
159159
/// <code>
@@ -173,7 +173,7 @@ public static RouteHandlerBuilder MapGetSelectSQL(this IEndpointRouteBuilder @th
173173
.Produces(StatusCodes.Status404NotFound, contentType: Text.Plain);
174174

175175
/// <summary>
176-
/// <c>GET /sql/update/{dataSource}/{database}/{schema}/{table}</c><br/><br/>
176+
/// <c>GET /sql/update/{source}/{database}/{schema}/{table}</c><br/><br/>
177177
/// Returns generated SQL statement.<br/><br/>
178178
/// <i><b>Requires calls to:</b></i>
179179
/// <code>
@@ -193,7 +193,7 @@ public static RouteHandlerBuilder MapGetUpdateSQL(this IEndpointRouteBuilder @th
193193
.Produces(StatusCodes.Status404NotFound, contentType: Text.Plain);
194194

195195
/// <summary>
196-
/// <c>POST /sql/update-values/{dataSource}/{database}/{schema}/{table}</c><br/><br/>
196+
/// <c>POST /sql/update-values/{source}/{database}/{schema}/{table}</c><br/><br/>
197197
/// Body is an array of data with values tp use for update.<br/><br/>
198198
/// Returns generated SQL statement.<br/><br/>
199199
/// <i><b>Requires calls to:</b></i>

src/TypeCache.Web/Extensions/EndpointRouteBuilderExtensions.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.Extensions.Primitives;
1010
using TypeCache.Converters;
1111
using TypeCache.Extensions;
12+
using static Microsoft.AspNetCore.Http.StatusCodes;
1213
using static System.Net.Mime.MediaTypeNames;
1314

1415
namespace TypeCache.Web.Extensions;
@@ -32,10 +33,10 @@ internal static class Route
3233
internal static class SqlApi
3334
{
3435
[StringSyntax(nameof(Route))]
35-
public const string DATABASE_SCHEMA = "/schema/{dataSource}/{database}/{collection}";
36+
public const string DATABASE_SCHEMA = "/schema/{source}/{database}/{collection}";
3637

3738
[StringSyntax(nameof(Route))]
38-
public const string TABLE = "/{dataSource}/{database}/{schema}/{table}";
39+
public const string TABLE = "/{source}/{database}/{schema}/{table}";
3940

4041
[StringSyntax(nameof(Route))]
4142
public const string DELETE = "/delete" + TABLE;
@@ -50,7 +51,7 @@ internal static class SqlApi
5051
public const string INSERT_VALUES = "/insert-values" + TABLE;
5152

5253
[StringSyntax(nameof(Route))]
53-
public const string PROCEDURE = "/execute/{dataSource}/{database}/{schema}/{procedure}";
54+
public const string PROCEDURE = "/execute/{source}/{database}/{schema}/{procedure}";
5455

5556
[StringSyntax(nameof(Route))]
5657
public const string SELECT = "/select" + TABLE;
@@ -143,21 +144,21 @@ public static IEndpointConventionBuilder MapGetRequestHeaderValue(this IEndpoint
143144

144145
var response = string.Empty;
145146
var acceptRequestHeader = context.Request.Headers.Accept.ToString().ToLowerInvariant();
146-
context.Response.StatusCode = context.Request.Headers.TryGetValue(key, out var value) ? StatusCodes.Status200OK : StatusCodes.Status204NoContent;
147+
context.Response.StatusCode = context.Request.Headers.TryGetValue(key, out var value) ? Status200OK : Status204NoContent;
147148
context.Response.Headers.ContentType = acceptRequestHeader switch
148149
{
149150
Text.Plain or Text.Html or Application.Xml or Text.Xml or Application.Json => acceptRequestHeader,
150151
_ => Application.Json
151152
};
152153
response = (context.Response.StatusCode, acceptRequestHeader) switch
153154
{
154-
(StatusCodes.Status200OK, Text.Plain) => Invariant($"{key}: {value}"),
155-
(StatusCodes.Status200OK, Text.Html) => Invariant($"<h1>{key}</h1><br><b>{value}<b/>"),
156-
(StatusCodes.Status200OK, Application.Xml or Text.Xml) => new XDocument(new XElement(key.Replace(' ', '_'), value.ToString())).ToString(),
157-
(StatusCodes.Status200OK, _) => JsonSerializer.Serialize(new Dictionary<string, string?>(1) { { key, value.ToString() } }, CreateJsonSerializerOptions()),
158-
(StatusCodes.Status204NoContent, Text.Plain) => Invariant($"{key}: "),
159-
(StatusCodes.Status204NoContent, Text.Html) => Invariant($"<h1>{key}</h1><br>"),
160-
(StatusCodes.Status204NoContent, Application.Xml or Text.Xml) => new XDocument(new XElement(key.Replace(' ', '_'))).ToString(),
155+
(Status200OK, Text.Plain) => Invariant($"{key}: {value}"),
156+
(Status200OK, Text.Html) => Invariant($"<h1>{key}</h1><br><b>{value}<b/>"),
157+
(Status200OK, Application.Xml or Text.Xml) => new XDocument(new XElement(key.Replace(' ', '_'), value.ToString())).ToString(),
158+
(Status200OK, _) => JsonSerializer.Serialize(new Dictionary<string, string?>(1) { { key, value.ToString() } }, CreateJsonSerializerOptions()),
159+
(Status204NoContent, Text.Plain) => Invariant($"{key}: "),
160+
(Status204NoContent, Text.Html) => Invariant($"<h1>{key}</h1><br>"),
161+
(Status204NoContent, Application.Xml or Text.Xml) => new XDocument(new XElement(key.Replace(' ', '_'))).ToString(),
161162
_ => JsonSerializer.Serialize(new Dictionary<string, string?>(1) { { key, null } }, CreateJsonSerializerOptions())
162163
};
163164

@@ -200,7 +201,7 @@ private static JsonSerializerOptions CreateJsonSerializerOptions()
200201
var options = new JsonSerializerOptions
201202
{
202203
PropertyNameCaseInsensitive = true,
203-
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
204+
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
204205
WriteIndented = true
205206
};
206207
options.Converters.Add(new StringValuesJsonConverter());

src/TypeCache.Web/TypeCache.Web.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Nullable>enable</Nullable>
66
<RootNamespace>TypeCache.Web</RootNamespace>
77
<PackageId>TypeCache.Web</PackageId>
8-
<Version>9.1.1</Version>
8+
<Version>9.1.2</Version>
99
<Authors>Samuel Abraham &lt;sam987883@gmail.com&gt;</Authors>
1010
<Company>Samuel Abraham &lt;sam987883@gmail.com&gt;</Company>
1111
<Title>TypeCache Web Library</Title>

0 commit comments

Comments
 (0)