-
Notifications
You must be signed in to change notification settings - Fork 19
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 #348 from JustinMacaulay/feature/outage-banner
VS-6971 Outage Banner
- Loading branch information
Showing
8 changed files
with
169 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
5 changes: 5 additions & 0 deletions
5
vsd-app/ClientApp/src/app/interfaces/configuration.interface.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,5 @@ | ||
export interface Configuration { | ||
outageStartDate?: string; | ||
outageEndDate?: string; | ||
outageMessage?: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { HttpClient, HttpHeaders } from '@angular/common/http'; | ||
import { Observable, throwError } from 'rxjs'; | ||
import { catchError } from 'rxjs/operators'; | ||
import { Configuration } from '../interfaces/configuration.interface'; | ||
import {environment} from "../../environments/environment"; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class ConfigService{ | ||
headers: HttpHeaders = new HttpHeaders({ | ||
'Content-Type': 'application/json' | ||
}); | ||
baseUrl = environment.apiRootUrl; | ||
apiPath = this.baseUrl.concat('api/Configuration'); | ||
|
||
constructor( | ||
private http: HttpClient, | ||
) { } | ||
|
||
public async load(): Promise<Configuration> { | ||
try { | ||
return await | ||
this.http.get<Configuration>(this.apiPath, { headers: this.headers }) | ||
.pipe(catchError(this.handleError)).toPromise(); | ||
} catch (error) { | ||
this.handleError(error); | ||
throw error; | ||
} | ||
} | ||
|
||
protected handleError(err): Observable<never> { | ||
let errorMessage = ''; | ||
if (err.error instanceof ErrorEvent) { | ||
// A client-side or network error occurred. Handle it accordingly. | ||
errorMessage = err.error.message; | ||
} else { | ||
// The backend returned an unsuccessful response code. | ||
// The response body may contain clues as to what went wrong, | ||
errorMessage = `Backend returned code ${err.status}, body was: ${err.message}`; | ||
} | ||
return throwError(errorMessage); | ||
} | ||
} |
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,57 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.AspNetCore.Authorization; | ||
|
||
namespace Gov.Cscp.VictimServices.Public.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class ConfigurationController : ControllerBase | ||
{ | ||
private readonly ILogger<ConfigurationController> logger; | ||
private readonly IConfiguration configuration; | ||
|
||
public ConfigurationController(ILogger<ConfigurationController> logger, IConfiguration configuration) | ||
{ | ||
this.logger = logger; | ||
this.configuration = configuration; | ||
} | ||
|
||
[AllowAnonymous] | ||
[HttpGet] | ||
public IActionResult GetConfiguration() | ||
{ | ||
try | ||
{ | ||
var config = new Configuration | ||
{ | ||
OutageMessage = configuration.GetValue<string>("CONFIGURATION_OUTAGEINFORMATION_MESSAGE"), | ||
OutageStartDate = configuration.GetValue<string>("CONFIGURATION_OUTAGEINFORMATION_STARTDATE"), | ||
OutageEndDate = configuration.GetValue<string>("CONFIGURATION_OUTAGEINFORMATION_ENDDATE") | ||
}; | ||
|
||
if (string.IsNullOrEmpty(config.OutageMessage) || string.IsNullOrEmpty(config.OutageStartDate) || string.IsNullOrEmpty(config.OutageEndDate)) | ||
{ | ||
return Ok(); | ||
}; | ||
|
||
return Ok(config); | ||
} | ||
catch (Exception ex) | ||
{ | ||
logger.LogError(ex, "Failed to retrieve configuration information."); | ||
return StatusCode(StatusCodes.Status500InternalServerError); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public class Configuration | ||
{ | ||
public string OutageMessage { get; set; } | ||
public string OutageStartDate { get; set; } | ||
public string OutageEndDate { get; set; } | ||
}; |