Skip to content

Commit 29a8938

Browse files
committed
add UserID filtering and TrackOnly property support.
1 parent e32d396 commit 29a8938

13 files changed

Lines changed: 862 additions & 75 deletions

File tree

BudgetFlow.Application/Budget/Queries/GetEntryPagination/GetEntryPaginationQuery.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class GetEntryPaginationQuery : IRequest<Result<PaginatedList<EntryRespon
1111
public int Page { get; set; } = 1;
1212
public int PageSize { get; set; } = 50;
1313
public int WalletID { get; set; }
14+
public int? UserID { get; set; }
1415
public class GetEntryPaginationQueryHandler : IRequestHandler<GetEntryPaginationQuery, Result<PaginatedList<EntryResponse>>>
1516
{
1617
private readonly IBudgetRepository _budgetRepository;
@@ -34,7 +35,7 @@ public async Task<Result<PaginatedList<EntryResponse>>> Handle(GetEntryPaginatio
3435
if (userWallet == null)
3536
return Result.Failure<PaginatedList<EntryResponse>>(UserWalletErrors.UserWalletNotFound);
3637

37-
var result = await _budgetRepository.GetPaginatedAsync(request.Page, request.PageSize, request.WalletID);
38+
var result = await _budgetRepository.GetPaginatedAsync(request.Page, request.PageSize, request.WalletID, request.UserID);
3839
if (result == null)
3940
return Result.Failure<PaginatedList<EntryResponse>>(EntryErrors.EntryNotFound);
4041

BudgetFlow.Application/Common/Dtos/InvestmentDto.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ public class InvestmentDto
1111
public InvestmentType Type { get; set; }
1212
public DateTime Date { get; set; }
1313
public int PortfolioId { get; set; }
14+
public bool TrackOnly { get; set; } = false;
1415
}

BudgetFlow.Application/Common/Interfaces/Repositories/IBudgetRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public interface IBudgetRepository
88
Task<bool> CreateEntryAsync(Entry Entry, bool saveChanges = true);
99
Task<bool> UpdateEntryAsync(int ID, Entry Entry, bool saveChanges = true);
1010
Task<bool> DeleteEntryAsync(int ID, bool saveChanges = true);
11-
Task<PaginatedList<EntryResponse>> GetPaginatedAsync(int Page, int PageSize, int walletID);
11+
Task<PaginatedList<EntryResponse>> GetPaginatedAsync(int Page, int PageSize, int walletID, int? userID = null);
1212
Task<bool> CheckEntryByCategoryAsync(int CategoryID, int UserID);
1313
Task<EntryResponse> GetEntryByIdAsync(int ID);
1414
}

BudgetFlow.Application/Investments/Commands/CreateInvestment/CreateInvestmentCommand.cs

Lines changed: 63 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class CreateInvestmentCommand : IRequest<Result<bool>>
1717
public InvestmentType Type { get; set; }
1818
public DateTime Date { get; set; }
1919
public int PortfolioID { get; set; }
20+
public bool TrackOnly { get; set; } = false;
2021
public class CreateInvestmentCommandHandler : IRequestHandler<CreateInvestmentCommand, Result<bool>>
2122
{
2223
private readonly IInvestmentRepository _investmentRepository;
@@ -72,7 +73,8 @@ public async Task<Result<bool>> Handle(CreateInvestmentCommand request, Cancella
7273
Description = request.Description,
7374
Date = DateTime.SpecifyKind(request.Date, DateTimeKind.Utc),
7475
PortfolioId = request.PortfolioID,
75-
Type = request.Type
76+
Type = request.Type,
77+
TrackOnly = request.TrackOnly
7678
};
7779

7880
investment.CurrencyAmount = investment.Type == InvestmentType.Buy
@@ -113,19 +115,28 @@ public async Task<Result<bool>> Handle(CreateInvestmentCommand request, Cancella
113115
walletAsset.Balance += investment.UnitAmount * asset.BuyPrice;
114116

115117
var walletAssetUpdate = await _walletRepository.UpdateWalletAssetAsync(walletAsset.ID, walletAsset.Amount, walletAsset.Balance, saveChanges: false);
116-
var walletUpdate = await _walletRepository.UpdateWalletAsync(portfolio.WalletID, -investment.CurrencyAmount, saveChanges: false);
117118

118-
// Create entry for investment purchase
119-
var entry = new Entry
119+
if (!investment.TrackOnly)
120120
{
121-
Name = $"{asset.Name} yatırımı",
122-
Amount = -investment.CurrencyAmount, // Negative because it's an expense
123-
Date = investment.Date,
124-
CategoryID = category.ID,
125-
WalletID = portfolio.WalletID,
126-
UserID = userID
127-
};
128-
await _budgetRepository.CreateEntryAsync(entry, saveChanges: false);
121+
var walletUpdate = await _walletRepository.UpdateWalletAsync(portfolio.WalletID, -investment.CurrencyAmount, saveChanges: false);
122+
123+
// Create entry for investment purchase
124+
var entry = new Entry
125+
{
126+
Name = $"{asset.Name} yatırımı",
127+
Amount = -investment.CurrencyAmount, // Negative because it's an expense
128+
Date = investment.Date,
129+
CategoryID = category.ID,
130+
WalletID = portfolio.WalletID,
131+
UserID = userID
132+
};
133+
await _budgetRepository.CreateEntryAsync(entry, saveChanges: false);
134+
}
135+
else
136+
{
137+
// For TrackOnly investments, increase wallet balance as it's a savings
138+
var walletUpdate = await _walletRepository.UpdateWalletAsync(portfolio.WalletID, investment.UnitAmount * asset.BuyPrice, saveChanges: false);
139+
}
129140
}
130141
else
131142
{
@@ -136,19 +147,28 @@ public async Task<Result<bool>> Handle(CreateInvestmentCommand request, Cancella
136147
walletAsset.Balance -= investment.UnitAmount * asset.BuyPrice;
137148

138149
var walletAssetUpdate = await _walletRepository.UpdateWalletAssetAsync(walletAsset.ID, walletAsset.Amount, walletAsset.Balance, saveChanges: false);
139-
var walletUpdate = await _walletRepository.UpdateWalletAsync(portfolio.WalletID, investment.CurrencyAmount, saveChanges: false);
140150

141-
// Create entry for investment sale
142-
var entry = new Entry
151+
if (!investment.TrackOnly)
152+
{
153+
var walletUpdate = await _walletRepository.UpdateWalletAsync(portfolio.WalletID, investment.CurrencyAmount, saveChanges: false);
154+
155+
// Create entry for investment sale
156+
var entry = new Entry
157+
{
158+
Name = $"{asset.Name} satışı",
159+
Amount = investment.CurrencyAmount, // Positive because it's income from sale
160+
Date = investment.Date,
161+
CategoryID = category.ID,
162+
WalletID = portfolio.WalletID,
163+
UserID = userID
164+
};
165+
await _budgetRepository.CreateEntryAsync(entry, saveChanges: false);
166+
}
167+
else
143168
{
144-
Name = $"{asset.Name} satışı",
145-
Amount = investment.CurrencyAmount, // Positive because it's income from sale
146-
Date = investment.Date,
147-
CategoryID = category.ID,
148-
WalletID = portfolio.WalletID,
149-
UserID = userID
150-
};
151-
await _budgetRepository.CreateEntryAsync(entry, saveChanges: false);
169+
// For TrackOnly investments, decrease wallet balance as it's a withdrawal from savings
170+
var walletUpdate = await _walletRepository.UpdateWalletAsync(portfolio.WalletID, -investment.UnitAmount * asset.SellPrice, saveChanges: false);
171+
}
152172
}
153173
}
154174
else
@@ -163,19 +183,27 @@ public async Task<Result<bool>> Handle(CreateInvestmentCommand request, Cancella
163183
Balance = investment.UnitAmount * asset.BuyPrice
164184
}, saveChanges: false);
165185

166-
var walletUpdate = await _walletRepository.UpdateWalletAsync(portfolio.WalletID, -investment.CurrencyAmount, saveChanges: false);
167-
168-
// Create entry for initial investment purchase
169-
var entry = new Entry
186+
if (!investment.TrackOnly)
187+
{
188+
var walletUpdate = await _walletRepository.UpdateWalletAsync(portfolio.WalletID, -investment.CurrencyAmount, saveChanges: false);
189+
190+
// Create entry for initial investment purchase
191+
var entry = new Entry
192+
{
193+
Name = $"{asset.Name} ilk yatırımı",
194+
Amount = -investment.CurrencyAmount, // Negative because it's an expense
195+
Date = investment.Date,
196+
CategoryID = category.ID,
197+
WalletID = portfolio.WalletID,
198+
UserID = userID
199+
};
200+
await _budgetRepository.CreateEntryAsync(entry, saveChanges: false);
201+
}
202+
else
170203
{
171-
Name = $"{asset.Name} ilk yatırımı",
172-
Amount = -investment.CurrencyAmount, // Negative because it's an expense
173-
Date = investment.Date,
174-
CategoryID = category.ID,
175-
WalletID = portfolio.WalletID,
176-
UserID = userID
177-
};
178-
await _budgetRepository.CreateEntryAsync(entry, saveChanges: false);
204+
// For TrackOnly investments, increase wallet balance as it's a savings
205+
var walletUpdate = await _walletRepository.UpdateWalletAsync(portfolio.WalletID, investment.UnitAmount * asset.BuyPrice, saveChanges: false);
206+
}
179207
}
180208
else
181209
{

BudgetFlow.Application/Investments/InvestmentResponse.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ public class InvestmentResponse
1515
public DateTime Date { get; set; }
1616
public DateTime CreatedAt { get; set; }
1717
public DateTime UpdatedAt { get; set; }
18+
public bool TrackOnly { get; set; }
1819
}

BudgetFlow.Application/Statistics/Responses/WalletContributionResponse.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,4 @@ public class WalletContributionResponse
88
public string UserName { get; set; }
99
public decimal TotalContribution { get; set; }
1010
public decimal Percentage { get; set; }
11-
public List<ContributionDetail> Details { get; set; } = new();
12-
}
13-
14-
public class ContributionDetail
15-
{
16-
public DateTime Date { get; set; }
17-
public decimal Amount { get; set; }
18-
public string Description { get; set; }
19-
public EntryType Type { get; set; }
2011
}

BudgetFlow.Domain/Entities/Investment.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ public class Investment : BaseEntity
1616
public Asset Asset { get; set; }
1717
public int UserId { get; set; }
1818
public User User { get; set; }
19+
public bool TrackOnly { get; set; } = false;
1920
}

0 commit comments

Comments
 (0)