Skip to content

Commit 0d15c4a

Browse files
authored
Update directory structure and file naming (#282)
1 parent 947d240 commit 0d15c4a

File tree

11 files changed

+170
-155
lines changed

11 files changed

+170
-155
lines changed
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
namespace AzureOpenAIProxy.ApiApp.Endpoints;
22

3+
/// <summary>
4+
/// This represents the collection of the admin endpoint URLs.
5+
/// </summary>
36
public static class AdminEndpointUrls
47
{
58
/// <summary>
69
/// Declares the admin event details endpoint.
710
/// </summary>
11+
/// <remarks>
12+
/// - GET method for an event details
13+
/// - PUT method for update an event details
14+
/// </remarks>
815
public const string AdminEventDetails = "/admin/events/{eventId}";
916

1017
/// <summary>
1118
/// Declares the admin event list endpoint.
1219
/// </summary>
1320
/// <remarks>
14-
/// - Get method for listing all events
15-
/// - Post method for new event creation
21+
/// - GET method for listing all events
22+
/// - POST method for new event creation
1623
/// </remarks>
1724
public const string AdminEvents = "/admin/events";
1825
}

src/AzureOpenAIProxy.ApiApp/Endpoints/AdminEventEndpoints.cs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,36 @@
55
namespace AzureOpenAIProxy.ApiApp.Endpoints;
66

77
/// <summary>
8-
/// This represents the endpoint entity for get event details by admin
8+
/// This represents the endpoint entity for event details by admin
99
/// </summary>
1010
public static class AdminEventEndpoints
1111
{
1212
/// <summary>
13-
/// Adds the get event details by admin endpoint
13+
/// Adds the admin event endpoint
1414
/// </summary>
1515
/// <param name="app"><see cref="WebApplication"/> instance.</param>
1616
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns>
17-
public static RouteHandlerBuilder AddAdminEvents(this WebApplication app)
17+
public static RouteHandlerBuilder AddNewAdminEvent(this WebApplication app)
1818
{
19-
// Todo: Issue #19 https://github.com/aliencube/azure-openai-sdk-proxy/issues/19
20-
// Need authorization by admin
21-
var builder = app.MapGet(AdminEndpointUrls.AdminEventDetails, (
22-
[FromRoute] string eventId) =>
19+
var builder = app.MapPost(AdminEndpointUrls.AdminEvents, async (
20+
[FromBody] AdminEventDetails payload,
21+
HttpRequest request) =>
2322
{
24-
// Todo: Issue #208 https://github.com/aliencube/azure-openai-sdk-proxy/issues/208
25-
return Results.Ok();
26-
// Todo: Issue #208
23+
return await Task.FromResult(Results.Ok());
2724
})
25+
// TODO: Check both request/response payloads
26+
.Accepts<AdminEventDetails>(contentType: "application/json")
2827
.Produces<AdminEventDetails>(statusCode: StatusCodes.Status200OK, contentType: "application/json")
28+
// TODO: Check both request/response payloads
29+
.Produces(statusCode: StatusCodes.Status400BadRequest)
2930
.Produces(statusCode: StatusCodes.Status401Unauthorized)
3031
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain")
3132
.WithTags("admin")
32-
.WithName("GetAdminEventDetails")
33+
.WithName("CreateAdminEvent")
3334
.WithOpenApi(operation =>
3435
{
35-
operation.Summary = "Gets event details from the given event ID";
36-
operation.Description = "This endpoint gets the event details from the given event ID.";
36+
operation.Summary = "Create admin event";
37+
operation.Description = "Create admin event";
3738

3839
return operation;
3940
});
@@ -46,7 +47,7 @@ public static RouteHandlerBuilder AddAdminEvents(this WebApplication app)
4647
/// </summary>
4748
/// <param name="app"><see cref="WebApplication"/> instance.</param>
4849
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns>
49-
public static RouteHandlerBuilder AddAdminEventList(this WebApplication app)
50+
public static RouteHandlerBuilder AddListAdminEvents(this WebApplication app)
5051
{
5152
// Todo: Issue #19 https://github.com/aliencube/azure-openai-sdk-proxy/issues/19
5253
// Need authorization by admin
@@ -73,65 +74,64 @@ public static RouteHandlerBuilder AddAdminEventList(this WebApplication app)
7374
}
7475

7576
/// <summary>
76-
/// Adds the update event details by admin endpoint
77+
/// Adds the get event details by admin endpoint
7778
/// </summary>
7879
/// <param name="app"><see cref="WebApplication"/> instance.</param>
7980
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns>
80-
public static RouteHandlerBuilder AddUpdateAdminEvents(this WebApplication app)
81+
public static RouteHandlerBuilder AddGetAdminEvent(this WebApplication app)
8182
{
8283
// Todo: Issue #19 https://github.com/aliencube/azure-openai-sdk-proxy/issues/19
8384
// Need authorization by admin
84-
var builder = app.MapPut(AdminEndpointUrls.AdminEventDetails, (
85-
[FromRoute] string eventId,
86-
[FromBody] AdminEventDetails payload) =>
85+
var builder = app.MapGet(AdminEndpointUrls.AdminEventDetails, (
86+
[FromRoute] string eventId) =>
8787
{
88-
// Todo: Issue #203 https://github.com/aliencube/azure-openai-sdk-proxy/issues/203
88+
// Todo: Issue #208 https://github.com/aliencube/azure-openai-sdk-proxy/issues/208
8989
return Results.Ok();
90+
// Todo: Issue #208
9091
})
91-
.Accepts<AdminEventDetails>(contentType: "application/json")
9292
.Produces<AdminEventDetails>(statusCode: StatusCodes.Status200OK, contentType: "application/json")
9393
.Produces(statusCode: StatusCodes.Status401Unauthorized)
94-
.Produces(statusCode: StatusCodes.Status404NotFound)
9594
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain")
9695
.WithTags("admin")
97-
.WithName("UpdateAdminEventDetails")
96+
.WithName("GetAdminEvent")
9897
.WithOpenApi(operation =>
9998
{
100-
operation.Summary = "Updates event details from the given event ID";
101-
operation.Description = "This endpoint updates the event details from the given event ID.";
99+
operation.Summary = "Gets event details from the given event ID";
100+
operation.Description = "This endpoint gets the event details from the given event ID.";
102101

103102
return operation;
104103
});
105104

106105
return builder;
107106
}
108-
107+
109108
/// <summary>
110-
/// Adds the admin event endpoint
109+
/// Adds the update event details by admin endpoint
111110
/// </summary>
112111
/// <param name="app"><see cref="WebApplication"/> instance.</param>
113112
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns>
114-
public static RouteHandlerBuilder CreateAdminEvent(this WebApplication app)
113+
public static RouteHandlerBuilder AddUpdateAdminEvent(this WebApplication app)
115114
{
116-
var builder = app.MapPost(AdminEndpointUrls.AdminEvents, async (
117-
[FromBody] AdminEventDetails payload,
118-
HttpRequest request) =>
115+
// Todo: Issue #19 https://github.com/aliencube/azure-openai-sdk-proxy/issues/19
116+
// Need authorization by admin
117+
var builder = app.MapPut(AdminEndpointUrls.AdminEventDetails, (
118+
[FromRoute] string eventId,
119+
[FromBody] AdminEventDetails payload) =>
119120
{
120-
return await Task.FromResult(Results.Ok());
121+
// Todo: Issue #203 https://github.com/aliencube/azure-openai-sdk-proxy/issues/203
122+
return Results.Ok();
121123
})
122-
// TODO: Check both request/response payloads
123124
.Accepts<AdminEventDetails>(contentType: "application/json")
124125
.Produces<AdminEventDetails>(statusCode: StatusCodes.Status200OK, contentType: "application/json")
125-
// TODO: Check both request/response payloads
126-
.Produces(statusCode: StatusCodes.Status400BadRequest)
127126
.Produces(statusCode: StatusCodes.Status401Unauthorized)
127+
.Produces(statusCode: StatusCodes.Status404NotFound)
128128
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain")
129129
.WithTags("admin")
130-
.WithName("CreateAdminEvent")
130+
.WithName("UpdateAdminEvent")
131131
.WithOpenApi(operation =>
132132
{
133-
operation.Summary = "Create admin event";
134-
operation.Description = "Create admin event";
133+
operation.Summary = "Updates event details from the given event ID";
134+
operation.Description = "This endpoint updates the event details from the given event ID.";
135135

136136
return operation;
137137
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace AzureOpenAIProxy.ApiApp.Endpoints;
2+
3+
/// <summary>
4+
/// This represents the collection of the playground endpoint URLs.
5+
/// </summary>
6+
public static class PlaygroundEndpointUrls
7+
{
8+
/// <summary>
9+
/// Declares the event endpoint.
10+
/// </summary>
11+
/// <remarks>
12+
/// - GET method for listing all events
13+
/// </remarks>
14+
public const string Events = "/events";
15+
}

src/AzureOpenAIProxy.ApiApp/Endpoints/EventEndpoint.cs renamed to src/AzureOpenAIProxy.ApiApp/Endpoints/PlaygroundEndpoints.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
using System.Text.Json;
2-
3-
using AzureOpenAIProxy.ApiApp.Models;
4-
51
namespace AzureOpenAIProxy.ApiApp.Endpoints;
62

73
/// <summary>
84
/// This represents the endpoint entity for events that the logged user joined.
95
/// </summary>
10-
public static class EventEndpoint
6+
public static class PlaygroundEndpoints
117
{
128
/// <summary>
139
/// Adds the event endpoint.
1410
/// </summary>
1511
/// <param name="app"><see cref="WebApplication"/> instance.</param>
1612
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns>
17-
public static RouteHandlerBuilder AddEventList(this WebApplication app)
13+
public static RouteHandlerBuilder AddListEvents(this WebApplication app)
1814
{
19-
var builder = app.MapGet(EndpointUrls.Events, () =>
15+
var builder = app.MapGet(PlaygroundEndpointUrls.Events, () =>
2016
{
2117
// TODO: Issue #179 https://github.com/aliencube/azure-openai-sdk-proxy/issues/179
2218
return Results.Ok();

src/AzureOpenAIProxy.ApiApp/Endpoints/ChatCompletionsEndpoint.cs renamed to src/AzureOpenAIProxy.ApiApp/Endpoints/ProxyChatCompletionsEndpoint.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace AzureOpenAIProxy.ApiApp.Endpoints;
1212
/// <summary>
1313
/// This represents the endpoint entity for chat completions.
1414
/// </summary>
15-
public static class ChatCompletionsEndpoint
15+
public static class ProxyChatCompletionsEndpoint
1616
{
1717
/// <summary>
1818
/// Adds the chat completion endpoint.
@@ -21,7 +21,7 @@ public static class ChatCompletionsEndpoint
2121
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns>
2222
public static RouteHandlerBuilder AddChatCompletions(this WebApplication app)
2323
{
24-
var builder = app.MapPost(EndpointUrls.ChatCompletions, async (
24+
var builder = app.MapPost(ProxyEndpointUrls.ChatCompletions, async (
2525
[OpenApiParameterIgnore][FromHeader(Name = "api-key")] string apiKey,
2626
[FromRoute] string deploymentName,
2727
[FromQuery(Name = "api-version")] string apiVersion,
@@ -30,7 +30,7 @@ public static RouteHandlerBuilder AddChatCompletions(this WebApplication app)
3030
IOpenAIService openai,
3131
ILoggerFactory loggerFactory) =>
3232
{
33-
var logger = loggerFactory.CreateLogger(nameof(ChatCompletionsEndpoint));
33+
var logger = loggerFactory.CreateLogger(nameof(ProxyChatCompletionsEndpoint));
3434
logger.LogInformation("Received a chat completion request");
3535

3636
request.Body.Position = 0;
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
namespace AzureOpenAIProxy.ApiApp.Endpoints;
22

33
/// <summary>
4-
/// This represents the collection of the endpoint URLs.
4+
/// This represents the collection of the proxy endpoint URLs.
55
/// </summary>
6-
public static class EndpointUrls
6+
public static class ProxyEndpointUrls
77
{
88
/// <summary>
99
/// Declares the weather forecast endpoint.
@@ -14,9 +14,4 @@ public static class EndpointUrls
1414
/// Declares the chat completions endpoint.
1515
/// </summary>
1616
public const string ChatCompletions = "/openai/deployments/{deploymentName}/chat/completions";
17-
18-
/// <summary>
19-
/// Declares the event endpoint.
20-
/// </summary>
21-
public const string Events = "/events";
2217
}

src/AzureOpenAIProxy.ApiApp/Endpoints/WeatherForecastEndpoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static class WeatherForecastEndpoint
1919
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns>
2020
public static RouteHandlerBuilder AddWeatherForecast(this WebApplication app)
2121
{
22-
var builder = app.MapGet(EndpointUrls.WeatherForecast, () =>
22+
var builder = app.MapGet(ProxyEndpointUrls.WeatherForecast, () =>
2323
{
2424
var forecast = Enumerable.Range(1, 5).Select(index =>
2525
new WeatherForecast

src/AzureOpenAIProxy.ApiApp/Extensions/HttpRequestExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static class HttpRequestExtensions
1010
/// Gets the base URL.
1111
/// </summary>
1212
/// <param name="req"><see cref="HttpRequest"/> instance.</param>
13-
/// <returns></returns>
13+
/// <returns>Returns the base URL from <see cref="HttpRequest"/>.</returns>
1414
public static string? BaseUrl(this HttpRequest req)
1515
{
1616
if (req == null) return null;

src/AzureOpenAIProxy.ApiApp/Program.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@
3737
app.UseHttpsRedirection();
3838

3939
app.AddWeatherForecast();
40+
41+
// Proxy endpoints
4042
app.AddChatCompletions();
4143

42-
// Event Endpoints
43-
app.AddEventList();
44+
// Playground endpoints
45+
app.AddListEvents();
4446

45-
// Admin Endpoints
46-
app.AddAdminEvents();
47-
app.AddAdminEventList();
48-
app.AddUpdateAdminEvents();
49-
app.CreateAdminEvent();
47+
// Admin endpoints
48+
app.AddNewAdminEvent();
49+
app.AddListAdminEvents();
50+
app.AddGetAdminEvent();
51+
app.AddUpdateAdminEvent();
5052

5153
await app.RunAsync();
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
using AzureOpenAIProxy.AppHost.Tests.Fixtures;
2-
3-
namespace AzureOpenAIProxy.AppHost.Tests.PlaygroundApp.Components.Pages;
4-
5-
public class PlaygroundPageTest(AspireAppHostFixture host) : IClassFixture<AspireAppHostFixture>
6-
{
7-
[Fact]
8-
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_OK()
9-
{
10-
// Arrange
11-
var httpClient = host.App!.CreateHttpClient("playgroundapp");
12-
await host.ResourceNotificationService.WaitForResourceAsync("playgroundapp", KnownResourceStates.Running).WaitAsync(TimeSpan.FromSeconds(30));
13-
14-
// Act
15-
var response = await httpClient.GetAsync("/playground");
16-
17-
// Assert
18-
response.EnsureSuccessStatusCode(); // Status Code 200-299
19-
}
1+
using AzureOpenAIProxy.AppHost.Tests.Fixtures;
2+
3+
namespace AzureOpenAIProxy.AppHost.Tests.PlaygroundApp.Pages;
4+
5+
public class PlaygroundPageTests(AspireAppHostFixture host) : IClassFixture<AspireAppHostFixture>
6+
{
7+
[Fact]
8+
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_OK()
9+
{
10+
// Arrange
11+
var httpClient = host.App!.CreateHttpClient("playgroundapp");
12+
await host.ResourceNotificationService.WaitForResourceAsync("playgroundapp", KnownResourceStates.Running).WaitAsync(TimeSpan.FromSeconds(30));
13+
14+
// Act
15+
var response = await httpClient.GetAsync("/playground");
16+
17+
// Assert
18+
response.EnsureSuccessStatusCode(); // Status Code 200-299
19+
}
2020
}

0 commit comments

Comments
 (0)