You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.6 KiB
72 lines
2.6 KiB
7 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using Nancy;
|
||
|
using NzbDrone.Core.DecisionEngine;
|
||
|
using NzbDrone.Core.Music;
|
||
|
using NzbDrone.SignalR;
|
||
|
using Lidarr.Http.Extensions;
|
||
|
using Lidarr.Http.REST;
|
||
|
using NzbDrone.Core.ArtistStats;
|
||
|
|
||
7 years ago
|
namespace Lidarr.Api.V1.Albums
|
||
7 years ago
|
{
|
||
|
public class AlbumModule : AlbumModuleWithSignalR
|
||
|
{
|
||
|
public AlbumModule(IArtistService artistService,
|
||
|
IAlbumService albumService,
|
||
|
IArtistStatisticsService artistStatisticsService,
|
||
|
IUpgradableSpecification upgradableSpecification,
|
||
|
IBroadcastSignalRMessage signalRBroadcaster)
|
||
|
: base(albumService, artistStatisticsService, artistService, upgradableSpecification, signalRBroadcaster)
|
||
|
{
|
||
|
GetResourceAll = GetAlbums;
|
||
|
Put[@"/(?<id>[\d]{1,10})"] = x => SetAlbumMonitored(x.Id);
|
||
|
Put["/monitor"] = x => SetAlbumsMonitored();
|
||
|
}
|
||
|
|
||
|
private List<AlbumResource> GetAlbums()
|
||
|
{
|
||
7 years ago
|
var artistIdQuery = Request.Query.ArtistId;
|
||
|
var albumIdsQuery = Request.Query.AlbumIds;
|
||
|
|
||
|
if (!Request.Query.ArtistId.HasValue && !albumIdsQuery.HasValue)
|
||
7 years ago
|
{
|
||
7 years ago
|
return MapToResource(_albumService.GetAllAlbums(), false);
|
||
7 years ago
|
}
|
||
|
|
||
|
if (artistIdQuery.HasValue)
|
||
|
{
|
||
|
int artistId = Convert.ToInt32(artistIdQuery.Value);
|
||
|
|
||
|
return MapToResource(_albumService.GetAlbumsByArtist(artistId), false);
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
string albumIdsValue = albumIdsQuery.Value.ToString();
|
||
7 years ago
|
|
||
7 years ago
|
var albumIds = albumIdsValue.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
|
||
7 years ago
|
.Select(e => Convert.ToInt32(e))
|
||
|
.ToList();
|
||
7 years ago
|
|
||
7 years ago
|
return MapToResource(_albumService.GetAlbums(albumIds), false);
|
||
7 years ago
|
}
|
||
|
|
||
|
private Response SetAlbumMonitored(int id)
|
||
|
{
|
||
|
var resource = Request.Body.FromJson<AlbumResource>();
|
||
|
_albumService.SetAlbumMonitored(id, resource.Monitored);
|
||
|
|
||
|
return MapToResource(_albumService.GetAlbum(id), false).AsResponse(HttpStatusCode.Accepted);
|
||
|
}
|
||
|
|
||
|
private Response SetAlbumsMonitored()
|
||
|
{
|
||
|
var resource = Request.Body.FromJson<AlbumsMonitoredResource>();
|
||
|
|
||
|
_albumService.SetMonitored(resource.AlbumIds, resource.Monitored);
|
||
|
|
||
|
return MapToResource(_albumService.GetAlbums(resource.AlbumIds), false).AsResponse(HttpStatusCode.Accepted);
|
||
|
}
|
||
|
}
|
||
|
}
|