Initial
This commit is contained in:
47
listify-client/src/app/lists/lists.service.ts
Normal file
47
listify-client/src/app/lists/lists.service.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import {
|
||||
AddListItemRequest,
|
||||
CreateListRequest,
|
||||
UpdateListItemRequest,
|
||||
UpdateListRequest,
|
||||
UserList,
|
||||
} from './lists.models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ListsService {
|
||||
private readonly http = inject(HttpClient);
|
||||
private readonly apiUrl = '/api/lists';
|
||||
|
||||
listLists(): Observable<UserList[]> {
|
||||
return this.http.get<UserList[]>(this.apiUrl);
|
||||
}
|
||||
|
||||
getList(listId: string): Observable<UserList> {
|
||||
return this.http.get<UserList>(`${this.apiUrl}/${listId}`);
|
||||
}
|
||||
|
||||
createList(data: CreateListRequest): Observable<UserList> {
|
||||
return this.http.post<UserList>(this.apiUrl, data);
|
||||
}
|
||||
|
||||
updateList(listId: string, data: UpdateListRequest): Observable<UserList> {
|
||||
return this.http.patch<UserList>(`${this.apiUrl}/${listId}`, data);
|
||||
}
|
||||
|
||||
addItem(listId: string, data: AddListItemRequest): Observable<UserList> {
|
||||
return this.http.post<UserList>(`${this.apiUrl}/${listId}/items`, data);
|
||||
}
|
||||
|
||||
updateItem(
|
||||
listId: string,
|
||||
itemId: string,
|
||||
data: UpdateListItemRequest,
|
||||
): Observable<UserList> {
|
||||
return this.http.patch<UserList>(
|
||||
`${this.apiUrl}/${listId}/items/${itemId}`,
|
||||
data,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user