-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added API methods for exposing data types
- Loading branch information
Showing
2 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
src/Limbo.Umbraco.MigrationsApi/MigrationsController.DataTypes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; | ||
|
||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters