324 lines
9.2 KiB
C#
324 lines
9.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using Microsoft.Extensions.Logging;
|
|
using xApi.Base;
|
|
using xCommons.Configurations;
|
|
using xCommons.Extensions;
|
|
using xCommons.Providers;
|
|
using xDataService.Interfaces;
|
|
using xFileService.Interfaces.Entities;
|
|
using xFileService.Models.Entities;
|
|
using xIdentityHelper;
|
|
using xIdentityService.Interfaces;
|
|
using xModels.Base;
|
|
using xModels.Dtos;
|
|
using xPushService.Base;
|
|
using xPushService.Constants;
|
|
|
|
namespace xApi.Controllers.V1.Entities
|
|
{
|
|
public class FilesController : XIBaseV1EntityHubController<XFile, Guid>
|
|
{
|
|
//
|
|
#region Constructor ...
|
|
public FilesController(
|
|
ILogger<FilesController> logger,
|
|
XAppConfiguration appConfiguration,
|
|
IXIdentityProvider identityProvider,
|
|
XValidationProvider validationProvider,
|
|
IXFileRepository repository,
|
|
IHubContext<XBaseEntityHub<XFile, Guid>> hub = null
|
|
) : base(
|
|
logger,
|
|
appConfiguration,
|
|
identityProvider,
|
|
validationProvider,
|
|
repository,
|
|
hub
|
|
)
|
|
{ }
|
|
#endregion
|
|
|
|
//
|
|
#region Interface Implementations ...
|
|
//
|
|
#region Retrieve ...
|
|
[HttpGet("{id}")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public override async Task<ActionResult<XFile>> Get(
|
|
[FromRoute] Guid id, [FromQuery] bool ignoreSoftDeleteds = true, [FromQuery] bool containsDetail = false
|
|
)
|
|
{
|
|
return await base
|
|
.Get(
|
|
id: id,
|
|
containsDetail: containsDetail,
|
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
);
|
|
}
|
|
|
|
[HttpGet]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public override async Task<ActionResult<IEnumerable<XFile>>> GetAll(
|
|
[FromQuery] bool ignoreSoftDeleteds = true, [FromQuery] bool containsDetail = false
|
|
)
|
|
{
|
|
return await base
|
|
.GetAll(
|
|
containsDetail: containsDetail,
|
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
);
|
|
}
|
|
|
|
[HttpGet("FindOne/{query}")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public override async Task<ActionResult<XFile>> FindOne(
|
|
[FromRoute] string query, [FromQuery] bool ignoreSoftDeleteds = true, [FromQuery] bool containsDetail = false
|
|
)
|
|
{
|
|
return await base
|
|
.FindOne(
|
|
query: query,
|
|
containsDetail: containsDetail,
|
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
);
|
|
}
|
|
|
|
[HttpGet("FindMany/{query}")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public override async Task<ActionResult<IEnumerable<XFile>>> FindMany(
|
|
[FromRoute] string query, [FromQuery] bool ignoreSoftDeleteds = true, [FromQuery] bool containsDetail = false
|
|
)
|
|
{
|
|
return await base
|
|
.FindMany(
|
|
query: query,
|
|
containsDetail: containsDetail,
|
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
);
|
|
}
|
|
|
|
[HttpGet("Query")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public override async Task<ActionResult<XQueryResult<XFile>>> Query(
|
|
[FromQuery] XQuery query, [FromQuery] bool ignoreSoftDeleteds = true
|
|
)
|
|
{
|
|
return await base
|
|
.Query(
|
|
query: query,
|
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
);
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Add ...
|
|
[HttpPost]
|
|
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
public override async Task<ActionResult<XFile>> Add(
|
|
[FromBody] XFile item
|
|
)
|
|
{
|
|
//
|
|
var entity = await base
|
|
.Add(item);
|
|
|
|
//
|
|
if (!entity.IsNullOrDefault())
|
|
{
|
|
//
|
|
await SendPush(
|
|
action: XBaseEntityHubAction.Add.GetStringValue(),
|
|
payLoad: entity.ToJSON()
|
|
);
|
|
}
|
|
|
|
//
|
|
return entity;
|
|
}
|
|
|
|
[HttpPost("AddOrUpdate")]
|
|
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
public override async Task<ActionResult<XFile>> AddOrUpdate(
|
|
[FromBody] XFile item
|
|
)
|
|
{
|
|
//
|
|
var entity = await base
|
|
.AddOrUpdate(item);
|
|
|
|
//
|
|
if (!entity.IsNullOrDefault())
|
|
{
|
|
//
|
|
await SendPush(
|
|
action: XBaseEntityHubAction.AddOrUpdate.GetStringValue(),
|
|
payLoad: entity.ToJSON()
|
|
);
|
|
}
|
|
|
|
//
|
|
return entity;
|
|
}
|
|
|
|
[HttpPost("AddMany")]
|
|
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
public override async Task<ActionResult> AddMany(
|
|
[FromBody] XBaseRangeRequest<XFile> request
|
|
)
|
|
{
|
|
//
|
|
var result = await base
|
|
.AddMany(request);
|
|
|
|
//
|
|
if (!(result as OkObjectResult).IsNull())
|
|
{
|
|
//
|
|
await SendPush(
|
|
action: XBaseEntityHubAction.AddMany.GetStringValue(),
|
|
payLoad: request.Items.ToJSON()
|
|
);
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Update ...
|
|
[HttpPut("{id}")]
|
|
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
public override async Task<ActionResult<XFile>> Update(
|
|
[FromRoute] Guid id, [FromBody] XFile item
|
|
)
|
|
{
|
|
//
|
|
var entity = await base
|
|
.Update(
|
|
id,
|
|
item
|
|
);
|
|
|
|
//
|
|
if (!entity.IsNullOrDefault())
|
|
{
|
|
//
|
|
await SendPush(
|
|
action: XBaseEntityHubAction.Update.GetStringValue(),
|
|
payLoad: entity.ToJSON()
|
|
);
|
|
}
|
|
|
|
//
|
|
return entity;
|
|
}
|
|
|
|
[HttpPost("UpdateMany")]
|
|
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
public override async Task<ActionResult<bool>> UpdateMany(
|
|
[FromBody] XBaseRangeRequest<XFile> request
|
|
)
|
|
{
|
|
//
|
|
var result = await base
|
|
.UpdateMany(request);
|
|
|
|
//
|
|
var resultObject = (result.Result as OkObjectResult).Value;
|
|
if (!resultObject.IsNull() && (bool)resultObject)
|
|
{
|
|
//
|
|
await SendPush(
|
|
action: XBaseEntityHubAction.UpdateMany.GetStringValue(),
|
|
payLoad: request.Items.ToJSON()
|
|
);
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Exists ...
|
|
[HttpGet("{id}/IsExists")]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public override async Task<ActionResult<bool>> IsExists(
|
|
[FromRoute] Guid id, [FromQuery] bool ignoreSoftDeleteds = true
|
|
)
|
|
{
|
|
return await base
|
|
.IsExists(
|
|
id: id,
|
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
);
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Remove ...
|
|
[HttpDelete("{id}")]
|
|
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
public override async Task<ActionResult<XFile>> Remove(
|
|
[FromRoute] Guid id, bool softDelete = true
|
|
)
|
|
{
|
|
//
|
|
var entity = await base
|
|
.Remove(
|
|
id: id,
|
|
softDelete: softDelete
|
|
);
|
|
|
|
//
|
|
if (!entity.IsNullOrDefault())
|
|
{
|
|
//
|
|
await SendPush(
|
|
action: XBaseEntityHubAction.Delete.GetStringValue(),
|
|
payLoad: entity.ToJSON()
|
|
);
|
|
}
|
|
|
|
//
|
|
return entity;
|
|
}
|
|
|
|
[HttpPost("RemoveMany")]
|
|
[Authorize(Policy = XPolicies.EnabledAdminOrAgent)]
|
|
public override async Task<ActionResult> RemoveMany(
|
|
[FromBody] XBaseRangeRequest<XFile> request, bool softDelete = true
|
|
)
|
|
{
|
|
//
|
|
var result = await base
|
|
.RemoveMany(
|
|
request: request,
|
|
softDelete: softDelete
|
|
);
|
|
|
|
//
|
|
if (!(result as OkObjectResult).IsNull())
|
|
{
|
|
//
|
|
await SendPush(
|
|
action: XBaseEntityHubAction.DeleteMany.GetStringValue(),
|
|
payLoad: request.Items.ToJSON()
|
|
);
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
#endregion
|
|
#endregion
|
|
}
|
|
} |