import { Injectable, signal } from '@angular/core'; import { HttpService } from './http.service'; @Injectable({ providedIn: 'root' }) export class CategoryService { private internalCategories = signal([]); public readonly categories = this.internalCategories.asReadonly(); public readonly categoryPath = 'http://localhost:3000/common-cents/categories'; public constructor(private readonly http: HttpService) { void this.fetchCategories(); } public async fetchCategories(): Promise { this.internalCategories.set(await this.http.get(this.categoryPath)); } public async createCategory(category: CreateCategory): Promise { return await this.http.post(this.categoryPath, category); } public async updateCategory(category: Category): Promise { return await this.http.put(this.categoryPath, category); } } export interface Category { id: string; name: string; } export interface CreateCategory { name: string; }