From 6101d25a7b6c5836a37a67779220e6a49ba35457 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Thu, 28 May 2026 16:16:44 +0330 Subject: [PATCH] last ... --- Controllers/XFileProviderControllerBase.cs | 50 ++++++++++++++++ Interfaces/IXFileProvider.cs | 4 +- Providers/XFileProvider.cs | 69 ++++++++++++++++++---- 3 files changed, 110 insertions(+), 13 deletions(-) diff --git a/Controllers/XFileProviderControllerBase.cs b/Controllers/XFileProviderControllerBase.cs index df66b35..d97ab21 100644 --- a/Controllers/XFileProviderControllerBase.cs +++ b/Controllers/XFileProviderControllerBase.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -8,6 +9,7 @@ using Microsoft.Extensions.Logging; using xCommons.Configurations; using xCommons.Extensions; using xCommons.Providers; +using xDataService.Models; using xExceptions.Constants; using xFileService.Interfaces; using xFileService.Models.Dtos; @@ -217,6 +219,54 @@ namespace xFileService.Controllers return result; } } + + /// + /// Retrieve References of Specified Itemfor providedFor ... + /// + /// + /// + /// + /// + /// + [HttpGet("{id}/References")] + public virtual async Task>>> GetReferences( + [FromRoute] Guid id, + [FromQuery] string providedFor, + CancellationToken cancellationToken = default + ) + { + // + try + { + // + // Validate ... + if (!ModelState.IsValid) + { + XException.InvalidArgs.Throw(); + } + await ValidationProvider + .GroupValidationBuilder() + .AddNotNull(id) + .AddNotEmpty(providedFor) + .ValidateGroupAsync(); + + // + var result = await provider.GetReferences( + id: id, + providedFor: providedFor, + cancellationToken: cancellationToken + ); + + // + return Ok(result.ToDynamicObject()); + } + catch (Exception ex) + { + // + var result = GetExceptionActionResult(ex); + return result; + } + } #endregion } } \ No newline at end of file diff --git a/Interfaces/IXFileProvider.cs b/Interfaces/IXFileProvider.cs index 4e47948..4a9ca48 100644 --- a/Interfaces/IXFileProvider.cs +++ b/Interfaces/IXFileProvider.cs @@ -7,6 +7,6 @@ using xTagService.Interfaces; namespace xFileService.Interfaces { - public interface IXFileProvider : IXBaseProvidedHasTag, IXBaseReferenced - {} + public interface IXFileProvider : IXBaseProvidedHasTag, IXBaseReferenced + { } } \ No newline at end of file diff --git a/Providers/XFileProvider.cs b/Providers/XFileProvider.cs index de594ba..f7f9a90 100644 --- a/Providers/XFileProvider.cs +++ b/Providers/XFileProvider.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -18,6 +19,8 @@ namespace xFileService.Providers { public class XFileProvider : XBaseProvidedHasTag, IXFileProvider { + private readonly IXFileServiceProvider provider; + public XFileProvider( IXFileTagProvider tagProvider, IXFileServiceProvider provider @@ -26,10 +29,12 @@ namespace xFileService.Providers tagProvider: tagProvider, permittedRoles: new string[] { "admin" } ) - { } + { + this.provider = provider; + } public override bool IsOwned( - XFile item, + XFile item, XUserClaimsInfoDto userInfo ) { @@ -45,7 +50,7 @@ namespace xFileService.Providers } public override bool IsOwned( - XFileDto item, + XFileDto item, XUserClaimsInfoDto userInfo ) { @@ -68,9 +73,9 @@ namespace xFileService.Providers /// /// /// - public string GetIdentifier( + public string GetIdentifier( string providedFor, - TKey forProvidedId + TReferenceKey forProvidedId ) { // @@ -88,9 +93,9 @@ namespace xFileService.Providers /// /// /// - public async Task IsProvidedFor( + public async Task IsProvidedFor( string providedFor, - TKey forProvidedId, + TReferenceKey forProvidedId, Guid id, CancellationToken cancellationToken = default ) @@ -155,9 +160,9 @@ namespace xFileService.Providers /// /// /// - public async Task AddReference( + public async Task AddReference( string providedFor, - TKey forProvidedId, + TReferenceKey forProvidedId, Guid id, int forIndex = 0, XUserClaimsInfoDto userInfo = null, @@ -239,9 +244,9 @@ namespace xFileService.Providers /// /// /// - public async Task RemoveReference( + public async Task RemoveReference( string providedFor, - TKey forProvidedId, + TReferenceKey forProvidedId, Guid id, int forIndex = 0, XUserClaimsInfoDto userInfo = null, @@ -317,6 +322,48 @@ namespace xFileService.Providers cancellationToken: cancellationToken ); } + + /// + /// Get Specified References ... + /// + /// + /// + /// + /// + public async Task>> GetReferences( + string providedFor, + Guid id, + CancellationToken cancellationToken = default + ) + { + // + IList> result = new List>(); + + // + var item = await provider.GetAsync( + id: id, + includeBuilder: null, + ignoreSoftDeleteds: true, + cancellationToken: cancellationToken + ); + var isValid = !item.IsNullOrDefault(); + if (!isValid) + { + return result; + } + + // + result = item.GetReferences(); + + // + result = result.Where(r => + r.ProvidedFor == providedFor + ) + .ToList(); + + // + return result; + } #endregion } } \ No newline at end of file