Add TransactionService
This commit is contained in:
parent
2074b5a5aa
commit
c1903c8f40
3 changed files with 48 additions and 18 deletions
15
src/app/transaction.service.spec.ts
Normal file
15
src/app/transaction.service.spec.ts
Normal file
|
@ -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();
|
||||
}));
|
||||
});
|
27
src/app/transaction.service.ts
Normal file
27
src/app/transaction.service.ts
Normal file
|
@ -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<Transaction[]> {
|
||||
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},
|
||||
])
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue