feat: basic api

This commit is contained in:
eneller
2026-03-05 23:31:56 +01:00
parent cef3474c3d
commit 0dd4b6590d
7 changed files with 83 additions and 10 deletions

View File

@@ -1,5 +1,7 @@
import { CommonModule, CurrencyPipe, DatePipe } from '@angular/common';
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { APIService } from '../../services/api';
import { Transaction } from '@shared/interfaces/transaction';
@Component({
selector: 'app-screen-profile',
@@ -7,14 +9,22 @@ import { Component } from '@angular/core';
templateUrl: './screen-profile.html',
styleUrl: './screen-profile.less',
})
export class ScreenProfile {
username = 'John Doe';
export class ScreenProfile implements OnInit{
username = 'John Doe';
email = 'john.doe@example.com';
transactions!: Transaction[];
constructor(private api: APIService){}
ngOnInit(): void {
this.api.getTransactions().subscribe({
next: (transactions) => {
this.transactions = transactions;
},
error: (err) => {
console.error('Error fetching transactions:', err);
},
})
}
transactions = [
{ partner: 'Alice Smith', amount: 50.00, date: new Date('2026-03-01'), type: 'Received' },
{ partner: 'Bob Johnson', amount: -25.50, date: new Date('2026-02-28'), type: 'Sent' },
{ partner: 'Charlie Brown', amount: 75.25, date: new Date('2026-02-27'), type: 'Received' },
{ partner: 'Diana Prince', amount: -100.00, date: new Date('2026-02-25'), type: 'Sent' },
];
}

View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { APIService } from './api';
describe('Api', () => {
let service: APIService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(APIService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@@ -0,0 +1,17 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { Transaction } from '@shared/interfaces/transaction'
@Injectable({
providedIn: 'root',
})
export class APIService {
private apiUrl = 'http://localhost:3000/api'
constructor(private http: HttpClient){}
getTransactions(): Observable<Transaction[]>{
return this.http.get<Transaction[]>(this.apiUrl + '/transactions');
}
}