[FA-misc] Mass transit overhaul, needs testing and review
This commit is contained in:
52
FictionArchive.Service.ReportingService/GraphQL/Query.cs
Normal file
52
FictionArchive.Service.ReportingService/GraphQL/Query.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Text.Json;
|
||||
using FictionArchive.Service.ReportingService.Models.Database;
|
||||
using FictionArchive.Service.ReportingService.Models.DTOs;
|
||||
using FictionArchive.Service.ReportingService.Services;
|
||||
using HotChocolate;
|
||||
using HotChocolate.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FictionArchive.Service.ReportingService.GraphQL;
|
||||
|
||||
public class Query
|
||||
{
|
||||
[UseProjection]
|
||||
[UseFiltering]
|
||||
[UseSorting]
|
||||
[GraphQLName("reportingJobs")]
|
||||
public IQueryable<Job> GetReportingJobs(ReportingServiceDbContext dbContext)
|
||||
=> dbContext.Jobs.Include(j => j.History);
|
||||
|
||||
[GraphQLName("reportingJob")]
|
||||
public async Task<JobDto?> GetReportingJob(Guid id, ReportingServiceDbContext dbContext)
|
||||
{
|
||||
var job = await dbContext.Jobs
|
||||
.Include(j => j.History.OrderBy(h => h.Timestamp))
|
||||
.FirstOrDefaultAsync(j => j.Id == id);
|
||||
|
||||
if (job == null) return null;
|
||||
|
||||
return new JobDto
|
||||
{
|
||||
Id = job.Id,
|
||||
JobType = job.JobType,
|
||||
Status = job.Status,
|
||||
CurrentStep = job.CurrentStep,
|
||||
ErrorMessage = job.ErrorMessage,
|
||||
Metadata = job.Metadata != null
|
||||
? JsonSerializer.Deserialize<Dictionary<string, object>>(job.Metadata.RootElement.GetRawText())
|
||||
: null,
|
||||
History = job.History.Select(h => new JobHistoryEntryDto
|
||||
{
|
||||
FromState = h.FromState,
|
||||
ToState = h.ToState,
|
||||
Message = h.Message,
|
||||
Error = h.Error,
|
||||
Timestamp = h.Timestamp
|
||||
}).ToList(),
|
||||
CreatedTime = job.CreatedTime,
|
||||
UpdatedTime = job.UpdatedTime,
|
||||
CompletedTime = job.CompletedTime
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user