Skip to content

Commit 4277978

Browse files
committed
Refactor code structure for improved readability and maintainability
1 parent 804822d commit 4277978

27 files changed

+3074
-105
lines changed

src/CryptoTracker.Client/Pages/Import.razor

Lines changed: 362 additions & 21 deletions
Large diffs are not rendered by default.

src/CryptoTracker.Client/Pages/Import.razor.cs

Lines changed: 0 additions & 69 deletions
This file was deleted.

src/CryptoTracker.Client/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
builder.Services.AddScoped<ICoinRatesApi, CoinRatesRestClient>();
1616
builder.Services.AddScoped<IDataImportApi, DataImportRestClient>();
1717
builder.Services.AddScoped<IImportEntriesApi, ImportEntriesRestClient>();
18+
builder.Services.AddScoped<IImportOverviewApi, ImportOverviewRestClient>();
1819

1920
builder.Services.AddRadzenComponents();
2021

src/CryptoTracker.Client/RestClients/DataImportRestClient.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,28 @@ public async Task ImportFileAsync(ImportDocumentType type, string walletName, IB
2626
response.EnsureSuccessStatusCode();
2727
}
2828

29+
public async Task<ImportPreviewResult> PreviewImportAsync(IBrowserFile file)
30+
{
31+
using var content = new MultipartFormDataContent();
32+
using var fileContent = new StreamContent(file.OpenReadStream(MAX_REQUEST_SIZE));
33+
fileContent.Headers.ContentType = new MediaTypeHeaderValue(file.ContentType);
34+
content.Add(fileContent, "file", file.Name);
35+
var response = await _http.PostAsync("api/DataImport/PreviewImport", content);
36+
response.EnsureSuccessStatusCode();
37+
return await response.Content.ReadFromJsonAsync<ImportPreviewResult>() ?? new ImportPreviewResult(false, "Leere Antwort vom Server.", null, null, null, new List<ImportPreviewTransactionRowDTO>(), false, new List<ImportPreviewTradeRowDTO>(), false);
38+
}
39+
40+
public async Task ImportAutoAsync(string walletName, IBrowserFile file, ImportDocumentType? documentType = null)
41+
{
42+
using var content = new MultipartFormDataContent();
43+
using var fileContent = new StreamContent(file.OpenReadStream(MAX_REQUEST_SIZE));
44+
fileContent.Headers.ContentType = new MediaTypeHeaderValue(file.ContentType);
45+
content.Add(fileContent, "file", file.Name);
46+
content.Add(JsonContent.Create(new ImportAutoRequest { WalletName = walletName, DocumentType = documentType }), "request");
47+
var response = await _http.PostAsync("api/DataImport/ImportAuto", content);
48+
response.EnsureSuccessStatusCode();
49+
}
50+
2951
public async Task ProcessTransactionPairsAsync()
3052
{
3153
using var content = new MultipartFormDataContent();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Net.Http.Json;
2+
using CryptoTracker.Shared;
3+
4+
namespace CryptoTracker.Client.RestClients;
5+
6+
public class ImportOverviewRestClient : IImportOverviewApi
7+
{
8+
private readonly HttpClient _http;
9+
10+
public ImportOverviewRestClient(HttpClient http)
11+
{
12+
_http = http;
13+
}
14+
15+
public async Task<ImportOverviewDTO> GetOverviewAsync()
16+
=> await _http.GetFromJsonAsync<ImportOverviewDTO>("api/ImportOverview/GetOverview")
17+
?? new ImportOverviewDTO(new List<ImportTransactionRowDTO>(), new List<ImportTransactionRowDTO>(), new List<ImportTradeRowDTO>());
18+
}

src/CryptoTracker.Client/Shared/Api/IDataImportApi.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ namespace CryptoTracker.Shared;
55
public interface IDataImportApi
66
{
77
Task ImportFileAsync(ImportDocumentType type, string walletName, IBrowserFile file);
8+
Task<ImportPreviewResult> PreviewImportAsync(IBrowserFile file);
9+
Task ImportAutoAsync(string walletName, IBrowserFile file, ImportDocumentType? documentType = null);
810
Task ProcessTransactionPairsAsync();
911
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace CryptoTracker.Shared;
2+
3+
public interface IImportOverviewApi
4+
{
5+
Task<ImportOverviewDTO> GetOverviewAsync();
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace CryptoTracker.Shared;
2+
3+
public class ImportAutoRequest
4+
{
5+
public string WalletName { get; set; } = string.Empty;
6+
7+
public ImportDocumentType? DocumentType { get; set; }
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace CryptoTracker.Shared;
2+
3+
public record ImportOverviewDTO(IList<ImportTransactionRowDTO> Deposits,
4+
IList<ImportTransactionRowDTO> Withdrawals,
5+
IList<ImportTradeRowDTO> Trades);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace CryptoTracker.Shared;
2+
3+
public record ImportPreviewResult(bool Success,
4+
string? ErrorMessage,
5+
string? DetectedSource,
6+
ImportDocumentType? DocumentType,
7+
string? DocumentTypeDisplayName,
8+
IList<ImportPreviewTransactionRowDTO> TransactionRows,
9+
bool TransactionsTruncated,
10+
IList<ImportPreviewTradeRowDTO> TradeRows,
11+
bool TradesTruncated);

0 commit comments

Comments
 (0)