import {HttpClient} from '@angular/common/http'; import {Injectable} from '@angular/core'; import {NGXLogger} from 'ngx-logger'; import {environment} from '../../environments/environment'; import {Observable} from 'rxjs'; import {tap} from 'rxjs/operators'; import {GetImageResponse, ImagePostResponse, StorageHealth} from '../interfaces/interface'; @Injectable() export class RestService { constructor( private logger: NGXLogger, private http: HttpClient ) { } private currentLocation = 'http://' + environment.location + ':' + environment.port; private imageUrl = this.currentLocation + '/image'; private getImageUrl = this.imageUrl + '/get'; private deleteImageUrl = this.imageUrl + '/delete'; private postImageUrl = this.imageUrl + '/post'; private updateImageUrl = this.imageUrl + '/update'; private healthCheckUrl = this.currentLocation + '/check'; public getAllImages(): Observable { return this.http.get(this.getImageUrl + '/all').pipe( tap(next => this.logger.debug('getAllImages', next)) ); } public getImage(id: string): Observable { return this.http.get(this.getImageUrl + '/' + id).pipe( tap(next => this.logger.debug('getImage', id, next)) ); } public getImageVersion(id: string, version: string): Observable { return this.http.get(this.getImageUrl + '/' + id + '/version/' + version).pipe( tap(next => this.logger.debug('getImageVersion', id, version, next)) ); } public deleteAllImages(): Observable { return this.http.delete(this.deleteImageUrl + 'all').pipe( tap(next => this.logger.debug('deleteAllImages', next)) ); } public deleteImage(filename: string): Observable { return this.http.delete(this.deleteImageUrl + '/' + filename).pipe( tap(next => this.logger.debug('deleteImage', filename, next)) ); } public postImage(imageForm: FormData): Observable { return this.http.post(this.postImageUrl, imageForm).pipe( tap(next => this.logger.debug('postImage', imageForm, next)) ); } // public getPostImageUrl(): string { // return this.postImageUrl; // } public updateImage(id: string, imageForm: FormData): Observable { return this.http.put(this.updateImageUrl + '/' + id, imageForm).pipe( tap(next => this.logger.debug('updateImage', id, imageForm, next)) ); } // public getUpdateImageUrl(filenameWithExtension: string): string { // return this.updateImageUrl + '/' + RestService.stripUploadFileName(filenameWithExtension); // } public healthCheck(): Observable { return this.http.get(this.healthCheckUrl).pipe( tap(next => this.logger.debug('healthCheck', next)) ); } }