Projekt

Obecné

Profil

Stáhnout (1.21 KB) Statistiky
| Větev: | Tag: | Revize:
1
import {Injectable} from '@angular/core';
2
import {HttpClient, HttpEventType, HttpHeaders} from '@angular/common/http';
3
import {Observable} from 'rxjs';
4
import {QueryResponse} from '../model/QueryResponse';
5
import {Query} from '../model/Query';
6
import {DocumentResponse} from '../model/DocumentResponse';
7

    
8
const httpOptions = {
9
  headers: new HttpHeaders( {
10
    'Content-Type': 'application/json'
11
  })
12
};
13

    
14
@Injectable({
15
  providedIn: 'root'
16
})
17
export class QueryService {
18

    
19
  backendUrl = 'http://localhost:8080/';
20
  uploadFileUrl = 'upload';
21
  documentsUrl = 'documents';
22

    
23
  constructor(private httpClient: HttpClient) {}
24

    
25
  sendQuery(query: Query): Observable<QueryResponse> {
26
    return this.httpClient.post<QueryResponse>(this.backendUrl, query, httpOptions);
27
  }
28

    
29

    
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

    
41
  getDocuments(): Observable<DocumentResponse[]> {
42
    return this.httpClient.get<DocumentResponse[]>(this.backendUrl + this.documentsUrl, httpOptions);
43
  }
44

    
45

    
46
}
(2-2/2)