已完成考生域第一批只读迁移:
GET /api/candidate/dashboard GET /api/candidate/notices GET /api/candidate/profile GET /api/candidate/exams GET /api/candidate/registrations
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
using Eis.Application.Candidate;
|
||||
using Eis.Infrastructure.Candidate;
|
||||
|
||||
namespace Eis.Web.Candidate;
|
||||
|
||||
public static class NativeCandidateReadEndpoints
|
||||
{
|
||||
public static IEndpointRouteBuilder MapNativeCandidateReadEndpoints(
|
||||
this IEndpointRouteBuilder endpoints,
|
||||
CandidateMigrationOptions options)
|
||||
{
|
||||
if (!options.NativeReadEnabled)
|
||||
{
|
||||
return endpoints;
|
||||
}
|
||||
|
||||
endpoints.MapGet("/api/candidate/dashboard", async (
|
||||
HttpContext context,
|
||||
ICandidateQueryService service,
|
||||
CancellationToken cancellationToken) => ToResult(
|
||||
context,
|
||||
await service.GetDashboardAsync(SessionToken(context), cancellationToken)));
|
||||
endpoints.MapGet("/api/candidate/notices", async (
|
||||
HttpContext context,
|
||||
ICandidateQueryService service,
|
||||
CancellationToken cancellationToken) => ToResult(
|
||||
context,
|
||||
await service.GetNoticesAsync(SessionToken(context), cancellationToken)));
|
||||
endpoints.MapGet("/api/candidate/profile", async (
|
||||
HttpContext context,
|
||||
ICandidateQueryService service,
|
||||
CancellationToken cancellationToken) => ToResult(
|
||||
context,
|
||||
await service.GetProfileAsync(SessionToken(context), cancellationToken)));
|
||||
endpoints.MapGet("/api/candidate/exams", async (
|
||||
HttpContext context,
|
||||
ICandidateQueryService service,
|
||||
CancellationToken cancellationToken) => ToResult(
|
||||
context,
|
||||
await service.GetExamsAsync(SessionToken(context), cancellationToken)));
|
||||
endpoints.MapGet("/api/candidate/registrations", async (
|
||||
HttpContext context,
|
||||
ICandidateQueryService service,
|
||||
CancellationToken cancellationToken) => ToResult(
|
||||
context,
|
||||
await service.GetRegistrationsAsync(SessionToken(context), cancellationToken)));
|
||||
|
||||
return endpoints;
|
||||
}
|
||||
|
||||
private static string SessionToken(HttpContext context) =>
|
||||
context.Request.Cookies.TryGetValue("hz_session", out var token) ? token : string.Empty;
|
||||
|
||||
private static IResult ToResult(HttpContext context, CandidateEndpointResult result)
|
||||
{
|
||||
context.Response.Headers.CacheControl = "no-store";
|
||||
context.Response.Headers["X-EIS-Implementation"] = "aspnet-core";
|
||||
return Results.Json(result.Body, statusCode: result.StatusCode);
|
||||
}
|
||||
}
|
||||
+16
-1
@@ -1,5 +1,6 @@
|
||||
using System.Net;
|
||||
using Eis.Infrastructure.Authentication;
|
||||
using Eis.Infrastructure.Candidate;
|
||||
using Eis.Application.Public;
|
||||
using Eis.Infrastructure;
|
||||
using Eis.Infrastructure.Data;
|
||||
@@ -7,6 +8,7 @@ using Eis.Infrastructure.Migration;
|
||||
using Eis.Infrastructure.Security;
|
||||
using Eis.Web.Configuration;
|
||||
using Eis.Web.Authentication;
|
||||
using Eis.Web.Candidate;
|
||||
using Eis.Web.Frontend;
|
||||
using Eis.Web.Legacy;
|
||||
using Eis.Web.Public;
|
||||
@@ -34,10 +36,15 @@ builder.Services.AddSingleton<IPublicSiteConfiguration, PublicSiteConfiguration>
|
||||
var authenticationOptions = AuthenticationOptions.FromEnvironment(
|
||||
builder.Environment.IsProduction(),
|
||||
builder.Configuration.GetValue<bool>("AuthenticationMigration:NativeEnabled"));
|
||||
var candidateMigrationOptions = CandidateMigrationOptions.FromEnvironment(
|
||||
builder.Configuration.GetValue<bool>("CandidateMigration:NativeReadEnabled"),
|
||||
authenticationOptions.NativeEnabled,
|
||||
authenticationOptions.SharesLegacySessions);
|
||||
builder.Services.AddEisInfrastructure(
|
||||
DatabaseOptions.FromEnvironment(applicationRoot, builder.Environment.IsProduction()),
|
||||
DocumentVerificationOptions.FromEnvironment(builder.Environment.IsProduction()),
|
||||
authenticationOptions);
|
||||
authenticationOptions,
|
||||
candidateMigrationOptions);
|
||||
|
||||
var app = builder.Build();
|
||||
app.Services.EnsureNativeAuthenticationReady(authenticationOptions);
|
||||
@@ -72,12 +79,20 @@ app.MapGet("/health/migration", async (LegacyApiProxy proxy, CancellationToken c
|
||||
stateBackend = authenticationOptions.UsesRedis ? "redis" : "memory",
|
||||
sharesLegacySessions = authenticationOptions.SharesLegacySessions
|
||||
},
|
||||
candidate = new
|
||||
{
|
||||
nativeReadEnabled = candidateMigrationOptions.NativeReadEnabled,
|
||||
nativeRoutes = candidateMigrationOptions.NativeReadEnabled
|
||||
? new[] { "dashboard", "notices", "profile", "exams", "registrations" }
|
||||
: []
|
||||
},
|
||||
features = MigrationFeatureCatalog.Current(authenticationOptions.NativeEnabled)
|
||||
}, statusCode: statusCode);
|
||||
});
|
||||
|
||||
app.MapNativePublicEndpoints();
|
||||
app.MapNativeAuthenticationEndpoints(authenticationOptions);
|
||||
app.MapNativeCandidateReadEndpoints(candidateMigrationOptions);
|
||||
|
||||
string[] methods =
|
||||
[
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
"AuthenticationMigration": {
|
||||
"NativeEnabled": false
|
||||
},
|
||||
"CandidateMigration": {
|
||||
"NativeReadEnabled": false
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
|
||||
Reference in New Issue
Block a user