Skip to content

Commit bdbd200

Browse files
authored
[OpenAPI] Add endpoint for list event details #217 (#265)
1 parent c710072 commit bdbd200

File tree

5 files changed

+287
-117
lines changed

5 files changed

+287
-117
lines changed
Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
namespace AzureOpenAIProxy.ApiApp.Endpoints;
2-
3-
public static class AdminEndpointUrls
4-
{
5-
/// <summary>
6-
/// Declares the admin event details endpoint.
7-
/// </summary>
8-
public const string AdminEventDetails = "/admin/events/{eventId}";
1+
namespace AzureOpenAIProxy.ApiApp.Endpoints;
2+
3+
public static class AdminEndpointUrls
4+
{
5+
/// <summary>
6+
/// Declares the admin event details endpoint.
7+
/// </summary>
8+
public const string AdminEventDetails = "/admin/events/{eventId}";
9+
10+
/// <summary>
11+
/// Declares the admin event list endpoint.
12+
/// </summary>
13+
/// <remarks>
14+
/// - Get method for listing all events
15+
/// - Post method for new event creation
16+
/// </remarks>
17+
public const string AdminEvents = "/admin/events";
918
}
Lines changed: 74 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,74 @@
1-
using AzureOpenAIProxy.ApiApp.Models;
2-
3-
using Microsoft.AspNetCore.Mvc;
4-
5-
namespace AzureOpenAIProxy.ApiApp.Endpoints;
6-
7-
/// <summary>
8-
/// This represents the endpoint entity for get event details by admin
9-
/// </summary>
10-
public static class AdminEventEndpoints
11-
{
12-
/// <summary>
13-
/// Adds the get event details by admin endpoint
14-
/// </summary>
15-
/// <param name="app"><see cref="WebApplication"/> instance.</param>
16-
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns>
17-
public static RouteHandlerBuilder AddAdminEvents(this WebApplication app)
18-
{
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) =>
23-
{
24-
// Todo: Issue #208 https://github.com/aliencube/azure-openai-sdk-proxy/issues/208
25-
return Results.Ok();
26-
// Todo: Issue #208
27-
})
28-
.Produces<AdminEventDetails>(statusCode: StatusCodes.Status200OK, contentType: "application/json")
29-
.Produces(statusCode: StatusCodes.Status401Unauthorized)
30-
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain")
31-
.WithTags("admin")
32-
.WithName("GetAdminEventDetails")
33-
.WithOpenApi(operation =>
34-
{
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.";
37-
38-
return operation;
39-
});
40-
41-
return builder;
42-
}
43-
}
1+
using AzureOpenAIProxy.ApiApp.Models;
2+
3+
using Microsoft.AspNetCore.Mvc;
4+
5+
namespace AzureOpenAIProxy.ApiApp.Endpoints;
6+
7+
/// <summary>
8+
/// This represents the endpoint entity for get event details by admin
9+
/// </summary>
10+
public static class AdminEventEndpoints
11+
{
12+
/// <summary>
13+
/// Adds the get event details by admin endpoint
14+
/// </summary>
15+
/// <param name="app"><see cref="WebApplication"/> instance.</param>
16+
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns>
17+
public static RouteHandlerBuilder AddAdminEvents(this WebApplication app)
18+
{
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) =>
23+
{
24+
// Todo: Issue #208 https://github.com/aliencube/azure-openai-sdk-proxy/issues/208
25+
return Results.Ok();
26+
// Todo: Issue #208
27+
})
28+
.Produces<AdminEventDetails>(statusCode: StatusCodes.Status200OK, contentType: "application/json")
29+
.Produces(statusCode: StatusCodes.Status401Unauthorized)
30+
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain")
31+
.WithTags("admin")
32+
.WithName("GetAdminEventDetails")
33+
.WithOpenApi(operation =>
34+
{
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.";
37+
38+
return operation;
39+
});
40+
41+
return builder;
42+
}
43+
44+
/// <summary>
45+
/// Adds the get event lists by admin endpoint
46+
/// </summary>
47+
/// <param name="app"><see cref="WebApplication"/> instance.</param>
48+
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns>
49+
public static RouteHandlerBuilder AddAdminEventList(this WebApplication app)
50+
{
51+
// Todo: Issue #19 https://github.com/aliencube/azure-openai-sdk-proxy/issues/19
52+
// Need authorization by admin
53+
var builder = app.MapGet(AdminEndpointUrls.AdminEvents, () =>
54+
{
55+
// Todo: Issue #218 https://github.com/aliencube/azure-openai-sdk-proxy/issues/218
56+
return Results.Ok();
57+
// Todo: Issue #218
58+
})
59+
.Produces<List<AdminEventDetails>>(statusCode: StatusCodes.Status200OK, contentType: "application/json")
60+
.Produces(statusCode: StatusCodes.Status401Unauthorized)
61+
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain")
62+
.WithTags("admin")
63+
.WithName("GetAdminEvents")
64+
.WithOpenApi(operation =>
65+
{
66+
operation.Summary = "Gets all events";
67+
operation.Description = "This endpoint gets all events";
68+
69+
return operation;
70+
});
71+
72+
return builder;
73+
}
74+
}
Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
using Microsoft.OpenApi.Models;
2-
3-
using Swashbuckle.AspNetCore.SwaggerGen;
4-
5-
namespace AzureOpenAIProxy.ApiApp.Filters;
6-
7-
/// <summary>
8-
/// This represents the document filter entity for global tags.
9-
/// </summary>
10-
public class OpenApiTagFilter : IDocumentFilter
11-
{
12-
/// <inheritdoc />
13-
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
14-
{
15-
swaggerDoc.Tags =
16-
[
17-
new OpenApiTag { Name = "weather", Description = "Weather forecast operations" },
18-
new OpenApiTag { Name = "openai", Description = "Azure OpenAI operations" },
19-
];
20-
}
21-
}
1+
using Microsoft.OpenApi.Models;
2+
3+
using Swashbuckle.AspNetCore.SwaggerGen;
4+
5+
namespace AzureOpenAIProxy.ApiApp.Filters;
6+
7+
/// <summary>
8+
/// This represents the document filter entity for global tags.
9+
/// </summary>
10+
public class OpenApiTagFilter : IDocumentFilter
11+
{
12+
/// <inheritdoc />
13+
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
14+
{
15+
swaggerDoc.Tags =
16+
[
17+
new OpenApiTag { Name = "weather", Description = "Weather forecast operations" },
18+
new OpenApiTag { Name = "openai", Description = "Azure OpenAI operations" },
19+
new OpenApiTag { Name = "admin", Description = "Admin for organizing events" }
20+
];
21+
}
22+
}
Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,46 @@
1-
using AzureOpenAIProxy.ApiApp.Endpoints;
2-
using AzureOpenAIProxy.ApiApp.Extensions;
3-
4-
var builder = WebApplication.CreateBuilder(args);
5-
6-
builder.AddServiceDefaults();
7-
8-
// Add KeyVault service
9-
builder.Services.AddKeyVaultService();
10-
11-
// Add Azure OpenAI service.
12-
builder.Services.AddOpenAIService();
13-
14-
// Add OpenAPI service
15-
builder.Services.AddOpenApiService();
16-
17-
var app = builder.Build();
18-
19-
app.MapDefaultEndpoints();
20-
21-
// https://stackoverflow.com/questions/76962735/how-do-i-set-a-prefix-in-my-asp-net-core-7-web-api-for-all-endpoints
22-
var basePath = "/api";
23-
app.UsePathBase(basePath);
24-
app.UseRouting();
25-
26-
// Configure the HTTP request pipeline.
27-
// Use Swagger UI
28-
app.UseSwaggerUI(basePath);
29-
30-
// Enable buffering
31-
app.Use(async (context, next) =>
32-
{
33-
context.Request.EnableBuffering();
34-
await next.Invoke();
35-
});
36-
37-
app.UseHttpsRedirection();
38-
39-
app.AddWeatherForecast();
40-
app.AddChatCompletions();
41-
42-
// Admin Endpoints
43-
app.AddAdminEvents();
44-
45-
await app.RunAsync();
1+
using AzureOpenAIProxy.ApiApp.Endpoints;
2+
using AzureOpenAIProxy.ApiApp.Extensions;
3+
4+
var builder = WebApplication.CreateBuilder(args);
5+
6+
builder.AddServiceDefaults();
7+
8+
// Add KeyVault service
9+
builder.Services.AddKeyVaultService();
10+
11+
// Add Azure OpenAI service.
12+
builder.Services.AddOpenAIService();
13+
14+
// Add OpenAPI service
15+
builder.Services.AddOpenApiService();
16+
17+
var app = builder.Build();
18+
19+
app.MapDefaultEndpoints();
20+
21+
// https://stackoverflow.com/questions/76962735/how-do-i-set-a-prefix-in-my-asp-net-core-7-web-api-for-all-endpoints
22+
var basePath = "/api";
23+
app.UsePathBase(basePath);
24+
app.UseRouting();
25+
26+
// Configure the HTTP request pipeline.
27+
// Use Swagger UI
28+
app.UseSwaggerUI(basePath);
29+
30+
// Enable buffering
31+
app.Use(async (context, next) =>
32+
{
33+
context.Request.EnableBuffering();
34+
await next.Invoke();
35+
});
36+
37+
app.UseHttpsRedirection();
38+
39+
app.AddWeatherForecast();
40+
app.AddChatCompletions();
41+
42+
// Admin Endpoints
43+
app.AddAdminEvents();
44+
app.AddAdminEventList();
45+
46+
await app.RunAsync();

0 commit comments

Comments
 (0)