diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-01-29 17:35:54 +0200 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-01-29 17:37:56 +0200 |
| commit | 18e7ba3a2ee9460905507ba1f1605bc7a4fdd150 (patch) | |
| tree | 9382877d845ad7db04cf19489b3b82e11d32e6fa | |
| parent | 2417df3ff2939b67695b80905f301ef53c905260 (diff) | |
| download | DevHive-18e7ba3a2ee9460905507ba1f1605bc7a4fdd150.tar DevHive-18e7ba3a2ee9460905507ba1f1605bc7a4fdd150.tar.gz DevHive-18e7ba3a2ee9460905507ba1f1605bc7a4fdd150.zip | |
Implemented angular languages and technologies service requests for getting data
| -rw-r--r-- | src/DevHive.Angular/src/app/services/language.service.ts | 40 | ||||
| -rw-r--r-- | src/DevHive.Angular/src/app/services/technology.service.ts | 41 |
2 files changed, 81 insertions, 0 deletions
diff --git a/src/DevHive.Angular/src/app/services/language.service.ts b/src/DevHive.Angular/src/app/services/language.service.ts index 8613a65..d85f178 100644 --- a/src/DevHive.Angular/src/app/services/language.service.ts +++ b/src/DevHive.Angular/src/app/services/language.service.ts @@ -2,6 +2,7 @@ import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http'; import {Injectable} from '@angular/core'; import {Guid} from 'guid-typescript'; import {Observable} from 'rxjs'; +import {Language} from 'src/models/identity/user'; import {AppConstants} from '../app-constants.module'; @Injectable({ @@ -16,4 +17,43 @@ export class LanguageService { }; return this.http.get(AppConstants.API_LANGUAGE_URL, options); } + + getAllLanguagesWithSessionStorageRequest(): Observable<object> { + const token = sessionStorage.getItem('UserCred') ?? ''; + return this.getAllLanguagesRequest(token); + } + + getAllLanguagesRequest(authToken: string): Observable<object> { + const options = { + headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) + }; + return this.http.get(AppConstants.API_LANGUAGE_URL + '/GetLanguages', options); + } + + getFullLanguagesFromIncomplete(givenLanguages: Language[]): Promise<Language[]> { + if (givenLanguages.length === 0) { + return new Promise(resolve => resolve(givenLanguages)); + } + + // This accepts language array with incomplete languages, meaning + // languages that only have an id, but no name + return new Promise(resolve => { + const lastGuid = givenLanguages[givenLanguages.length - 1].id; + + // For each language, request his name and assign it + for (const lang of givenLanguages) { + this.getLanguageRequest(lang.id).subscribe( + (result: object) => { + // this only assigns the "name" property to the language, + // because only the name is returned from the request + Object.assign(lang, result); + + if (lastGuid === lang.id) { + resolve(givenLanguages); + } + } + ); + } + }); + } } diff --git a/src/DevHive.Angular/src/app/services/technology.service.ts b/src/DevHive.Angular/src/app/services/technology.service.ts index 4df0412..207303f 100644 --- a/src/DevHive.Angular/src/app/services/technology.service.ts +++ b/src/DevHive.Angular/src/app/services/technology.service.ts @@ -2,6 +2,7 @@ import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http'; import {Injectable} from '@angular/core'; import {Guid} from 'guid-typescript'; import {Observable} from 'rxjs'; +import {Technology} from 'src/models/identity/user'; import {AppConstants} from '../app-constants.module'; @Injectable({ @@ -16,4 +17,44 @@ export class TechnologyService { }; return this.http.get(AppConstants.API_TECHNOLOGY_URL, options); } + + getAllTechnologiesWithSessionStorageRequest(): Observable<object> { + const token = sessionStorage.getItem('UserCred') ?? ''; + return this.getAllTechnologiesRequest(token); + } + + getAllTechnologiesRequest(authToken: string): Observable<object> { + const options = { + headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) + }; + return this.http.get(AppConstants.API_TECHNOLOGY_URL + '/GetTechnologies', options); + } + + getFullTechnologiesFromIncomplete(givenTechnologies: Technology[]): Promise<Technology[]> { + if (givenTechnologies.length === 0) { + return new Promise(resolve => resolve(givenTechnologies)); + } + + // This accepts language array with incomplete languages, meaning + // languages that only have an id, but no name + return new Promise(resolve => { + const lastGuid = givenTechnologies[givenTechnologies.length - 1].id; + + // For each language, request his name and assign it + for (const tech of givenTechnologies) { + this.getTechnologyRequest(tech.id).subscribe( + (result: object) => { + // this only assigns the "name" property to the language, + // because only the name is returned from the request + Object.assign(tech, result); + + if (lastGuid === tech.id) { + resolve(givenTechnologies); + } + } + ); + } + }); + } + } |
