Skip to content

Commit

Permalink
Fix #224 and #225
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAxelander committed Mar 5, 2024
1 parent 827ab32 commit 3367e25
Show file tree
Hide file tree
Showing 15 changed files with 139 additions and 118 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* Adding a Mapping Rule to an existing Rule Set no longer fails [#200](https://github.com/TheAxelander/OpenBudgeteer/pull/200) Thanks [Lucaber](https://github.com/Lucaber)
* Exception after canceling creation of a new Recurring Transactions [#210](https://github.com/TheAxelander/OpenBudgeteer/issues/210)
* Guid issues using Sqlite database [#221](https://github.com/TheAxelander/OpenBudgeteer/issues/221)
* Fix `Expand All` button typo on Bucket Page [#224](https://github.com/TheAxelander/OpenBudgeteer/issues/224)

### :hammer: Maintenance

Expand Down
8 changes: 5 additions & 3 deletions OpenBudgeteer.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

var versionSet = app.NewApiVersionSet()
.HasApiVersion(1, 0)
.HasApiVersion(2, 0)
// reporting api versions will return the headers
// "api-supported-versions" and "api-deprecated-versions"
.ReportApiVersions()
Expand Down Expand Up @@ -91,7 +90,7 @@
transaction.MapGet("/fromAccount/{id:guid}", (Guid id, DateTime? start, DateTime? end, int? limit) =>
bankTransactionService.GetFromAccount(id, start, end, limit ?? 0))
.MapToApiVersion(1,0);
transaction.MapGet( "/withBucket/{id:guid}", (Guid id) =>
transaction.MapGet( "/withEntities/{id:guid}", (Guid id) =>
bankTransactionService.GetWithEntities(id))
.MapToApiVersion(1,0);

Expand Down Expand Up @@ -128,7 +127,10 @@
// GET
recurring.MapGet("{id:guid}", (Guid id) => recurringTransactionService.Get(id))
.MapToApiVersion(1,0);
recurring.MapGet("/", () => recurringTransactionService.GetAll())
recurring.MapGet("/", () => recurringTransactionService.GetAllWithEntities())
.MapToApiVersion(1,0);
recurring.MapGet( "/withEntities/{id:guid}", (Guid id) =>
recurringTransactionService.GetWithEntities(id))
.MapToApiVersion(1,0);
recurring.MapGet("/pendingTransactions", async (DateTime yearMonth) =>
await recurringTransactionService.GetPendingBankTransactionAsync(yearMonth))
Expand Down
2 changes: 1 addition & 1 deletion OpenBudgeteer.Blazor/Pages/Bucket.razor
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<button class="btn btn-sm btn-primary me-2 mb-2" @onclick="@ShowNewBucketGroupDialog">Create Bucket Group</button>
<button class="btn btn-sm btn-primary me-2 mb-2" @onclick="@DistributeBudget">Distribute Budget</button>
<button class="btn btn-sm btn-primary me-2 mb-2" @onclick="@(() => _dataContext.ChangeBucketGroupCollapse())">Collapse All</button>
<button class="btn btn-sm btn-primary me-auto mb-2" @onclick="@(() => _dataContext.ChangeBucketGroupCollapse(false))">Expend All</button>
<button class="btn btn-sm btn-primary me-auto mb-2" @onclick="@(() => _dataContext.ChangeBucketGroupCollapse(false))">Expand All</button>
<YearMonthSelector Class="mb-2" DataContext="YearMonthDataContext" />
</div>

Expand Down
6 changes: 3 additions & 3 deletions OpenBudgeteer.Blazor/Pages/Transaction.razor
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</td>
<td class="d-none d-md-table-cell">
<select class="form-select form-select-sm"
@bind:get="_dataContext.NewTransaction.AccountId.ToString()"
@bind:get="_dataContext.NewTransaction.SelectedAccount.AccountId.ToString()"
@bind:set="NewTransactionAccount_SelectionChanged">
@foreach (var account in _dataContext.NewTransaction.AvailableAccounts)
{
Expand Down Expand Up @@ -126,7 +126,7 @@
</td>
<td class="d-none d-md-table-cell">
<select class="form-select form-select-sm"
@bind:get="transaction.AccountId.ToString()"
@bind:get="transaction.SelectedAccount.AccountId.ToString()"
@bind:set="(value) => { TransactionAccount_SelectionChanged(value, transaction); }">
@foreach (var account in transaction.AvailableAccounts)
{
Expand Down Expand Up @@ -174,7 +174,7 @@
{
<tr>
<td class="d-none d-sm-table-cell col-numbers">@transaction.TransactionDate.ToShortDateString()</td>
<td class="d-none d-md-table-cell">@transaction.AccountName</td>
<td class="d-none d-md-table-cell">@transaction.SelectedAccount.Name</td>
<td class="d-none d-xl-table-cell">@transaction.Payee</td>
<td class="d-none d-sm-table-cell">@transaction.Memo</td>
<td class="d-none d-sm-table-cell col-numbers">@transaction.Amount.ToString("C", CultureInfo.CurrentCulture)</td>
Expand Down
4 changes: 2 additions & 2 deletions OpenBudgeteer.Blazor/Pages/Transaction.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private void EditAllTransaction()
private void NewTransactionAccount_SelectionChanged(string? value)
{
if (string.IsNullOrEmpty(value)) return;
_dataContext.NewTransaction!.UpdateSelectedAccount(Guid.Parse(value));
_dataContext.NewTransaction!.SelectedAccount = _dataContext.NewTransaction!.AvailableAccounts.First(i => i.AccountId == Guid.Parse(value));
}

private async Task ProposeBucketsAsync()
Expand All @@ -84,7 +84,7 @@ private async Task ProposeBucketsAsync()
private void TransactionAccount_SelectionChanged(string? value, TransactionViewModel transactionViewModel)
{
if (string.IsNullOrEmpty(value)) return;
transactionViewModel.UpdateSelectedAccount(Guid.Parse(value));
transactionViewModel.SelectedAccount = transactionViewModel.AvailableAccounts.First(i => i.AccountId == Guid.Parse(value));
}

private void SplitTransaction(TransactionViewModel transaction) =>
Expand Down
2 changes: 1 addition & 1 deletion OpenBudgeteer.Blazor/Shared/BucketDetailsDialog.razor
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
{
<tr>
<td style="text-align: right">@transaction.TransactionDate.ToShortDateString()</td>
<td class="d-none d-md-table-cell">@transaction.AccountName</td>
<td class="d-none d-md-table-cell">@transaction.SelectedAccount.Name</td>
<td class="d-none d-md-table-cell">@transaction.Payee</td>
<td>@transaction.Memo</td>
<td style="text-align: right">@transaction.Amount.ToString("C", CultureInfo.CurrentCulture)</td>
Expand Down
11 changes: 7 additions & 4 deletions OpenBudgeteer.Blazor/Shared/RecurringTransactionDialog.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@using OpenBudgeteer.Core.ViewModels
@using System.Drawing
@using System.Globalization
@using OpenBudgeteer.Core.Common.Extensions
@using OpenBudgeteer.Core.ViewModels.EntityViewModels
@using OpenBudgeteer.Core.ViewModels.Helper
@if (IsDialogVisible)
Expand Down Expand Up @@ -53,9 +54,9 @@
<select class="form-select form-select-sm"
@bind:get="transaction.RecurrenceType.ToString()"
@bind:set="(value) => { TransactionRecurrenceType_SelectionChanged(value, transaction); }">
@foreach (var recurrenceType in transaction.AvailableRecurrenceTypes)
@foreach (var recurrenceType in Enum.GetValues<RecurringTransactionRecurrenceType>())
{
<option value="@recurrenceType.Key">@recurrenceType.Value</option>
<option value="@recurrenceType">@recurrenceType.GetStringValue()</option>
}
</select>
</td>
Expand Down Expand Up @@ -83,7 +84,7 @@
<tr>
<td class="col-numbers">@transaction.FirstOccurrenceDate.ToShortDateString()</td>
<td style="width:70px">Every @transaction.RecurrenceAmount</td>
<td style="width:130px">@transaction.RecurrenceTypeOutput</td>
<td style="width:130px">@transaction.RecurrenceType.GetStringValue()</td>
<td>@transaction.SelectedAccount.Name</td>
<td>@transaction.Payee</td>
<td>@transaction.Memo</td>
Expand Down Expand Up @@ -172,7 +173,9 @@
void TransactionRecurrenceType_SelectionChanged(string? value, RecurringTransactionViewModel transaction)
{
if (string.IsNullOrEmpty(value)) return;
transaction.RecurrenceType = (RecurringTransactionViewModel.RecurringTransactionRecurrenceType)Convert.ToInt32(value);
transaction.RecurrenceType = Enum.TryParse(typeof(RecurringTransactionRecurrenceType), value, out var result)
? (RecurringTransactionRecurrenceType)result
: RecurringTransactionRecurrenceType.Weeks;
}

void TransactionAccount_SelectionChanged(string? value, RecurringTransactionViewModel transaction)
Expand Down
2 changes: 1 addition & 1 deletion OpenBudgeteer.Blazor/Shared/TransactionDialog.razor
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{
<tr>
<td style="text-align: right">@transaction.TransactionDate.ToShortDateString()</td>
<td class="d-none d-lg-table-cell">@transaction.AccountName</td>
<td class="d-none d-lg-table-cell">@transaction.SelectedAccount.Name</td>
<td class="d-none d-lg-table-cell">@transaction.Payee</td>
<td>@transaction.Memo</td>
<td style="text-align: right">@transaction.Amount.ToString("C", CultureInfo.CurrentCulture)</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace OpenBudgeteer.Core.Data.Contracts.Services;

public interface IRecurringBankTransactionService : IBaseService<RecurringBankTransaction>
{
public RecurringBankTransaction GetWithEntities(Guid id);
public IEnumerable<RecurringBankTransaction> GetAllWithEntities();
public Task<IEnumerable<BankTransaction>> GetPendingBankTransactionAsync(DateTime yearMonth);
public Task<IEnumerable<BankTransaction>> CreatePendingBankTransactionAsync(DateTime yearMonth);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,42 @@ internal RecurringBankTransactionService(DbContextOptions<DatabaseContext> dbCon
: base(dbContextOptions, new RecurringBankTransactionRepository(new DatabaseContext(dbContextOptions)))
{
}

public RecurringBankTransaction GetWithEntities(Guid id)
{
try
{
using var dbContext = new DatabaseContext(DbContextOptions);
var repository = new RecurringBankTransactionRepository(dbContext);

var result = repository.ByIdWithIncludedEntities(id);
if (result == null) throw new Exception($"{typeof(RecurringBankTransaction)} not found in database");
return result;
}
catch (Exception e)
{
Console.WriteLine(e);
throw new Exception($"Error on querying database: {e.Message}");
}
}

public IEnumerable<RecurringBankTransaction> GetAllWithEntities()
{
try
{
using var dbContext = new DatabaseContext(DbContextOptions);
var repository = new RecurringBankTransactionRepository(dbContext);

return repository
.AllWithIncludedEntities()
.ToList();
}
catch (Exception e)
{
Console.WriteLine(e);
throw new Exception($"Error on querying database: {e.Message}");
}
}

public async Task<IEnumerable<BankTransaction>> GetPendingBankTransactionAsync(DateTime yearMonth)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using OpenBudgeteer.Core.ViewModels.EntityViewModels;

namespace OpenBudgeteer.Core.Common.Extensions;

/// <summary>
/// Identifier which kind of recurrence can be selected for a RecurringTransaction in <see cref="RecurringTransactionViewModel"/>
/// </summary>
public enum RecurringTransactionRecurrenceType
{
[StringValue("Weeks")]
Weeks = 1,
[StringValue("Months")]
Months = 2,
[StringValue("Quarters")]
Quarters = 3,
[StringValue("Years")]
Years = 4,
}
10 changes: 10 additions & 0 deletions OpenBudgeteer.Core/ViewModels/EntityViewModels/AccountViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ protected AccountViewModel(IServiceManager serviceManager, Account? account) : b
AccountId = account.Id;
_name = account.Name ?? string.Empty;
_isActive = account.IsActive != 0;
if (!IsActive) _name += " (Inactive)";
}
}

Expand Down Expand Up @@ -118,6 +119,15 @@ public static AccountViewModel CreateFromAccount(IServiceManager serviceManager,
{
return new AccountViewModel(serviceManager, account);
}

/// <summary>
/// Initialize a copy of the passed ViewModel
/// </summary>
/// <param name="accountViewModel">Current ViewModel instance</param>
public static AccountViewModel CreateAsCopy(AccountViewModel accountViewModel)
{
return new AccountViewModel(accountViewModel);
}

#endregion

Expand Down
Loading

0 comments on commit 3367e25

Please sign in to comment.