using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; using NzbDrone.Core.Datastore.Events; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Tags; using NzbDrone.SignalR; using Sonarr.Http; using Sonarr.Http.REST; using Sonarr.Http.REST.Attributes; namespace Sonarr.Api.V3.Tags { [V3ApiController] public class TagController : RestControllerWithSignalR, IHandle { private readonly ITagService _tagService; public TagController(IBroadcastSignalRMessage signalRBroadcaster, ITagService tagService) : base(signalRBroadcaster) { _tagService = tagService; } protected override TagResource GetResourceById(int id) { return _tagService.GetTag(id).ToResource(); } [HttpGet] [Produces("application/json")] public List GetAll() { return _tagService.All().ToResource(); } [RestPostById] [Consumes("application/json")] public ActionResult Create(TagResource resource) { return Created(_tagService.Add(resource.ToModel()).Id); } [RestPutById] [Consumes("application/json")] public ActionResult Update(TagResource resource) { _tagService.Update(resource.ToModel()); return Accepted(resource.Id); } [RestDeleteById] public void DeleteTag(int id) { _tagService.Delete(id); } [NonAction] public void Handle(TagsUpdatedEvent message) { BroadcastResourceChange(ModelAction.Sync); } } }