Skip to content

Commit

Permalink
Added API methods for exposing data types
Browse files Browse the repository at this point in the history
  • Loading branch information
abjerner committed Dec 9, 2024
1 parent bd81f1b commit e70ba9d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
66 changes: 66 additions & 0 deletions src/Limbo.Umbraco.MigrationsApi/MigrationsController.DataTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Linq;
using System;
using System.Web.Http;
using Newtonsoft.Json.Linq;
using Umbraco.Core.Models;
using Skybrud.Essentials.Time;

namespace Limbo.Umbraco.MigrationsApi {

public partial class MigrationsController {

[HttpGet]
public object GetDataTypeById(int id) {
if (!HasAccess()) return Unauthorized();
IDataType dataType = _dataTypeService.GetDataType(id);
return MapDataType(dataType);
}

[HttpGet]
public object GetDataTypeByKey(Guid key) {
if (!HasAccess()) return Unauthorized();
IDataType dataType = _dataTypeService.GetDataType(key);
return MapDataType(dataType);
}

[HttpGet]
public object GetDataTypes() {
if (!HasAccess()) return Unauthorized();
return _dataTypeService
.GetAll()
.Select(MapDataType);
}

private static object MapDataType(IDataType dataType) {
if (dataType == null) return null;
return new {
id = dataType.Id,
key = dataType.Key,
name = dataType.Name,
dbType = dataType.DatabaseType,
createDate = EssentialsTime.FromTicks(dataType.CreateDate.Ticks, TimeZoneInfo.Local),
updateDate = EssentialsTime.FromTicks(dataType.UpdateDate.Ticks, TimeZoneInfo.Local),
editorAlias = dataType.EditorAlias,
editor = MapDataEditor(dataType),
config = dataType.Configuration is null ? new JObject() : JObject.FromObject(dataType.Configuration)
};
}

private static object MapDataEditor(IDataType dataType) {

if (dataType.Editor is null) return null;

return new {
alias = dataType.Editor.Alias,
name = dataType.Editor.Name,
icon = dataType.Editor.Icon,
group = dataType.Editor.Group,
type = dataType.Editor.Type.ToString(),
deprecated = dataType.Editor.IsDeprecated
};

}

}

}
6 changes: 4 additions & 2 deletions src/Limbo.Umbraco.MigrationsApi/MigrationsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ namespace Limbo.Umbraco.MigrationsApi {

[JsonOnlyConfiguration]
[PluginController("Limbo")]
public class MigrationsController : UmbracoApiController {
public partial class MigrationsController : UmbracoApiController {

private readonly IContentTypeService _contentTypeService;
private readonly IDataTypeService _dataTypeService;
private readonly IMediaTypeService _mediaTypeService;
private readonly IMemberTypeService _memberTypeService;
private readonly IMemberService _memberService;
Expand All @@ -34,8 +35,9 @@ public class MigrationsController : UmbracoApiController {

#region Constructors

public MigrationsController(IContentTypeService contentTypeService, IMediaTypeService mediaTypeService, IMemberTypeService memberTypeService, IMemberService memberService) {
public MigrationsController(IContentTypeService contentTypeService, IDataTypeService dataTypeService, IMediaTypeService mediaTypeService, IMemberTypeService memberTypeService, IMemberService memberService) {
_contentTypeService = contentTypeService;
_dataTypeService = dataTypeService;
_mediaTypeService = mediaTypeService;
_memberTypeService = memberTypeService;
_memberService = memberService;
Expand Down

0 comments on commit e70ba9d

Please sign in to comment.