Initial commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import { Observable } from 'rxjs';
|
||||
import { Book, PaginatedBooksResponse } from '../model/book.model';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class BookService {
|
||||
private readonly pageSize = 25;
|
||||
private readonly libraryUrl = 'http://localhost:8080/v1/library';
|
||||
private readonly bookUrl = 'http://localhost:8080/v1/book';
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
getBook(bookId: number): Observable<Book> {
|
||||
return this.http.get<Book>(`${this.bookUrl}/${bookId}`);
|
||||
}
|
||||
|
||||
loadBooks(libraryId: number, page: number): Observable<PaginatedBooksResponse> {
|
||||
return this.http.get<PaginatedBooksResponse>(
|
||||
`${this.libraryUrl}/${libraryId}/book?page=${page}&size=${this.pageSize}`
|
||||
);
|
||||
}
|
||||
|
||||
searchBooks(query: string): Observable<Book[]> {
|
||||
if (query.length < 3) {
|
||||
return new Observable<Book[]>();
|
||||
}
|
||||
return this.http.get<Book[]>(`${this.bookUrl}/search?title=${encodeURIComponent(query)}`);
|
||||
}
|
||||
|
||||
updateViewerSetting(viewerSetting: any, bookId: number): Observable<void> {
|
||||
const url = `${this.bookUrl}/${bookId}/viewer-setting`;
|
||||
return this.http.put<void>(url, viewerSetting);
|
||||
}
|
||||
|
||||
getBookDataUrl(bookId: number): string {
|
||||
return `${this.bookUrl}/${bookId}/data`;
|
||||
}
|
||||
|
||||
getBookCoverUrl(bookId: number): string {
|
||||
return `${this.bookUrl}/${bookId}/cover`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { Injectable, signal } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { catchError, map, tap } from 'rxjs/operators';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { Library, LibraryApiResponse } from '../model/library.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class LibraryService {
|
||||
private libraryUrl: string = 'http://localhost:8080/v1/library';
|
||||
|
||||
libraries = signal<Library[]>([]);
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
this.getLibrariesFromAPI();
|
||||
}
|
||||
|
||||
getLibrariesFromAPI(): void {
|
||||
this.http.get<LibraryApiResponse>(this.libraryUrl).pipe(
|
||||
map(response => response.content),
|
||||
catchError(error => {
|
||||
console.error('Error loading libraries:', error);
|
||||
return of([]);
|
||||
})
|
||||
).subscribe(
|
||||
(libraries) => {
|
||||
this.libraries.set(libraries);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
createLibrary(newLibrary: Library): Observable<Library> {
|
||||
return this.http.post<Library>(this.libraryUrl, newLibrary).pipe(
|
||||
tap((createdLibrary) => {
|
||||
this.libraries.set([...this.libraries(), createdLibrary]);
|
||||
}),
|
||||
catchError(error => {
|
||||
console.error('Error creating library:', error);
|
||||
throw error;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
checkLibraryNameExists(name: string): Observable<any> {
|
||||
return this.http.get<Library>(`${this.libraryUrl}/search?name=${name}`).pipe(
|
||||
catchError(error => {
|
||||
console.error('Error checking library name:', error);
|
||||
return of(null);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {Observable} from 'rxjs';
|
||||
import {HttpClient, HttpParams} from '@angular/common/http';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UtilityService {
|
||||
|
||||
private pathUrl = 'http://localhost:8080/v1/path';
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
getFolders(path: string): Observable<string[]> {
|
||||
const params = new HttpParams().set('path', path);
|
||||
return this.http.get<string[]>(this.pathUrl, { params });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user