Initial ...
This commit is contained in:
@@ -0,0 +1,309 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xCommons.Attributes;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Providers;
|
||||
using xFileService.Controllers;
|
||||
using xFileService.Interfaces;
|
||||
using xIdentityHelper;
|
||||
using xIdentityService.Interfaces;
|
||||
using xModels.Dtos;
|
||||
using XFileDto = xFileService.Models.Dtos.XFileDto;
|
||||
|
||||
namespace xApi.Controllers.V1.Services
|
||||
{
|
||||
[ApiController]
|
||||
[ApiVersion("1.0")]
|
||||
[RequireXPowered(true)]
|
||||
[Route("api/v{version:apiVersion}/services/[controller]")]
|
||||
public class FilesController : XFileServiceControllerBase, IXFileServiceControllerActions
|
||||
{
|
||||
//
|
||||
#region Constructor ...
|
||||
public FilesController(
|
||||
ILogger<FilesController> logger,
|
||||
IXFileProvider fileProvider,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
XValidationProvider validationProvider
|
||||
) : base(
|
||||
logger,
|
||||
fileProvider,
|
||||
appConfiguration,
|
||||
identityProvider,
|
||||
validationProvider
|
||||
)
|
||||
{ }
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Tools ...
|
||||
/// <summary>
|
||||
/// Stream Specified File ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}/Stream/ById")]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public override async Task<ActionResult> Stream(
|
||||
[FromRoute] Guid id
|
||||
)
|
||||
{
|
||||
return await base.Stream(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stream Specified File ...
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{name}/Stream/ByName")]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public override async Task<ActionResult> Stream(
|
||||
[FromRoute] string name
|
||||
)
|
||||
{
|
||||
return await base.Stream(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download Specified File ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}/Download/ById")]
|
||||
public override async Task<ActionResult> Download(
|
||||
[FromRoute] Guid id
|
||||
)
|
||||
{
|
||||
return await base.Download(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download Specified File ...
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{name}/Download/ByName")]
|
||||
public override async Task<ActionResult> Download(
|
||||
[FromRoute] string name
|
||||
)
|
||||
{
|
||||
return await base.Download(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Upload Files ...
|
||||
/// </summary>
|
||||
/// <param name="files"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("")]
|
||||
[RequestSizeLimit(966_367_641)]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public override async Task<ActionResult<IEnumerable<XFileDto>>> Upload(
|
||||
[FromForm] IFormFileCollection files
|
||||
)
|
||||
{
|
||||
return await base.Upload(files);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove Specified Files ...
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
/// [HttpDelete("Remove")]
|
||||
[HttpDelete("")]
|
||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
||||
public override async Task<ActionResult<IEnumerable<Guid>>> Remove(
|
||||
[FromQuery] string ids
|
||||
)
|
||||
{
|
||||
return await base.Remove(ids);
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Model ...
|
||||
/// <summary>
|
||||
/// Get Specified File Model ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}")]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public override async Task<ActionResult<XFileDto>> Get(
|
||||
[FromRoute] Guid id
|
||||
)
|
||||
{
|
||||
return await base.Get(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get All Exists File Models ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("All")]
|
||||
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
||||
public override async Task<ActionResult<IEnumerable<XFileDto>>> GetAll()
|
||||
{
|
||||
return await base.GetAll();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// retrieve Entities based on XQuery Pagination structure ...
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Query")]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public override async Task<ActionResult<XQueryResult<XFileDto>>> Query(
|
||||
[FromQuery] XQuery query
|
||||
)
|
||||
{
|
||||
return await base.Query(query);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// retrieve Owned Entities based on XQuery Pagination structure ...
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Query/Owned")]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public override async Task<ActionResult<XQueryResult<XFileDto>>> QueryOwned(
|
||||
[FromQuery] XQuery query
|
||||
)
|
||||
{
|
||||
return await base.QueryOwned(query);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// count all exists Entities ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Count")]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public override async Task<ActionResult<int>> Count()
|
||||
{
|
||||
return await base.Count();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check an Entity exists or not ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}/IsExists")]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public override async Task<ActionResult<bool>> IsExists(
|
||||
[FromRoute] Guid id
|
||||
)
|
||||
{
|
||||
return await base.IsExists(id);
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Tags ...
|
||||
/// <summary>
|
||||
/// Attach Tag to Specified Model ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="tag"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("{id}/Tags/Attach")]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public override async Task<ActionResult> AttachTag(
|
||||
[FromRoute] Guid id,
|
||||
[FromQuery] string tag
|
||||
)
|
||||
{
|
||||
//
|
||||
return await base.AttachTag(
|
||||
id: id,
|
||||
tag: tag
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detach Tag From Specified Model ...
|
||||
/// </summary>
|
||||
/// <param name="tag"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{id}/Tags/Detach")]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public override async Task<ActionResult> DetachTag(
|
||||
[FromRoute] Guid id,
|
||||
[FromQuery] string tag
|
||||
)
|
||||
{
|
||||
//
|
||||
return await base.DetachTag(
|
||||
id: id,
|
||||
tag: tag
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attach Tags to Specified Model ...
|
||||
/// </summary>
|
||||
/// <param name="tags"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("{id}/Tags/AttachMany")]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public override async Task<ActionResult> AttachTags(
|
||||
[FromRoute] Guid id,
|
||||
[FromQuery] string tags
|
||||
)
|
||||
{
|
||||
//
|
||||
return await base.AttachTags(
|
||||
id: id,
|
||||
tags: tags
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detach Tags From Specified Model ...
|
||||
/// </summary>
|
||||
/// <param name="tags"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{id}/Tags/DetachMany")]
|
||||
[Authorize(Policy = XPolicies.EnabledUser)]
|
||||
public override async Task<ActionResult> DetachTags(
|
||||
[FromRoute] Guid id,
|
||||
[FromQuery] string tags
|
||||
)
|
||||
{
|
||||
//
|
||||
return await base.DetachTags(
|
||||
id: id,
|
||||
tags: tags
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Tags of Specified File ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}/Tags")]
|
||||
public override async Task<ActionResult<IEnumerable<string>>> GetTags(
|
||||
[FromRoute] Guid id
|
||||
)
|
||||
{
|
||||
//
|
||||
return await base.GetTags(id);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user