generated from ricardo/MVCLogin
115 lines
4.5 KiB
C#
115 lines
4.5 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using SumaTube.Application.Videos.ApplicationServices;
|
|
using SumaTube.Application.Videos.Contracts;
|
|
using SumaTube.Domain.Entities.Videos;
|
|
using SumaTube.Models;
|
|
using System.Collections.Generic;
|
|
|
|
namespace SumaTube.Controllers
|
|
{
|
|
public class VideoController : Controller
|
|
{
|
|
private readonly IVideoApplicationService _videoApplicationService;
|
|
private readonly ILogger<VideoController> _logger;
|
|
|
|
public VideoController(
|
|
IVideoApplicationService videoApplicationService,
|
|
ILogger<VideoController> logger)
|
|
{
|
|
_videoApplicationService = videoApplicationService;
|
|
_logger = logger;
|
|
}
|
|
|
|
public IActionResult Extract()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
public async Task<IActionResult> VideoSummary(string id)
|
|
{
|
|
// Aqui você chamaria sua WebAPI para processar o vídeo
|
|
// e retornaria o modelo para a view
|
|
var model = new VideoSummaryViewModel
|
|
{
|
|
VideoId = id,
|
|
VideoTitle = "Título do Vídeo",
|
|
ChannelName = "Nome do Canal",
|
|
ChannelThumbnail = "URL da Thumbnail do Canal",
|
|
PublishedDate = "Data de Publicação",
|
|
ViewCount = "Quantidade de Visualizações",
|
|
LikeCount = "Quantidade de Curtidas",
|
|
CommentCount = "Quantidade de Comentarios",
|
|
SummaryText = "Resumo do Vídeo",
|
|
KeyPoints = new List<object> { "Ponto 1", "Ponto 2", "Ponto 3" },
|
|
Captions = new List<object> { "Legenda 1", "Legenda 2", "Legenda 3" },
|
|
Keywords = new List<string> { "Palavra 1", "Palavra 2", "Palavra 3" },
|
|
RelatedTopics = new List<string> { "Tópico 1", "Tópico 2", "Tópico 3" },
|
|
RelatedVideos = new List<object> { "Vídeo 1", "Vídeo 2", "Vídeo 3" }
|
|
};
|
|
return View(model);
|
|
}
|
|
|
|
public async Task<IActionResult> MySummary()
|
|
{
|
|
var userId = User.Identity.Name; // Ou outra forma de obter o ID do usuário
|
|
_logger.LogInformation("Carregando página 'Meus Resumos' para usuário: {UserId}", userId);
|
|
|
|
var videos = new List<VideoSummary>();
|
|
if (userId != null)
|
|
videos = await _videoApplicationService.GetUserVideosAsync(userId);
|
|
|
|
return View(videos);
|
|
}
|
|
|
|
// Endpoint para enviar solicitação de novo resumo
|
|
[HttpPost]
|
|
public async Task<IActionResult> RequestSummary(string youtubeUrl, string language)
|
|
{
|
|
var userId = User.Identity.Name; // Ou outra forma de obter o ID do usuário
|
|
_logger.LogInformation("Recebido pedido de resumo. URL: {Url}, Idioma: {Language}, Usuário: {UserId}",
|
|
youtubeUrl, language, userId);
|
|
|
|
try
|
|
{
|
|
var result = await _videoApplicationService.RequestVideoSummaryAsync(youtubeUrl, language, userId);
|
|
_logger.LogInformation("Resumo solicitado com sucesso. ID: {Id}", result.Id);
|
|
|
|
return Json(new { success = true, videoId = result.VideoId, summaryId = result.Id });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Erro ao solicitar resumo: {Message}", ex.Message);
|
|
return Json(new { success = false, error = ex.Message });
|
|
}
|
|
}
|
|
|
|
// Página para exibir um resumo específico
|
|
public async Task<IActionResult> Summary(string id)
|
|
{
|
|
var userId = User.Identity.Name; // Ou outra forma de obter o ID do usuário
|
|
_logger.LogInformation("Acessando resumo. ID: {Id}, Usuário: {UserId}", id, userId);
|
|
|
|
var summary = await _videoApplicationService.GetVideoSummaryByIdAsync(id, userId);
|
|
|
|
if (summary == null)
|
|
{
|
|
_logger.LogWarning("Resumo não encontrado. ID: {Id}", id);
|
|
return NotFound();
|
|
}
|
|
|
|
return View(summary);
|
|
}
|
|
|
|
// Endpoint para verificar status de processamento
|
|
[HttpGet]
|
|
public async Task<IActionResult> CheckStatus(string id)
|
|
{
|
|
var userId = User.Identity.Name; // Ou outra forma de obter o ID do usuário
|
|
_logger.LogInformation("Verificando status do resumo. ID: {Id}, Usuário: {UserId}", id, userId);
|
|
|
|
var status = await _videoApplicationService.CheckSummaryStatusAsync(id, userId);
|
|
return Json(status);
|
|
}
|
|
}
|
|
}
|