diff --git a/Controllers/XFileServiceControllerBase.cs b/Controllers/XFileServiceControllerBase.cs index a0a21d6..b5c8481 100644 --- a/Controllers/XFileServiceControllerBase.cs +++ b/Controllers/XFileServiceControllerBase.cs @@ -51,13 +51,13 @@ namespace xFileService.Controllers /// /// Attach Tag to Specified Model ... /// - /// /// + /// /// - [HttpGet("Tags/Attach")] - public virtual async Task TagAttach( - [FromQuery] string tag, - [FromQuery] Guid id + [HttpPost("{id}/Tags/Attach")] + public virtual async Task AttachTag( + [FromRoute] Guid id, + [FromQuery] string tag ) { // @@ -72,7 +72,7 @@ namespace xFileService.Controllers var userId = userInfo.UserId; // - await FileProvider.TagAttach( + await FileProvider.AttachTag( id: id, tag: tag, userInfo: userInfo, @@ -96,10 +96,10 @@ namespace xFileService.Controllers /// /// /// - [HttpGet("Tags/Detach")] - public virtual async Task TagDetach( - [FromQuery] string tag, - [FromQuery] Guid id + [HttpDelete("{id}/Tags/Detach")] + public virtual async Task DetachTag( + [FromRoute] Guid id, + [FromQuery] string tag ) { // @@ -114,7 +114,7 @@ namespace xFileService.Controllers var userId = userInfo.UserId; // - await FileProvider.TagDetach( + await FileProvider.DetachTag( id: id, tag: tag, userInfo: userInfo, @@ -138,10 +138,10 @@ namespace xFileService.Controllers /// /// /// - [HttpGet("Tags/AttachMany")] - public virtual async Task TagsAttach( - [FromQuery] string tags, - [FromQuery] Guid id + [HttpPost("{id}/Tags/AttachMany")] + public virtual async Task AttachTags( + [FromRoute] Guid id, + [FromQuery] string tags ) { // @@ -159,7 +159,7 @@ namespace xFileService.Controllers var userId = userInfo.UserId; // - await FileProvider.TagsAttach( + await FileProvider.AttachTags( id: id, tags: tagsList, userInfo: userInfo, @@ -183,10 +183,10 @@ namespace xFileService.Controllers /// /// /// - [HttpGet("Tags/DetachMany")] - public virtual async Task TagsDetach( - [FromQuery] string tags, - [FromQuery] Guid id + [HttpDelete("{id}/Tags/DetachMany")] + public virtual async Task DetachTags( + [FromRoute] Guid id, + [FromQuery] string tags ) { // @@ -204,7 +204,7 @@ namespace xFileService.Controllers var userId = userInfo.UserId; // - await FileProvider.TagsDetach( + await FileProvider.DetachTags( id: id, tags: tagsList, userInfo: userInfo, @@ -221,6 +221,35 @@ namespace xFileService.Controllers return result; } } + + /// + /// Retrieve Tags of Specified File ... + /// + /// + /// + [HttpGet("{id}/Tags")] + public virtual async Task>> GetTags( + [FromRoute] Guid id + ) + { + // + // Do ... + try + { + // + var result = await FileProvider.GetTags(id); + + // + return Ok(result + .ToDynamicObject()); + } + catch (Exception ex) + { + // + var result = GetExceptionActionResult(ex); + return result; + } + } #endregion // @@ -342,7 +371,7 @@ namespace xFileService.Controllers /// /// /// - [HttpPost("Upload")] + [HttpPost("")] [RequestSizeLimit(966_367_641)] public virtual async Task>> Upload( [FromForm] IFormFileCollection files @@ -384,7 +413,7 @@ namespace xFileService.Controllers /// /// /// [HttpDelete("Remove")] - [HttpDelete("Remove")] + [HttpDelete("")] public virtual async Task>> Remove( [FromQuery] string ids ) { @@ -507,7 +536,7 @@ namespace xFileService.Controllers /// /// /// - [HttpGet("Owned/Query")] + [HttpGet("Query/Owned")] public virtual async Task>> QueryOwned( [FromQuery] XQuery query ) { diff --git a/Interfaces/IXFileProvider.cs b/Interfaces/IXFileProvider.cs index 4d0a869..6bf1bbf 100644 --- a/Interfaces/IXFileProvider.cs +++ b/Interfaces/IXFileProvider.cs @@ -59,14 +59,14 @@ namespace xFileService.Interfaces /// /// Attach Tag to Specified File ... /// - /// /// + /// /// /// /// - Task TagAttach( - string tag, + Task AttachTag( Guid id, + string tag, XUserClaimsInfoDto userInfo = null, string connectionId = null ); @@ -74,14 +74,14 @@ namespace xFileService.Interfaces /// /// Detach Tag fro Specified File ... /// - /// /// + /// /// /// /// - Task TagDetach( - string tag, + Task DetachTag( Guid id, + string tag, XUserClaimsInfoDto userInfo = null, string connectionId = null ); @@ -89,14 +89,14 @@ namespace xFileService.Interfaces /// /// Attach Tags for Specified File ... /// - /// /// + /// /// /// /// - Task TagsAttach( - IEnumerable tags, + Task AttachTags( Guid id, + IEnumerable tags, XUserClaimsInfoDto userInfo = null, string connectionId = null ); @@ -104,14 +104,14 @@ namespace xFileService.Interfaces /// /// Detach Tags for Specified File ... /// - /// /// + /// /// /// /// - Task TagsDetach( - IEnumerable tags, + Task DetachTags( Guid id, + IEnumerable tags, XUserClaimsInfoDto userInfo = null, string connectionId = null ); @@ -123,11 +123,18 @@ namespace xFileService.Interfaces /// /// /// - Task TagsDetach( + Task DetachTags( Guid id, XUserClaimsInfoDto userInfo = null, string connectionId = null ); + + /// + /// Get Specified Model's Tag ... + /// + /// + /// + Task> GetTags(Guid id); #endregion // diff --git a/Interfaces/IXFileServiceControllerActions.cs b/Interfaces/IXFileServiceControllerActions.cs index eca2282..5cb7908 100644 --- a/Interfaces/IXFileServiceControllerActions.cs +++ b/Interfaces/IXFileServiceControllerActions.cs @@ -17,12 +17,12 @@ namespace xFileService.Interfaces /// /// Attach Tag to Specified Model ... /// - /// /// + /// /// - Task TagAttach( - [FromQuery] string tag, - [FromQuery] Guid id + Task AttachTag( + [FromRoute] Guid id, + [FromQuery] string tag ); /// @@ -31,9 +31,9 @@ namespace xFileService.Interfaces /// /// /// - Task TagDetach( - [FromQuery] string tag, - [FromQuery] Guid id + Task DetachTag( + [FromRoute] Guid id, + [FromQuery] string tag ); /// @@ -42,9 +42,9 @@ namespace xFileService.Interfaces /// /// /// - Task TagsAttach( - [FromQuery] string tags, - [FromQuery] Guid id + Task AttachTags( + [FromRoute] Guid id, + [FromQuery] string tags ); /// @@ -53,9 +53,18 @@ namespace xFileService.Interfaces /// /// /// - Task TagsDetach( - [FromQuery] string tags, - [FromQuery] Guid id + Task DetachTags( + [FromRoute] Guid id, + [FromQuery] string tags + ); + + /// + /// Retrieve Tags of Specified File ... + /// + /// + /// + Task>> GetTags( + [FromRoute] Guid id ); #endregion @@ -95,8 +104,8 @@ namespace xFileService.Interfaces /// Task Download( [FromRoute] string name - ); - + ); + /// /// Upload Files ... /// @@ -104,8 +113,8 @@ namespace xFileService.Interfaces /// Task>> Upload( [FromForm] IFormFileCollection files - ); - + ); + /// /// Remove Specified Files ... /// @@ -113,7 +122,7 @@ namespace xFileService.Interfaces /// Task>> Remove( [FromQuery] string ids - ); + ); #endregion // @@ -126,7 +135,7 @@ namespace xFileService.Interfaces /// Task> Get( [FromRoute] Guid id - ); + ); /// /// Get All Exists File Models ... @@ -166,7 +175,7 @@ namespace xFileService.Interfaces /// Task> IsExists( [FromRoute] Guid id - ); + ); #endregion } } \ No newline at end of file diff --git a/Providers/XFileProvider.cs b/Providers/XFileProvider.cs index c2469e3..f210999 100644 --- a/Providers/XFileProvider.cs +++ b/Providers/XFileProvider.cs @@ -216,14 +216,14 @@ namespace xFileService.Providers /// /// Attach Tag to Specified File ... /// - /// /// + /// /// /// /// - public async Task TagAttach( - string tag, + public async Task AttachTag( Guid id, + string tag, XUserClaimsInfoDto userInfo = null, string connectionId = null ) @@ -264,14 +264,14 @@ namespace xFileService.Providers /// /// Detach Tag fro Specified File ... /// - /// /// + /// /// /// /// - public async Task TagDetach( - string tag, + public async Task DetachTag( Guid id, + string tag, XUserClaimsInfoDto userInfo = null, string connectionId = null ) @@ -311,14 +311,14 @@ namespace xFileService.Providers /// /// Attach Tags for Specified File ... /// - /// /// + /// /// /// /// - public async Task TagsAttach( - IEnumerable tags, + public async Task AttachTags( Guid id, + IEnumerable tags, XUserClaimsInfoDto userInfo = null, string connectionId = null ) @@ -349,11 +349,11 @@ namespace xFileService.Providers foreach (var tag in tags) { // - await TagAttach( - tag, - id, - userInfo, - connectionId + await AttachTag( + id: id, + tag: tag, + userInfo: userInfo, + connectionId: connectionId ); } } @@ -364,14 +364,14 @@ namespace xFileService.Providers /// /// Detach Tags for Specified File ... /// - /// /// + /// /// /// /// - public async Task TagsDetach( - IEnumerable tags, + public async Task DetachTags( Guid id, + IEnumerable tags, XUserClaimsInfoDto userInfo = null, string connectionId = null ) @@ -402,11 +402,11 @@ namespace xFileService.Providers foreach (var tag in tags) { // - await TagDetach( - tag, - id, - userInfo, - connectionId + await DetachTag( + id: id, + tag: tag, + userInfo: userInfo, + connectionId: connectionId ); } } @@ -421,7 +421,7 @@ namespace xFileService.Providers /// /// /// - public async Task TagsDetach( + public async Task DetachTags( Guid id, XUserClaimsInfoDto userInfo = null, string connectionId = null @@ -452,6 +452,47 @@ namespace xFileService.Providers catch { } } } + + /// + /// Get Specified Model's Tag ... + /// + /// + /// + public async Task> GetTags(Guid id) + { + // + // Validate ... + var isValid = !id.IsNull() && + !id.IsDefaultGuid(); + if (!isValid) + { + XException.InvalidArgs.Throw(); + } + + // + // Check Model Exists ... + isValid = await IsExists(id); + if (!isValid) + { + XException.NotFound.Throw(); + } + + // + var tags = await TagProvider.GetTags(id); + + // + var result = new List(); + isValid = !tags.IsNull() && tags.HasChild(); + if (isValid) + { + // + result = tags.Select(t => t.Tag) + .ToList(); + } + + // + return result; + } #endregion // @@ -805,7 +846,11 @@ namespace xFileService.Providers // // Here we send Null Connection ID for Preventing Update Push ... // since we Remove Entity ... - await TagsDetach(id, userInfo, null); + await DetachTags( + id: id, + userInfo: userInfo, + connectionId: null + ); } }