Files
mixtape/zero.Core/Api/ModulesApi.cs
T

54 lines
1.2 KiB
C#
Raw Normal View History

2020-10-20 16:00:55 +02:00
using System;
using System.Collections.Generic;
2020-08-19 12:53:18 +02:00
using System.Linq;
using zero.Core.Entities;
using zero.Core.Options;
namespace zero.Core.Api
{
public class ModulesApi : BackofficeApi, IModulesApi
{
protected IZeroOptions Options { get; private set; }
public ModulesApi(IZeroOptions options, IBackofficeStore store) : base(store)
{
Options = options;
}
/// <inheritdoc />
2020-10-20 16:00:55 +02:00
public IList<ModuleType> GetModuleTypes(string[] tags = default)
2020-08-19 12:53:18 +02:00
{
2020-10-20 16:00:55 +02:00
IEnumerable<ModuleType> modules = Options.Modules.GetAllItems();
if (tags?.Length > 0)
{
modules = modules.Where(x => x.Tags.Any(t => tags.Contains(t, StringComparer.InvariantCultureIgnoreCase)));
}
return modules.ToList();
2020-08-19 12:53:18 +02:00
}
/// <inheritdoc />
public ModuleType GetModuleType(string alias)
{
return Options.Modules.GetAllItems().FirstOrDefault(x => x.Alias == alias);
}
}
public interface IModulesApi
{
/// <summary>
2020-10-20 16:00:55 +02:00
/// Get all available module types (can be limited to the passed tags)
2020-08-19 12:53:18 +02:00
/// </summary>
2020-10-20 16:00:55 +02:00
IList<ModuleType> GetModuleTypes(string[] tags = default);
2020-08-19 12:53:18 +02:00
/// <summary>
/// Get a specific module type by alias
/// </summary>
ModuleType GetModuleType(string alias);
}
}