diff --git a/AnalysisData/AnalysisData/Graph/GraphUtility.cs b/AnalysisData/AnalysisData/Graph/GraphUtility.cs index 07c185d..209bc4f 100644 --- a/AnalysisData/AnalysisData/Graph/GraphUtility.cs +++ b/AnalysisData/AnalysisData/Graph/GraphUtility.cs @@ -1,77 +1,80 @@ -using AnalysisData.Graph.DataManage.Model; -using AnalysisData.Repository.AccountRepository; -using AnalysisData.Repository.TransactionRepository; -using QuickGraph; - -namespace AnalysisData.Graph; - -public class GraphUtility -{ - public BidirectionalGraph Graph { get; private set; } - private readonly AccountRepository _accountService; - private readonly TransactionRepository _transactionService; - - public GraphUtility(AccountRepository accountService, TransactionRepository transactionService) - { - Graph = new BidirectionalGraph(); - _accountService = accountService; - _transactionService = transactionService; - } - - public async Task BuildGraphAsync() - { - var accounts = await _accountService.GetAllAccounts(); - foreach (var account in accounts) - { - if (!Graph.ContainsVertex(account)) - { - Graph.AddVertex(account); - } - } - - var transactions = await _transactionService.GetAllTransaction(); - foreach (var transaction in transactions) - { - await AddTransactionAsync(transaction); - } - } - - public async Task AddTransactionAsync(Transaction transaction) - { - var sourceAccount = await _accountService.GetAccountById(transaction.SourceAccount); - var targetAccount = await _accountService.GetAccountById(transaction.DestinationAccount); - - if (sourceAccount == null || targetAccount == null) - { - throw new ArgumentException("Both accounts must exist in the database."); - } - - var edge = new TransactionEdgeAdapter(sourceAccount, targetAccount, transaction); - Graph.AddEdge(edge); - } - - public string ToJson() - { - var transactions = new List(); - - foreach (var edge in Graph.Edges) - { - transactions.Add(new - { - From = edge.Source.AccountID, - To = edge.Target.AccountID, - Transaction = new - { - SourceAccount = edge.Transaction.SourceAccount, - DestinationAccount = edge.Transaction.DestinationAccount, - Amount = edge.Transaction.Amount, - Date = edge.Transaction.Date, - TransactionID = edge.Transaction.TransactionID, - Type = edge.Transaction.Type - } - }); - } - - return System.Text.Json.JsonSerializer.Serialize(transactions, new System.Text.Json.JsonSerializerOptions { WriteIndented = true }); - } -} \ No newline at end of file +// using AnalysisData.Graph.DataManage.Model; +// using AnalysisData.Repository.AccountRepository; +// using AnalysisData.Repository.TransactionRepository; +// using QuickGraph; +// +// namespace AnalysisData.Graph; +// +// public class GraphUtility +// { +// public BidirectionalGraph Graph { get; private set; } +// private readonly AccountRepository _accountService; +// private readonly TransactionRepository _transactionService; +// +// public GraphUtility(AccountRepository accountService, TransactionRepository transactionService) +// { +// Graph = new BidirectionalGraph(); +// _accountService = accountService; +// _transactionService = transactionService; +// } +// +// public async Task BuildGraphAsync() +// { +// var accounts = await _accountService.GetAllAccounts(); +// foreach (var account in accounts) +// { +// if (!Graph.ContainsVertex(account)) +// { +// Graph.AddVertex(account); +// } +// } +// +// var transactions = await _transactionService.GetAllTransaction(); +// foreach (var transaction in transactions) +// { +// await AddTransactionAsync(transaction); +// } +// } +// +// public async Task AddTransactionAsync(Transaction transaction) +// { +// var sourceAccount = await _accountService.GetAccountById(transaction.SourceAccount); +// var targetAccount = await _accountService.GetAccountById(transaction.DestinationAccount); +// +// if (sourceAccount == null || targetAccount == null) +// { +// throw new ArgumentException("Both accounts must exist in the database."); +// } +// +// var edge = new TransactionEdgeAdapter(sourceAccount, targetAccount, transaction); +// Graph.AddEdge(edge); +// } +// +// public string ToJson() +// { +// var transactions = new List(); +// +// foreach (var edge in Graph.Edges) +// { +// transactions.Add(new +// { +// From = edge.Source.AccountID, +// To = edge.Target.AccountID, +// Transaction = new +// { +// SourceAccount = edge.Transaction.SourceAccount, +// DestinationAccount = edge.Transaction.DestinationAccount, +// Amount = edge.Transaction.Amount, +// Date = edge.Transaction.Date, +// TransactionID = edge.Transaction.TransactionID, +// Type = edge.Transaction.Type +// } +// }); +// } +// +// return System.Text.Json.JsonSerializer.Serialize(transactions, new System.Text.Json.JsonSerializerOptions { WriteIndented = true }); +// } +// +// +// public BidirectionalGraph GetGraph() => Graph; +// } \ No newline at end of file diff --git a/AnalysisData/AnalysisData/Graph/IGraphUtility.cs b/AnalysisData/AnalysisData/Graph/IGraphUtility.cs new file mode 100644 index 0000000..8181b7e --- /dev/null +++ b/AnalysisData/AnalysisData/Graph/IGraphUtility.cs @@ -0,0 +1,12 @@ +// using AnalysisData.Graph.DataManage.Model; +// using QuickGraph; +// +// namespace AnalysisData.Graph; +// +// public interface IGraphUtility +// { +// Task BuildGraphAsync(); +// Task AddTransactionAsync(Transaction transaction); +// string ToJson(); +// BidirectionalGraph GetGraph(); +// } \ No newline at end of file diff --git a/AnalysisData/AnalysisData/Program.cs b/AnalysisData/AnalysisData/Program.cs index bcafab0..e2176cd 100644 --- a/AnalysisData/AnalysisData/Program.cs +++ b/AnalysisData/AnalysisData/Program.cs @@ -42,6 +42,14 @@ builder.Services.AddDbContext(options => options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"))); builder.Services.AddControllers(); +builder.Services.AddCors(options => +{ + options.AddPolicy("AllowAngularApp", + corsPolicyBuilder => corsPolicyBuilder.WithOrigins("http://localhost:4200") + .AllowAnyMethod() + .AllowAnyHeader() + .AllowCredentials()); +}); builder.Services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; @@ -90,17 +98,4 @@ app.UseAuthentication(); app.UseAuthorization(); app.MapControllers(); - -using (var scope = app.Services.CreateScope()) -{ - var services = scope.ServiceProvider; - - var context = services.GetRequiredService(); - context.Database.EnsureCreated(); - - if (context.Database.GetPendingMigrations().Any()) - { - context.Database.Migrate(); - } -} app.Run(); \ No newline at end of file