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 logger, IXFileProvider fileProvider, XAppConfiguration appConfiguration, IXIdentityProvider identityProvider, XValidationProvider validationProvider ) : base( logger, fileProvider, appConfiguration, identityProvider, validationProvider ) { } #endregion // #region Tools ... /// /// Stream Specified File ... /// /// /// [HttpGet("{id}/Stream/ById")] [Authorize(Policy = XPolicies.EnabledUser)] public override async Task Stream( [FromRoute] Guid id ) { return await base.Stream(id); } /// /// Stream Specified File ... /// /// /// [HttpGet("{name}/Stream/ByName")] [Authorize(Policy = XPolicies.EnabledUser)] public override async Task Stream( [FromRoute] string name ) { return await base.Stream(name); } /// /// Download Specified File ... /// /// /// [HttpGet("{id}/Download/ById")] public override async Task Download( [FromRoute] Guid id ) { return await base.Download(id); } /// /// Download Specified File ... /// /// /// [HttpGet("{name}/Download/ByName")] public override async Task Download( [FromRoute] string name ) { return await base.Download(name); } /// /// Upload Files ... /// /// /// [HttpPost("")] [RequestSizeLimit(966_367_641)] [Authorize(Policy = XPolicies.EnabledUser)] public override async Task>> Upload( [FromForm] IFormFileCollection files ) { return await base.Upload(files); } /// /// Remove Specified Files ... /// /// /// /// [HttpDelete("Remove")] [HttpDelete("")] [Authorize(Policy = XPolicies.EnabledAdminOrAgent)] public override async Task>> Remove( [FromQuery] string ids ) { return await base.Remove(ids); } #endregion // #region Model ... /// /// Get Specified File Model ... /// /// /// [HttpGet("{id}")] [Authorize(Policy = XPolicies.EnabledUser)] public override async Task> Get( [FromRoute] Guid id ) { return await base.Get(id); } /// /// Get All Exists File Models ... /// /// [HttpGet("All")] [Authorize(Policy = XPolicies.EnabledAdminOrAgent)] public override async Task>> GetAll() { return await base.GetAll(); } /// /// retrieve Entities based on XQuery Pagination structure ... /// /// /// [HttpGet("Query")] [Authorize(Policy = XPolicies.EnabledUser)] public override async Task>> Query( [FromQuery] XQuery query ) { return await base.Query(query); } /// /// retrieve Owned Entities based on XQuery Pagination structure ... /// /// /// [HttpGet("Query/Owned")] [Authorize(Policy = XPolicies.EnabledUser)] public override async Task>> QueryOwned( [FromQuery] XQuery query ) { return await base.QueryOwned(query); } /// /// count all exists Entities ... /// /// [HttpGet("Count")] [Authorize(Policy = XPolicies.EnabledUser)] public override async Task> Count() { return await base.Count(); } /// /// Check an Entity exists or not ... /// /// /// [HttpGet("{id}/IsExists")] [Authorize(Policy = XPolicies.EnabledUser)] public override async Task> IsExists( [FromRoute] Guid id ) { return await base.IsExists(id); } #endregion // #region Tags ... /// /// Attach Tag to Specified Model ... /// /// /// /// [HttpPost("{id}/Tags/Attach")] [Authorize(Policy = XPolicies.EnabledUser)] public override async Task AttachTag( [FromRoute] Guid id, [FromQuery] string tag ) { // return await base.AttachTag( id: id, tag: tag ); } /// /// Detach Tag From Specified Model ... /// /// /// /// [HttpDelete("{id}/Tags/Detach")] [Authorize(Policy = XPolicies.EnabledUser)] public override async Task DetachTag( [FromRoute] Guid id, [FromQuery] string tag ) { // return await base.DetachTag( id: id, tag: tag ); } /// /// Attach Tags to Specified Model ... /// /// /// /// [HttpPost("{id}/Tags/AttachMany")] [Authorize(Policy = XPolicies.EnabledUser)] public override async Task AttachTags( [FromRoute] Guid id, [FromQuery] string tags ) { // return await base.AttachTags( id: id, tags: tags ); } /// /// Detach Tags From Specified Model ... /// /// /// /// [HttpDelete("{id}/Tags/DetachMany")] [Authorize(Policy = XPolicies.EnabledUser)] public override async Task DetachTags( [FromRoute] Guid id, [FromQuery] string tags ) { // return await base.DetachTags( id: id, tags: tags ); } /// /// Retrieve Tags of Specified File ... /// /// /// [HttpGet("{id}/Tags")] public override async Task>> GetTags( [FromRoute] Guid id ) { // return await base.GetTags(id); } #endregion } }