rename model list to usercollection & fixed redlated errors
This commit is contained in:
1 parent
60b517500f
commit
b48b395574
37 files changed
+2479
-1210
No files matched your search
@@ -0,0 +1,79 @@
|
||||
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
|
||||
getLists(): Observable<UserCollection[]> {
|
||||
return this.http.get<UserCollection[]>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}`
|
||||
);
|
||||
}
|
||||
|
||||
// get a list by id
|
||||
getList(userCollectionId: string) {
|
||||
return this.http.get<UserCollection[]>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}`
|
||||
);
|
||||
}
|
||||
|
||||
// Create a new list
|
||||
createList(userCollection: UserCollection): Observable<UserCollection> {
|
||||
return this.http.post<UserCollection>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}`,
|
||||
userCollection
|
||||
);
|
||||
}
|
||||
|
||||
// Delete a list by ID
|
||||
deleteList(userCollectionId: number): Observable<any> {
|
||||
return this.http.delete(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}`
|
||||
);
|
||||
}
|
||||
|
||||
// Add an entry to a list
|
||||
addEntryToList(
|
||||
userCollectionId: number,
|
||||
entryId: number,
|
||||
order: number
|
||||
): Observable<UserCollectionEntry> {
|
||||
return this.http.post<UserCollectionEntry>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}/entries/${entryId}`,
|
||||
{ order: order }
|
||||
);
|
||||
}
|
||||
|
||||
// Update an entry's order in a list
|
||||
updateEntryOrder(
|
||||
userCollectionId: string,
|
||||
entryId: number,
|
||||
newOrder: number
|
||||
): Observable<any> {
|
||||
return this.http.patch(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}/entries/${entryId}/order`,
|
||||
{ newOrder }
|
||||
);
|
||||
}
|
||||
|
||||
// Remove an entry from a list
|
||||
removeEntryFromList(
|
||||
userCollectionId: string,
|
||||
entryId: number
|
||||
): Observable<Entry> {
|
||||
return this.http.delete<Entry>(
|
||||
`${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}/entries/${entryId}`
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user