generated from nhcarrigan/template
feat: initial prototype works
I can log in and create a book! Woo!
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* @copyright 2026 NHCarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ApiService } from './api.service';
|
||||
import { Book, CreateBookDto, UpdateBookDto } from '@library/shared-types';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class BooksService {
|
||||
constructor(private api: ApiService) {}
|
||||
|
||||
getAllBooks(): Observable<Book[]> {
|
||||
return this.api.get<Book[]>('/books');
|
||||
}
|
||||
|
||||
getBookById(id: string): Observable<Book | null> {
|
||||
return this.api.get<Book | null>(`/books/${id}`);
|
||||
}
|
||||
|
||||
createBook(book: CreateBookDto): Observable<Book> {
|
||||
return this.api.post<Book>('/books', book);
|
||||
}
|
||||
|
||||
updateBook(id: string, book: UpdateBookDto): Observable<Book> {
|
||||
return this.api.put<Book>(`/books/${id}`, book);
|
||||
}
|
||||
|
||||
deleteBook(id: string): Observable<{ success: boolean }> {
|
||||
return this.api.delete<{ success: boolean }>(`/books/${id}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user