Fixes EntityController to have a correct model mapper and removes invalidly named 'map' method. Removes the key from entity since we don't need it. Added some notes to the controller since we have to implement security for the results.

This commit is contained in:
Shannon
2013-08-19 16:49:07 +10:00
parent 024511a605
commit 78e836025b
4 changed files with 32 additions and 34 deletions

View File

@@ -19,41 +19,24 @@ namespace Umbraco.Web.Editors
[PluginController("UmbracoApi")]
public class EntityController : UmbracoAuthorizedJsonController
{
public EntityDisplay GetById(int id)
public EntityBasic GetById(int id)
{
return map((UmbracoEntity)Services.EntityService.Get(id, UmbracoObjectTypes.Document));
return Mapper.Map<EntityBasic>(Services.EntityService.Get(id, UmbracoObjectTypes.Document));
}
public IEnumerable<EntityDisplay> GetByIds([FromUri]int[] ids)
//TODO: This should probably be change to GetContentByIds since it will be different for media, etc...!
//TODO: Because this is a publicly accessible API, we need to filter the results for what the currently logged in user
// is actually allowed to access. We'll need to enhance the FilterAllowedOutgoingContent to acheive that.
public IEnumerable<EntityBasic> GetByIds([FromUri]int[] ids)
{
if (ids == null) throw new ArgumentNullException("ids");
return ids.Select(id => map(((UmbracoEntity)Services.EntityService.Get(id, UmbracoObjectTypes.Document)))).Where(entity => entity != null).ToList();
return ids.Select(id =>
Mapper.Map<EntityBasic>(Services.EntityService.Get(id, UmbracoObjectTypes.Document)));
}
private EntityDisplay map(UmbracoEntity input)
{
EntityDisplay output = new EntityDisplay();
output.Name = input.Name;
output.Id = input.Id;
output.Key = input.Key;
output.Icon = input.ContentTypeIcon;
return output;
}
//public IEnumerable<UmbracoEntity> GetContentByIds(int[] ids)
//{
// var list = new List<UmbracoEntity>();
// foreach (var id in ids)
// list.Add((UmbracoEntity)Services.EntityService.Get(id));
// return list;
//}
//public UmbracoEntity GetContentById(int id)
//{
// return (UmbracoEntity)Services.EntityService.Get(id);
//}
}
}

View File

@@ -8,17 +8,14 @@ using System.Threading.Tasks;
namespace Umbraco.Web.Models.ContentEditing
{
[DataContract(Name = "entity", Namespace = "")]
public class EntityDisplay
public class EntityBasic
{
[DataMember(Name = "name")]
public string Name { get; set; }
[DataMember(Name = "id")]
public int Id { get; set; }
[DataMember(Name = "key")]
public Guid Key { get; set; }
[DataMember(Name = "icon")]
public string Icon { get; set; }
}

View File

@@ -0,0 +1,17 @@
using AutoMapper;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Mapping;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Mapping
{
internal class EntityModelMapper : MapperConfiguration
{
public override void ConfigureMappings(IConfiguration config, ApplicationContext applicationContext)
{
config.CreateMap<UmbracoEntity, EntityBasic>()
.ForMember(basic => basic.Icon, expression => expression.MapFrom(entity => entity.ContentTypeIcon));
}
}
}

View File

@@ -299,8 +299,9 @@
<Compile Include="Editors\AuthenticationController.cs" />
<Compile Include="Editors\ContentController.cs" />
<Compile Include="Editors\EntityController.cs" />
<Compile Include="Models\ContentEditing\EntityDisplay.cs" />
<Compile Include="Models\ContentEditing\EntityBasic.cs" />
<Compile Include="Models\ContentEditing\TemplateBasic.cs" />
<Compile Include="Models\Mapping\EntityModelMapper.cs" />
<Compile Include="Models\PagedResult.cs" />
<Compile Include="PropertyEditors\DatePropertyEditor.cs" />
<Compile Include="PropertyEditors\DateTimePropertyEditor.cs" />