Front: renamed most collection related files
This commit is contained in:
1 parent
75de013f82
commit
8724a96b81
55 files changed
+294
-394
No files matched your search
@@ -0,0 +1,106 @@
|
||||
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 lists
|
||||
getCollections(): Observable<Collection[]> {
|
||||
return this.http.get<Collection[]>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}`
|
||||
);
|
||||
}
|
||||
|
||||
// get a list by id
|
||||
getCollection(collectionId: string) {
|
||||
return this.http.get<Collection>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${collectionId}`
|
||||
);
|
||||
}
|
||||
|
||||
// Create a new list
|
||||
createCollection(collection: Collection): Observable<Collection> {
|
||||
return this.http.post<Collection>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}`,
|
||||
collection
|
||||
);
|
||||
}
|
||||
|
||||
// * PUT - update a collection
|
||||
updateCollection(
|
||||
collectionId: number,
|
||||
formData: FormData
|
||||
): Observable<Collection> {
|
||||
return this.http.put<Collection>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${collectionId}`,
|
||||
formData
|
||||
);
|
||||
}
|
||||
|
||||
// * PUT - REFRESH COLLECTION
|
||||
refreshCollection(collectionId: number): Observable<Collection> {
|
||||
return this.http.put<Collection>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${collectionId}/refresh`,
|
||||
{}
|
||||
);
|
||||
}
|
||||
|
||||
// * PUT - GET COLLECTION PARTS
|
||||
getCollectionParts(collectionId: number): Observable<Collection> {
|
||||
return this.http.put<Collection>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${collectionId}/parts`,
|
||||
{}
|
||||
);
|
||||
}
|
||||
|
||||
// Delete a list by ID
|
||||
deleteCollection(collectionId: number): Observable<any> {
|
||||
return this.http.delete(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${collectionId}`
|
||||
);
|
||||
}
|
||||
|
||||
// Add an entry to a list
|
||||
addEntryToCollection(
|
||||
collectionId: number,
|
||||
entryId: number
|
||||
): Observable<CollectionEntry> {
|
||||
return this.http.post<CollectionEntry>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${collectionId}/entries/${entryId}`,
|
||||
{}
|
||||
);
|
||||
}
|
||||
|
||||
// Update an entry's order in a list
|
||||
updateEntryOrder(
|
||||
collectionId: number,
|
||||
entryId: number,
|
||||
newOrder: number
|
||||
): Observable<any> {
|
||||
return this.http.patch(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${collectionId}/entries/${entryId}`,
|
||||
{ newOrder: newOrder }
|
||||
);
|
||||
}
|
||||
|
||||
// Remove an entry from a list
|
||||
removeEntryFromCollection(
|
||||
collectionId: number,
|
||||
entryId: number
|
||||
): Observable<Entry> {
|
||||
return this.http.delete<Entry>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${collectionId}/entries/${entryId}`
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user