71 lines
1.7 KiB
C#
71 lines
1.7 KiB
C#
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using DomainResults.Common;
|
|
using DomainResults.Mvc;
|
|
|
|
using DataProviders.Buckets;
|
|
using WeatherForecast.Services;
|
|
|
|
namespace WeatherForecast.Controllers;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[AllowAnonymous]
|
|
[Route("api/[controller]")]
|
|
public class TemplateController : ControllerBase {
|
|
|
|
|
|
private readonly IAuthorizationService _authorizationService;
|
|
private readonly ITemplateService _templateService;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="authorizationService"></param>
|
|
/// <param name="templateService"></param>
|
|
public TemplateController(
|
|
IAuthorizationService authorizationService,
|
|
ITemplateService templateService
|
|
) {
|
|
_authorizationService = authorizationService;
|
|
_templateService = templateService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Allows to upload private dkim certificate
|
|
/// </summary>
|
|
/// <param name="siteId"></param>
|
|
/// <param name="file"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("{siteId}")]
|
|
public IActionResult Post([FromRoute] Guid siteId, IFormFile file) {
|
|
|
|
if (!(file.Length > 0))
|
|
return IDomainResult.Failed().ToActionResult();
|
|
|
|
using var ms = new MemoryStream();
|
|
file.CopyTo(ms);
|
|
|
|
var result = _templateService.Post(new BucketFile(siteId, file.FileName, ms.ToArray(), file.ContentType));
|
|
|
|
return result.ToActionResult();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Delete template
|
|
/// </summary>
|
|
/// <param name="siteId"></param>
|
|
/// <param name="fileId"></param>
|
|
/// <returns></returns>
|
|
[HttpDelete("{siteId}/{fileId}")]
|
|
public IActionResult Delete([FromRoute] Guid siteId, [FromRoute] Guid fileId) {
|
|
|
|
var result = _templateService.Delete(siteId, fileId);
|
|
return result.ToActionResult();
|
|
}
|
|
}
|