-
Notifications
You must be signed in to change notification settings - Fork 18
[OpenAPI] Add endpoint for list event details #217 #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 17 additions & 8 deletions
25
src/AzureOpenAIProxy.ApiApp/Endpoints/AdminEndpointUrls.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
namespace AzureOpenAIProxy.ApiApp.Endpoints; | ||
|
||
public static class AdminEndpointUrls | ||
{ | ||
/// <summary> | ||
/// Declares the admin event details endpoint. | ||
/// </summary> | ||
public const string AdminEventDetails = "/admin/events/{eventId}"; | ||
namespace AzureOpenAIProxy.ApiApp.Endpoints; | ||
|
||
public static class AdminEndpointUrls | ||
{ | ||
/// <summary> | ||
/// Declares the admin event details endpoint. | ||
/// </summary> | ||
public const string AdminEventDetails = "/admin/events/{eventId}"; | ||
|
||
/// <summary> | ||
/// Declares the admin event list endpoint. | ||
/// </summary> | ||
/// <remarks> | ||
/// - Get method for listing all events | ||
/// - Post method for new event creation | ||
/// </remarks> | ||
public const string AdminEvents = "/admin/events"; | ||
} |
117 changes: 74 additions & 43 deletions
117
src/AzureOpenAIProxy.ApiApp/Endpoints/AdminEventEndpoints.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,74 @@ | ||
using AzureOpenAIProxy.ApiApp.Models; | ||
|
||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace AzureOpenAIProxy.ApiApp.Endpoints; | ||
|
||
/// <summary> | ||
/// This represents the endpoint entity for get event details by admin | ||
/// </summary> | ||
public static class AdminEventEndpoints | ||
{ | ||
/// <summary> | ||
/// Adds the get event details by admin endpoint | ||
/// </summary> | ||
/// <param name="app"><see cref="WebApplication"/> instance.</param> | ||
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns> | ||
public static RouteHandlerBuilder AddAdminEvents(this WebApplication app) | ||
{ | ||
// Todo: Issue #19 https://github.com/aliencube/azure-openai-sdk-proxy/issues/19 | ||
// Need authorization by admin | ||
var builder = app.MapGet(AdminEndpointUrls.AdminEventDetails, ( | ||
[FromRoute] string eventId) => | ||
{ | ||
// Todo: Issue #208 https://github.com/aliencube/azure-openai-sdk-proxy/issues/208 | ||
return Results.Ok(); | ||
// Todo: Issue #208 | ||
}) | ||
.Produces<AdminEventDetails>(statusCode: StatusCodes.Status200OK, contentType: "application/json") | ||
.Produces(statusCode: StatusCodes.Status401Unauthorized) | ||
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain") | ||
.WithTags("admin") | ||
.WithName("GetAdminEventDetails") | ||
.WithOpenApi(operation => | ||
{ | ||
operation.Summary = "Gets event details from the given event ID"; | ||
operation.Description = "This endpoint gets the event details from the given event ID."; | ||
|
||
return operation; | ||
}); | ||
|
||
return builder; | ||
} | ||
} | ||
using AzureOpenAIProxy.ApiApp.Models; | ||
|
||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace AzureOpenAIProxy.ApiApp.Endpoints; | ||
|
||
/// <summary> | ||
/// This represents the endpoint entity for get event details by admin | ||
/// </summary> | ||
public static class AdminEventEndpoints | ||
{ | ||
/// <summary> | ||
/// Adds the get event details by admin endpoint | ||
/// </summary> | ||
/// <param name="app"><see cref="WebApplication"/> instance.</param> | ||
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns> | ||
public static RouteHandlerBuilder AddAdminEvents(this WebApplication app) | ||
{ | ||
// Todo: Issue #19 https://github.com/aliencube/azure-openai-sdk-proxy/issues/19 | ||
// Need authorization by admin | ||
var builder = app.MapGet(AdminEndpointUrls.AdminEventDetails, ( | ||
[FromRoute] string eventId) => | ||
{ | ||
// Todo: Issue #208 https://github.com/aliencube/azure-openai-sdk-proxy/issues/208 | ||
return Results.Ok(); | ||
// Todo: Issue #208 | ||
}) | ||
.Produces<AdminEventDetails>(statusCode: StatusCodes.Status200OK, contentType: "application/json") | ||
.Produces(statusCode: StatusCodes.Status401Unauthorized) | ||
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain") | ||
.WithTags("admin") | ||
.WithName("GetAdminEventDetails") | ||
.WithOpenApi(operation => | ||
{ | ||
operation.Summary = "Gets event details from the given event ID"; | ||
operation.Description = "This endpoint gets the event details from the given event ID."; | ||
|
||
return operation; | ||
}); | ||
|
||
return builder; | ||
} | ||
|
||
/// <summary> | ||
/// Adds the get event lists by admin endpoint | ||
/// </summary> | ||
/// <param name="app"><see cref="WebApplication"/> instance.</param> | ||
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns> | ||
public static RouteHandlerBuilder AddAdminEventList(this WebApplication app) | ||
{ | ||
// Todo: Issue #19 https://github.com/aliencube/azure-openai-sdk-proxy/issues/19 | ||
// Need authorization by admin | ||
var builder = app.MapGet(AdminEndpointUrls.AdminEvents, () => | ||
{ | ||
// Todo: Issue #218 https://github.com/aliencube/azure-openai-sdk-proxy/issues/218 | ||
return Results.Ok(); | ||
// Todo: Issue #218 | ||
}) | ||
.Produces<List<AdminEventDetails>>(statusCode: StatusCodes.Status200OK, contentType: "application/json") | ||
.Produces(statusCode: StatusCodes.Status401Unauthorized) | ||
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain") | ||
.WithTags("admin") | ||
.WithName("GetAdminEvents") | ||
.WithOpenApi(operation => | ||
{ | ||
operation.Summary = "Gets all events"; | ||
operation.Description = "This endpoint gets all events"; | ||
|
||
return operation; | ||
}); | ||
|
||
return builder; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
using Microsoft.OpenApi.Models; | ||
|
||
using Swashbuckle.AspNetCore.SwaggerGen; | ||
|
||
namespace AzureOpenAIProxy.ApiApp.Filters; | ||
|
||
/// <summary> | ||
/// This represents the document filter entity for global tags. | ||
/// </summary> | ||
public class OpenApiTagFilter : IDocumentFilter | ||
{ | ||
/// <inheritdoc /> | ||
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) | ||
{ | ||
swaggerDoc.Tags = | ||
[ | ||
new OpenApiTag { Name = "weather", Description = "Weather forecast operations" }, | ||
new OpenApiTag { Name = "openai", Description = "Azure OpenAI operations" }, | ||
]; | ||
} | ||
} | ||
using Microsoft.OpenApi.Models; | ||
|
||
using Swashbuckle.AspNetCore.SwaggerGen; | ||
|
||
namespace AzureOpenAIProxy.ApiApp.Filters; | ||
|
||
/// <summary> | ||
/// This represents the document filter entity for global tags. | ||
/// </summary> | ||
public class OpenApiTagFilter : IDocumentFilter | ||
{ | ||
/// <inheritdoc /> | ||
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) | ||
{ | ||
swaggerDoc.Tags = | ||
[ | ||
new OpenApiTag { Name = "weather", Description = "Weather forecast operations" }, | ||
new OpenApiTag { Name = "openai", Description = "Azure OpenAI operations" }, | ||
new OpenApiTag { Name = "admin", Description = "Admin for organizing events" } | ||
]; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,46 @@ | ||
using AzureOpenAIProxy.ApiApp.Endpoints; | ||
using AzureOpenAIProxy.ApiApp.Extensions; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.AddServiceDefaults(); | ||
|
||
// Add KeyVault service | ||
builder.Services.AddKeyVaultService(); | ||
|
||
// Add Azure OpenAI service. | ||
builder.Services.AddOpenAIService(); | ||
|
||
// Add OpenAPI service | ||
builder.Services.AddOpenApiService(); | ||
|
||
var app = builder.Build(); | ||
|
||
app.MapDefaultEndpoints(); | ||
|
||
// https://stackoverflow.com/questions/76962735/how-do-i-set-a-prefix-in-my-asp-net-core-7-web-api-for-all-endpoints | ||
var basePath = "/api"; | ||
app.UsePathBase(basePath); | ||
app.UseRouting(); | ||
|
||
// Configure the HTTP request pipeline. | ||
// Use Swagger UI | ||
app.UseSwaggerUI(basePath); | ||
|
||
// Enable buffering | ||
app.Use(async (context, next) => | ||
{ | ||
context.Request.EnableBuffering(); | ||
await next.Invoke(); | ||
}); | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.AddWeatherForecast(); | ||
app.AddChatCompletions(); | ||
|
||
// Admin Endpoints | ||
app.AddAdminEvents(); | ||
|
||
await app.RunAsync(); | ||
using AzureOpenAIProxy.ApiApp.Endpoints; | ||
using AzureOpenAIProxy.ApiApp.Extensions; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.AddServiceDefaults(); | ||
|
||
// Add KeyVault service | ||
builder.Services.AddKeyVaultService(); | ||
|
||
// Add Azure OpenAI service. | ||
builder.Services.AddOpenAIService(); | ||
|
||
// Add OpenAPI service | ||
builder.Services.AddOpenApiService(); | ||
|
||
var app = builder.Build(); | ||
|
||
app.MapDefaultEndpoints(); | ||
|
||
// https://stackoverflow.com/questions/76962735/how-do-i-set-a-prefix-in-my-asp-net-core-7-web-api-for-all-endpoints | ||
var basePath = "/api"; | ||
app.UsePathBase(basePath); | ||
app.UseRouting(); | ||
|
||
// Configure the HTTP request pipeline. | ||
// Use Swagger UI | ||
app.UseSwaggerUI(basePath); | ||
|
||
// Enable buffering | ||
app.Use(async (context, next) => | ||
{ | ||
context.Request.EnableBuffering(); | ||
await next.Invoke(); | ||
}); | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.AddWeatherForecast(); | ||
app.AddChatCompletions(); | ||
|
||
// Admin Endpoints | ||
app.AddAdminEvents(); | ||
app.AddAdminEventList(); | ||
|
||
await app.RunAsync(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.