2017-09-04 02:20:56 +00:00
|
|
|
using System.Linq;
|
2021-08-04 20:42:40 +00:00
|
|
|
using Lidarr.Http;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2017-09-04 02:20:56 +00:00
|
|
|
using NzbDrone.Core.Music;
|
|
|
|
|
2017-10-31 01:28:29 +00:00
|
|
|
namespace Lidarr.Api.V1.AlbumStudio
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
2021-08-04 20:42:40 +00:00
|
|
|
[V1ApiController]
|
|
|
|
public class AlbumStudioController : Controller
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
|
|
|
private readonly IArtistService _artistService;
|
2017-12-02 05:03:12 +00:00
|
|
|
private readonly IAlbumMonitoredService _albumMonitoredService;
|
2017-09-04 02:20:56 +00:00
|
|
|
|
2021-08-04 20:42:40 +00:00
|
|
|
public AlbumStudioController(IArtistService artistService, IAlbumMonitoredService albumMonitoredService)
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
|
|
|
_artistService = artistService;
|
2017-12-02 05:03:12 +00:00
|
|
|
_albumMonitoredService = albumMonitoredService;
|
2017-09-04 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
2021-08-04 20:42:40 +00:00
|
|
|
[HttpPost]
|
2023-07-21 23:16:05 +00:00
|
|
|
[Consumes("application/json")]
|
|
|
|
[Produces("application/json")]
|
|
|
|
public IActionResult UpdateAll([FromBody] AlbumStudioResource resource)
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
2023-07-21 23:16:05 +00:00
|
|
|
var artistToUpdate = _artistService.GetArtists(resource.Artist.Select(s => s.Id));
|
2017-09-04 02:20:56 +00:00
|
|
|
|
2023-07-21 23:16:05 +00:00
|
|
|
foreach (var s in resource.Artist)
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
|
|
|
var artist = artistToUpdate.Single(c => c.Id == s.Id);
|
|
|
|
|
|
|
|
if (s.Monitored.HasValue)
|
|
|
|
{
|
|
|
|
artist.Monitored = s.Monitored.Value;
|
|
|
|
}
|
|
|
|
|
2023-07-21 23:16:05 +00:00
|
|
|
if (resource.MonitoringOptions is { Monitor: MonitorTypes.None })
|
2019-06-12 02:28:57 +00:00
|
|
|
{
|
|
|
|
artist.Monitored = false;
|
|
|
|
}
|
|
|
|
|
2023-07-21 23:16:05 +00:00
|
|
|
if (resource.MonitorNewItems.HasValue)
|
2022-04-28 20:04:09 +00:00
|
|
|
{
|
2023-07-21 23:16:05 +00:00
|
|
|
artist.MonitorNewItems = resource.MonitorNewItems.Value;
|
2022-04-28 20:04:09 +00:00
|
|
|
}
|
|
|
|
|
2023-07-21 23:16:05 +00:00
|
|
|
_albumMonitoredService.SetAlbumMonitoredStatus(artist, resource.MonitoringOptions);
|
2017-09-04 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
2023-07-21 23:16:05 +00:00
|
|
|
return Accepted(resource);
|
2017-09-04 02:20:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|