diff --git a/Tranga/Server/v2Jobs.cs b/Tranga/Server/v2Jobs.cs index 5a6813f..e9c4bf9 100644 --- a/Tranga/Server/v2Jobs.cs +++ b/Tranga/Server/v2Jobs.cs @@ -1,5 +1,6 @@ using System.Net; using System.Text.RegularExpressions; +using Tranga.Jobs; namespace Tranga.Server; @@ -7,22 +8,28 @@ public partial class Server { private ValueTuple GetV2Jobs(GroupCollection groups, Dictionary requestParameters) { - return new ValueTuple(HttpStatusCode.NotImplemented, "Not Implemented"); + return new ValueTuple(HttpStatusCode.OK, _parent.jobBoss.jobs.Select(job => job.id)); } private ValueTuple GetV2JobsRunning(GroupCollection groups, Dictionary requestParameters) { - return new ValueTuple(HttpStatusCode.NotImplemented, "Not Implemented"); + return new ValueTuple(HttpStatusCode.OK, _parent.jobBoss.jobs + .Where(job => job.progressToken.state is ProgressToken.State.Running) + .Select(job => job.id)); } private ValueTuple GetV2JobsWaiting(GroupCollection groups, Dictionary requestParameters) { - return new ValueTuple(HttpStatusCode.NotImplemented, "Not Implemented"); + return new ValueTuple(HttpStatusCode.OK, _parent.jobBoss.jobs + .Where(job => job.progressToken.state is ProgressToken.State.Waiting) + .Select(job => job.id)); } private ValueTuple GetV2JobsMonitoring(GroupCollection groups, Dictionary requestParameters) { - return new ValueTuple(HttpStatusCode.NotImplemented, "Not Implemented"); + return new ValueTuple(HttpStatusCode.OK, _parent.jobBoss.jobs + .Where(job => job.jobType is Job.JobType.DownloadNewChaptersJob) + .Select(job => job.id)); } private ValueTuple PostV2JobsCreateMonitorInternalId(GroupCollection groups, Dictionary requestParameters) @@ -47,7 +54,13 @@ public partial class Server private ValueTuple GetV2JobJobId(GroupCollection groups, Dictionary requestParameters) { - return new ValueTuple(HttpStatusCode.NotImplemented, "Not Implemented"); + if (groups.Count < 1 || + !_parent.jobBoss.TryGetJobById(groups[1].Value, out Job? job) || + job is null) + { + return new ValueTuple(HttpStatusCode.BadRequest, $"Job with ID: '{groups[1].Value}' does not exist."); + } + return new ValueTuple(HttpStatusCode.OK, job); } private ValueTuple DeleteV2JobJobId(GroupCollection groups, Dictionary requestParameters) @@ -57,7 +70,14 @@ public partial class Server private ValueTuple GetV2JobJobIdProgress(GroupCollection groups, Dictionary requestParameters) { - return new ValueTuple(HttpStatusCode.NotImplemented, "Not Implemented"); + + if (groups.Count < 1 || + !_parent.jobBoss.TryGetJobById(groups[1].Value, out Job? job) || + job is null) + { + return new ValueTuple(HttpStatusCode.BadRequest, $"Job with ID: '{groups[1].Value}' does not exist."); + } + return new ValueTuple(HttpStatusCode.OK, job.progressToken); } private ValueTuple PostV2JobJobIdStartNow(GroupCollection groups, Dictionary requestParameters)