Skip to content

Commit 66a5ba3

Browse files
committed
feat: add post book
1 parent 7b0d05f commit 66a5ba3

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

frontend/src/angular/src/app/book-import/book-import.component.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
See the License for the specific language governing permissions and
1111
limitations under the License.
1212
*/
13-
import { HttpClient } from '@angular/common/http';
14-
import { Component } from '@angular/core';
13+
import { Component, DestroyRef, inject } from '@angular/core';
1514
import { MatIconModule } from '@angular/material/icon';
15+
import { DocumentService } from '../service/document.service';
16+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
17+
import { tap } from 'rxjs';
18+
import { ChapterPages } from '../model/book';
1619

1720
@Component({
1821
selector: 'app-book-import',
@@ -23,24 +26,26 @@ import { MatIconModule } from '@angular/material/icon';
2326
})
2427
export class BookImportComponent {
2528
protected file: File | null = null;
29+
private destroyRef = inject(DestroyRef);
30+
protected uploading = false;
2631

27-
constructor(private http: HttpClient) {}
32+
constructor(private documentService: DocumentService) {}
2833

29-
onFileSelected($event: Event) {
34+
protected onFileSelected($event: Event): void {
3035
const files = !$event.target
3136
? null
3237
: ($event.target as HTMLInputElement).files;
3338
this.file = !!files && files.length > 0 ? files[0] : null;
3439

35-
this.file?.name
3640
if (!!this.file) {
3741
const formData = new FormData();
42+
const chapters = [{startPage: 1, endPage: 2} as ChapterPages];
43+
formData.append('book', this.file)
44+
formData.append('chapters', JSON.stringify(chapters));
3845

39-
formData.append("thumbnail", this.file);
40-
41-
const upload$ = this.http.post("/api/thumbnail-upload", formData);
42-
43-
upload$.subscribe();
46+
this.documentService.postBookForm(formData).pipe(tap(() => {
47+
this.uploading = true;
48+
}),takeUntilDestroyed(this.destroyRef)).subscribe(result => console.log(result));
4449
}
4550
}
4651
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright 2023 Sven Loesekann
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
export interface ChapterPages {
15+
startPage: number;
16+
endPage: number;
17+
}

frontend/src/angular/src/app/service/document.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export class DocumentService {
3030
return this.httpClient.get<DocumentFile>(`/rest/document/id/${id}`);
3131
}
3232

33+
public postBookForm(formData: FormData): Observable<string> {
34+
return this.httpClient.post<string>('/rest/document/upload-book', formData);
35+
}
36+
3337
public postDocumentForm(formData: FormData): Observable<string> {
3438
return this.httpClient.post<string>('/rest/document/upload', formData);
3539
}

0 commit comments

Comments
 (0)