using System;
using System.Threading;
using System.Threading.Tasks;
using FastEndpoints;
using FrameworkBLL.SysJobShare;
using GB5Shared.DTO.Framework.Login;
using GB5Shared.DTO.Framework.ResponseStandard;
using GB5Shared.FastEndPoint;
using static FrameworkDAL.Constant.Constant;
namespace FrameworkSL.Endpoints.SysJobShare
{
///
/// Returns all users a given job has been shared with.
/// Used to render the share panel / share dialog for a job.
///
public class GetListSysJobShare : BaseEndpoint>
{
private readonly ISysJobShareBLL _SysJobShareBLL;
public GetListSysJobShare(ISysJobShareBLL sysJobShareBLL)
{
_SysJobShareBLL = sysJobShareBLL;
}
public override void Configure()
{
Get("/SysJobShare/GetListSysJobShare");
AllowAnonymous();
}
public record GetListSysJobShareParameters(
[property: FromHeader] string Login,
[property: QueryParam] int SysJobId
);
protected override async Task> ExecuteAsync(GetListSysJobShareParameters req, LoginDTO LoginDTO, CancellationToken ct)
{
try
{
var Result = await _SysJobShareBLL.GetListSysJobShare(req.SysJobId, LoginDTO!);
return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(Result, CacheKeyLevel.UserLevel, LoginDTO);
}
catch (Exception ex)
{
return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.UserLevel, LoginDTO, ex.Message, 500);
}
}
}
}