Reorganize root folder structure: Remove apps layer layer
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using MediatR;
|
||||
using Host.Models;
|
||||
using Knot.Shared.Kernel;
|
||||
using Knot.Modules.Chats.Application.TelegramImport;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Host.Controllers;
|
||||
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
[Route("api/import/telegram")]
|
||||
public sealed class TelegramImportController : ControllerBase
|
||||
{
|
||||
private readonly ISender _sender;
|
||||
private readonly IUserContext _userContext;
|
||||
|
||||
public TelegramImportController(ISender sender, IUserContext userContext)
|
||||
{
|
||||
_sender = sender;
|
||||
_userContext = userContext;
|
||||
}
|
||||
|
||||
[HttpPost("analyze")]
|
||||
[DisableRequestSizeLimit]
|
||||
[RequestFormLimits(MultipartBodyLengthLimit = 10L * 1024 * 1024 * 1024)] // 10GB for big exports
|
||||
public async Task<IActionResult> Analyze(IFormFile file, CancellationToken ct)
|
||||
{
|
||||
if (file == null)
|
||||
{
|
||||
return BadRequest("No file uploaded.");
|
||||
}
|
||||
|
||||
using var stream = file.OpenReadStream();
|
||||
var command = new AnalyzeImportCommand(stream, file.FileName);
|
||||
|
||||
var result = await _sender.Send(command, ct);
|
||||
|
||||
if (result.IsFailure)
|
||||
{
|
||||
return BadRequest(result.Error.Description ?? result.Error.Code);
|
||||
}
|
||||
|
||||
return Ok(result.Value);
|
||||
}
|
||||
|
||||
[HttpPost("execute")]
|
||||
public async Task<IActionResult> Execute([FromBody] ExecuteImportRequest req, CancellationToken ct)
|
||||
{
|
||||
var command = new ExecuteImportCommand(_userContext.UserId, req.Token, req.Mapping, req.GroupName);
|
||||
|
||||
var result = await _sender.Send(command, ct);
|
||||
|
||||
if (result.IsFailure)
|
||||
{
|
||||
return BadRequest(result.Error.Description ?? result.Error.Code);
|
||||
}
|
||||
|
||||
return Ok(result.Value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user