Lidarr/src/Lidarr.Api.V1/AlbumStudio/AlbumStudioController.cs

53 lines
1.6 KiB
C#
Raw Normal View History

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;
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;
_albumMonitoredService = albumMonitoredService;
2017-09-04 02:20:56 +00:00
}
2021-08-04 20:42:40 +00:00
[HttpPost]
[Consumes("application/json")]
[Produces("application/json")]
public IActionResult UpdateAll([FromBody] AlbumStudioResource resource)
2017-09-04 02:20:56 +00:00
{
var artistToUpdate = _artistService.GetArtists(resource.Artist.Select(s => s.Id));
2017-09-04 02:20:56 +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;
}
if (resource.MonitoringOptions is { Monitor: MonitorTypes.None })
{
artist.Monitored = false;
}
if (resource.MonitorNewItems.HasValue)
{
artist.MonitorNewItems = resource.MonitorNewItems.Value;
}
_albumMonitoredService.SetAlbumMonitoredStatus(artist, resource.MonitoringOptions);
2017-09-04 02:20:56 +00:00
}
return Accepted(resource);
2017-09-04 02:20:56 +00:00
}
}
}