import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; import { Collection } from '../../shared/models/collection.model'; import { CollectionEntry } from '../../shared/models/collection-entry.model'; import { Entry } from '../../shared/models/entry.model'; import { environment } from '../../../environments/environment.prod'; @Injectable({ providedIn: 'root', }) export class CollectionService { private backend_apiUrl = environment.API_URL; private apiAction = 'collections'; constructor(private http: HttpClient) {} // get all collections getCollections(): Observable { return this.http.get( `${this.backend_apiUrl}/${this.apiAction}` ); } // get a collection by id getCollection(collectionId: number): Observable { return this.http.get( `${this.backend_apiUrl}/${this.apiAction}/${collectionId}` ); } // Create a new collection createCollection(collection: Collection): Observable { return this.http.post( `${this.backend_apiUrl}/${this.apiAction}`, collection ); } // * PUT - update a collection updateCollection( collectionId: number, formData: FormData ): Observable { return this.http.put( `${this.backend_apiUrl}/${this.apiAction}/${collectionId}`, formData ); } // * PUT - REFRESH COLLECTION refreshCollection(collectionId: number): Observable { return this.http.put( `${this.backend_apiUrl}/${this.apiAction}/${collectionId}/refresh`, {} ); } // * PUT - GET COLLECTION PARTS getCollectionParts(collectionId: number): Observable { return this.http.put( `${this.backend_apiUrl}/${this.apiAction}/${collectionId}/parts`, {} ); } // Delete a collection by ID deleteCollection(collectionId: number): Observable { return this.http.delete( `${this.backend_apiUrl}/${this.apiAction}/${collectionId}` ); } // Add an entry to a collection addEntryToCollection( collectionId: number, entryId: number ): Observable { return this.http.post( `${this.backend_apiUrl}/${this.apiAction}/${collectionId}/entries/${entryId}`, {} ); } // Update an entry's order in a collection updateEntryOrder( collectionId: number, entryId: number, newOrder: number ): Observable { return this.http.patch( `${this.backend_apiUrl}/${this.apiAction}/${collectionId}/entries/${entryId}`, { newOrder: newOrder } ); } // Remove an entry from a collection removeEntryFromCollection( collectionId: number, entryId: number ): Observable { return this.http.delete( `${this.backend_apiUrl}/${this.apiAction}/${collectionId}/entries/${entryId}` ); } }