Lidarr/src/Lidarr.Api.V1/Tags/TagController.cs

62 lines
1.6 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using Lidarr.Http;
2021-08-04 20:42:40 +00:00
using Lidarr.Http.REST;
using Lidarr.Http.REST.Attributes;
using Microsoft.AspNetCore.Mvc;
2017-09-04 02:20:56 +00:00
using NzbDrone.Core.Datastore.Events;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Tags;
using NzbDrone.SignalR;
2017-10-31 01:28:29 +00:00
namespace Lidarr.Api.V1.Tags
2017-09-04 02:20:56 +00:00
{
2021-08-04 20:42:40 +00:00
[V1ApiController]
public class TagController : RestControllerWithSignalR<TagResource, Tag>, IHandle<TagsUpdatedEvent>
2017-09-04 02:20:56 +00:00
{
private readonly ITagService _tagService;
2021-08-04 20:42:40 +00:00
public TagController(IBroadcastSignalRMessage signalRBroadcaster,
2017-09-04 02:20:56 +00:00
ITagService tagService)
: base(signalRBroadcaster)
{
_tagService = tagService;
}
2021-08-04 20:42:40 +00:00
public override TagResource GetResourceById(int id)
2017-09-04 02:20:56 +00:00
{
return _tagService.GetTag(id).ToResource();
}
2021-08-04 20:42:40 +00:00
[HttpGet]
public List<TagResource> GetAll()
2017-09-04 02:20:56 +00:00
{
return _tagService.All().ToResource();
}
2021-08-04 20:42:40 +00:00
[RestPostById]
public ActionResult<TagResource> Create(TagResource resource)
2017-09-04 02:20:56 +00:00
{
2021-08-04 20:42:40 +00:00
return Created(_tagService.Add(resource.ToModel()).Id);
2017-09-04 02:20:56 +00:00
}
2021-08-04 20:42:40 +00:00
[RestPutById]
public ActionResult<TagResource> Update(TagResource resource)
2017-09-04 02:20:56 +00:00
{
_tagService.Update(resource.ToModel());
2021-08-04 20:42:40 +00:00
return Accepted(resource.Id);
2017-09-04 02:20:56 +00:00
}
2021-08-04 20:42:40 +00:00
[RestDeleteById]
public void DeleteTag(int id)
2017-09-04 02:20:56 +00:00
{
_tagService.Delete(id);
}
2021-08-04 20:42:40 +00:00
[NonAction]
2017-09-04 02:20:56 +00:00
public void Handle(TagsUpdatedEvent message)
{
BroadcastResourceChange(ModelAction.Sync);
}
}
}