Got index server list working
This commit is contained in:
parent
36d99b1e35
commit
271cf1f407
19 changed files with 445 additions and 67 deletions
21
backend/src/Controllers/SearchController.cs
Normal file
21
backend/src/Controllers/SearchController.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace JellyGlass.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class SearchController : ControllerBase
|
||||
{
|
||||
private ILogger<SearchController> _logger;
|
||||
|
||||
public SearchController(ILogger<SearchController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> handleSearch([FromQuery] string searchTerm)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
26
backend/src/Controllers/ServersController.cs
Normal file
26
backend/src/Controllers/ServersController.cs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
using JellyGlass.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace JellyGlass.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class ServersController : ControllerBase
|
||||
{
|
||||
private ILogger<ServersController> _logger;
|
||||
private IServerService _service;
|
||||
|
||||
public ServersController(ILogger<ServersController> logger, IServerService service)
|
||||
{
|
||||
_logger = logger;
|
||||
_service = service;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> getServers()
|
||||
{
|
||||
var servers = await _service.GetServers();
|
||||
|
||||
return Ok(servers);
|
||||
}
|
||||
}
|
||||
BIN
backend/src/JellyGlass-test.db-shm
Normal file
BIN
backend/src/JellyGlass-test.db-shm
Normal file
Binary file not shown.
0
backend/src/JellyGlass-test.db-wal
Normal file
0
backend/src/JellyGlass-test.db-wal
Normal file
17
backend/src/Models/ServerDTO.cs
Normal file
17
backend/src/Models/ServerDTO.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
namespace JellyGlass.Models;
|
||||
|
||||
public class ServerDTO
|
||||
{
|
||||
public ServerDTO() { }
|
||||
|
||||
public ServerDTO(Server s)
|
||||
{
|
||||
Owner = s.Owner;
|
||||
Url = s.Url;
|
||||
Id = s.Id;
|
||||
}
|
||||
|
||||
public string Owner { get; set; } = string.Empty;
|
||||
public string Url { get; set; } = string.Empty;
|
||||
public string Id { get; set; } = string.Empty;
|
||||
}
|
||||
|
|
@ -25,7 +25,8 @@ builder.Services.AddSqlite<DatabaseContext>(dbConnectionString);
|
|||
|
||||
builder.Services.AddTransient<ILibraryService, LibraryService>();
|
||||
builder.Services.AddTransient<IServerRepository, ServerRepository>();
|
||||
builder.Services.AddScoped<IServerService, ServerService>();
|
||||
builder.Services.AddScoped<IClientService, ClientService>();
|
||||
builder.Services.AddTransient<IServerService, ServerService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
|
|
|||
51
backend/src/Services/ClientService.cs
Normal file
51
backend/src/Services/ClientService.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
using JellyGlass.Exceptions;
|
||||
using JellyGlass.Repositories;
|
||||
|
||||
namespace JellyGlass.Services;
|
||||
|
||||
public class ClientService : IClientService
|
||||
{
|
||||
private IServerRepository _repository;
|
||||
private static JellyfinApiClient[] _clients = [];
|
||||
private ILogger<ClientService> _logger;
|
||||
|
||||
public ClientService(IServerRepository repository, ILogger<ClientService> logger)
|
||||
{
|
||||
_repository = repository;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<JellyfinApiClient[]> GetJellyfinClients()
|
||||
{
|
||||
if (!_clients.Any())
|
||||
{
|
||||
await LoadClients();
|
||||
}
|
||||
|
||||
return _clients;
|
||||
}
|
||||
|
||||
private async Task LoadClients()
|
||||
{
|
||||
var servers = await _repository.GetServers();
|
||||
var clients = new List<JellyfinApiClient>();
|
||||
|
||||
foreach (var server in servers)
|
||||
{
|
||||
var client = new JellyfinApiClient(server.Url, server.Username, server.Password);
|
||||
|
||||
try
|
||||
{
|
||||
await client.Authenticate();
|
||||
}
|
||||
catch (JellyfinApiClientException e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
clients.Add(client);
|
||||
}
|
||||
|
||||
_clients = clients.ToArray();
|
||||
}
|
||||
}
|
||||
10
backend/src/Services/IClientService.cs
Normal file
10
backend/src/Services/IClientService.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using JellyGlass.Repositories;
|
||||
|
||||
namespace JellyGlass.Services;
|
||||
|
||||
public interface IClientService
|
||||
{
|
||||
public Task<JellyfinApiClient[]> GetJellyfinClients();
|
||||
// public JellyfinApiClient GetClientForServer(string url);
|
||||
// public JellyfinApiClient GetClientForServerId(string serverId);
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
using JellyGlass.Repositories;
|
||||
|
||||
|
||||
using JellyGlass.Models;
|
||||
|
||||
namespace JellyGlass.Services;
|
||||
|
||||
public interface IServerService
|
||||
{
|
||||
public Task<JellyfinApiClient[]> GetJellyfinClients();
|
||||
// public JellyfinApiClient GetClientForServer(string url);
|
||||
// public JellyfinApiClient GetClientForServerId(string serverId);
|
||||
public Task<ServerDTO[]> GetServers();
|
||||
}
|
||||
|
|
@ -4,9 +4,9 @@ namespace JellyGlass.Services;
|
|||
|
||||
public class LibraryService : ILibraryService
|
||||
{
|
||||
private IServerService _serverService;
|
||||
private IClientService _serverService;
|
||||
|
||||
public LibraryService(IServerService serverService)
|
||||
public LibraryService(IClientService serverService)
|
||||
{
|
||||
_serverService = serverService;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using JellyGlass.Exceptions;
|
||||
|
||||
|
||||
using JellyGlass.Models;
|
||||
using JellyGlass.Repositories;
|
||||
|
||||
|
|
@ -6,47 +7,24 @@ namespace JellyGlass.Services;
|
|||
|
||||
public class ServerService : IServerService
|
||||
{
|
||||
private IServerRepository _repository;
|
||||
private static JellyfinApiClient[] _clients = [];
|
||||
private ILogger<ServerService> _logger;
|
||||
private readonly IServerRepository _repository;
|
||||
|
||||
public ServerService(IServerRepository repository, ILogger<ServerService> logger)
|
||||
public ServerService(IServerRepository repository)
|
||||
{
|
||||
_repository = repository;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<JellyfinApiClient[]> GetJellyfinClients()
|
||||
{
|
||||
if (!_clients.Any())
|
||||
{
|
||||
await LoadClients();
|
||||
}
|
||||
|
||||
return _clients;
|
||||
}
|
||||
|
||||
private async Task LoadClients()
|
||||
public async Task<ServerDTO[]> GetServers()
|
||||
{
|
||||
var servers = await _repository.GetServers();
|
||||
var clients = new List<JellyfinApiClient>();
|
||||
|
||||
foreach (var server in servers)
|
||||
var dtos = new List<ServerDTO>();
|
||||
|
||||
foreach (var s in servers)
|
||||
{
|
||||
var client = new JellyfinApiClient(server.Url, server.Username, server.Password);
|
||||
|
||||
try
|
||||
{
|
||||
await client.Authenticate();
|
||||
}
|
||||
catch (JellyfinApiClientException e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
clients.Add(client);
|
||||
dtos.Add(new ServerDTO(s));
|
||||
}
|
||||
|
||||
_clients = clients.ToArray();
|
||||
return dtos.ToArray();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue