From 7bb21f8796e05aa96f3aa4cc808c1dc54412e2b6 Mon Sep 17 00:00:00 2001 From: Joe Arndt Date: Thu, 12 Feb 2026 14:56:09 -0600 Subject: [PATCH] added services and interfaces for expense types --- src/app/app.config.ts | 1 - .../components/expense-list/expense-list.ts | 4 +- src/app/services/categories.ts | 19 +++++++++ src/app/services/expenses.ts | 26 ++++++++++-- src/app/services/http.ts | 40 +++++++++++++++++++ src/app/services/merchants.ts | 19 +++++++++ src/app/services/sub-categories.ts | 19 +++++++++ src/app/services/tags.ts | 19 +++++++++ 8 files changed, 142 insertions(+), 5 deletions(-) create mode 100644 src/app/services/categories.ts create mode 100644 src/app/services/http.ts create mode 100644 src/app/services/merchants.ts create mode 100644 src/app/services/sub-categories.ts create mode 100644 src/app/services/tags.ts diff --git a/src/app/app.config.ts b/src/app/app.config.ts index cb1270e..e60fc79 100644 --- a/src/app/app.config.ts +++ b/src/app/app.config.ts @@ -1,6 +1,5 @@ import { ApplicationConfig, provideBrowserGlobalErrorListeners } from '@angular/core'; import { provideRouter } from '@angular/router'; - import { routes } from './app.routes'; export const appConfig: ApplicationConfig = { diff --git a/src/app/components/expense-list/expense-list.ts b/src/app/components/expense-list/expense-list.ts index 05427fb..1206cbb 100644 --- a/src/app/components/expense-list/expense-list.ts +++ b/src/app/components/expense-list/expense-list.ts @@ -11,6 +11,8 @@ export class ExpenseList implements OnInit { public constructor(private readonly expenses: Expenses) { } public ngOnInit() { - void this.expenses.getExpenses(); + this.expenses.getExpenses().then(expenses => { + console.log({ expenses }); + }); } } diff --git a/src/app/services/categories.ts b/src/app/services/categories.ts new file mode 100644 index 0000000..405b7e9 --- /dev/null +++ b/src/app/services/categories.ts @@ -0,0 +1,19 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root', +}) +export class Categories { + public static readonly BASE_URL = 'http://localhost:3000/common-cents/categories'; + + public async getCategories(): Promise { + console.log('getCategories called'); + + return []; + } +} + +export interface Category { + id: string; + name: string; +} diff --git a/src/app/services/expenses.ts b/src/app/services/expenses.ts index 5c51b87..7b8b65f 100644 --- a/src/app/services/expenses.ts +++ b/src/app/services/expenses.ts @@ -1,12 +1,32 @@ import { Injectable } from '@angular/core'; +import { SubCategory } from './sub-categories'; +import { Category } from './categories'; +import { Merchant } from './merchants'; +import { Tag } from './tags'; +import { Http } from './http'; @Injectable({ providedIn: 'root', }) export class Expenses { - public static readonly BASE_URL = 'http://localhost:3000/common-cents/expenses'; + public static readonly EXPENSES_URI = 'http://localhost:3000/common-cents/expenses'; - public async getExpenses(): Promise { - console.log('getExpenses called'); + public constructor(private readonly http: Http) { } + + public async getExpenses(): Promise { + return this.http.get(Expenses.EXPENSES_URI); } } + +export interface Expense { + id: string; + year: string; + month: string; + day: string; + cents: number; + description?: string; + category: Category; + subCategory?: SubCategory; + merchant?: Merchant; + tags: Tag[]; +} diff --git a/src/app/services/http.ts b/src/app/services/http.ts new file mode 100644 index 0000000..ccda4b4 --- /dev/null +++ b/src/app/services/http.ts @@ -0,0 +1,40 @@ +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { firstValueFrom } from 'rxjs'; + +@Injectable({ + providedIn: 'root', +}) +export class Http { + public constructor(private httpClient: HttpClient) { } + + public async get(url: string): Promise { + return this.request(url, 'get'); + } + + public async post(url: string, body?: any): Promise { + return this.request(url, 'post', body); + } + + public async put(url: string, body?: any): Promise { + return this.request(url, 'put', body); + } + + public async delete(url: string): Promise { + return this.request(url, 'delete'); + } + + private async request(url: string, method: 'get' | 'post' | 'put' | 'delete', body?: any): Promise { + const headers = { 'Accept': 'application/json', 'Content-Type': 'application/json' }; + switch (method) { + case 'post': + return firstValueFrom(this.httpClient.post(url, body, { headers })); + case 'put': + return firstValueFrom(this.httpClient.put(url, body, { headers })); + case 'delete': + return firstValueFrom(this.httpClient.delete(url, { headers })); + default: + return firstValueFrom(this.httpClient.get(url, { headers })); + } + } +} diff --git a/src/app/services/merchants.ts b/src/app/services/merchants.ts new file mode 100644 index 0000000..730c177 --- /dev/null +++ b/src/app/services/merchants.ts @@ -0,0 +1,19 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root', +}) +export class Merchants { + public static readonly BASE_URL = 'http://localhost:3000/common-cents/merchants'; + + public async getMerchants(): Promise { + console.log('getMerchants called'); + + return []; + } +} + +export interface Merchant { + id: string; + name: string; +} diff --git a/src/app/services/sub-categories.ts b/src/app/services/sub-categories.ts new file mode 100644 index 0000000..8615603 --- /dev/null +++ b/src/app/services/sub-categories.ts @@ -0,0 +1,19 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root', +}) +export class SubCategories { + public static readonly BASE_URL = 'http://localhost:3000/common-cents/sub-categories'; + + public async getSubCategories(): Promise { + console.log('getSubCategories called'); + + return []; + } +} + +export interface SubCategory { + id: string; + name: string; +} diff --git a/src/app/services/tags.ts b/src/app/services/tags.ts new file mode 100644 index 0000000..282b344 --- /dev/null +++ b/src/app/services/tags.ts @@ -0,0 +1,19 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root', +}) +export class Tags { + public static readonly BASE_URL = 'http://localhost:3000/common-cents/tags'; + + public async getTags(): Promise { + console.log('getTags called'); + + return []; + } +} + +export interface Tag { + id: string; + name: string; +}