Skip to content

Commit

Permalink
Encapsulate DataDictionaryRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
gumbarros committed Nov 1, 2024
1 parent a9e5c0a commit ced6185
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/Core/DataDictionary/Services/ActionsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ActionsService(IValidationDictionary validationDictionary,
IDataDictionaryRepository dataDictionaryRepository,
IEnumerable<IExpressionProvider> expressionProviders,
IEnumerable<IPluginHandler> pluginHandlers)
: BaseService(validationDictionary, dataDictionaryRepository,stringLocalizer)
: DataDictionaryServiceBase(validationDictionary, dataDictionaryRepository,stringLocalizer)
{
public async Task<bool> DeleteActionAsync(string elementName, string actionName, ActionSource context, string fieldName = null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Core/DataDictionary/Services/ApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace JJMasterData.Core.DataDictionary.Services;
public class ApiService(IValidationDictionary validationDictionary,
IDataDictionaryRepository dataDictionaryRepository,
IStringLocalizer<MasterDataResources> stringLocalizer)
: BaseService(validationDictionary, dataDictionaryRepository,stringLocalizer)
: DataDictionaryServiceBase(validationDictionary, dataDictionaryRepository,stringLocalizer)
{
public async Task<bool> SetFormElementWithApiValidation(FormElement formElement)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

namespace JJMasterData.Core.DataDictionary.Services;

public abstract class BaseService(IValidationDictionary validationDictionary,
public abstract class DataDictionaryServiceBase(
IValidationDictionary validationDictionary,
IDataDictionaryRepository dataDictionaryRepository,
IStringLocalizer<MasterDataResources> stringLocalizer)
{
public IDataDictionaryRepository DataDictionaryRepository { get; } = dataDictionaryRepository;
protected IDataDictionaryRepository DataDictionaryRepository { get; } = dataDictionaryRepository;
protected IStringLocalizer<MasterDataResources> StringLocalizer { get; } = stringLocalizer;

protected void AddError(string field, string message)
Expand All @@ -40,6 +41,11 @@ public ValueTask<FormElement> GetFormElementAsync(string elementName)
{
return DataDictionaryRepository.GetFormElementAsync(elementName);
}

public Task<List<string>> GetNameListAsync()
{
return DataDictionaryRepository.GetNameListAsync();
}

public bool ValidateName(string name)
{
Expand Down
7 changes: 6 additions & 1 deletion src/Core/DataDictionary/Services/ElementService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ElementService(
IDataDictionaryRepository dataDictionaryRepository,
DataDictionaryFormElementFactory dataDictionaryFormElementFactory,
IMasterDataUrlHelper urlHelper)
: BaseService(validationDictionary, dataDictionaryRepository, stringLocalizer)
: DataDictionaryServiceBase(validationDictionary, dataDictionaryRepository, stringLocalizer)
{
#region Add Dictionary

Expand Down Expand Up @@ -263,4 +263,9 @@ public Task CreateStructureIfNotExistsAsync()
{
return DataDictionaryRepository.CreateStructureIfNotExistsAsync();
}

public Task DeleteAsync(string? elementName)
{
return DataDictionaryRepository.DeleteAsync(elementName);
}
}
2 changes: 1 addition & 1 deletion src/Core/DataDictionary/Services/EntityService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace JJMasterData.Core.DataDictionary.Services;
public class EntityService(IValidationDictionary validationDictionary,
IDataDictionaryRepository dataDictionaryRepository,
IStringLocalizer<MasterDataResources> stringLocalizer)
: BaseService(validationDictionary, dataDictionaryRepository,stringLocalizer)
: DataDictionaryServiceBase(validationDictionary, dataDictionaryRepository,stringLocalizer)
{
private async Task<bool> ValidateEntity(Entity entity, string originName)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Core/DataDictionary/Services/FieldService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class FieldService(IValidationDictionary validationDictionary,
IDataDictionaryRepository dataDictionaryRepository,
IEnumerable<IExpressionProvider> expressionProviders,
IStringLocalizer<MasterDataResources> stringLocalizer)
: BaseService(validationDictionary, dataDictionaryRepository,stringLocalizer)
: DataDictionaryServiceBase(validationDictionary, dataDictionaryRepository,stringLocalizer)
{
public async Task<bool> SaveFieldAsync(string elementName, FormElementField field, string originalName)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Core/DataDictionary/Services/IndexesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace JJMasterData.Core.DataDictionary.Services;
public class IndexesService(IValidationDictionary validationDictionary,
IDataDictionaryRepository dataDictionaryRepository,
IStringLocalizer<MasterDataResources> stringLocalizer)
: BaseService(validationDictionary, dataDictionaryRepository,stringLocalizer)
: DataDictionaryServiceBase(validationDictionary, dataDictionaryRepository,stringLocalizer)
{
public async Task<bool> SaveAsync(string id, string index, ElementIndex elementIndex)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Core/DataDictionary/Services/PanelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class PanelService(IValidationDictionary validationDictionary,
IEnumerable<IExpressionProvider> expressionProviders,
IDataDictionaryRepository dataDictionaryRepository,
IStringLocalizer<MasterDataResources> stringLocalizer)
: BaseService(validationDictionary, dataDictionaryRepository,stringLocalizer)
: DataDictionaryServiceBase(validationDictionary, dataDictionaryRepository,stringLocalizer)
{
private IEnumerable<IExpressionProvider> ExpressionProviders { get; } = expressionProviders;

Expand Down
2 changes: 1 addition & 1 deletion src/Core/DataDictionary/Services/RelationshipsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class RelationshipsService(IValidationDictionary validationDictionary,
IDataDictionaryRepository dataDictionaryRepository,
IStringLocalizer<MasterDataResources> stringLocalizer,
PanelService panelService)
: BaseService(validationDictionary, dataDictionaryRepository,stringLocalizer)
: DataDictionaryServiceBase(validationDictionary, dataDictionaryRepository,stringLocalizer)
{
public async Task SaveElementRelationship(ElementRelationship elementRelationship, int? id, string elementName)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Core/DataDictionary/Services/UIOptionsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace JJMasterData.Core.DataDictionary.Services;

public class UIOptionsService(IValidationDictionary validationDictionary,
IDataDictionaryRepository dataDictionaryRepository, IStringLocalizer<MasterDataResources> stringLocalizer)
: BaseService(validationDictionary, dataDictionaryRepository,stringLocalizer)
: DataDictionaryServiceBase(validationDictionary, dataDictionaryRepository,stringLocalizer)
{
private async Task<bool> ValidateOptions(FormElementOptions options, string elementName)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Web/Areas/DataDictionary/Controllers/ActionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ActionsController(ActionsService actionsService,
{
public async Task<ActionResult> Index(string elementName)
{
var formElement = await actionsService.DataDictionaryRepository.GetFormElementAsync(elementName);
var formElement = await actionsService.GetFormElementAsync(elementName);
var model = new ActionsListViewModel(elementName, "Actions")
{
GridTableActions = formElement.Options.GridTableActions.GetAllSorted(),
Expand All @@ -36,7 +36,7 @@ public async Task<IActionResult> Edit(string elementName, string actionName, Act
throw new ArgumentNullException(nameof(elementName));


var formElement = await actionsService.DataDictionaryRepository.GetFormElementAsync(elementName);
var formElement = await actionsService.GetFormElementAsync(elementName);

var action = context switch
{
Expand Down Expand Up @@ -414,7 +414,7 @@ private async Task PopulateViewBag(string elementName, BasicAction basicAction,
ViewBag.FieldName = fieldName!;
var formElement = await actionsService.GetFormElementAsync(elementName);
ViewBag.FormElement = formElement;
ViewBag.CodeMirrorHintList = JsonConvert.SerializeObject(BaseService.GetAutocompleteHintsList(formElement, includeAdditionalHints:false));
ViewBag.CodeMirrorHintList = JsonConvert.SerializeObject(DataDictionaryServiceBase.GetAutocompleteHintsList(formElement, includeAdditionalHints:false));

if (basicAction is InternalAction internalAction)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Web/Areas/DataDictionary/Controllers/ApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ public class ApiController(ApiService apiService) : DataDictionaryController
{
public async Task<ActionResult> Index(string elementName)
{
var dic = await apiService.DataDictionaryRepository.GetFormElementAsync(elementName);
var dic = await apiService.GetFormElementAsync(elementName);
var model = PopulateViewModel(dic);

return View(model);
}

public async Task<ActionResult> Edit(string elementName)
{
var dic = await apiService.DataDictionaryRepository.GetFormElementAsync(elementName);
var dic = await apiService.GetFormElementAsync(elementName);
var model = PopulateViewModel(dic);

return View(model);
Expand All @@ -27,7 +27,7 @@ public async Task<ActionResult> Edit(string elementName)
[HttpPost]
public async Task<ActionResult> Edit(ApiViewModel apiViewModel)
{
var formElement = await apiService.DataDictionaryRepository.GetFormElementAsync( apiViewModel.ElementName);
var formElement = await apiService.GetFormElementAsync( apiViewModel.ElementName);
formElement.ApiOptions = apiViewModel.ApiOptions;
formElement.EnableSynchronism = apiViewModel.EnableSynchronism;
formElement.SynchronismMode = apiViewModel.SynchronismMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public async Task<IActionResult> Delete()

foreach (var elementName in elementNamesToDelete)
{
await elementService.DataDictionaryRepository.DeleteAsync(elementName);
await elementService.DeleteAsync(elementName);
}

return RedirectToAction(nameof(Index));
Expand Down
4 changes: 2 additions & 2 deletions src/Web/Areas/DataDictionary/Controllers/FieldController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public async Task<IActionResult> Sort(string elementName, string fieldsOrder)
[HttpPost]
public async Task<IActionResult> Copy(string elementName, FormElementField? field)
{
var dictionary = await fieldService.DataDictionaryRepository.GetFormElementAsync(elementName);
var dictionary = await fieldService.GetFormElementAsync(elementName);
await fieldService.CopyFieldAsync(dictionary, field);
if (!ModelState.IsValid)
ViewBag.Error = fieldService.GetValidationSummary().GetHtml();
Expand Down Expand Up @@ -208,7 +208,7 @@ private async Task PopulateViewBag(FormElement formElement, FormElementField? fi
ViewBag.MenuId = "Fields";
ViewBag.FormElement = formElement;
ViewBag.ElementName = formElement.Name;
ViewBag.CodeMirrorHintList = JsonConvert.SerializeObject(BaseService.GetAutocompleteHintsList(formElement));
ViewBag.CodeMirrorHintList = JsonConvert.SerializeObject(DataDictionaryServiceBase.GetAutocompleteHintsList(formElement));

// ASP.NET Core enforces 30MB (~28.6 MiB) max request body size limit, be it Kestrel and HttpSys.
// Under normal circumstances, there is no need to increase the size of the HTTP request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private void PopulateViewBag(FormElement formElement, FormElementPanel panel)
ViewBag.PanelId = panel.PanelId;
ViewBag.Panels = formElement.Panels;
ViewBag.AvailableFields = GetAvailableFields(formElement);
ViewBag.CodeMirrorHintList = JsonConvert.SerializeObject(BaseService.GetAutocompleteHintsList(formElement));
ViewBag.CodeMirrorHintList = JsonConvert.SerializeObject(DataDictionaryServiceBase.GetAutocompleteHintsList(formElement));
ViewBag.SelectedFields = (panel.PanelId > 0) ?
formElement.Fields.FindAll(x => x.PanelId == panel.PanelId) : [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private async Task<List<SelectListItem>> GetForeignKeysSelectList(string childEl
}
else
{
var formElement = await relationshipsService.DataDictionaryRepository.GetFormElementAsync(childElementName);
var formElement = await relationshipsService.GetFormElementAsync(childElementName);
selectList.AddRange(formElement.Fields.Select(field => new SelectListItem(field.Name, field.Name)));
}

Expand All @@ -157,7 +157,7 @@ private async Task<List<SelectListItem>> GetForeignKeysSelectList(string childEl

private async Task<List<SelectListItem>> GetElementsSelectList(string childElementName)
{
var list = await relationshipsService.DataDictionaryRepository.GetNameListAsync();
var list = await relationshipsService.GetNameListAsync();

var selectList = list.Select(name => new SelectListItem(name, name)).OrderBy(n=>n.Text).ToList();

Expand Down Expand Up @@ -202,11 +202,11 @@ private async Task<RelationshipsLayoutDetailsViewModel> CreateLayoutDetailsViewM
string elementName,
int id)
{
var formElement = await relationshipsService.DataDictionaryRepository.GetFormElementAsync(elementName);
var formElement = await relationshipsService.GetFormElementAsync(elementName);

var relationship = formElement.Relationships.GetById(id);

ViewBag.CodeMirrorHintList = JsonConvert.SerializeObject(BaseService.GetAutocompleteHintsList(formElement));
ViewBag.CodeMirrorHintList = JsonConvert.SerializeObject(DataDictionaryServiceBase.GetAutocompleteHintsList(formElement));

return new RelationshipsLayoutDetailsViewModel(elementName, "Relationships")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task<ActionResult> Edit(FormElementOptions uIMetadataOptions, strin

private async Task<FormElementOptions> Populate(string elementName)
{
var dicParser = await optionsService!.DataDictionaryRepository.GetFormElementAsync(elementName);
var dicParser = await optionsService.GetFormElementAsync(elementName);
var uIOptions = dicParser.Options;
ViewBag.MenuId = "Options";
ViewBag.ElementName = elementName;
Expand Down

0 comments on commit ced6185

Please sign in to comment.