import { Injectable, Inject } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import { _MODULE_CONFIG } from '../types/token'; import { ModuleConfig } from '../types/module-config'; import { FileProfileSaveRequest, FileProfileSaveResponse, encodeFileProfileSave, decodeFileProfileSave } from '../apis/file-profile-save'; import { FileTalkDownloadRequest, encodeFileTalkDownload } from '../apis/file-talk-download'; import { FileTalkSaveRequest, FileTalkSaveResponse, encodeFileTalkSave, decodeFileTalkSave } from '../apis/file-talk-save'; import { FileTalkShareRequest, FileTalkShareResponse, encodeFileTalkShare, decodeFileTalkShare } from '../apis/file-talk-share'; import { MassTalkDownloadRequest, MassTalkDownloadResponse, encodeMassTalkDownload, decodeMassTalkDownload } from '../apis/mass-talk-download'; import { MassTalkSaveRequest, MassTalkSaveResponse, encodeMassTalkSave, decodeMassTalkSave } from '../apis/mass-talk-save'; import { TransMassTalkDownloadRequest, TransMassTalkDownloadResponse, encodeTransMassTalkDownload, decodeTransMassTalkDownload } from '../apis/trans-mass-talk-download'; import { TransMassTalkSaveRequest, TransMassTalkSaveResponse, encodeTransMassTalkSave, decodeTransMassTalkSave } from '../apis/trans-mass-talk-save'; import { TranslationReqRequest, TranslationReqResponse, encodeTranslationReq, decodeTranslationReq } from '../apis/translation-req'; import { TranslationSaveRequest, TranslationSaveResponse, encodeTranslationSave, decodeTranslationSave } from '../apis/translation-save'; @Injectable({ providedIn: 'root' }) export class CommonApiService { constructor( @Inject(_MODULE_CONFIG) private moduleConfig: ModuleConfig, private httpClient: HttpClient ) {} public fileProfileSave( req: FileProfileSaveRequest ): Observable { return this.httpClient .post( this.moduleConfig.urls.fileProfileSave, {}, { params: encodeFileProfileSave(req) } ) .pipe(map(res => decodeFileProfileSave(res))); } public fileTalkDownload(req: FileTalkDownloadRequest): Observable { return this.httpClient.post( this.moduleConfig.urls.fileTalkDownload, { responseType: 'blob' }, { params: encodeFileTalkDownload(req) } ); } public fileTalkSave( req: FileTalkSaveRequest ): Observable { return this.httpClient .post( this.moduleConfig.urls.fileTalkSave, {}, { params: encodeFileTalkSave(req) } ) .pipe(map(res => decodeFileTalkSave(res))); } public fileTalkShare( req: FileTalkShareRequest ): Observable { return this.httpClient .post( this.moduleConfig.urls.fileTalkShare, {}, { params: encodeFileTalkShare(req) } ) .pipe(map(res => decodeFileTalkShare(res))); } public massTalkDownload( req: MassTalkDownloadRequest ): Observable { return this.httpClient .post( this.moduleConfig.urls.massTalkDownload, {}, { params: encodeMassTalkDownload(req), responseType: 'text' as 'json' } ) .pipe(map(res => decodeMassTalkDownload(res))); } public massTalkSave( req: MassTalkSaveRequest ): Observable { return this.httpClient .post( this.moduleConfig.urls.massTalkSave, {}, { params: encodeMassTalkSave(req), responseType: 'text' as 'json' } ) .pipe(map(res => decodeMassTalkSave(res))); } public transMassTalkDownload( req: TransMassTalkDownloadRequest ): Observable { return this.httpClient .post( this.moduleConfig.urls.transMassTalkDownload, {}, { params: encodeTransMassTalkDownload(req) } ) .pipe(map(res => decodeTransMassTalkDownload(res))); } public transMassTalkSave( req: TransMassTalkSaveRequest ): Observable { return this.httpClient .post( this.moduleConfig.urls.transMassTalkSave, {}, { params: encodeTransMassTalkSave(req) } ) .pipe(map(res => decodeTransMassTalkSave(res))); } public translationReq( req: TranslationReqRequest ): Observable { return this.httpClient .post( this.moduleConfig.urls.translationReq, {}, { params: encodeTranslationReq(req) } ) .pipe(map(res => decodeTranslationReq(res))); } public translationSave( req: TranslationSaveRequest ): Observable { return this.httpClient .post( this.moduleConfig.urls.translationSave, {}, { params: encodeTranslationSave(req) } ) .pipe(map(res => decodeTranslationSave(res))); } }