473 lines
15 KiB
C#
473 lines
15 KiB
C#
using System;
|
|
using xModels.Dtos;
|
|
using xModels.Base;
|
|
using xIdentityHelper;
|
|
using System.Threading;
|
|
using xCommons.Providers;
|
|
using xAiModels.Models.Dtos;
|
|
using System.Threading.Tasks;
|
|
using xCommons.Configurations;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using xAiModels.Interfaces.Dtos;
|
|
using System.Collections.Generic;
|
|
using xIdentityService.Interfaces;
|
|
using Microsoft.Extensions.Logging;
|
|
using xIdentityService.Controllers;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
namespace xAiApi.Controllers
|
|
{
|
|
[Authorize]
|
|
public class McpServerController : XBaseIdentityApiV1Controller
|
|
{
|
|
public McpServerController(
|
|
XAppConfiguration appConfiguration,
|
|
ILogger<McpServerController> logger,
|
|
IXIdentityProvider identityProvider,
|
|
XValidationProvider validationProvider,
|
|
IXAiMcpServerRepositoryService repositoryService
|
|
) : base(
|
|
logger,
|
|
appConfiguration,
|
|
identityProvider,
|
|
validationProvider
|
|
)
|
|
{ }
|
|
|
|
//
|
|
#region Provider ...
|
|
[HttpPost]
|
|
[Authorize(Policy = XPolicies.EnabledUser)]
|
|
public static async Task<ActionResult<XAiMcpServerDto>> AddMcpServer(
|
|
[FromBody] XAiMcpServerDto item,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
try
|
|
{
|
|
//
|
|
// Validate ...
|
|
if (!files.HasChild())
|
|
{
|
|
XException.InvalidArgs.Throw();
|
|
}
|
|
|
|
//
|
|
var userInfo = await GetUserInfo();
|
|
var connectionId = GetConnectionId();
|
|
|
|
//
|
|
var result = await ragService.IngestAsync(
|
|
files: files,
|
|
userInfo: userInfo,
|
|
connectionId: connectionId,
|
|
replaceExisting: replaceExisting,
|
|
cancellationToken: cancellationToken,
|
|
scope: BuildScope(scope, scopeId, knowledgeType)
|
|
);
|
|
|
|
//
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//
|
|
var result = GetExceptionActionResult(ex);
|
|
return result;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Actions ...
|
|
//
|
|
#region Add ...
|
|
/// <summary>
|
|
/// Add Specified Item ...
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// </remarks>
|
|
/// <param name="item"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
public override async Task<ActionResult<XAiMcpServerDto>> Add(
|
|
[FromBody] XAiMcpServerDto item,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = await base.Add(
|
|
item: item,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add or Update Specified Item ...
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// </remarks>
|
|
/// <param name="item"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("AddOrUpdate")]
|
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
public override async Task<ActionResult<XAiMcpServerDto>> AddOrUpdate(
|
|
[FromBody] XAiMcpServerDto item,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = await base.AddOrUpdate(
|
|
item: item,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add a Collection of Items ...
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// </remarks>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("AddMany")]
|
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
public override async Task<ActionResult> AddMany(
|
|
[FromBody] XBaseRangeRequest<XAiMcpServerDto> request,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = await base.AddMany(
|
|
request: request,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Retrieve ...
|
|
/// <summary>
|
|
/// Get Specified Item ...
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// </remarks>
|
|
/// <param name="id"></param>
|
|
/// <param name="ignoreSoftDeleteds"></param>
|
|
/// <param name="useDefaultIncludes"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("{id}")]
|
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
public override async Task<ActionResult<XAiMcpServerDto>> Get(
|
|
[FromRoute] Guid id,
|
|
[FromQuery] bool ignoreSoftDeleteds = true,
|
|
[FromQuery] bool useDefaultIncludes = false,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = await base.Get(
|
|
id: id,
|
|
cancellationToken: cancellationToken,
|
|
ignoreSoftDeleteds: ignoreSoftDeleteds,
|
|
useDefaultIncludes: useDefaultIncludes
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get All Items ...
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// </remarks>
|
|
/// <param name="ignoreSoftDeleteds"></param>
|
|
/// <param name="useDefaultOrders"></param>
|
|
/// <param name="useDefaultIncludes"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
public override async Task<ActionResult<IEnumerable<XAiMcpServerDto>>> GetAll(
|
|
[FromQuery] bool ignoreSoftDeleteds = true,
|
|
[FromQuery] bool useDefaultOrders = false,
|
|
[FromQuery] bool useDefaultIncludes = false,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = await base.GetAll(
|
|
useDefaultOrders: useDefaultOrders,
|
|
cancellationToken: cancellationToken,
|
|
ignoreSoftDeleteds: ignoreSoftDeleteds,
|
|
useDefaultIncludes: useDefaultIncludes
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Find Specified Item ...
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// </remarks>
|
|
/// <param name="query"></param>
|
|
/// <param name="ignoreSoftDeleteds"></param>
|
|
/// <param name="useDefaultIncludes"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("FindOne/{query}")]
|
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
public override async Task<ActionResult<XAiMcpServerDto>> FindOne(
|
|
[FromRoute] string query,
|
|
[FromQuery] bool ignoreSoftDeleteds = true,
|
|
[FromQuery] bool useDefaultIncludes = false,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = await base.FindOne(
|
|
query: query,
|
|
cancellationToken: cancellationToken,
|
|
ignoreSoftDeleteds: ignoreSoftDeleteds,
|
|
useDefaultIncludes: useDefaultIncludes
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Find Many Items ...
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// </remarks>
|
|
/// <param name="query"></param>
|
|
/// <param name="ignoreSoftDeleteds"></param>
|
|
/// <param name="useDefaultOrders"></param>
|
|
/// <param name="useDefaultIncludes"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("FindMany/{query}")]
|
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
public override async Task<ActionResult<IEnumerable<XAiMcpServerDto>>> FindMany(
|
|
[FromRoute] string query,
|
|
[FromQuery] bool ignoreSoftDeleteds = true,
|
|
[FromQuery] bool useDefaultOrders = false,
|
|
[FromQuery] bool useDefaultIncludes = false,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = await base.FindMany(
|
|
query: query,
|
|
useDefaultOrders: useDefaultOrders,
|
|
cancellationToken: cancellationToken,
|
|
ignoreSoftDeleteds: ignoreSoftDeleteds,
|
|
useDefaultIncludes: useDefaultIncludes
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve Items Based on Query Mechanism ...
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// </remarks>
|
|
/// <param name="query"></param>
|
|
/// <param name="ignoreSoftDeleteds"></param>
|
|
/// <param name="useDefaultOrders"></param>
|
|
/// <param name="useDefaultIncludes"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("Query")]
|
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
public override async Task<ActionResult<XQueryResult<XAiMcpServerDto>>> Query(
|
|
[FromQuery] XQuery query,
|
|
[FromQuery] bool ignoreSoftDeleteds = true,
|
|
[FromQuery] bool useDefaultOrders = false,
|
|
[FromQuery] bool useDefaultIncludes = false,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = await base.Query(
|
|
query: query,
|
|
useDefaultOrders: useDefaultOrders,
|
|
cancellationToken: cancellationToken,
|
|
ignoreSoftDeleteds: ignoreSoftDeleteds,
|
|
useDefaultIncludes: useDefaultIncludes
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Update ...
|
|
/// <summary>
|
|
/// Update Item ...
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// </remarks>
|
|
/// <param name="id"></param>
|
|
/// <param name="item"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPut("{id}")]
|
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
public override async Task<ActionResult<XAiMcpServerDto>> Update(
|
|
[FromRoute] Guid id,
|
|
[FromBody] XAiMcpServerDto item,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = await base.Update(
|
|
id: id,
|
|
item: item,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update a Collection of items ...
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// </remarks>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("UpdateMany")]
|
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
public override async Task<ActionResult<bool>> UpdateMany(
|
|
[FromBody] XBaseRangeRequest<XAiMcpServerDto> request,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = await base.UpdateMany(
|
|
request: request,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Exists ...
|
|
/// <summary>
|
|
///Check an Item Exists or not ...
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// </remarks>
|
|
/// <param name="id"></param>
|
|
/// <param name="ignoreSoftDeleteds"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("{id}/IsExists")]
|
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
public override async Task<ActionResult<bool>> IsExists(
|
|
[FromRoute] Guid id,
|
|
[FromQuery] bool ignoreSoftDeleteds = true,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = await base.IsExists(
|
|
id: id,
|
|
cancellationToken: cancellationToken,
|
|
ignoreSoftDeleteds: ignoreSoftDeleteds
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
//
|
|
#region Remove ...
|
|
/// <summary>
|
|
/// Remove an Items ...
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// </remarks>
|
|
/// <param name="id"></param>
|
|
/// <param name="softDelete"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpDelete("{id}")]
|
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
public override async Task<ActionResult<XAiMcpServerDto>> Remove(
|
|
[FromRoute] Guid id,
|
|
[FromQuery] bool softDelete = false,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = await base.Remove(
|
|
id: id,
|
|
softDelete: softDelete,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove Many Items ...
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// </remarks>
|
|
/// <param name="request"></param>
|
|
/// <param name="softDelete"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("RemoveMany")]
|
|
[Authorize(Policy = XPolicies.EnabledAdmin)]
|
|
public override async Task<ActionResult> RemoveMany(
|
|
[FromBody] XBaseRangeRequest<XAiMcpServerDto> request,
|
|
[FromQuery] bool softDelete = false,
|
|
CancellationToken cancellationToken = default
|
|
)
|
|
{
|
|
//
|
|
var result = await base.RemoveMany(
|
|
request: request,
|
|
softDelete: softDelete,
|
|
cancellationToken: cancellationToken
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
#endregion
|
|
#endregion
|
|
}
|
|
} |