1 import { Injectable } from '@angular/core'
2 import { HttpClient } from '@angular/common/http'
4 import { ServerConfig } from '../../../../../shared'
7 export class ServerService {
8 private static BASE_CONFIG_URL = API_URL + '/api/v1/config/'
9 private static BASE_VIDEO_URL = API_URL + '/api/v1/videos/'
11 private config: ServerConfig = {
16 private videoCategories: Array<{ id: number, label: string }> = []
17 private videoLicences: Array<{ id: number, label: string }> = []
18 private videoLanguages: Array<{ id: number, label: string }> = []
20 constructor (private http: HttpClient) {}
23 this.http.get<ServerConfig>(ServerService.BASE_CONFIG_URL)
24 .subscribe(data => this.config = data)
27 loadVideoCategories () {
28 return this.loadVideoAttributeEnum('categories', this.videoCategories)
31 loadVideoLicences () {
32 return this.loadVideoAttributeEnum('licences', this.videoLicences)
35 loadVideoLanguages () {
36 return this.loadVideoAttributeEnum('languages', this.videoLanguages)
43 getVideoCategories () {
44 return this.videoCategories
48 return this.videoLicences
51 getVideoLanguages () {
52 return this.videoLanguages
55 private loadVideoAttributeEnum (attributeName: 'categories' | 'licences' | 'languages', hashToPopulate: { id: number, label: string }[]) {
56 return this.http.get(ServerService.BASE_VIDEO_URL + attributeName)
61 id: parseInt(dataKey, 10),