Refactored and cleaned some stuff

This commit is contained in:
Marcel Baumgartner
2024-02-06 19:30:30 +01:00
parent caa34dd79d
commit 26ed50c94b
11 changed files with 144 additions and 54 deletions

View File

@@ -1,4 +1,8 @@
using Microsoft.EntityFrameworkCore;
using MoonCore.Abstractions;
using MoonCore.Helpers;
using Moonlight.Features.Servers.Entities;
using Moonlight.Features.Servers.Exceptions;
using Moonlight.Features.Servers.Models.Abstractions;
namespace Moonlight.Features.Servers.Extensions;
@@ -71,4 +75,17 @@ public static class ServerExtensions
return installConfiguration;
}
public static HttpApiClient<NodeException> CreateHttpClient(this Server server, IServiceProvider serviceProvider)
{
using var scope = serviceProvider.CreateScope();
var serverRepo = scope.ServiceProvider.GetRequiredService<Repository<Server>>();
var serverWithNode = serverRepo
.Get()
.Include(x => x.Node)
.First(x => x.Id == server.Id);
return serverWithNode.Node.CreateHttpClient();
}
}