diff --git a/backend/src/main/java/ch/xxx/aidoclibchat/adapter/controller/DocumentController.java b/backend/src/main/java/ch/xxx/aidoclibchat/adapter/controller/DocumentController.java index 384ea5c..4211803 100644 --- a/backend/src/main/java/ch/xxx/aidoclibchat/adapter/controller/DocumentController.java +++ b/backend/src/main/java/ch/xxx/aidoclibchat/adapter/controller/DocumentController.java @@ -15,6 +15,7 @@ import java.util.List; import java.util.stream.Stream; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -57,12 +58,19 @@ public List getDocumentList() { }).toList(); } - @GetMapping("/id/{id}") + @GetMapping("/doc/{id}") public ResponseEntity getDocument(@PathVariable("id") Long id) { return ResponseEntity.ofNullable(this.documentService.getDocumentById(id).stream() .map(myDocument -> this.documentMapper.toDto(myDocument)).findFirst().orElse(null)); } + @GetMapping("/pdf/{id}") + public ResponseEntity getDocumentPdf(@PathVariable("id") Long id) { + var resultOpt = this.documentService.getDocumentById(id).stream() + .map(myDocument -> this.documentMapper.toDto(myDocument)).map(myDocument -> myDocument.getDocumentContent()).findFirst(); + return resultOpt.isPresent() ? ResponseEntity.ok().contentType(MediaType.APPLICATION_PDF).body(resultOpt.get()) : ResponseEntity.notFound().build(); + } + @PostMapping("/search") public DocumentSearchDto postDocumentSearch(@RequestBody SearchDto searchDto) { var result = this.documentMapper.toDto(this.documentService.queryDocuments(searchDto.getSearchString())); diff --git a/frontend/src/angular/src/app/doc-search/doc-search.component.html b/frontend/src/angular/src/app/doc-search/doc-search.component.html index 37e8ea2..57e13f2 100644 --- a/frontend/src/angular/src/app/doc-search/doc-search.component.html +++ b/frontend/src/angular/src/app/doc-search/doc-search.component.html @@ -28,10 +28,16 @@
-
The AI is working on the answer.
-
Please be patient. {{ (msWorking / 1000) | number: '1.3'}} sec.
+
The AI is working on the answer.
+
Please be patient. {{ (msWorking / 1000) | number: '1.3'}} sec.
-
- {{searchResult}} +
+
\ No newline at end of file diff --git a/frontend/src/angular/src/app/doc-search/doc-search.component.ts b/frontend/src/angular/src/app/doc-search/doc-search.component.ts index 84c9e8c..2ea469e 100644 --- a/frontend/src/angular/src/app/doc-search/doc-search.component.ts +++ b/frontend/src/angular/src/app/doc-search/doc-search.component.ts @@ -20,7 +20,7 @@ import {MatFormFieldModule} from '@angular/material/form-field'; import {FormControl, FormsModule,ReactiveFormsModule, Validators} from '@angular/forms'; import { Router } from '@angular/router'; import { DocumentService } from '../service/document.service'; -import { DocumentSearch } from '../model/documents'; +import { DocumentSearch, DocumentSearchResult } from '../model/documents'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { map, tap } from 'rxjs/operators'; import {MatProgressSpinnerModule} from '@angular/material/progress-spinner'; @@ -36,7 +36,7 @@ import { Subscription, interval } from 'rxjs'; }) export class DocSearchComponent { protected searchValueControl = new FormControl('', [Validators.required, Validators.minLength(3)]); - protected searchResults: string[] = []; + protected searchResult: DocumentSearchResult | null = null; protected searching = false; protected msWorking = 0; private repeatSub: Subscription | null = null; @@ -48,7 +48,7 @@ export class DocSearchComponent { } protected search(): void { - this.searchResults = []; + this.searchResult = null; const startDate = new Date(); this.msWorking = 0; this.searching = true; @@ -58,8 +58,8 @@ export class DocSearchComponent { this.documentService.postDocumentSearch(documentSearch) .pipe(takeUntilDestroyed(this.destroyRef), tap(() => this.searching = false), tap(() => this.repeatSub?.unsubscribe())) .subscribe(result => { - this.searchResults = result.resultStrings; - console.log(this.searchResults); + this.searchResult = result; + console.log(this.searchResult); }); }