All calls to get items now require passing in a userId. Made the model project portable. Also filled in more api calls.

This commit is contained in:
LukePulverenti Luke Pulverenti luke pulverenti
2012-07-16 12:50:44 -04:00
parent baedafbeb9
commit 6fbd5cf464
46 changed files with 986 additions and 410 deletions

View File

@@ -9,52 +9,91 @@ namespace MediaBrowser.Api
{
public static BaseItem GetItemById(string id)
{
if (string.IsNullOrEmpty(id))
Guid guid = string.IsNullOrEmpty(id) ? Guid.Empty : new Guid(id);
return Kernel.Instance.GetItemById(guid);
}
public static IEnumerable<CategoryInfo> GetAllStudios(Folder parent, Guid userId)
{
Dictionary<string, int> data = new Dictionary<string, int>();
IEnumerable<BaseItem> allItems = Kernel.Instance.GetParentalAllowedRecursiveChildren(parent, userId);
foreach (var item in allItems)
{
return Kernel.Instance.RootFolder;
if (item.Studios == null)
{
continue;
}
foreach (string val in item.Studios)
{
if (!data.ContainsKey(val))
{
data.Add(val, 1);
}
else
{
data[val]++;
}
}
}
return GetItemById(new Guid(id));
List<CategoryInfo> list = new List<CategoryInfo>();
foreach (string key in data.Keys)
{
list.Add(new CategoryInfo()
{
Name = key,
ItemCount = data[key]
});
}
return list;
}
public static BaseItem GetItemById(Guid id)
public static IEnumerable<CategoryInfo> GetAllGenres(Folder parent, Guid userId)
{
if (id == Guid.Empty)
Dictionary<string, int> data = new Dictionary<string, int>();
IEnumerable<BaseItem> allItems = Kernel.Instance.GetParentalAllowedRecursiveChildren(parent, userId);
foreach (var item in allItems)
{
return Kernel.Instance.RootFolder;
if (item.Genres == null)
{
continue;
}
foreach (string val in item.Genres)
{
if (!data.ContainsKey(val))
{
data.Add(val, 1);
}
else
{
data[val]++;
}
}
}
return Kernel.Instance.RootFolder.FindById(id);
}
List<CategoryInfo> list = new List<CategoryInfo>();
public static Person GetPersonByName(string name)
{
return null;
}
foreach (string key in data.Keys)
{
list.Add(new CategoryInfo()
{
Name = key,
ItemCount = data[key]
public static IEnumerable<BaseItem> GetItemsWithGenre(Folder parent, string genre)
{
return new BaseItem[] { };
}
});
}
public static IEnumerable<string> GetAllGenres(Folder parent)
{
return new string[] { };
}
public static IEnumerable<BaseItem> GetRecentlyAddedItems(Folder parent)
{
return new BaseItem[] { };
}
public static IEnumerable<BaseItem> GetRecentlyAddedUnplayedItems(Folder parent)
{
return new BaseItem[] { };
}
public static IEnumerable<BaseItem> GetInProgressItems(Folder parent)
{
return new BaseItem[] { };
return list;
}
}
}

View File

@@ -1,7 +1,7 @@
using System.Collections.Generic;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
using MediaBrowser.Model.Entities;
using MediaBrowser.Api;
namespace MediaBrowser.Api.HttpHandlers
{
@@ -21,7 +21,7 @@ namespace MediaBrowser.Api.HttpHandlers
{
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
return ApiService.GetItemsWithGenre(parent, QueryString["name"]);
return Kernel.Instance.GetItemsWithGenre(parent, QueryString["name"], UserId);
}
}
}

View File

@@ -1,4 +1,5 @@
using MediaBrowser.Common.Net;
using System;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Model.Entities;
@@ -16,8 +17,9 @@ namespace MediaBrowser.Api.HttpHandlers
get
{
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
Guid userId = Guid.Parse(QueryString["userid"]);
return ApiService.GetAllGenres(parent);
return ApiService.GetAllGenres(parent, userId);
}
}
}

View File

@@ -1,9 +1,10 @@
using System;
using System.IO;
using System.IO.Compression;
using System.Linq;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
using MediaBrowser.Model.Entities;
using System.IO.Compression;
namespace MediaBrowser.Api.HttpHandlers
{
@@ -174,7 +175,7 @@ namespace MediaBrowser.Api.HttpHandlers
if (!string.IsNullOrEmpty(personName))
{
item = ApiService.GetPersonByName(personName);
item = Kernel.Instance.ItemController.GetPerson(personName);
}
else
{

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Api.HttpHandlers
@@ -17,7 +18,7 @@ namespace MediaBrowser.Api.HttpHandlers
{
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
return ApiService.GetInProgressItems(parent);
return Kernel.Instance.GetInProgressItems(parent, UserId);
}
}
}

View File

@@ -1,7 +1,9 @@
using MediaBrowser.Common.Net;
using System;
using MediaBrowser.Api.Model;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Controller;
using MediaBrowser.Model.Entities;
using MediaBrowser.Common.Json;
namespace MediaBrowser.Api.HttpHandlers
{
@@ -16,26 +18,31 @@ namespace MediaBrowser.Api.HttpHandlers
{
get
{
return GetSerializationObject(ItemToSerialize, true);
Guid userId = Guid.Parse(QueryString["userid"]);
return GetSerializationObject(ItemToSerialize, true, userId);
}
}
public static object GetSerializationObject(BaseItem item, bool includeChildren)
public static object GetSerializationObject(BaseItem item, bool includeChildren, Guid userId)
{
if (includeChildren && item.IsFolder)
BaseItemInfo wrapper = new BaseItemInfo()
{
Folder folder = item as Folder;
Item = item,
UserItemData = Kernel.Instance.GetUserItemData(userId, item.Id)
};
return new
{
BaseItem = item,
Children = folder.Children
};
}
else
if (includeChildren)
{
return item;
var folder = item as Folder;
if (folder != null)
{
wrapper.Children = Kernel.Instance.GetParentalAllowedChildren(folder, userId);
}
}
return wrapper;
}
protected virtual BaseItem ItemToSerialize

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Net.Handlers;
@@ -19,7 +20,7 @@ namespace MediaBrowser.Api.HttpHandlers
{
return ItemsToSerialize.Select(i =>
{
return ItemHandler.GetSerializationObject(i, false);
return ItemHandler.GetSerializationObject(i, false, UserId);
});
}
@@ -29,5 +30,13 @@ namespace MediaBrowser.Api.HttpHandlers
{
get;
}
protected Guid UserId
{
get
{
return Guid.Parse(QueryString["userid"]);
}
}
}
}

View File

@@ -1,4 +1,5 @@
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Api.HttpHandlers
@@ -14,7 +15,7 @@ namespace MediaBrowser.Api.HttpHandlers
{
get
{
return ApiService.GetPersonByName(QueryString["name"]);
return Kernel.Instance.ItemController.GetPerson(QueryString["name"]);
}
}
}

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Api.HttpHandlers
@@ -19,10 +20,10 @@ namespace MediaBrowser.Api.HttpHandlers
if (QueryString["unplayed"] == "1")
{
return ApiService.GetRecentlyAddedUnplayedItems(parent);
return Kernel.Instance.GetRecentlyAddedUnplayedItems(parent, UserId);
}
return ApiService.GetRecentlyAddedItems(parent);
return Kernel.Instance.GetRecentlyAddedItems(parent, UserId);
}
}
}

View File

@@ -0,0 +1,28 @@
using System.Collections.Generic;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Api.HttpHandlers
{
/// <summary>
/// Gets all items within containing a studio
/// </summary>
public class StudioHandler : ItemListHandler
{
public StudioHandler(RequestContext ctx)
: base(ctx)
{
}
protected override IEnumerable<BaseItem> ItemsToSerialize
{
get
{
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
return Kernel.Instance.GetItemsWithStudio(parent, QueryString["name"], UserId);
}
}
}
}

View File

@@ -0,0 +1,26 @@
using System;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Api.HttpHandlers
{
public class StudiosHandler : JsonHandler
{
public StudiosHandler(RequestContext ctx)
: base(ctx)
{
}
protected sealed override object ObjectToSerialize
{
get
{
Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder;
Guid userId = Guid.Parse(QueryString["userid"]);
return ApiService.GetAllStudios(parent, userId);
}
}
}
}

View File

@@ -0,0 +1,22 @@
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Controller;
namespace MediaBrowser.Api.HttpHandlers
{
class UsersHandler : JsonHandler
{
public UsersHandler(RequestContext ctx)
: base(ctx)
{
}
protected override object ObjectToSerialize
{
get
{
return Kernel.Instance.Users;
}
}
}
}

View File

@@ -53,8 +53,12 @@
<Compile Include="HttpHandlers\ItemListHandler.cs" />
<Compile Include="HttpHandlers\PersonHandler.cs" />
<Compile Include="HttpHandlers\RecentlyAddedItemsHandler.cs" />
<Compile Include="HttpHandlers\StudioHandler.cs" />
<Compile Include="HttpHandlers\StudiosHandler.cs" />
<Compile Include="HttpHandlers\UsersHandler.cs" />
<Compile Include="ImageProcessor.cs" />
<Compile Include="HttpHandlers\MediaHandler.cs" />
<Compile Include="Model\BaseItemInfo.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
@@ -68,13 +72,14 @@
<Name>MediaBrowser.Controller</Name>
</ProjectReference>
<ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj">
<Project>{9b1ddd79-5134-4df3-ace3-d1957a7350d8}</Project>
<Project>{7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b}</Project>
<Name>MediaBrowser.Model</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy "$(TargetPath)" "$(SolutionDir)\ProgramData\Plugins\$(ProjectName)\" /y</PostBuildEvent>

View File

@@ -0,0 +1,15 @@
using System.Collections.Generic;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Users;
namespace MediaBrowser.Api.Model
{
public class BaseItemInfo
{
public BaseItem Item { get; set; }
public UserItemData UserItemData { get; set; }
public IEnumerable<BaseItem> Children { get; set; }
}
}

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Reactive.Linq;
using MediaBrowser.Api.HttpHandlers;
using MediaBrowser.Common.Plugins;
@@ -13,6 +12,8 @@ namespace MediaBrowser.Api
{
var httpServer = Kernel.Instance.HttpServer;
httpServer.Where(ctx => ctx.LocalPath.EndsWith("/api/users", StringComparison.OrdinalIgnoreCase)).Subscribe(ctx => ctx.Respond(new UsersHandler(ctx)));
httpServer.Where(ctx => ctx.LocalPath.EndsWith("/api/media", StringComparison.OrdinalIgnoreCase)).Subscribe(ctx => ctx.Respond(new MediaHandler(ctx)));
httpServer.Where(ctx => ctx.LocalPath.EndsWith("/api/item", StringComparison.OrdinalIgnoreCase)).Subscribe(ctx => ctx.Respond(new ItemHandler(ctx)));
@@ -23,6 +24,10 @@ namespace MediaBrowser.Api
httpServer.Where(ctx => ctx.LocalPath.EndsWith("/api/genres", StringComparison.OrdinalIgnoreCase)).Subscribe(ctx => ctx.Respond(new GenresHandler(ctx)));
httpServer.Where(ctx => ctx.LocalPath.EndsWith("/api/studio", StringComparison.OrdinalIgnoreCase)).Subscribe(ctx => ctx.Respond(new StudioHandler(ctx)));
httpServer.Where(ctx => ctx.LocalPath.EndsWith("/api/studios", StringComparison.OrdinalIgnoreCase)).Subscribe(ctx => ctx.Respond(new StudiosHandler(ctx)));
httpServer.Where(ctx => ctx.LocalPath.EndsWith("/api/recentlyaddeditems", StringComparison.OrdinalIgnoreCase)).Subscribe(ctx => ctx.Respond(new RecentlyAddedItemsHandler(ctx)));
httpServer.Where(ctx => ctx.LocalPath.EndsWith("/api/inprogressitems", StringComparison.OrdinalIgnoreCase)).Subscribe(ctx => ctx.Respond(new InProgressItemsHandler(ctx)));