feat(api): в Works добавлена маска динамической генерации имени шаблона; добавлены Shortcodes; актализированы валидация, запросы,ответы; миграция БД - запрет приёма нулевых значений в маску

This commit is contained in:
Mikhail Kuznetsov
2025-04-17 16:38:35 +10:00
parent ecd3bdac9b
commit a89e7f7b86
14 changed files with 3375 additions and 8 deletions

View 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;
}
}
}