From 5b22246c41d1a4adc48f0d7e23ead4a67b43f2ad Mon Sep 17 00:00:00 2001 From: Glax Date: Fri, 26 Apr 2024 00:14:46 +0200 Subject: [PATCH] Add Endpoint GET /v2/Job returns list of jobs specified by jobid --- Tranga/Server/Server.cs | 1 + Tranga/Server/v2Jobs.cs | 17 ++++++++++++++++- docs/API_Calls_v2.md | 29 +++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/Tranga/Server/Server.cs b/Tranga/Server/Server.cs index cc8db46..f842e1f 100644 --- a/Tranga/Server/Server.cs +++ b/Tranga/Server/Server.cs @@ -37,6 +37,7 @@ public partial class Server : GlobalBase, IDisposable new ("GET", @"/v2/Jobs/Monitoring", GetV2JobsMonitoring), new ("Get", @"/v2/Job/Types", GetV2JobTypes), new ("POST", @"/v2/Job/Create/([a-zA-Z]+)", PostV2JobCreateType), + new ("GET", @"/v2/Job", GetV2Job), new ("GET", @"/v2/Job/([a-zA-Z\.]+-[-A-Za-z0-9+/]*={0,3}(?:-[0-9]+)?)", GetV2JobJobId), new ("DELETE", @"/v2/Job/([a-zA-Z\.]+-[-A-Za-z0-9+/]*={0,3}(?:-[0-9]+)?)", DeleteV2JobJobId), new ("GET", @"/v2/Job/([a-zA-Z\.]+-[-A-Za-z0-9+/]*={0,3}(?:-[0-9]+)?)/Progress", GetV2JobJobIdProgress), diff --git a/Tranga/Server/v2Jobs.cs b/Tranga/Server/v2Jobs.cs index cc4e738..adf6fdb 100644 --- a/Tranga/Server/v2Jobs.cs +++ b/Tranga/Server/v2Jobs.cs @@ -150,5 +150,20 @@ public partial class Server job.Cancel(); return new ValueTuple(HttpStatusCode.OK, null); } - + + private ValueTuple GetV2Job(GroupCollection groups, Dictionary requestParameters) + { + if(!requestParameters.TryGetValue("jobIds", out string? jobIdListStr)) + return new ValueTuple(HttpStatusCode.BadRequest, "Missing parameter 'jobIds'."); + string[] jobIdList = jobIdListStr.Split(','); + List ret = new(); + foreach (string jobId in jobIdList) + { + if(!_parent.jobBoss.TryGetJobById(jobId, out Job? job) || job is null) + return new ValueTuple(HttpStatusCode.NotFound, $"Job with id '{jobId}' not found."); + ret.Add(job); + } + + return new ValueTuple(HttpStatusCode.OK, ret); + } } \ No newline at end of file diff --git a/docs/API_Calls_v2.md b/docs/API_Calls_v2.md index e42a1f4..1587e2a 100644 --- a/docs/API_Calls_v2.md +++ b/docs/API_Calls_v2.md @@ -333,6 +333,35 @@ Creates a Job. | 500 | Error parsing interval | +### ![GET](https://img.shields.io/badge/GET-0f0) `/v2/Job/` + +Returns the list of Jobs requested. + +
+ Request + + | Parameter | Value | + |------------|--------------------------------| + | jobIds | Comma-Seperated list of jobIds | + + `jobId` is returned in the response of + * [GET /v2/Jobs](#-v2jobs) + * [GET /v2/Jobs/Running](#-v2jobsrunning) + * [GET /v2/Jobs/Waiting](#-v2jobswaiting) + * [GET /v2/Jobs/Monitoring](#-v2jobsmonitoring) +
+ +
+ Returns + + List of [Jobs](Types.md#job) + + | StatusCode | Meaning | + |------------|---------------------------------------| + | 400 | Missing Parameter | + | 404 | Manga with `jobId` could not be found | +
+ ### ![GET](https://img.shields.io/badge/GET-0f0) `/v2/Job/` Returns the specified Job.