Files
TxSearchApi/BusinessLogic/SearchLogic/SearchLogic.cs
2021-10-14 16:53:06 +02:00

105 lines
3.2 KiB
C#

using Datamodels.DatabaseModels;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Repositories.Interfaces;
using Datamodels.BusinessModels;
using Datamodels.SearchModels;
using Newtonsoft.Json;
using System.Linq;
using System.Linq.Expressions;
using SearchApi.Exceptions;
namespace SearchApi.SearchLogic
{
public class SearchLogic : ISearchLogic
{
private readonly ILogger<SearchLogic> _logger;
private readonly IFwMariaSearchRepo _searchRepo;
private List<string> _tableNames;
private List<string> _joinConditions;
private List<string> _fieldNames;
private List<string> _whereConditions;
private List<string> _sortFields;
public SearchLogic(ILogger<SearchLogic> logger, IFwMariaSearchRepo searchRepo)
{
_logger = logger;
_searchRepo = searchRepo;
}
public async Task<DataResult<List<Address>>> GetAllAddresses()
{
var result = await _searchRepo.GetAllAddresses();
return result;
}
public async Task<DataResult<ResultModel>> GetFilteredData(FilterModel filter, long skip = 0, long take = -1)
{
var result = new DataResult<ResultModel>();
result.Data = new ResultModel();
result.Data.SearchModel = filter;
return result;
}
// Extract Table
private void GetTables(FilterModel filter)
{
bool hasTableList = filter.TableDescriptions.Count > 0;
_tableNames = new List<string>();
foreach(var table in filter.TableDescriptions)
{
if (hasTableList && string.IsNullOrEmpty(table.TableAlias))
{
throw new TableAliasMissingException($"No Alias defined for Table {table.TableName}");
}
_tableNames.Add($"{table.TableName} {(string.IsNullOrEmpty(table.TableAlias) ? string.Empty : table.TableAlias)}");
}
}
// Extract Fieldlist
private void GetFields(FilterModel filter)
{
var tables = filter.TableDescriptions;
foreach (var table in tables)
{
bool hasMultipleFields = table.Fields.Count > 0;
foreach (var field in table.Fields) {
if (hasMultipleFields && string.IsNullOrEmpty(field.FieldAlias))
{
throw new FieldAliasMissingException($"No Alias defined for Field {field.FieldName} in Table {table.TableName}");
}
_fieldNames.Add($"{table.TableAlias}.{field.FieldName} {field.FieldAlias}");
}
}
}
// Extract Join Path if more than one table
private void GetTableJoinConditions(FilterModel filter)
{
}
// Extract Where Conditions
private void GetWhereConditions(FilterModel filter)
{
}
// Extract Sort Items
private void GetSortFields(FilterModel filter)
{
}
// Assemble SQL Query
private string AssembleSqlQuery()
{
return null;
}
}
}