-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #755 from upb-uc4/feature/configuration_management
Configuration Management
- Loading branch information
Showing
44 changed files
with
782 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import axios, { AxiosError, AxiosResponse } from "axios"; | ||
import Configuration from "./api_models/configuration_management/Configuration"; | ||
import HyperledgerNetworkVersion from "./api_models/configuration_management/HyperledgerVersion"; | ||
import APIError from "./api_models/errors/APIError"; | ||
import Common from "./Common"; | ||
import APIResponse from "./helpers/models/APIResponse"; | ||
|
||
export default class ConfigurationManagement extends Common { | ||
protected static endpoint = "/configuration-management"; | ||
|
||
constructor() { | ||
super(ConfigurationManagement.endpoint); | ||
} | ||
|
||
static async getVersion(): Promise<string> { | ||
return super.getVersion(); | ||
} | ||
|
||
static async getHyperledgerNetworkVersion(): Promise<HyperledgerNetworkVersion> { | ||
const instance = axios.create({ | ||
baseURL: process.env.VUE_APP_API_BASE_URL + ConfigurationManagement.endpoint, | ||
headers: { | ||
"Accept": "*/*", | ||
"Content-Type": "application/json;charset=UTF-8", | ||
}, | ||
}); | ||
|
||
return await instance | ||
.get(`/version/hyperledger-network`) | ||
.then((response: AxiosResponse) => { | ||
return response.data as HyperledgerNetworkVersion; | ||
}) | ||
.catch((error: AxiosError) => { | ||
return { networkVersion: "unavailable" } as HyperledgerNetworkVersion; | ||
}); | ||
} | ||
|
||
async getConfiguration(): Promise<APIResponse<Configuration>> { | ||
return await this._axios | ||
.get(`/configuration`) | ||
.then((response: AxiosResponse) => { | ||
return { | ||
returnValue: response.data as Configuration, | ||
statusCode: response.status, | ||
networkError: false, | ||
error: {} as APIError, | ||
}; | ||
}) | ||
.catch(async (error: AxiosError) => { | ||
if (error.response) { | ||
return { | ||
returnValue: {} as Configuration, | ||
statusCode: error.response.status, | ||
networkError: false, | ||
error: error.response.data as APIError, | ||
}; | ||
} else { | ||
return { | ||
returnValue: {} as Configuration, | ||
statusCode: 0, | ||
networkError: true, | ||
error: {} as APIError, | ||
}; | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* | ||
* @param date must be in format YYYY-MM-DD | ||
*/ | ||
async getSemester(date: string): Promise<APIResponse<string>> { | ||
const requestParameter = { params: {} as any }; | ||
requestParameter.params.date = date; | ||
return await this._axios | ||
.get(`/semester`, requestParameter) | ||
.then((response: AxiosResponse) => { | ||
return { | ||
returnValue: response.data.semester, | ||
statusCode: response.status, | ||
networkError: false, | ||
error: {} as APIError, | ||
}; | ||
}) | ||
.catch(async (error: AxiosError) => { | ||
if (error.response) { | ||
return { | ||
returnValue: "", | ||
statusCode: error.response.status, | ||
networkError: false, | ||
error: error.response.data as APIError, | ||
}; | ||
} else { | ||
return { | ||
returnValue: "", | ||
statusCode: 0, | ||
networkError: true, | ||
error: {} as APIError, | ||
}; | ||
} | ||
}); | ||
} | ||
|
||
async getCurrentSemester(): Promise<APIResponse<string>> { | ||
const today = new Date().toISOString().slice(0, 10); | ||
return await this.getSemester(today); | ||
} | ||
|
||
async getValidation(): Promise<APIResponse<any>> { | ||
return await this._axios | ||
.get(`/validation`) | ||
.then((response: AxiosResponse) => { | ||
return { | ||
returnValue: response.data, | ||
statusCode: response.status, | ||
networkError: false, | ||
error: {} as APIError, | ||
}; | ||
}) | ||
.catch(async (error: AxiosError) => { | ||
if (error.response) { | ||
return { | ||
returnValue: {}, | ||
statusCode: error.response.status, | ||
networkError: false, | ||
error: error.response.data as APIError, | ||
}; | ||
} else { | ||
return { | ||
returnValue: {}, | ||
statusCode: 0, | ||
networkError: true, | ||
error: {} as APIError, | ||
}; | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default interface Configuration { | ||
countries: string[]; | ||
languages: string[]; | ||
courseTypes: string[]; | ||
} |
3 changes: 3 additions & 0 deletions
3
src/api/api_models/configuration_management/HyperledgerVersion.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default interface HyperledgerNetworkVersion { | ||
networkVersion: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.