import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; import { UserCollection } from '../../shared/models/userCollection.model'; import { UserCollectionEntry } from '../../shared/models/userCollectionEntry.model'; import { Entry } from '../../shared/models/entry.model'; @Injectable({ providedIn: 'root', }) export class UserCollectionService { private backend_apiUrl = 'http://localhost:4000/api/v1'; private apiAction = 'user-collections'; constructor(private http: HttpClient) {} // get all lists getCollections(): Observable { return this.http.get( `${this.backend_apiUrl}/${this.apiAction}` ); } // get a list by id getCollection(userCollectionId: string) { return this.http.get( `${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}` ); } // Create a new list createCollection(userCollection: UserCollection): Observable { return this.http.post( `${this.backend_apiUrl}/${this.apiAction}`, userCollection ); } // Delete a list by ID deleteCollection(userCollectionId: number): Observable { return this.http.delete( `${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}` ); } // Add an entry to a list addEntryToCollection( userCollectionId: number, entryId: number ): Observable { return this.http.post( `${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}/entries/${entryId}`, {} ); } // Update an entry's order in a list updateEntryOrder( userCollectionId: string, entryId: number, newOrder: number ): Observable { return this.http.patch( `${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}/entries/${entryId}`, { newOrder: newOrder } ); } // Remove an entry from a list removeEntryFromCollection( userCollectionId: string, entryId: number ): Observable { return this.http.delete( `${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}/entries/${entryId}` ); } }