Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<table>
<tr *ngFor="let budget of budgets()">
<td>{{ budget.name }}</td>
<td>{{ budget.amount }}</td>
</tr>
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component, Input, Signal } from '@angular/core';
import { Budget } from '../../models/budget.model';

@Component({
selector: 'app-budget-table',
templateUrl: './budget-table.component.html',
})
export class BudgetTableComponent {
@Input() budgets!: Signal<Budget[]>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
<app-budget-table [budgets]="allBudgets"></app-budget-table>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Component, inject, signal, computed, effect } from '@angular/core';
import { BudgetService } from '../../services/budget.service';
import { Budget } from '../../models/budget.model';

@Component({
selector: 'app-select-budget-page',
templateUrl: './select-budget-page.component.html',
})
export class SelectBudgetPageComponent {
private budgetService = inject(BudgetService);

allBudgets = signal<Budget[]>([]);
selectedBudgetId = signal<string | null>(null);

overview = computed(() =>
this.allBudgets().find(b => b.id === this.selectedBudgetId())
);

constructor() {
this.loadBudgets();
}

loadBudgets() {
this.budgetService.getBudgets().subscribe(budgets => this.allBudgets.set(budgets));
}

selectBudget(budgetId: string) {
this.selectedBudgetId.set(budgetId);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class AddNoteToBudgetCommand {
constructor(
public readonly budgetId: string,
public readonly content: string,
public readonly createdBy: string,
) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { AddNoteToBudgetCommand } from './add-note.command';
import { FunctionHandler } from '@ngfire/functions';

export interface ICommandHandler<TCommand> {
execute(command: TCommand): Promise<void>;
}

export class AddNoteToBudgetHandler implements FunctionHandler<AddNoteToBudgetCommand, void>, ICommandHandler<AddNoteToBudgetCommand> {
async execute(command: AddNoteToBudgetCommand): Promise<void> {
if (!command.content || !command.budgetId) {
throw new Error('Budget ID and content are required');
}

const repo = this.getRepository();
await repo.addNote(command.budgetId, command.content, command.createdBy);
}

private getRepository() {
return {
addNote: async (budgetId: string, content: string, createdBy: string) => {
// logic to persist the note
}
};
}
}