kast ...
This commit is contained in:
@@ -0,0 +1,222 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore.Query;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using xCommons.Configurations;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xCommons.Providers;
|
||||||
|
using xExceptions.Constants;
|
||||||
|
using xFileService.Interfaces;
|
||||||
|
using xFileService.Models.Dtos;
|
||||||
|
using xFileService.Models.Entities;
|
||||||
|
using xFileService.Providers.Dtos;
|
||||||
|
using xIdentityService.Interfaces;
|
||||||
|
using xTagService.Controllers;
|
||||||
|
|
||||||
|
namespace xFileService.Controllers
|
||||||
|
{
|
||||||
|
public abstract class XFileProviderControllerBase : XBaseProvidedHasTagControllerBase<XFile, XFileDto, Guid, XFileDtoHub>, IXFileProviderController
|
||||||
|
{
|
||||||
|
private readonly IXFileProvider provider;
|
||||||
|
|
||||||
|
protected XFileProviderControllerBase(
|
||||||
|
ILogger<XFileProviderControllerBase> logger,
|
||||||
|
XAppConfiguration appConfiguration,
|
||||||
|
IXIdentityProvider identityProvider,
|
||||||
|
XValidationProvider validationProvider,
|
||||||
|
IXFileProvider provider,
|
||||||
|
IXFileTagProvided tagProvided,
|
||||||
|
Func<IQueryable<XFile>, IOrderedQueryable<XFile>> defaultOrderBuilder = null,
|
||||||
|
Func<IQueryable<XFile>, IIncludableQueryable<XFile, object>> defaultIncludeBuilder = null
|
||||||
|
) : base(
|
||||||
|
logger,
|
||||||
|
appConfiguration,
|
||||||
|
identityProvider,
|
||||||
|
validationProvider,
|
||||||
|
provider,
|
||||||
|
tagProvided,
|
||||||
|
defaultOrderBuilder,
|
||||||
|
defaultIncludeBuilder
|
||||||
|
)
|
||||||
|
{
|
||||||
|
this.provider = provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Reference ...
|
||||||
|
/// <summary>
|
||||||
|
/// Check an Item Has Reference to Specified ProvideFor and Specified forProvidedId ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="providedFor"></param>
|
||||||
|
/// <param name="forProvidedId"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("{id}/Reference/IsProvidedFor")]
|
||||||
|
public virtual async Task<ActionResult<bool>> IsProvidedFor(
|
||||||
|
[FromRoute] Guid id,
|
||||||
|
[FromQuery] string providedFor,
|
||||||
|
[FromQuery] object forProvidedId,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
await ValidationProvider
|
||||||
|
.GroupValidationBuilder()
|
||||||
|
.AddNotNull(id)
|
||||||
|
.AddNotEmpty(providedFor)
|
||||||
|
.AddNotNull(forProvidedId)
|
||||||
|
.ValidateGroupAsync();
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await provider.IsProvidedFor(
|
||||||
|
id: id,
|
||||||
|
providedFor: providedFor,
|
||||||
|
forProvidedId: forProvidedId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a Reference to Item for Specified ProvideFor and Specified forProvidedId ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="providedFor"></param>
|
||||||
|
/// <param name="forProvidedId"></param>
|
||||||
|
/// <param name="forIndex"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("{id}/Reference")]
|
||||||
|
public virtual async Task<ActionResult> AddReference(
|
||||||
|
[FromRoute] Guid id,
|
||||||
|
[FromQuery] string providedFor,
|
||||||
|
[FromQuery] object forProvidedId,
|
||||||
|
[FromQuery] int forIndex = 0,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
await ValidationProvider
|
||||||
|
.GroupValidationBuilder()
|
||||||
|
.AddNotNull(id)
|
||||||
|
.AddNotEmpty(providedFor)
|
||||||
|
.AddNotNull(forProvidedId)
|
||||||
|
.ValidateGroupAsync();
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
var connectionId = GetConnectionId();
|
||||||
|
|
||||||
|
//
|
||||||
|
await provider.AddReference(
|
||||||
|
id: id,
|
||||||
|
forIndex: forIndex,
|
||||||
|
userInfo: userInfo,
|
||||||
|
providedFor: providedFor,
|
||||||
|
connectionId: connectionId,
|
||||||
|
forProvidedId: forProvidedId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove a Reference from Item for Specified ProvideFor and Specified forProvidedId ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="providedFor"></param>
|
||||||
|
/// <param name="forProvidedId"></param>
|
||||||
|
/// <param name="forIndex"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpDelete("{id}/Reference")]
|
||||||
|
public virtual async Task<ActionResult> RemoveReference(
|
||||||
|
[FromRoute] Guid id,
|
||||||
|
[FromQuery] string providedFor,
|
||||||
|
[FromQuery] object forProvidedId,
|
||||||
|
[FromQuery] int forIndex = 0,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
await ValidationProvider
|
||||||
|
.GroupValidationBuilder()
|
||||||
|
.AddNotNull(id)
|
||||||
|
.AddNotEmpty(providedFor)
|
||||||
|
.AddNotNull(forProvidedId)
|
||||||
|
.ValidateGroupAsync();
|
||||||
|
|
||||||
|
//
|
||||||
|
var userInfo = await GetUserInfo();
|
||||||
|
var connectionId = GetConnectionId();
|
||||||
|
|
||||||
|
//
|
||||||
|
await provider.RemoveReference(
|
||||||
|
id: id,
|
||||||
|
forIndex: forIndex,
|
||||||
|
userInfo: userInfo,
|
||||||
|
providedFor: providedFor,
|
||||||
|
connectionId: connectionId,
|
||||||
|
forProvidedId: forProvidedId,
|
||||||
|
cancellationToken: cancellationToken
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result = GetExceptionActionResult(ex);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,8 @@ using xFileService.Interfaces.Dtos;
|
|||||||
using xFileService.Interfaces.Entities;
|
using xFileService.Interfaces.Entities;
|
||||||
using xFileService.Providers.Dtos;
|
using xFileService.Providers.Dtos;
|
||||||
using xFileService.Providers.Entities;
|
using xFileService.Providers.Entities;
|
||||||
|
using xFileService.Interfaces;
|
||||||
|
using xFileService.Providers;
|
||||||
|
|
||||||
namespace xFileService.DI
|
namespace xFileService.DI
|
||||||
{
|
{
|
||||||
@@ -213,6 +215,18 @@ namespace xFileService.DI
|
|||||||
new ServiceDescriptor(typeof(IXFileRepositoryProvider), typeof(XFileRepositoryProvider), lifeTime)
|
new ServiceDescriptor(typeof(IXFileRepositoryProvider), typeof(XFileRepositoryProvider), lifeTime)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Register Additional Service ...
|
||||||
|
services.Add(
|
||||||
|
new ServiceDescriptor(typeof(IXFileTagProvider), typeof(XFileTagProvider), lifeTime)
|
||||||
|
);
|
||||||
|
services.Add(
|
||||||
|
new ServiceDescriptor(typeof(IXFileTagProvided), typeof(XFileTagProvided), lifeTime)
|
||||||
|
);
|
||||||
|
services.Add(
|
||||||
|
new ServiceDescriptor(typeof(IXFileProvider), typeof(XFileProvider), lifeTime)
|
||||||
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
Log("Service Regitration Succeed ...");
|
Log("Service Regitration Succeed ...");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using xFileService.Models.Dtos;
|
||||||
using System.Linq;
|
using xFileService.Models.Entities;
|
||||||
using System.Threading.Tasks;
|
using xFileService.Providers.Dtos;
|
||||||
|
using xIdentityService.Interfaces;
|
||||||
|
using xTagService.Interfaces;
|
||||||
|
|
||||||
namespace xFileService.Interfaces
|
namespace xFileService.Interfaces
|
||||||
{
|
{
|
||||||
public interface IXFileProviderController
|
public interface IXFileProviderController : IXBaseProvidedHasTagController<XFile, XFileDto, Guid, XFileDtoHub>, IXBaseReferencedController<XFile, Guid>
|
||||||
{
|
{ }
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
using xFileService.Models.Dtos;
|
||||||
|
using xFileService.Models.Entities;
|
||||||
|
using xFileService.Providers.Dtos;
|
||||||
|
using xTagService.Interfaces;
|
||||||
|
|
||||||
|
namespace xFileService.Interfaces
|
||||||
|
{
|
||||||
|
public interface IXFileTagProvided : IXTagProvided<XFile, XFileDto, Guid, XFileDtoHub>
|
||||||
|
{ }
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xFileService.Interfaces;
|
||||||
|
using xFileService.Interfaces.Dtos;
|
||||||
|
using xFileService.Models.Dtos;
|
||||||
|
using xFileService.Models.Entities;
|
||||||
|
using xFileService.Providers.Dtos;
|
||||||
|
using xIdentityModels.Models;
|
||||||
|
using xTagService.Interfaces;
|
||||||
|
using xTagService.Providers;
|
||||||
|
|
||||||
|
namespace xFileService.Providers
|
||||||
|
{
|
||||||
|
public class XFileTagProvided : XBaseTagProvided<XFile, XFileDto, Guid, XFileDtoHub>, IXFileTagProvided
|
||||||
|
{
|
||||||
|
public XFileTagProvided(
|
||||||
|
IXFileTagProvider tagProvider,
|
||||||
|
IXFileServiceProvider provider
|
||||||
|
) : base(
|
||||||
|
provider: provider,
|
||||||
|
tagProvider: tagProvider,
|
||||||
|
permittedRoles: new string[] { "admin" }
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public override bool IsOwned(
|
||||||
|
XFileDto item,
|
||||||
|
XUserClaimsInfoDto userInfo
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result =
|
||||||
|
!item.IsNullOrDefault() &&
|
||||||
|
!userInfo.IsNullOrDefault() &&
|
||||||
|
item.OwnerId == userInfo.UserId;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool IsOwned(
|
||||||
|
XFile item,
|
||||||
|
XUserClaimsInfoDto userInfo
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var result =
|
||||||
|
!item.IsNullOrDefault() &&
|
||||||
|
!userInfo.IsNullOrDefault() &&
|
||||||
|
item.OwnerId == userInfo.UserId;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,6 @@ namespace xFileService.Providers
|
|||||||
public class XFileTagProvider : XBaseTagProvider<Guid>, IXFileTagProvider
|
public class XFileTagProvider : XBaseTagProvider<Guid>, IXFileTagProvider
|
||||||
{
|
{
|
||||||
public XFileTagProvider(
|
public XFileTagProvider(
|
||||||
string providedFor,
|
|
||||||
IXTagServiceProvider tagProvider
|
IXTagServiceProvider tagProvider
|
||||||
) : base(
|
) : base(
|
||||||
providedFor: nameof(XFile),
|
providedFor: nameof(XFile),
|
||||||
|
|||||||
Reference in New Issue
Block a user