Skip to content

Commit

Permalink
update UserActionService
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiiyasenev committed Aug 28, 2023
1 parent 780d8f9 commit 7ed7d96
Showing 1 changed file with 20 additions and 33 deletions.
53 changes: 20 additions & 33 deletions backend/Squirrel.ConsoleApp/Services/UserActionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,47 +27,23 @@ public async Task<IEnumerable<UserAction>> GetAllTablesAsync()

public async Task<UserAction> GetTableDataAsync(string tableName, int rowsCount)
{
var query = DatabaseFactory.GetTableDataQuery(_dbType, tableName, rowsCount);
var result = await _databaseService.ExecuteQueryAsync(query);

var data = string.Join(Environment.NewLine, result.Rows.Select(ConvertRowToString));

return new UserAction
{
Name = $"Data from '{tableName}' for first '{rowsCount}' rows",
Type = DataType.TableData,
Data = data
};
return await GetUserActionAsync($"Data from '{tableName}' Table for first '{rowsCount}' rows",
DataType.TableData,
DatabaseFactory.GetTableDataQuery(_dbType, tableName, rowsCount));
}

public async Task<UserAction> GetFunctionAsync(string functionName)
{
var query = DatabaseFactory.GetFunctionQuery(_dbType, functionName);
var result = await _databaseService.ExecuteQueryAsync(query);

var data = string.Join(Environment.NewLine, result.Rows.Select(ConvertRowToString));

return new UserAction
{
Name = $"Data from '{functionName}' Function",
Type = DataType.Function,
Data = data
};
return await GetUserActionAsync($"Data from '{functionName}' Function",
DataType.Function,
DatabaseFactory.GetFunctionQuery(_dbType, functionName));
}

public async Task<UserAction> GetStoredProcedureAsync(string storedProcedureName)
{
var query = DatabaseFactory.GetStoredProcedureQuery(_dbType, storedProcedureName);
var result = await _databaseService.ExecuteQueryAsync(query);

var data = string.Join(Environment.NewLine, result.Rows.Select(ConvertRowToString));

return new UserAction
{
Name = $"Data from '{storedProcedureName}' StoredProcedure",
Type = DataType.StoredProcedure,
Data = data
};
return await GetUserActionAsync($"Data from '{storedProcedureName}' StoredProcedure",
DataType.StoredProcedure,
DatabaseFactory.GetStoredProcedureQuery(_dbType, storedProcedureName));
}

private async Task<IEnumerable<UserAction>> GetActionsAsync(DataType dataType, string query)
Expand All @@ -81,6 +57,17 @@ private async Task<IEnumerable<UserAction>> GetActionsAsync(DataType dataType, s
});
}

private async Task<UserAction> GetUserActionAsync(string name, DataType dataType, string query)
{
var result = await _databaseService.ExecuteQueryAsync(query);
return new UserAction
{
Name = name,
Type = dataType,
Data = string.Join(Environment.NewLine, result.Rows.Select(ConvertRowToString))
};
}

private string ConvertRowToString(string[] row) => string.Join(", ", row);
}
}

0 comments on commit 7ed7d96

Please sign in to comment.