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

58 lines
1.5 KiB
C#
Raw Normal View History

2017-09-04 02:20:56 +00:00
using System.Collections.Generic;
using NzbDrone.Core.Datastore.Events;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Tags;
using NzbDrone.SignalR;
using Lidarr.Http;
2017-10-31 01:28:29 +00:00
namespace Lidarr.Api.V1.Tags
2017-09-04 02:20:56 +00:00
{
public class TagModule : LidarrRestModuleWithSignalR<TagResource, Tag>, IHandle<TagsUpdatedEvent>
{
private readonly ITagService _tagService;
public TagModule(IBroadcastSignalRMessage signalRBroadcaster,
ITagService tagService)
: base(signalRBroadcaster)
{
_tagService = tagService;
GetResourceById = Get;
GetResourceAll = GetAll;
CreateResource = Create;
UpdateResource = Update;
DeleteResource = Delete;
}
private TagResource Get(int id)
{
return _tagService.GetTag(id).ToResource();
}
private List<TagResource> GetAll()
{
return _tagService.All().ToResource();
}
private int Create(TagResource resource)
{
return _tagService.Add(resource.ToModel()).Id;
}
private void Update(TagResource resource)
{
_tagService.Update(resource.ToModel());
}
private void Delete(int id)
{
_tagService.Delete(id);
}
public void Handle(TagsUpdatedEvent message)
{
BroadcastResourceChange(ModelAction.Sync);
}
}
}