2023-02-18 08:52:17 +01:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
2023-02-19 00:43:43 +01:00
|
|
|
using PrivaPub.ClientModels;
|
|
|
|
using PrivaPub.ClientModels.Data;
|
|
|
|
using PrivaPub.Services.ClientToServer.Public;
|
2023-02-18 08:52:17 +01:00
|
|
|
|
2023-02-19 00:43:43 +01:00
|
|
|
namespace PrivaPub.Controllers.ClientToServer
|
2023-02-18 08:52:17 +01:00
|
|
|
{
|
|
|
|
[ApiController,
|
|
|
|
Route("clientapi/data")]
|
|
|
|
public class DataController : ControllerBase
|
|
|
|
{
|
|
|
|
readonly IDataService DataService;
|
|
|
|
readonly ILogger<DataController> Logger;
|
|
|
|
|
|
|
|
public DataController(IDataService dataService,
|
|
|
|
ILogger<DataController> logger)
|
|
|
|
{
|
|
|
|
DataService = dataService;
|
|
|
|
Logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet, Route("/clientapi/data/ping"), AllowAnonymous]
|
|
|
|
public async ValueTask<IActionResult> Ping() => NoContent();
|
|
|
|
|
|
|
|
[HttpGet, Route("/clientapi/data/current-version"), AllowAnonymous]
|
|
|
|
public IActionResult CurrentVersion() =>
|
|
|
|
Ok(DataService.GetCurrentVersion());
|
|
|
|
|
|
|
|
[HttpGet, Route("/clientapi/data/languages"), AllowAnonymous]
|
|
|
|
public async Task<IActionResult> Languages(CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
var result = new WebResult();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var languages = await DataService.GetLanguages(cancellationToken);
|
|
|
|
var viewLanguages = new List<ViewLanguage>();
|
|
|
|
|
|
|
|
viewLanguages.AddRange(languages.Select(l => new ViewLanguage
|
|
|
|
{
|
|
|
|
Name = l.NativeName,
|
|
|
|
International2Code = l.International2Code
|
2023-02-19 00:43:43 +01:00
|
|
|
}).ToArray());
|
2023-02-18 08:52:17 +01:00
|
|
|
|
|
|
|
return Ok(viewLanguages);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
Logger.LogError(ex, $"{nameof(DataController)}.{nameof(Languages)}()");
|
|
|
|
return BadRequest(result.Invalidate(ex.Message, exception: ex));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|