Skip to content

Commit a7c25ca

Browse files
authored
[OpenAPI] Add endpoint for update event details (#241)
1 parent 485cbe9 commit a7c25ca

File tree

4 files changed

+359
-122
lines changed

4 files changed

+359
-122
lines changed

.spectral.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ rules:
7272
function: truthy
7373
message: Response 500 is required
7474

75-
# 401을 제외한 모든 응답 코드는 content를 포함해야함
75+
# 400, 401, 404를 제외한 모든 응답 코드는 content를 포함해야함
7676
operation-responsedetail-content-convention:
77-
description: All Operation response might include content, except 401
78-
given: $.paths[*][*].responses[?(@property != '401')]
77+
description: All Operation response might include content, except 400, 401 and 404
78+
given: $.paths[*][*].responses[?(@property != '400' && @property != '401' && @property != '404')]
7979
severity: error
8080
then:
8181
- field: 'content'
Lines changed: 107 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,108 @@
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-
}
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+
75+
/// <summary>
76+
/// Adds the update event details by admin endpoint
77+
/// </summary>
78+
/// <param name="app"><see cref="WebApplication"/> instance.</param>
79+
/// <returns>Returns <see cref="RouteHandlerBuilder"/> instance.</returns>
80+
public static RouteHandlerBuilder AddUpdateAdminEvents(this WebApplication app)
81+
{
82+
// Todo: Issue #19 https://github.com/aliencube/azure-openai-sdk-proxy/issues/19
83+
// Need authorization by admin
84+
var builder = app.MapPut(AdminEndpointUrls.AdminEventDetails, (
85+
[FromRoute] string eventId,
86+
[FromBody] AdminEventDetails payload) =>
87+
{
88+
// Todo: Issue #203 https://github.com/aliencube/azure-openai-sdk-proxy/issues/203
89+
return Results.Ok();
90+
})
91+
.Accepts<AdminEventDetails>(contentType: "application/json")
92+
.Produces<AdminEventDetails>(statusCode: StatusCodes.Status200OK, contentType: "application/json")
93+
.Produces(statusCode: StatusCodes.Status401Unauthorized)
94+
.Produces(statusCode: StatusCodes.Status404NotFound)
95+
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain")
96+
.WithTags("admin")
97+
.WithName("UpdateAdminEventDetails")
98+
.WithOpenApi(operation =>
99+
{
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.";
102+
103+
return operation;
104+
});
105+
106+
return builder;
107+
}
74108
}
Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,47 @@
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();
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+
app.AddUpdateAdminEvents();
46+
47+
await app.RunAsync();

0 commit comments

Comments
 (0)