feat(news,calendar): improve corporate calendar filters and news sentiment dialogs
This commit is contained in:
@@ -240,4 +240,87 @@ public class NewsController : ControllerBase
|
||||
|
||||
return NotFound(new { message = $"No sentiment analysis found for article {articleId}." });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggers or renews sentiment analysis for a specific news article via FinlyticSentiment.
|
||||
/// </summary>
|
||||
[HttpPost("sentiment/article/{articleId}/analyze")]
|
||||
[HttpPost("{articleId}/reanalyze")]
|
||||
public async Task<IActionResult> ReanalyzeArticleSentiment(string articleId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(articleId)) return BadRequest(new { message = "ArticleId ist erforderlich." });
|
||||
|
||||
var targetId = articleId.Trim();
|
||||
|
||||
try
|
||||
{
|
||||
if (_mqttClient.IsConnected)
|
||||
{
|
||||
var rpcResult = await _mqttClient.SendRpcRequestAsync<IsinAnalysisEntry, AnalyzeSentimentRequest>(
|
||||
"sentiment_Analyze",
|
||||
new AnalyzeSentimentRequest(ArticleId: targetId, ForceReload: true),
|
||||
TimeSpan.FromSeconds(20)
|
||||
);
|
||||
|
||||
if (rpcResult != null)
|
||||
{
|
||||
// Fetch full article from FinlyticNews to return complete updated DTO
|
||||
var article = await _mqttClient.SendRpcRequestAsync<NewsArticleDto, ArticleRequest>(
|
||||
"news_GetById",
|
||||
new ArticleRequest(targetId, targetId),
|
||||
TimeSpan.FromSeconds(5)
|
||||
);
|
||||
|
||||
if (article != null && rpcResult.FinbertResult != null)
|
||||
{
|
||||
var res = rpcResult.FinbertResult;
|
||||
var enriched = article with
|
||||
{
|
||||
Sentiment = res.Label,
|
||||
SentimentScore = res.CompoundScore,
|
||||
Confidence = res.Confidence,
|
||||
FinbertResult = res,
|
||||
Status = "Analyzed"
|
||||
};
|
||||
return Ok(enriched);
|
||||
}
|
||||
|
||||
if (article != null)
|
||||
{
|
||||
return Ok(article);
|
||||
}
|
||||
|
||||
// Fallback to synthetic DTO from entry
|
||||
var synthetic = new NewsArticleDto
|
||||
{
|
||||
Id = Guid.TryParse(targetId, out var g) ? g : Guid.NewGuid(),
|
||||
Title = rpcResult.Article?.Title ?? "Artikel",
|
||||
Author = rpcResult.Article?.Source ?? "FinlyticNews",
|
||||
Summary = rpcResult.SummarySnippet,
|
||||
ContentRaw = "",
|
||||
SourceUrl = "",
|
||||
ScrapedAt = DateTime.UtcNow,
|
||||
PublishedAt = DateTime.TryParse(rpcResult.Article?.PublishedAt, out var pDate) ? pDate : DateTime.UtcNow,
|
||||
Status = "Analyzed",
|
||||
Sentiment = rpcResult.FinbertResult?.Label ?? "NEUTRAL",
|
||||
SentimentScore = rpcResult.FinbertResult?.CompoundScore ?? 0.0,
|
||||
Confidence = rpcResult.FinbertResult?.Confidence ?? 0.0,
|
||||
FinbertResult = rpcResult.FinbertResult
|
||||
};
|
||||
return Ok(synthetic);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return StatusCode(503, new { message = "MQTT Broker nicht verbunden." });
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Fehler beim erneuten Analysieren des Artikels {ArticleId}", targetId);
|
||||
return StatusCode(500, new { message = $"Analyse fehlgeschlagen: {ex.Message}" });
|
||||
}
|
||||
|
||||
return NotFound(new { message = $"Artikel {targetId} konnte nicht analysiert werden." });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user