1 |
00466dc7
|
Ondřej Váně
|
import {Injectable} from '@angular/core';
|
2 |
|
|
import {HttpClient, HttpEventType, HttpHeaders} from '@angular/common/http';
|
3 |
|
|
import {Observable} from 'rxjs';
|
4 |
5da39206
|
castic96
|
import {SearchResponse} from '../model/SearchResponse';
|
5 |
00466dc7
|
Ondřej Váně
|
import {Query} from '../model/Query';
|
6 |
2b790e00
|
Ondřej Váně
|
import {DocumentResponse} from '../model/DocumentResponse';
|
7 |
5da39206
|
castic96
|
import {SearchRequest} from '../model/SearchRequest';
|
8 |
efc2257b
|
castic96
|
|
9 |
|
|
const httpOptions = {
|
10 |
|
|
headers: new HttpHeaders( {
|
11 |
|
|
'Content-Type': 'application/json'
|
12 |
|
|
})
|
13 |
|
|
};
|
14 |
f3d8e7de
|
Ondřej Váně
|
|
15 |
|
|
@Injectable({
|
16 |
|
|
providedIn: 'root'
|
17 |
|
|
})
|
18 |
|
|
export class QueryService {
|
19 |
|
|
|
20 |
00466dc7
|
Ondřej Váně
|
backendUrl = 'http://localhost:8080/';
|
21 |
|
|
uploadFileUrl = 'upload';
|
22 |
2b790e00
|
Ondřej Váně
|
documentsUrl = 'documents';
|
23 |
f3d8e7de
|
Ondřej Váně
|
|
24 |
efc2257b
|
castic96
|
constructor(private httpClient: HttpClient) {}
|
25 |
f3d8e7de
|
Ondřej Váně
|
|
26 |
5da39206
|
castic96
|
searchPost(searchRequest: SearchRequest): Observable<SearchResponse> {
|
27 |
|
|
return this.httpClient.post<SearchResponse>(this.backendUrl, searchRequest, httpOptions);
|
28 |
f3d8e7de
|
Ondřej Váně
|
}
|
29 |
00466dc7
|
Ondřej Váně
|
|
30 |
|
|
uploadFile(files: File[]): Observable<any> {
|
31 |
|
|
const formDate = new FormData();
|
32 |
|
|
for (const file of files) {
|
33 |
|
|
formDate.append('file', file);
|
34 |
|
|
}
|
35 |
|
|
return this.httpClient.post(this.backendUrl + this.uploadFileUrl, formDate, {
|
36 |
|
|
reportProgress: true,
|
37 |
|
|
observe: 'events'
|
38 |
|
|
});
|
39 |
|
|
}
|
40 |
2b790e00
|
Ondřej Váně
|
|
41 |
|
|
getDocuments(): Observable<DocumentResponse[]> {
|
42 |
|
|
return this.httpClient.get<DocumentResponse[]>(this.backendUrl + this.documentsUrl, httpOptions);
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
|
46 |
f3d8e7de
|
Ondřej Váně
|
}
|