Skip to content

Variants RestService

mto3737 edited this page Apr 24, 2021 · 3 revisions

In the VariantRestService.ts the HTTPClient calls the backend mehtods of Variants. The methods return an Observable Object.

"Observables provide support for passing messages between parts of your application. They are used frequently in Angular and are a technique for event handling, asynchronous programming, and handling multiple values." Source: https://angular.io/guide/observables

export class VariantRestService {

  constructor(private http: HttpClient){}

  getVariants(): Observable<any> {
    return this.http.get<any>(RestService.getVariantsURL());
  }

  getVariantsById(id: any): Observable<any> {
    return this.http.get<any>(RestService.getVariantsURL() + '/' + id);
  }

  getVariantsByAnalysisId(id: any): Observable<any> {
    return this.http.get<any>(RestService.getVariantsURL() + '?analysisId=' + id);
  }

  createVariants(variantDTO: VariantDTO): Observable<any> {
    return this.http.post(RestService.getVariantsURL(), variantDTO, httpOptions);
  }

  updateVariants(variantDTO: VariantDTO): Observable<any> {
    return this.http.put(RestService.getVariantsURL(), variantDTO, httpOptions);
  }

  deleteVariants(id: string): Observable<any> {
    return this.http.delete(RestService.getVariantsURL() + '/' + id);
  }
}

"As a publisher, you create an Observable instance that defines a subscriber function. This is the function that is executed when a consumer calls the subscribe() method. The subscriber function defines how to obtain or generate values or messages to be published.

To execute the observable you have created and begin receiving notifications, you call its subscribe() method, passing an observer. This is a JavaScript object that defines the handlers for the notifications you receive. The subscribe() call returns a Subscription object that has an unsubscribe() method, which you call to stop receiving notifications."

Soruce: https://angular.io/guide/observables

This call returns all variants by analysisiId. Now we get an result (VariantsDTO). And can work with them.

this.variantRestService.getVariantsByAnalysisId(this.analysisid).subscribe((result: VariantsDTO) => 
{

});

Clone this wiki locally