Skip to content

Commit

Permalink
feat: add document link
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed Nov 15, 2023
1 parent 94c44f6 commit 587b685
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,12 +58,19 @@ public List<DocumentDto> getDocumentList() {
}).toList();
}

@GetMapping("/id/{id}")
@GetMapping("/doc/{id}")
public ResponseEntity<DocumentDto> 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<byte[]> 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()));
Expand Down
14 changes: 10 additions & 4 deletions frontend/src/angular/src/app/doc-search/doc-search.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@
<div *ngIf="searching" class="spinner-container">
<div class="spinner-box">
<mat-spinner></mat-spinner>
<div i18n="@@searchComponentWorking">The AI is working on the answer.</div>
<div i18n="@@searchComponentBePatient">Please be patient. {{ (msWorking / 1000) | number: '1.3'}} sec.</div>
<div i18n="@@docSearchWorking">The AI is working on the answer.</div>
<div i18n="@@docSearchBePatient">Please be patient. {{ (msWorking / 1000) | number: '1.3'}} sec.</div>
</div>
</div>
<div *ngFor="let searchResult of searchResults">
{{searchResult}}
<div *ngFor="let searchResultStr of searchResult?.resultStrings; index as arrayIndex">
<ul>
<li i18n="@@docSearchResultDocument">Result Document:</li>
<ul>
<li i18n="@@link">Link: <a mat-button href="/rest/document/pdf/{{!!searchResult && searchResult.documents[arrayIndex].id}}" target="_blank">{{!!searchResult && searchResult.documents[arrayIndex].documentName}}</a></li>
<li>{{searchResultStr}}</li>
</ul>
</ul>
</div>
10 changes: 5 additions & 5 deletions frontend/src/angular/src/app/doc-search/doc-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
});
}

Expand Down

0 comments on commit 587b685

Please sign in to comment.