Skip to content
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

[OpenAPI] Add endpoint for update event details #241

180 changes: 107 additions & 73 deletions src/AzureOpenAIProxy.ApiApp/Endpoints/AdminEventEndpoints.cs
Original file line number Diff line number Diff line change
@@ -1,74 +1,108 @@
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;
}
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;
}

/// <summary>
/// Adds the update event details by admin endpoint
/// </summary>
/// <param name="app"><see cref="WebApplication"/> instance.</param>
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns>
public static RouteHandlerBuilder AddUpdateAdminEvents(this WebApplication app)
{
// Todo: Issue #19 https://github.com/aliencube/azure-openai-sdk-proxy/issues/19
// Need authorization by admin
var builder = app.MapPut(AdminEndpointUrls.AdminEventDetails, (
[FromBody] AdminEventDetails payload,
[FromRoute] string eventId) =>
justinyoo marked this conversation as resolved.
Show resolved Hide resolved
{
justinyoo marked this conversation as resolved.
Show resolved Hide resolved
// Todo: Issue #203 https://github.com/aliencube/azure-openai-sdk-proxy/issues/203
return Results.Ok();
})
.Accepts<AdminEventDetails>(contentType: "application/json")
.Produces<AdminEventDetails>(statusCode: StatusCodes.Status200OK, contentType: "application/json")
.Produces(statusCode: StatusCodes.Status401Unauthorized)
.Produces<string>(statusCode: StatusCodes.Status404NotFound, contentType: "text/plain")
justinyoo marked this conversation as resolved.
Show resolved Hide resolved
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain")
justinyoo marked this conversation as resolved.
Show resolved Hide resolved
.WithTags("admin")
.WithName("UpdateAdminEventDetails")
.WithOpenApi(operation =>
{
operation.Summary = "Updates event details from the given event ID";
operation.Description = "This endpoint updates the event details from the given event ID.";

return operation;
});

return builder;
}
}
93 changes: 47 additions & 46 deletions src/AzureOpenAIProxy.ApiApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
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();
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();
app.AddUpdateAdminEvents();

await app.RunAsync();
Loading