Skip to content

Commit

Permalink
feat(Web-UI): The Plex servers on the left side are now ordered from …
Browse files Browse the repository at this point in the history
…owned to then sorted by name
  • Loading branch information
JasonLandbridge committed May 28, 2023
1 parent 9c6cad9 commit dec9bb0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/Domain/Extensions/PlexServerListExtensions.cs
@@ -0,0 +1,22 @@
using NaturalSort.Extension;

namespace PlexRipper.Domain;

public static class PlexServerListExtensions
{
#region Methods

#region Public

public static List<PlexServer> SortByOwnedOrder(this List<PlexServer> plexServers)
{
return plexServers
.OrderByDescending(x => x.Owned)
.ThenBy(x => x.Name, StringComparison.OrdinalIgnoreCase.WithNaturalSort())
.ToList();
}

#endregion

#endregion
}
26 changes: 24 additions & 2 deletions src/WebAPI/Controllers/PlexServerController.cs
Expand Up @@ -13,10 +13,16 @@ namespace PlexRipper.WebAPI.Controllers;
[ApiController]
public class PlexServerController : BaseController
{
#region Fields

private readonly IMediator _mediator;
private readonly IPlexServerService _plexServerService;
private readonly ISyncServerScheduler _syncServerScheduler;

#endregion

#region Constructors

public PlexServerController(
ILog log,
IMapper mapper,
Expand All @@ -30,12 +36,24 @@ public class PlexServerController : BaseController
_syncServerScheduler = syncServerScheduler;
}

#endregion

#region Methods

#region Public

// GET api/<PlexServerController>/
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ResultDTO<List<PlexServerDTO>>))]
public async Task<IActionResult> GetAll()
{
var plexServersResult = await _mediator.Send(new GetAllPlexServersQuery(true, false));
var plexServersResult = await _mediator.Send(new GetAllPlexServersQuery(true));

if (plexServersResult.IsFailed)
return ToActionResult(plexServersResult.ToResult());

plexServersResult.WithValue(plexServersResult.Value.SortByOwnedOrder());

return ToActionResult<List<PlexServer>, List<PlexServerDTO>>(plexServersResult);
}

Expand All @@ -49,7 +67,7 @@ public async Task<IActionResult> GetById(int id)
if (id <= 0)
return BadRequestInvalidId();

var plexServerResult = await _mediator.Send(new GetPlexServerByIdQuery(id, true, false));
var plexServerResult = await _mediator.Send(new GetPlexServerByIdQuery(id, true));
return ToActionResult<PlexServer, PlexServerDTO>(plexServerResult);
}

Expand Down Expand Up @@ -107,4 +125,8 @@ public async Task<IActionResult> SetPreferredConnection(int plexServerId, int pl

return ToActionResult(await _plexServerService.SetPreferredConnection(plexServerId, plexServerConnectionId));
}

#endregion

#endregion
}

0 comments on commit dec9bb0

Please sign in to comment.