fix: align web api parameter binding with m42 example
This commit is contained in:
@@ -38,15 +38,17 @@ namespace C4IT.F4SD
|
||||
//public readonly IObjectService _objectService;
|
||||
//public readonly IFragmentService _fragmentService;
|
||||
private readonly IDependencyResolver _resolver;
|
||||
private readonly IEnumerationProvider _enumerationProvider;
|
||||
|
||||
|
||||
private readonly F4SDHelperService _f4stHelperService;
|
||||
public string BaseUrl => Request?.RequestUri == null ? string.Empty : $"{Request.RequestUri.Scheme}://{Request.RequestUri.Host}";
|
||||
public string EndpointBaseUrl => $"{BaseUrl}/m42Services/api/c4itf4sdwebapi";
|
||||
|
||||
public F4SDM42WebApiController(IDependencyResolver resolver)
|
||||
public F4SDM42WebApiController(IDependencyResolver resolver, IEnumerationProvider enumerationProvider)
|
||||
{
|
||||
_resolver = resolver ?? throw new ArgumentNullException(nameof(resolver));
|
||||
_enumerationProvider = enumerationProvider ?? throw new ArgumentNullException(nameof(enumerationProvider));
|
||||
defaultInstance = this;
|
||||
//_objectService = objectService;
|
||||
//_fragmentService = fragmentService;
|
||||
@@ -84,11 +86,6 @@ namespace C4IT.F4SD
|
||||
return GetRequiredService<IJournalService>();
|
||||
}
|
||||
|
||||
private IEnumerationProvider GetEnumerationProvider()
|
||||
{
|
||||
return GetRequiredService<IEnumerationProvider>();
|
||||
}
|
||||
|
||||
private T GetRequiredService<T>() where T : class
|
||||
{
|
||||
var service = _resolver.TryGet<T>();
|
||||
@@ -99,34 +96,25 @@ namespace C4IT.F4SD
|
||||
}
|
||||
|
||||
[Route("getDirectLinkCreateTicket"), HttpGet]
|
||||
public async Task<F4SDHelperService.DirectLink> getDirectLinkCreateTicket([FromUri] string sid = "", [FromUri] string assetname = "")
|
||||
public async Task<F4SDHelperService.DirectLink> getDirectLinkCreateTicket(string sid = "", string assetname = "")
|
||||
{
|
||||
await Task.Delay(0);
|
||||
sid = GetQueryString("sid", sid);
|
||||
assetname = GetQueryString("assetname", assetname);
|
||||
return await _f4stHelperService.getDirectLinkCreateTicket(sid, assetname);
|
||||
}
|
||||
[Route("getDirectLinkF4SD"), HttpGet]
|
||||
public async Task<string> getDirectLinkF4SD([FromUri] Guid EOID, [FromUri] string Type)
|
||||
public async Task<string> getDirectLinkF4SD(Guid EOID, string Type)
|
||||
{
|
||||
EOID = GetQueryGuid("EOID", EOID);
|
||||
Type = GetQueryString("Type", Type);
|
||||
return await _f4stHelperService.getDirectLinkF4SD(EOID, Type);
|
||||
}
|
||||
|
||||
[Route("getTicketList"), HttpGet]
|
||||
public async Task<List<cF4SDTicketSummary>> getTicketList(
|
||||
[FromUri] string sid,
|
||||
[FromUri] int hours,
|
||||
[FromUri] int queueoption = 0,
|
||||
[FromUri] string queues = ""
|
||||
string sid,
|
||||
int hours,
|
||||
int queueoption = 0,
|
||||
string queues = ""
|
||||
)
|
||||
{
|
||||
sid = GetQueryString("sid", sid);
|
||||
hours = GetQueryInt("hours", hours);
|
||||
queueoption = GetQueryInt("queueoption", queueoption);
|
||||
queues = GetQueryString("queues", queues);
|
||||
|
||||
var decodedPairs = ParseQueues(queues);
|
||||
|
||||
// Nun weiterreichen an Service
|
||||
@@ -140,9 +128,8 @@ namespace C4IT.F4SD
|
||||
|
||||
|
||||
[Route("getTicketDetails"), HttpGet]
|
||||
public async Task<cF4SDTicket> getTicketDetails([FromUri] Guid objectId)
|
||||
public async Task<cF4SDTicket> getTicketDetails(Guid objectId)
|
||||
{
|
||||
objectId = GetQueryGuid("objectId", objectId);
|
||||
var tickets = await _f4stHelperService.getTicketDetails(new List<Guid>() { objectId });
|
||||
if (tickets.Count > 0)
|
||||
return tickets[0];
|
||||
@@ -151,27 +138,20 @@ namespace C4IT.F4SD
|
||||
}
|
||||
|
||||
[Route("getTicketHistory"), HttpGet]
|
||||
public async Task<List<cTicketJournalItem>> getTicketHistory([FromUri] Guid objectId)
|
||||
public async Task<List<cTicketJournalItem>> getTicketHistory(Guid objectId)
|
||||
{
|
||||
objectId = GetQueryGuid("objectId", objectId);
|
||||
return await _f4stHelperService.GetJournalEntries(objectId);
|
||||
}
|
||||
|
||||
[Route("getTicketOverviewCounts"), HttpGet]
|
||||
public async Task<F4SDHelperService.TicketOverviewCountsResult> getTicketOverviewCounts(
|
||||
[FromUri] string sid,
|
||||
[FromUri] string scope = "personal",
|
||||
[FromUri] string keys = "",
|
||||
[FromUri] int queueoption = 0,
|
||||
[FromUri] string queues = ""
|
||||
string sid,
|
||||
string scope = "personal",
|
||||
string keys = "",
|
||||
int queueoption = 0,
|
||||
string queues = ""
|
||||
)
|
||||
{
|
||||
sid = GetQueryString("sid", sid);
|
||||
scope = GetQueryString("scope", scope);
|
||||
keys = GetQueryString("keys", keys);
|
||||
queueoption = GetQueryInt("queueoption", queueoption);
|
||||
queues = GetQueryString("queues", queues);
|
||||
|
||||
var parsedKeys = (keys ?? string.Empty)
|
||||
.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(key => key.Trim())
|
||||
@@ -208,21 +188,14 @@ namespace C4IT.F4SD
|
||||
|
||||
[Route("getTicketOverviewRelations"), HttpGet]
|
||||
public async Task<List<F4SDHelperService.TicketOverviewRelationDto>> getTicketOverviewRelations(
|
||||
[FromUri] string sid,
|
||||
[FromUri] string scope = "personal",
|
||||
[FromUri] string key = "",
|
||||
[FromUri] int count = 0,
|
||||
[FromUri] int queueoption = 0,
|
||||
[FromUri] string queues = ""
|
||||
string sid,
|
||||
string scope = "personal",
|
||||
string key = "",
|
||||
int count = 0,
|
||||
int queueoption = 0,
|
||||
string queues = ""
|
||||
)
|
||||
{
|
||||
sid = GetQueryString("sid", sid);
|
||||
scope = GetQueryString("scope", scope);
|
||||
key = GetQueryString("key", key);
|
||||
count = GetQueryInt("count", count);
|
||||
queueoption = GetQueryInt("queueoption", queueoption);
|
||||
queues = GetQueryString("queues", queues);
|
||||
|
||||
var decodedQueues = ParseQueues(queues);
|
||||
return await _f4stHelperService.getTicketOverviewRelations(sid, scope, key, count, queueoption, decodedQueues);
|
||||
}
|
||||
@@ -238,11 +211,9 @@ namespace C4IT.F4SD
|
||||
*/
|
||||
[Route("getPickup/{name}"), HttpGet]
|
||||
//[CacheOutput(UseETAG = true)]
|
||||
public async Task<HttpResponseMessage> getPickup(string name, [FromUri] EntityEnumerationVisibilityMode mode = EntityEnumerationVisibilityMode.None, [FromUri] Int32 group = -1)
|
||||
public async Task<HttpResponseMessage> getPickup(string name, EntityEnumerationVisibilityMode mode = EntityEnumerationVisibilityMode.None, Int32 group = -1)
|
||||
{
|
||||
await Task.Delay(0);
|
||||
mode = GetQueryEnum("mode", mode);
|
||||
group = GetQueryInt("group", group);
|
||||
EntityEnumeration enumerationTemp = GetEnumeration(name, mode);
|
||||
var vals = enumerationTemp.Values;
|
||||
|
||||
@@ -278,26 +249,21 @@ namespace C4IT.F4SD
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("getRoleMemberships")]
|
||||
public async Task<HttpResponseMessage> getRoleMemberships([FromUri] GetRoleMembershipsRequest req)
|
||||
public async Task<HttpResponseMessage> getRoleMemberships(Guid? id = null, string sid = "", string upn = "")
|
||||
{
|
||||
req = req ?? new GetRoleMembershipsRequest();
|
||||
req.Id = GetQueryGuid("id", req.Id ?? Guid.Empty);
|
||||
req.Sid = GetQueryString("sid", req.Sid);
|
||||
req.Upn = GetQueryString("upn", req.Upn);
|
||||
|
||||
var filter = "";
|
||||
|
||||
if (req.Id != null && req.Id.Value != Guid.Empty)
|
||||
if (id != null && id.Value != Guid.Empty)
|
||||
{
|
||||
filter = AsqlHelper.BuildInCondition("ID", new Guid[] { req.Id.Value });
|
||||
filter = AsqlHelper.BuildInCondition("ID", new Guid[] { id.Value });
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(req.Sid))
|
||||
else if (!string.IsNullOrEmpty(sid))
|
||||
{
|
||||
filter = AsqlHelper.BuildInCondition("Accounts.T(SPSAccountClassAD).Sid", new string[] { req.Sid });
|
||||
filter = AsqlHelper.BuildInCondition("Accounts.T(SPSAccountClassAD).Sid", new string[] { sid });
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(req.Upn))
|
||||
else if (!string.IsNullOrEmpty(upn))
|
||||
{
|
||||
filter = AsqlHelper.BuildInCondition("Accounts.T(SPSAccountClassAD).UserPrincipalName", new string[] { req.Upn });
|
||||
filter = AsqlHelper.BuildInCondition("Accounts.T(SPSAccountClassAD).UserPrincipalName", new string[] { upn });
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(filter))
|
||||
@@ -310,14 +276,6 @@ namespace C4IT.F4SD
|
||||
}
|
||||
}
|
||||
|
||||
public class GetRoleMembershipsRequest
|
||||
{
|
||||
public Guid? Id { get; set; }
|
||||
public string Sid { get; set; }
|
||||
public string Upn { get; set; }
|
||||
public GetRoleMembershipsRequest() { }
|
||||
}
|
||||
|
||||
public class TicketOverviewCountsByRolesRequest
|
||||
{
|
||||
public string Sid { get; set; }
|
||||
@@ -330,7 +288,7 @@ namespace C4IT.F4SD
|
||||
private EntityEnumeration GetEnumeration(string name, EntityEnumerationVisibilityMode mode)
|
||||
{
|
||||
name = name?.Trim();
|
||||
var dataTable = GetEnumerationProvider().GetEnumeration(name, GetVisibilityFilter(mode));
|
||||
var dataTable = _enumerationProvider.GetEnumeration(name, GetVisibilityFilter(mode));
|
||||
if (dataTable == null)
|
||||
throw new InvalidOperationException($"Enumeration '{name}' was not found.");
|
||||
|
||||
@@ -416,49 +374,6 @@ namespace C4IT.F4SD
|
||||
?? Guid.Empty;
|
||||
}
|
||||
|
||||
private string GetQueryString(string name, string currentValue)
|
||||
{
|
||||
var queryValue = GetQueryValue(name);
|
||||
return string.IsNullOrEmpty(queryValue) ? currentValue : queryValue;
|
||||
}
|
||||
|
||||
private int GetQueryInt(string name, int currentValue)
|
||||
{
|
||||
var queryValue = GetQueryValue(name);
|
||||
return int.TryParse(queryValue, out var parsedValue) ? parsedValue : currentValue;
|
||||
}
|
||||
|
||||
private Guid GetQueryGuid(string name, Guid currentValue)
|
||||
{
|
||||
var queryValue = GetQueryValue(name);
|
||||
return Guid.TryParse(queryValue, out var parsedValue) ? parsedValue : currentValue;
|
||||
}
|
||||
|
||||
private TEnum GetQueryEnum<TEnum>(string name, TEnum currentValue) where TEnum : struct
|
||||
{
|
||||
var queryValue = GetQueryValue(name);
|
||||
return Enum.TryParse<TEnum>(queryValue, true, out var parsedValue) ? parsedValue : currentValue;
|
||||
}
|
||||
|
||||
private string GetQueryValue(string name)
|
||||
{
|
||||
var query = Request?.RequestUri?.Query;
|
||||
if (string.IsNullOrWhiteSpace(query))
|
||||
return null;
|
||||
|
||||
foreach (var pair in query.TrimStart('?').Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
var parts = pair.Split(new[] { '=' }, 2);
|
||||
var key = WebUtility.UrlDecode(parts[0]);
|
||||
if (!string.Equals(key, name, StringComparison.OrdinalIgnoreCase))
|
||||
continue;
|
||||
|
||||
return parts.Length > 1 ? WebUtility.UrlDecode(parts[1]) : string.Empty;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static List<cApiM42TicketQueueInfo> ParseQueues(string queues)
|
||||
{
|
||||
return (queues ?? string.Empty)
|
||||
@@ -487,14 +402,13 @@ namespace C4IT.F4SD
|
||||
}
|
||||
|
||||
[Route("loglevel"), HttpGet]
|
||||
public async Task<string> setDebugMode([FromUri] string debug = "0")
|
||||
public async Task<string> setDebugMode(string debug = "0")
|
||||
{
|
||||
var CM = MethodBase.GetCurrentMethod();
|
||||
LogMethodBegin(CM);
|
||||
try
|
||||
{
|
||||
await Task.Delay(0);
|
||||
debug = GetQueryString("debug", debug);
|
||||
DefaultLogger.Manager.Level = debug == "1" || debug.Equals("true", StringComparison.OrdinalIgnoreCase) ? LogLevels.Debug : LogLevels.Info;
|
||||
return DefaultLogger.Manager.Level.ToString();
|
||||
}
|
||||
@@ -510,13 +424,10 @@ namespace C4IT.F4SD
|
||||
}
|
||||
|
||||
[Route("log"), HttpGet]
|
||||
public HttpResponseMessage getLog([FromUri] string download = "0", [FromUri] int count = 50, [FromUri] string filter = "")
|
||||
public HttpResponseMessage getLog(string download = "0", int count = 50, string filter = "")
|
||||
{
|
||||
try
|
||||
{
|
||||
download = GetQueryString("download", download);
|
||||
count = GetQueryInt("count", count);
|
||||
filter = GetQueryString("filter", filter);
|
||||
return _f4stHelperService.privGetLog(download, count, Request, filter);
|
||||
}
|
||||
catch (Exception E)
|
||||
|
||||
Reference in New Issue
Block a user