Changes
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
using System.Net.Http;
|
|
||||||
using Refit;
|
using Refit;
|
||||||
using Api.Models.Requests;
|
using Api.Models.Requests;
|
||||||
|
|
||||||
|
|||||||
@@ -16,18 +16,15 @@ namespace Api.Controllers;
|
|||||||
public sealed class CvMatcherController : ControllerBase
|
public sealed class CvMatcherController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly ICvMatcherApi _cvApi;
|
private readonly ICvMatcherApi _cvApi;
|
||||||
private readonly IConfiguration _configuration;
|
|
||||||
private readonly ICaptchaVerifier _captcha;
|
private readonly ICaptchaVerifier _captcha;
|
||||||
private readonly ILogger<CvMatcherController> _logger;
|
private readonly ILogger<CvMatcherController> _logger;
|
||||||
|
|
||||||
public CvMatcherController(
|
public CvMatcherController(
|
||||||
ICvMatcherApi cvApi,
|
ICvMatcherApi cvApi,
|
||||||
IConfiguration configuration,
|
|
||||||
ICaptchaVerifier captcha,
|
ICaptchaVerifier captcha,
|
||||||
ILogger<CvMatcherController> logger)
|
ILogger<CvMatcherController> logger)
|
||||||
{
|
{
|
||||||
_cvApi = cvApi;
|
_cvApi = cvApi;
|
||||||
_configuration = configuration;
|
|
||||||
_captcha = captcha;
|
_captcha = captcha;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
@@ -60,9 +57,6 @@ public sealed class CvMatcherController : ControllerBase
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Proxying CV upload to cv-matcher-api. FileName={FileName}, Size={SizeBytes}, GdprConsent={GdprConsent}",
|
|
||||||
cv.FileName, cv.Length, gdprConsent);
|
|
||||||
|
|
||||||
var userIp = HttpContext.Connection.RemoteIpAddress?.ToString();
|
var userIp = HttpContext.Connection.RemoteIpAddress?.ToString();
|
||||||
var verdict = await _captcha.VerifyAsync(request.CaptchaToken ?? string.Empty, userIp, "cv_upload", ct);
|
var verdict = await _captcha.VerifyAsync(request.CaptchaToken ?? string.Empty, userIp, "cv_upload", ct);
|
||||||
if (!verdict.Success)
|
if (!verdict.Success)
|
||||||
@@ -71,6 +65,9 @@ public sealed class CvMatcherController : ControllerBase
|
|||||||
return BadRequest(new { error = "Captcha verification failed." });
|
return BadRequest(new { error = "Captcha verification failed." });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Proxying CV upload to cv-matcher-api. FileName={FileName}, Size={SizeBytes}, GdprConsent={GdprConsent}",
|
||||||
|
cv.FileName, cv.Length, gdprConsent);
|
||||||
|
|
||||||
var stream = cv.OpenReadStream();
|
var stream = cv.OpenReadStream();
|
||||||
var part = new Refit.StreamPart(stream, cv.FileName, "application/pdf");
|
var part = new Refit.StreamPart(stream, cv.FileName, "application/pdf");
|
||||||
using var response = await _cvApi.Upload(part, gdprConsent);
|
using var response = await _cvApi.Upload(part, gdprConsent);
|
||||||
@@ -105,11 +102,6 @@ public sealed class CvMatcherController : ControllerBase
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Proxying job match request to cv-matcher-api. CvDocumentId={CvDocumentId}, HasJobUrl={HasJobUrl}, HasJobDescription={HasJobDescription}",
|
|
||||||
request.CvDocumentId,
|
|
||||||
!string.IsNullOrWhiteSpace(request.JobUrl),
|
|
||||||
!string.IsNullOrWhiteSpace(request.JobDescription));
|
|
||||||
|
|
||||||
var userIp = HttpContext.Connection.RemoteIpAddress?.ToString();
|
var userIp = HttpContext.Connection.RemoteIpAddress?.ToString();
|
||||||
var verdict = await _captcha.VerifyAsync(request.CaptchaToken ?? string.Empty, userIp, "match_job", ct);
|
var verdict = await _captcha.VerifyAsync(request.CaptchaToken ?? string.Empty, userIp, "match_job", ct);
|
||||||
if (!verdict.Success)
|
if (!verdict.Success)
|
||||||
@@ -118,6 +110,11 @@ public sealed class CvMatcherController : ControllerBase
|
|||||||
return BadRequest(new { error = "Captcha verification failed." });
|
return BadRequest(new { error = "Captcha verification failed." });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Proxying job match request to cv-matcher-api. CvDocumentId={CvDocumentId}, HasJobUrl={HasJobUrl}, HasJobDescription={HasJobDescription}",
|
||||||
|
request.CvDocumentId,
|
||||||
|
!string.IsNullOrWhiteSpace(request.JobUrl),
|
||||||
|
!string.IsNullOrWhiteSpace(request.JobDescription));
|
||||||
|
|
||||||
using var response = await _cvApi.MatchJob(request);
|
using var response = await _cvApi.MatchJob(request);
|
||||||
return await ProxyResponseAsync(response, ct);
|
return await ProxyResponseAsync(response, ct);
|
||||||
}
|
}
|
||||||
@@ -132,7 +129,6 @@ public sealed class CvMatcherController : ControllerBase
|
|||||||
return StatusCode(StatusCodes.Status502BadGateway, new { error = "CV matcher API request failed." });
|
return StatusCode(StatusCodes.Status502BadGateway, new { error = "CV matcher API request failed." });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Refit client is configured in Program.cs; this helper only reads config for diagnostics
|
|
||||||
|
|
||||||
private static async Task<ContentResult> ProxyResponseAsync(HttpResponseMessage response, CancellationToken ct)
|
private static async Task<ContentResult> ProxyResponseAsync(HttpResponseMessage response, CancellationToken ct)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user