using System; using System.Threading.Tasks; using Asp.Versioning; using AutoMapper; using gehGassi.Core.Interfaces; using gehGassi.Core.Services; using gehGassi.Domain.Common; using gehGassi.Dto; using gehGassi.Dto.Common; using gehGassi.Web.Helper; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; namespace gehGassi.Web.Controllers.Api { /// /// Controller für die Verwaltung vom Server-Status /// [ApiController] [ApiVersion(1)] [Route("api/status")] [Route("api/v{v:apiVersion}/status")] public class ApiStatusController : ApiBaseController { private readonly IMapper _mapper; private readonly ILogger _logger; private readonly IAppVersionService _appVersionService; /// /// Erstellt eine Instanz /// /// Instanz eines IMapper /// Instanz eines ILogger /// Instanz von LocalizationOptions /// Instanz eines IDogOwnerService /// Instanz eines IAppVersionService public ApiStatusController(IMapper mapper, ILogger logger, IOptions localizationOptions, IAppUserService appUserService, IAppVersionService appVersionService) : base(mapper, localizationOptions, appUserService) { _mapper = mapper; _logger = logger; _appVersionService = appVersionService; } /// /// Gibt zurück, dass der Server online ist... /// /// 200 OK [HttpGet("IsOnline")] public IActionResult IsOnline() { var clientOffset = GetClientDateOffset(); return Ok(true); } /// /// Gibt die Server-Zeit zurück /// /// Server-Zeit [HttpGet("ServerTime")] public IActionResult ServerTime() { var clientOffset = GetClientDateOffset(); return Ok(DateTimeOffset.UtcNow); } /// /// Gibt die aktuelle Version der App für eine Plattform zurück /// /// Appversion [HttpGet("AppVersion")] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] public async Task AppVersion(PlatformDto platform, string language) { if (User?.Identity != null && User.Identity.IsAuthenticated) { var currentVersion = await _appVersionService.GetCurrentwithNamesAsync((Platform)platform, language, LocalizationOptions.Value.DefaultCulture); if (currentVersion != null) { var currentVersionDto = _mapper.Map(currentVersion); return Ok(currentVersionDto); } } return NotFound(CommunicationErrors.Common_NotFound); } /// /// Gibt die aktuelle Version der App für eine Plattform zurück /// /// Appversion [HttpGet("CheckAppVersion")] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] public async Task CheckAppVersion(PlatformDto platform, string language) { if (User?.Identity != null && User.Identity.IsAuthenticated) { var currentVersion = await _appVersionService.GetCurrentwithNamesAsync((Platform)platform, language, LocalizationOptions.Value.DefaultCulture); if (currentVersion != null) { var currentVersionDto = _mapper.Map(currentVersion); return Ok(currentVersionDto); } } return NotFound(CommunicationErrors.Common_NotFound); } } }