69 lines
1.9 KiB
C#
69 lines
1.9 KiB
C#
using Core.Enumerations;
|
|
using DomainResults.Mvc;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using WeatherForecast.Policies;
|
|
using WeatherForecast.Services;
|
|
|
|
namespace WeatherForecast.Controllers;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[AllowAnonymous]
|
|
[Route("api/[controller]")]
|
|
public class FilesController : ControllerBase {
|
|
|
|
private readonly IAuthorizationService _authorizationService;
|
|
private readonly IFilesService _filesService;
|
|
|
|
private readonly WebapiControllers _webapiController = WebapiControllers.Files;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="filesService"></param>
|
|
public FilesController(
|
|
IAuthorizationService authorizationService,
|
|
IFilesService filesService
|
|
) {
|
|
_authorizationService = authorizationService;
|
|
_filesService = filesService;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="siteId"></param>
|
|
/// <param name="userId"></param>
|
|
/// <param name="file"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("{siteId}/{userId}")]
|
|
public async Task<IActionResult> Post([FromRoute] Guid siteId, [FromRoute] Guid userId, List<IFormFile> file) {
|
|
|
|
if ((await _authorizationService.AuthorizeAsync(User, null, new CrudActionRequirement(_webapiController, CrudActions.Create))).Succeeded) {
|
|
var result = _filesService.Post(siteId, userId, file);
|
|
return result.ToActionResult();
|
|
}
|
|
|
|
return Unauthorized();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="siteId"></param>
|
|
/// <param name="userId"></param>
|
|
/// <returns></returns>
|
|
|
|
[HttpDelete("{siteId}/{userId}")]
|
|
public async Task<IActionResult> Delete([FromRoute] Guid siteId, [FromRoute] Guid userId) {
|
|
if ((await _authorizationService.AuthorizeAsync(User, null, new CrudActionRequirement(_webapiController, CrudActions.Create))).Succeeded) {
|
|
var result = _filesService.Delete(siteId, userId);
|
|
return result.ToActionResult();
|
|
}
|
|
|
|
return Unauthorized();
|
|
}
|
|
}
|