diff --git a/src/app/transaction.service.spec.ts b/src/app/transaction.service.spec.ts new file mode 100644 index 0000000..43a784b --- /dev/null +++ b/src/app/transaction.service.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { TransactionService } from './transaction.service'; + +describe('TransactionService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [TransactionService] + }); + }); + + it('should be created', inject([TransactionService], (service: TransactionService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/src/app/transaction.service.ts b/src/app/transaction.service.ts new file mode 100644 index 0000000..244ada0 --- /dev/null +++ b/src/app/transaction.service.ts @@ -0,0 +1,27 @@ +import { Injectable } from '@angular/core'; +import { of, Observable } from 'rxjs'; +import { Transaction } from './transaction'; +import { TransactionType } from './transaction.type'; + +@Injectable({ + providedIn: 'root' +}) +export class TransactionService { + + constructor() { } + + getTransactions(): Observable { + return of([ + {id: 0, amount: Math.random() * 100, date: new Date(), description: "Spent some money", title: "An Expense", type: TransactionType.EXPENSE, categoryId: 0}, + {id: 0, amount: Math.random() * 100, date: new Date(), description: "Earned some money", title: "Some Income", type: TransactionType.INCOME, categoryId: 0}, + {id: 0, amount: Math.random() * 100, date: new Date(), description: "Spent some money", title: "An Expense", type: TransactionType.EXPENSE, categoryId: 0}, + {id: 0, amount: Math.random() * 100, date: new Date(), description: "Earned some money", title: "Some Income", type: TransactionType.INCOME, categoryId: 0}, + {id: 0, amount: Math.random() * 100, date: new Date(), description: "Spent some money", title: "An Expense", type: TransactionType.EXPENSE, categoryId: 0}, + {id: 0, amount: Math.random() * 100, date: new Date(), description: "Earned some money", title: "Some Income", type: TransactionType.INCOME, categoryId: 0}, + {id: 0, amount: Math.random() * 100, date: new Date(), description: "Spent some money", title: "An Expense", type: TransactionType.EXPENSE, categoryId: 0}, + {id: 0, amount: Math.random() * 100, date: new Date(), description: "Earned some money", title: "Some Income", type: TransactionType.INCOME, categoryId: 0}, + {id: 0, amount: Math.random() * 100, date: new Date(), description: "Spent some money", title: "An Expense", type: TransactionType.EXPENSE, categoryId: 0}, + {id: 0, amount: Math.random() * 100, date: new Date(), description: "Earned some money", title: "Some Income", type: TransactionType.INCOME, categoryId: 0}, + ]) + } +} diff --git a/src/app/transactions/transactions.component.ts b/src/app/transactions/transactions.component.ts index 2e043c3..c1ed6dc 100644 --- a/src/app/transactions/transactions.component.ts +++ b/src/app/transactions/transactions.component.ts @@ -1,6 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { Transaction } from '../transaction'; import { TransactionType } from '../transaction.type'; +import { TransactionService } from '../transaction.service'; @Component({ selector: 'app-transactions', @@ -12,29 +13,16 @@ export class TransactionsComponent implements OnInit { public transactionType = TransactionType; public transactions: Transaction[] - - constructor() { } + + constructor(private transactionService: TransactionService) { } ngOnInit() { this.getTransactions() } - onScroll() { - - } - getTransactions(): void { - this.transactions = [ - {id: 0, amount: Math.random() * 100, date: new Date(), description: "Spent some money", title: "An Expense", type: TransactionType.EXPENSE, categoryId: 0}, - {id: 0, amount: Math.random() * 100, date: new Date(), description: "Earned some money", title: "Some Income", type: TransactionType.INCOME, categoryId: 0}, - {id: 0, amount: Math.random() * 100, date: new Date(), description: "Spent some money", title: "An Expense", type: TransactionType.EXPENSE, categoryId: 0}, - {id: 0, amount: Math.random() * 100, date: new Date(), description: "Earned some money", title: "Some Income", type: TransactionType.INCOME, categoryId: 0}, - {id: 0, amount: Math.random() * 100, date: new Date(), description: "Spent some money", title: "An Expense", type: TransactionType.EXPENSE, categoryId: 0}, - {id: 0, amount: Math.random() * 100, date: new Date(), description: "Earned some money", title: "Some Income", type: TransactionType.INCOME, categoryId: 0}, - {id: 0, amount: Math.random() * 100, date: new Date(), description: "Spent some money", title: "An Expense", type: TransactionType.EXPENSE, categoryId: 0}, - {id: 0, amount: Math.random() * 100, date: new Date(), description: "Earned some money", title: "Some Income", type: TransactionType.INCOME, categoryId: 0}, - {id: 0, amount: Math.random() * 100, date: new Date(), description: "Spent some money", title: "An Expense", type: TransactionType.EXPENSE, categoryId: 0}, - {id: 0, amount: Math.random() * 100, date: new Date(), description: "Earned some money", title: "Some Income", type: TransactionType.INCOME, categoryId: 0}, - ] + this.transactionService.getTransactions().subscribe(transactions => { + this.transactions = transactions; + }) } }