mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-25 22:01:16 +00:00
finished unit tests and docstrings
This commit is contained in:
@@ -5,6 +5,9 @@ using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace MalwareMultiScan.Api.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Downloads controller.
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/download")]
|
||||
[Produces("application/octet-stream")]
|
||||
@@ -12,11 +15,19 @@ namespace MalwareMultiScan.Api.Controllers
|
||||
{
|
||||
private readonly IScanResultService _scanResultService;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize downloads controller.
|
||||
/// </summary>
|
||||
/// <param name="scanResultService">Scan result service.</param>
|
||||
public DownloadController(IScanResultService scanResultService)
|
||||
{
|
||||
_scanResultService = scanResultService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download file by id.
|
||||
/// </summary>
|
||||
/// <param name="id">File id.</param>
|
||||
[HttpGet("{id}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
|
@@ -8,6 +8,9 @@ using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace MalwareMultiScan.Api.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Queue controller.
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/queue")]
|
||||
[Produces("application/json")]
|
||||
@@ -15,23 +18,33 @@ namespace MalwareMultiScan.Api.Controllers
|
||||
{
|
||||
private readonly IScanResultService _scanResultService;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize queue controller.
|
||||
/// </summary>
|
||||
/// <param name="scanResultService">Scan result service.</param>
|
||||
public QueueController(IScanResultService scanResultService)
|
||||
{
|
||||
_scanResultService = scanResultService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Queue file for scanning.
|
||||
/// </summary>
|
||||
/// <param name="file">File from form data.</param>
|
||||
[HttpPost("file")]
|
||||
[ProducesResponseType(typeof(ScanResult), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> ScanFile(
|
||||
[Required, MaxFileSize] IFormFile file)
|
||||
[Required] [MaxFileSize] IFormFile file)
|
||||
{
|
||||
var result = await _scanResultService.CreateScanResult();
|
||||
|
||||
string storedFileId;
|
||||
|
||||
await using (var uploadFileStream = file.OpenReadStream())
|
||||
{
|
||||
storedFileId = await _scanResultService.StoreFile(file.FileName, uploadFileStream);
|
||||
}
|
||||
|
||||
await _scanResultService.QueueUrlScan(result, Url.Action("Index", "Download", new {id = storedFileId},
|
||||
Request?.Scheme, Request?.Host.Value));
|
||||
@@ -39,11 +52,15 @@ namespace MalwareMultiScan.Api.Controllers
|
||||
return CreatedAtAction("Index", "ScanResults", new {id = result.Id}, result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Queue URL for scanning.
|
||||
/// </summary>
|
||||
/// <param name="url">URL from form data.</param>
|
||||
[HttpPost("url")]
|
||||
[ProducesResponseType(typeof(ScanResult), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> ScanUrl(
|
||||
[FromForm, Required, IsHttpUrl] string url)
|
||||
[FromForm] [Required] [IsHttpUrl] string url)
|
||||
{
|
||||
var result = await _scanResultService.CreateScanResult();
|
||||
|
||||
|
@@ -1,25 +1,34 @@
|
||||
using System.Threading.Tasks;
|
||||
using MalwareMultiScan.Api.Data.Models;
|
||||
using MalwareMultiScan.Api.Services;
|
||||
using MalwareMultiScan.Api.Services.Implementations;
|
||||
using MalwareMultiScan.Api.Services.Interfaces;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace MalwareMultiScan.Api.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Scan results controller.
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/results")]
|
||||
[Produces("application/json")]
|
||||
public class ScanResultsController : Controller
|
||||
{
|
||||
private readonly IScanResultService _scanResultService;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initialize scan results controller.
|
||||
/// </summary>
|
||||
/// <param name="scanResultService">Scan result service.</param>
|
||||
public ScanResultsController(IScanResultService scanResultService)
|
||||
{
|
||||
_scanResultService = scanResultService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get scan result by id.
|
||||
/// </summary>
|
||||
/// <param name="id">Scan result id.</param>
|
||||
[HttpGet("{id}")]
|
||||
[ProducesResponseType(typeof(ScanResult), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
|
Reference in New Issue
Block a user