last ...
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -8,6 +9,7 @@ using Microsoft.Extensions.Logging;
|
|||||||
using xCommons.Configurations;
|
using xCommons.Configurations;
|
||||||
using xCommons.Extensions;
|
using xCommons.Extensions;
|
||||||
using xCommons.Providers;
|
using xCommons.Providers;
|
||||||
|
using xDataService.Models;
|
||||||
using xExceptions.Constants;
|
using xExceptions.Constants;
|
||||||
using xFileService.Interfaces;
|
using xFileService.Interfaces;
|
||||||
using xFileService.Models.Dtos;
|
using xFileService.Models.Dtos;
|
||||||
@@ -217,6 +219,54 @@ namespace xFileService.Controllers
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve References of Specified Itemfor providedFor ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="providedFor"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <typeparam name="TReferenceKey"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("{id}/References")]
|
||||||
|
public virtual async Task<ActionResult<IEnumerable<XReference<string>>>> 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
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,6 @@ using xTagService.Interfaces;
|
|||||||
|
|
||||||
namespace xFileService.Interfaces
|
namespace xFileService.Interfaces
|
||||||
{
|
{
|
||||||
public interface IXFileProvider : IXBaseProvidedHasTag<XFile, XFileDto, Guid, XFileDtoHub>, IXBaseReferenced
|
public interface IXFileProvider : IXBaseProvidedHasTag<XFile, XFileDto, Guid, XFileDtoHub>, IXBaseReferenced<XFile, Guid>
|
||||||
{}
|
{ }
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -18,6 +19,8 @@ namespace xFileService.Providers
|
|||||||
{
|
{
|
||||||
public class XFileProvider : XBaseProvidedHasTag<XFile, XFileDto, Guid, XFileDtoHub>, IXFileProvider
|
public class XFileProvider : XBaseProvidedHasTag<XFile, XFileDto, Guid, XFileDtoHub>, IXFileProvider
|
||||||
{
|
{
|
||||||
|
private readonly IXFileServiceProvider provider;
|
||||||
|
|
||||||
public XFileProvider(
|
public XFileProvider(
|
||||||
IXFileTagProvider tagProvider,
|
IXFileTagProvider tagProvider,
|
||||||
IXFileServiceProvider provider
|
IXFileServiceProvider provider
|
||||||
@@ -26,7 +29,9 @@ namespace xFileService.Providers
|
|||||||
tagProvider: tagProvider,
|
tagProvider: tagProvider,
|
||||||
permittedRoles: new string[] { "admin" }
|
permittedRoles: new string[] { "admin" }
|
||||||
)
|
)
|
||||||
{ }
|
{
|
||||||
|
this.provider = provider;
|
||||||
|
}
|
||||||
|
|
||||||
public override bool IsOwned(
|
public override bool IsOwned(
|
||||||
XFile item,
|
XFile item,
|
||||||
@@ -68,9 +73,9 @@ namespace xFileService.Providers
|
|||||||
/// <param name="providedFor"></param>
|
/// <param name="providedFor"></param>
|
||||||
/// <param name="forProvidedId"></param>
|
/// <param name="forProvidedId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GetIdentifier<TKey>(
|
public string GetIdentifier<TReferenceKey>(
|
||||||
string providedFor,
|
string providedFor,
|
||||||
TKey forProvidedId
|
TReferenceKey forProvidedId
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -88,9 +93,9 @@ namespace xFileService.Providers
|
|||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<bool> IsProvidedFor<TKey>(
|
public async Task<bool> IsProvidedFor<TReferenceKey>(
|
||||||
string providedFor,
|
string providedFor,
|
||||||
TKey forProvidedId,
|
TReferenceKey forProvidedId,
|
||||||
Guid id,
|
Guid id,
|
||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
)
|
)
|
||||||
@@ -155,9 +160,9 @@ namespace xFileService.Providers
|
|||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task AddReference<TKey>(
|
public async Task AddReference<TReferenceKey>(
|
||||||
string providedFor,
|
string providedFor,
|
||||||
TKey forProvidedId,
|
TReferenceKey forProvidedId,
|
||||||
Guid id,
|
Guid id,
|
||||||
int forIndex = 0,
|
int forIndex = 0,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
XUserClaimsInfoDto userInfo = null,
|
||||||
@@ -239,9 +244,9 @@ namespace xFileService.Providers
|
|||||||
/// <param name="connectionId"></param>
|
/// <param name="connectionId"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task RemoveReference<TKey>(
|
public async Task RemoveReference<TReferenceKey>(
|
||||||
string providedFor,
|
string providedFor,
|
||||||
TKey forProvidedId,
|
TReferenceKey forProvidedId,
|
||||||
Guid id,
|
Guid id,
|
||||||
int forIndex = 0,
|
int forIndex = 0,
|
||||||
XUserClaimsInfoDto userInfo = null,
|
XUserClaimsInfoDto userInfo = null,
|
||||||
@@ -317,6 +322,48 @@ namespace xFileService.Providers
|
|||||||
cancellationToken: cancellationToken
|
cancellationToken: cancellationToken
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get Specified References ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="providedFor"></param>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<IEnumerable<XReference<string>>> GetReferences(
|
||||||
|
string providedFor,
|
||||||
|
Guid id,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
IList<XReference<string>> result = new List<XReference<string>>();
|
||||||
|
|
||||||
|
//
|
||||||
|
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
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user