Skip to content

Commit 315ff88

Browse files
authored
Release v0.6.1
+ Adds Accounts, Transactions, Categories and Balances Response DTOs + Add Accounts, Transactions, Categories and Balances Request DTOs + Adds Validation from Request DTOs + Adds Dto to Api Controllers + Adds Mapping DTOs to Models in Application Layer * Convert all dto classes with init sets * Reorganize Application Injections - Comments the entire TransactionBalanceService.UpdateTransactionAsync
1 parent ad1f812 commit 315ff88

144 files changed

Lines changed: 3723 additions & 1555 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/api/common/FinancialHub.Common/Models/BaseModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,12 @@
33
public abstract class BaseModel
44
{
55
public Guid? Id { get; set; }
6+
7+
protected BaseModel() { }
8+
9+
protected BaseModel(Guid? id)
10+
{
11+
Id = id;
12+
}
613
}
714
}

src/api/core/FinancialHub.Core.Application/Extensions/Configurations/IServiceCollectionExtensions.cs

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,75 @@
11
using Microsoft.Extensions.DependencyInjection;
22
using FinancialHub.Core.Application.Services;
3-
using FinancialHub.Core.Application.Validators;
43
using FluentValidation;
4+
using FinancialHub.Core.Domain.DTOS.Accounts;
5+
using FinancialHub.Core.Domain.DTOS.Categories;
6+
using FinancialHub.Core.Domain.DTOS.Balances;
7+
using FinancialHub.Core.Domain.DTOS.Transactions;
8+
using FinancialHub.Core.Application.Mappers;
9+
using FinancialHub.Core.Application.Validators.Accounts;
10+
using FinancialHub.Core.Application.Validators.Balances;
11+
using FinancialHub.Core.Application.Validators.Categories;
12+
using FinancialHub.Core.Application.Validators.Transactions;
513

614
namespace FinancialHub.Core.Application.Extensions.Configurations
715
{
816
public static class IServiceCollectionExtensions
917
{
1018
public static IServiceCollection AddCoreServices(this IServiceCollection services)
1119
{
12-
services.AddServices();
13-
services.AddValidators();
20+
services
21+
.AddCategoriesService()
22+
.AddAccountService()
23+
.AddBalanceService()
24+
.AddTransactionService();
1425

1526
return services;
1627
}
1728

18-
private static IServiceCollection AddServices(this IServiceCollection services)
29+
private static IServiceCollection AddBalanceService(this IServiceCollection services)
1930
{
20-
services.AddScoped<IAccountsService, AccountsService>();
21-
services.AddScoped<ICategoriesService, CategoriesService>();
22-
services.AddScoped<ITransactionsService, TransactionsService>();
2331
services.AddScoped<IBalancesService, BalancesService>();
2432

33+
services.AddAutoMapper(typeof(BalanceMapper));
34+
35+
services.AddScoped<IValidator<CreateBalanceDto>, CreateBalanceValidator>();
36+
services.AddScoped<IValidator<UpdateBalanceDto>, UpdateBalanceValidator>();
37+
38+
return services;
39+
}
40+
41+
private static IServiceCollection AddTransactionService(this IServiceCollection services)
42+
{
43+
services.AddScoped<ITransactionsService, TransactionsService>();
44+
45+
services.AddAutoMapper(typeof(TransactionMapper));
46+
47+
services.AddScoped<IValidator<CreateTransactionDto>, CreateTransactionValidator>();
48+
services.AddScoped<IValidator<UpdateTransactionDto>, UpdateTransactionValidator>();
49+
50+
return services;
51+
}
52+
53+
private static IServiceCollection AddAccountService(this IServiceCollection services)
54+
{
55+
services.AddScoped<IAccountsService, AccountsService>();
56+
57+
services.AddAutoMapper(typeof(AccountMapper));
58+
59+
services.AddScoped<IValidator<CreateAccountDto>, CreateAccountValidator>();
60+
services.AddScoped<IValidator<UpdateAccountDto>, UpdateAccountValidator>();
61+
2562
return services;
2663
}
2764

28-
private static IServiceCollection AddValidators(this IServiceCollection services)
65+
private static IServiceCollection AddCategoriesService(this IServiceCollection services)
2966
{
30-
services.AddScoped<IValidator<AccountModel>, AccountValidator>();
31-
services.AddScoped<IValidator<CategoryModel>, CategoryValidator>();
32-
services.AddScoped<IValidator<TransactionModel>, TransactionValidator>();
67+
services.AddScoped<ICategoriesService, CategoriesService>();
68+
69+
services.AddAutoMapper(typeof(CategoryMapper));
70+
71+
services.AddScoped<IValidator<CreateCategoryDto>, CreateCategoryValidator>();
72+
services.AddScoped<IValidator<UpdateCategoryDto>, UpdateCategoryValidator>();
3373

3474
return services;
3575
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using AutoMapper;
2+
using FinancialHub.Core.Domain.DTOS.Accounts;
3+
4+
namespace FinancialHub.Core.Application.Mappers
5+
{
6+
public class AccountMapper : Profile
7+
{
8+
public AccountMapper()
9+
{
10+
CreateMap<CreateAccountDto, AccountModel>();
11+
CreateMap<UpdateAccountDto, AccountModel>();
12+
13+
CreateMap<AccountBalanceDto, BalanceModel>().ReverseMap();
14+
CreateMap<AccountDto, AccountModel>().ReverseMap();
15+
}
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using AutoMapper;
2+
using FinancialHub.Core.Domain.DTOS.Balances;
3+
4+
namespace FinancialHub.Core.Application.Mappers
5+
{
6+
public class BalanceMapper : Profile
7+
{
8+
public BalanceMapper()
9+
{
10+
CreateMap<CreateBalanceDto, BalanceModel>();
11+
CreateMap<UpdateBalanceDto, BalanceModel>();
12+
13+
CreateMap<AccountModel, BalanceAccountDto>();
14+
CreateMap<BalanceModel, BalanceDto>();
15+
}
16+
}
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using AutoMapper;
2+
using FinancialHub.Core.Domain.DTOS.Categories;
3+
4+
namespace FinancialHub.Core.Application.Mappers
5+
{
6+
public class CategoryMapper : Profile
7+
{
8+
public CategoryMapper()
9+
{
10+
CreateMap<CreateCategoryDto, CategoryModel>();
11+
CreateMap<UpdateCategoryDto, CategoryModel>();
12+
CreateMap<CategoryDto, CategoryModel>().ReverseMap();
13+
}
14+
}
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using AutoMapper;
2+
using FinancialHub.Core.Domain.DTOS.Transactions;
3+
4+
namespace FinancialHub.Core.Application.Mappers
5+
{
6+
public class TransactionMapper : Profile
7+
{
8+
public TransactionMapper()
9+
{
10+
CreateMap<CreateTransactionDto, TransactionModel>();
11+
CreateMap<UpdateTransactionDto, TransactionModel>();
12+
13+
CreateMap<TransactionAccountDto, AccountModel>().ReverseMap();
14+
CreateMap<TransactionBalanceDto, BalanceModel>().ReverseMap();
15+
CreateMap<TransactionCategoryDto, CategoryModel>().ReverseMap();
16+
CreateMap<TransactionDto, TransactionModel>().ReverseMap();
17+
}
18+
}
19+
}
Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,44 @@
1-
using FinancialHub.Core.Domain.Interfaces.Resources;
1+
using AutoMapper;
2+
using FinancialHub.Core.Domain.DTOS.Accounts;
3+
using FinancialHub.Core.Domain.Interfaces.Resources;
24

35
namespace FinancialHub.Core.Application.Services
46
{
57
public class AccountsService : IAccountsService
68
{
79
private readonly IAccountsProvider provider;
10+
private readonly IMapper mapper;
811
private readonly IErrorMessageProvider errorMessageProvider;
912

10-
public AccountsService(IAccountsProvider provider, IErrorMessageProvider errorMessageProvider)
13+
public AccountsService(IAccountsProvider provider, IMapper mapper,IErrorMessageProvider errorMessageProvider)
1114
{
1215
this.provider = provider;
16+
this.mapper = mapper;
1317
this.errorMessageProvider = errorMessageProvider;
1418
}
1519

16-
public async Task<ServiceResult<AccountModel>> CreateAsync(AccountModel account)
20+
public async Task<ServiceResult<AccountDto>> CreateAsync(CreateAccountDto accountDto)
1721
{
18-
return await this.provider.CreateAsync(account);
22+
var account = this.mapper.Map<AccountModel>(accountDto);
23+
24+
var result = await this.provider.CreateAsync(account);
25+
26+
return this.mapper.Map<AccountDto>(result);
1927
}
2028

2129
public async Task<ServiceResult<int>> DeleteAsync(Guid id)
2230
{
2331
return await this.provider.DeleteAsync(id);
2432
}
2533

26-
public async Task<ServiceResult<ICollection<AccountModel>>> GetAllByUserAsync(string userId)
34+
public async Task<ServiceResult<ICollection<AccountDto>>> GetAllByUserAsync(string userId)
2735
{
2836
var accounts = await this.provider.GetAllAsync();
2937

30-
return accounts.ToArray();
38+
return this.mapper.Map<ICollection<AccountDto>>(accounts).ToArray();
3139
}
3240

33-
public async Task<ServiceResult<AccountModel>> GetByIdAsync(Guid id)
41+
public async Task<ServiceResult<AccountDto>> GetByIdAsync(Guid id)
3442
{
3543
var existingAccount = await this.provider.GetByIdAsync(id);
3644
if (existingAccount == null)
@@ -40,24 +48,27 @@ public async Task<ServiceResult<AccountModel>> GetByIdAsync(Guid id)
4048
);
4149
}
4250

43-
return existingAccount;
51+
return this.mapper.Map<AccountDto>(existingAccount);
4452
}
4553

46-
public async Task<ServiceResult<AccountModel>> UpdateAsync(Guid id, AccountModel account)
54+
public async Task<ServiceResult<AccountDto>> UpdateAsync(Guid id, UpdateAccountDto account)
4755
{
4856
var existingAccountResult = await this.GetByIdAsync(id);
4957
if (existingAccountResult.HasError)
58+
{
5059
return existingAccountResult.Error;
60+
}
61+
var accountModel = this.mapper.Map<AccountModel>(account);
5162

52-
var updatedAccount = await this.provider.UpdateAsync(id, account);
63+
var updatedAccount = await this.provider.UpdateAsync(id, accountModel);
5364
if (updatedAccount == null)
5465
{
5566
return new InvalidDataError(
5667
this.errorMessageProvider.UpdateFailedMessage("Account", id)
5768
);
5869
}
5970

60-
return updatedAccount;
71+
return this.mapper.Map<AccountDto>(updatedAccount);
6172
}
6273
}
6374
}

src/api/core/FinancialHub.Core.Application/Services/BalancesService.cs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using FinancialHub.Core.Domain.Interfaces.Resources;
1+
using AutoMapper;
2+
using FinancialHub.Core.Domain.DTOS.Balances;
3+
using FinancialHub.Core.Domain.Interfaces.Resources;
24

35
namespace FinancialHub.Core.Application.Services
46
{
@@ -7,16 +9,19 @@ public class BalancesService : IBalancesService
79
private readonly IAccountsProvider accountsProvider;
810
private readonly IBalancesProvider balancesProvider;
911
private readonly IErrorMessageProvider errorMessageProvider;
12+
private readonly IMapper mapper;
1013

1114
public BalancesService(
1215
IBalancesProvider balancesProvider,
1316
IAccountsProvider accountsProvider,
14-
IErrorMessageProvider errorMessageProvider
17+
IErrorMessageProvider errorMessageProvider,
18+
IMapper mapper
1519
)
1620
{
1721
this.balancesProvider = balancesProvider;
1822
this.accountsProvider = accountsProvider;
1923
this.errorMessageProvider = errorMessageProvider;
24+
this.mapper = mapper;
2025
}
2126

2227
private async Task<ServiceResult> ValidateAccountAsync(Guid accountId)
@@ -33,21 +38,25 @@ private async Task<ServiceResult> ValidateAccountAsync(Guid accountId)
3338
return new ServiceResult();
3439
}
3540

36-
public async Task<ServiceResult<BalanceModel>> CreateAsync(BalanceModel balance)
41+
public async Task<ServiceResult<BalanceDto>> CreateAsync(CreateBalanceDto balance)
3742
{
3843
var validationResult = await this.ValidateAccountAsync(balance.AccountId);
3944
if (validationResult.HasError)
4045
return validationResult.Error;
4146

42-
return await this.balancesProvider.CreateAsync(balance);
47+
var balanceModel = this.mapper.Map<BalanceModel>(balance);
48+
49+
var createdBalance = await this.balancesProvider.CreateAsync(balanceModel);
50+
51+
return this.mapper.Map<BalanceDto>(createdBalance);
4352
}
4453

4554
public async Task<ServiceResult<int>> DeleteAsync(Guid id)
4655
{
4756
return await this.balancesProvider.DeleteAsync(id);
4857
}
4958

50-
public async Task<ServiceResult<BalanceModel>> GetByIdAsync(Guid id)
59+
public async Task<ServiceResult<BalanceDto>> GetByIdAsync(Guid id)
5160
{
5261
var balance = await this.balancesProvider.GetByIdAsync(id);
5362
if (balance == null)
@@ -57,23 +66,23 @@ public async Task<ServiceResult<BalanceModel>> GetByIdAsync(Guid id)
5766
);
5867
}
5968

60-
return balance;
69+
return this.mapper.Map<BalanceDto>(balance);
6170
}
6271

63-
public async Task<ServiceResult<ICollection<BalanceModel>>> GetAllByAccountAsync(Guid accountId)
72+
public async Task<ServiceResult<ICollection<BalanceDto>>> GetAllByAccountAsync(Guid accountId)
6473
{
6574
var validationResult = await this.ValidateAccountAsync(accountId);
6675
if (validationResult.HasError)
6776
{
6877
return validationResult.Error;
6978
}
7079

71-
var accounts = await this.balancesProvider.GetAllByAccountAsync(accountId);
80+
var balances = await this.balancesProvider.GetAllByAccountAsync(accountId);
7281

73-
return accounts.ToArray();
82+
return this.mapper.Map<ICollection<BalanceDto>>(balances).ToArray();
7483
}
7584

76-
public async Task<ServiceResult<BalanceModel>> UpdateAsync(Guid id, BalanceModel balance)
85+
public async Task<ServiceResult<BalanceDto>> UpdateAsync(Guid id, UpdateBalanceDto balance)
7786
{
7887
var oldBalance = await this.GetByIdAsync(id);
7988
if (oldBalance.HasError)
@@ -87,7 +96,11 @@ public async Task<ServiceResult<BalanceModel>> UpdateAsync(Guid id, BalanceModel
8796
return validationResult.Error;
8897
}
8998

90-
return await this.balancesProvider.UpdateAsync(id, balance);
99+
var balanceModel = this.mapper.Map<BalanceModel>(balance);
100+
101+
var updatedBalance = await this.balancesProvider.UpdateAsync(id, balanceModel);
102+
103+
return this.mapper.Map<BalanceDto>(updatedBalance);
91104
}
92105

93106
public async Task<ServiceResult<BalanceModel>> UpdateAmountAsync(Guid id, decimal newAmount)

0 commit comments

Comments
 (0)