SceneMapping added to Services API

This commit is contained in:
Mark McDowall
2013-01-31 20:18:11 -08:00
committed by kay.one
parent 4176e7e9e4
commit 27afb2402a
10 changed files with 171 additions and 15 deletions
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AutoMapper;
using MongoDB.Bson;
using Nancy;
using NzbDrone.Services.Api.Extensions;
namespace NzbDrone.Services.Api.SceneMapping
{
public class SceneMappingModule : NancyModule
{
private readonly SceneMappingRepository _sceneMappingRepository;
public SceneMappingModule(SceneMappingRepository sceneMappingRepository)
: base("/scenemapping")
{
_sceneMappingRepository = sceneMappingRepository;
Get["/"] = x => OnGet();
Get["/active"] = x => OnGet();
Get["/{MapId}"] = x => OnGet(x.MapId);
}
private Response OnGet()
{
var mappings = _sceneMappingRepository.Public();
return Mapper.Map<List<SceneMappingModel>, List<SceneMappingJsonModel>>(mappings).AsResponse();
}
private Response OnGet(string mapId)
{
var mapping = _sceneMappingRepository.Find(ObjectId.Parse(mapId));
return Mapper.Map<SceneMappingModel, SceneMappingJsonModel>(mapping).AsResponse();
}
}
}