Skip to content

Commit

Permalink
Merge pull request #14 from Star-Academy/refactor/refactor-transaction
Browse files Browse the repository at this point in the history
refactor: refactor transaction related apis
  • Loading branch information
mobinbr authored Aug 19, 2024
2 parents b25b194 + 9b17121 commit 6787d32
Show file tree
Hide file tree
Showing 27 changed files with 1,211 additions and 2,149 deletions.
10 changes: 5 additions & 5 deletions src/Application/DTOs/Account/AccountCsvModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

public class AccountCsvModel
{
public long AccountId { get; set; }
public long CardId { get; set; }
public string Iban { get; set; } = string.Empty;
public long AccountID { get; set; }
public long CardID { get; set; }
public string IBAN { get; set; } = string.Empty;
public string AccountType { get; set; } = string.Empty;
public string BranchTelephone { get; set; } = string.Empty;
public string BranchAddress { get; set; } = string.Empty;
public string BranchAdress { get; set; } = string.Empty;
public string BranchName { get; set; } = string.Empty;
public string OwnerName { get; set; } = string.Empty;
public string OwnerLastName { get; set; } = string.Empty;
public string OwnerId { get; set; } = string.Empty;
public long OwnerID { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Application.DTOs.TransactionCsv;
namespace Application.DTOs.Transaction;

public class GetAllTransactionsResponse
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using Application.Services.SharedService;
using CsvHelper.Configuration.Attributes;

namespace Application.DTOs.TransactionCsv;

public class TransactionCsvModel
{
public long TransactionID { get; set; }
public long SourceAcount { get; set; }
public long DestiantionAccount { get; set; }
public decimal Amount { get; set; }
[TypeConverter(typeof(PersianDateConverter))]
public DateTime Date { get; set; }
public string Type { get; set; } = string.Empty;
using Application.Services.SharedService;
using CsvHelper.Configuration.Attributes;

namespace Application.DTOs.Transaction;

public class TransactionCsvModel
{
public long TransactionID { get; set; }
public long SourceAcount { get; set; }
public long DestiantionAccount { get; set; }
public decimal Amount { get; set; }
[TypeConverter(typeof(PersianDateConverter))]
public DateTime Date { get; set; }
public string Type { get; set; } = string.Empty;
}
2 changes: 1 addition & 1 deletion src/Application/Interfaces/Services/IAccountService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ public interface IAccountService
Task AddAccountsFromCsvAsync(string filePath);
Task<Account?> GetAccountByIdAsync(long accountId);
Task<Result<List<Transaction>>> GetTransactionsByUserId(long accountId);
Task<Result<GetAllAccountsResponse>> GetAllAccounts();
Task<Result<GetAllAccountsResponse>> GetAllAccountsAsync();
}
4 changes: 2 additions & 2 deletions src/Application/Interfaces/Services/ITransactionService.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Application.DTOs;
using Application.DTOs.TransactionCsv;
using Application.DTOs.Transaction;

namespace Application.Interfaces.Services;

public interface ITransactionService
{
Task AddTransactionsFromCsvAsync(string filePath);
Task<Result<GetAllTransactionsResponse>> GetAllTransactions();
Task<Result<GetAllTransactionsResponse>> GetAllTransactionsAsync();
}
10 changes: 5 additions & 5 deletions src/Application/Mappers/AccountMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ public static GetAllAccountsResponse ToGetAllAccountsResponse(this List<Account>
{
Accounts = accounts.Select(account => new AccountCsvModel
{
AccountId = account.AccountId,
CardId = account.CardId,
Iban = account.Iban,
AccountID = account.AccountId,
CardID = account.CardId,
IBAN = account.Iban,
AccountType = account.AccountType,
BranchTelephone = account.BranchTelephone,
BranchAddress = account.BranchAddress,
BranchAdress = account.BranchAddress,
BranchName = account.BranchName,
OwnerName = account.OwnerName,
OwnerLastName = account.OwnerLastName,
OwnerId = account.OwnerId
OwnerID = account.OwnerId
}).ToList()
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Mappers/TransactionMapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Application.DTOs.TransactionCsv;
using Application.DTOs.Transaction;
using Domain.Entities;

namespace Application.Mappers;
Expand Down
12 changes: 6 additions & 6 deletions src/Application/Services/AccountService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ public async Task AddAccountsFromCsvAsync(string filePath)

var accounts = accountCsvModels.Select(csvModel => new Account
{
AccountId = csvModel.AccountId,
CardId = csvModel.CardId,
Iban = csvModel.Iban,
AccountId = csvModel.AccountID,
CardId = csvModel.CardID,
Iban = csvModel.IBAN,
AccountType = csvModel.AccountType,
BranchTelephone = csvModel.BranchTelephone,
BranchAddress = csvModel.BranchAddress,
BranchAddress = csvModel.BranchAdress,
BranchName = csvModel.BranchName,
OwnerName = csvModel.OwnerName,
OwnerLastName = csvModel.OwnerLastName,
OwnerId = csvModel.OwnerId
OwnerId = csvModel.OwnerID
}).ToList();

await _accountRepository.CreateBulkAsync(accounts);
Expand All @@ -57,7 +57,7 @@ public async Task<Result<List<Transaction>>> GetTransactionsByUserId(long accoun
return Result<List<Transaction>>.Ok(transactions);
}

public async Task<Result<GetAllAccountsResponse>> GetAllAccounts()
public async Task<Result<GetAllAccountsResponse>> GetAllAccountsAsync()
{
try
{
Expand Down
1 change: 0 additions & 1 deletion src/Application/Services/SharedService/CsvReaderService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Globalization;
using Application.DTOs.TransactionCsv;
using CsvHelper;
using CsvHelper.Configuration;

Expand Down
5 changes: 2 additions & 3 deletions src/Application/Services/TransactionService.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using Application.DTOs;
using Application.DTOs.TransactionCsv;
using Application.DTOs.Transaction;
using Application.Interfaces;
using Application.Interfaces.Services;
using Application.Mappers;
using Application.Services.SharedService;
using Domain.Entities;
using Application.DTOs.TransactionCsv;
using Application.Interfaces.Repositories;

namespace Application.Services;
Expand Down Expand Up @@ -36,7 +35,7 @@ public async Task AddTransactionsFromCsvAsync(string filePath)
await _transactionRepository.CreateBulkAsync(transactions);
}

public async Task<Result<GetAllTransactionsResponse>> GetAllTransactions()
public async Task<Result<GetAllTransactionsResponse>> GetAllTransactionsAsync()
{
try
{
Expand Down
18 changes: 8 additions & 10 deletions src/Domain/Entities/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,26 @@ public class Account
public long CardId { get; set; }

[MaxLength(50)]
public string Iban { get; set; } = string.Empty;
public string Iban { get; set; } = String.Empty;

[MaxLength(50)]
public string AccountType { get; set; } = string.Empty;
public string AccountType { get; set; } = String.Empty;

[MaxLength(20)]
public string BranchTelephone { get; set; } = string.Empty;
public string BranchTelephone { get; set; } = String.Empty;

[MaxLength(150)]
public string BranchAddress { get; set; } = string.Empty;
public string BranchAddress { get; set; } = String.Empty;

[MaxLength(50)]
public string BranchName { get; set; } = string.Empty;
public string BranchName { get; set; } = String.Empty;

[MaxLength(50)]
public string OwnerName { get; set; } = string.Empty;
public string OwnerName { get; set; } = String.Empty;

[MaxLength(50)]
public string OwnerLastName { get; set; } = string.Empty;

[MaxLength(50)]
public string OwnerId { get; set; } = string.Empty;
public string OwnerLastName { get; set; } = String.Empty;
public long OwnerId { get; set; }

public List<Transaction> SourceTransactions { get; set; } = new();
public List<Transaction> DestinationTransactions { get; set; } = new();
Expand Down
10 changes: 7 additions & 3 deletions src/Domain/Entities/Transaction.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics.CodeAnalysis;

namespace Domain.Entities;
[Table("Transactions")]
public class Transaction
{
[Key]
public long TransactionId { get; set; }
public long SourceAccountId { get; set; }
public Account SourceAccount { get; set; }
public Account? SourceAccount { get; set; }
public long DestinationAccountId { get; set; }
public Account DestinationAccount { get; set; }
public Account? DestinationAccount { get; set; }
public decimal Amount { get; set; }
public DateTime Date { get; set; }
[MaxLength(50)]
public string Type { get; set; } = String.Empty;
}
Loading

0 comments on commit 6787d32

Please sign in to comment.