feat(api): в Works добавлена маска динамической генерации имени шаблона; добавлены Shortcodes; актализированы валидация, запросы,ответы; миграция БД - запрет приёма нулевых значений в маску
This commit is contained in:
43
PARR.BLL/Services/Implementations/TemplateMaskValidator.cs
Normal file
43
PARR.BLL/Services/Implementations/TemplateMaskValidator.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using PARR.BLL.Services.Interfaces;
|
||||
using PARR.Constants.Shortcodes;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace PARR.BLL.Services.Implementations
|
||||
{
|
||||
internal class TemplateMaskValidator : ITemplateMaskValidator
|
||||
{
|
||||
public bool IsValid(string mask)
|
||||
{
|
||||
if (!mask.Contains("ПАРР"))
|
||||
return false;
|
||||
|
||||
var shortcodePattern = "%[^%\\s]+%";
|
||||
var shortcodesInMask = Regex.Matches(mask, shortcodePattern).ToList();
|
||||
|
||||
if (shortcodesInMask.Count() == 0)
|
||||
return false;
|
||||
|
||||
var validShortcodes = GetShortcodesNames();
|
||||
|
||||
foreach (var shortcode in shortcodesInMask)
|
||||
{
|
||||
if (!validShortcodes.Contains(shortcode.ToString().ToUpper()))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private List<string> GetShortcodesNames()
|
||||
{
|
||||
var result = new List<string>();
|
||||
var shortcodes = Enum.GetValues(typeof(ShortcodeEnum)).Cast<ShortcodeEnum>();
|
||||
foreach (var item in shortcodes)
|
||||
{
|
||||
result.Add(Shortcodes.GetShortcodeName(item).ToUpper());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user