Files
claude 75bc9509c5
Build and Push Docker Images / build (push) Successful in 4m35s
Changes
2026-05-14 14:12:29 +03:00

58 lines
2.3 KiB
C#

using Models.Settings;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Swashbuckle.AspNetCore.Annotations;
namespace Api.Controllers
{
/// <summary>
/// Provides simple endpoints to expose Google related public keys used by
/// the frontend (for example Google Analytics tag id and Maps API key).
/// These endpoints return only public values safe to be exposed to clients.
/// </summary>
[ApiController]
[Route("api/[controller]")]
[EnableCors("FrontendOnly")]
public sealed class GoogleController : ControllerBase
{
private readonly GoogleSettings _googleSettings;
private readonly ILogger<GoogleController> _log;
public GoogleController(IOptions<GoogleSettings> options, ILogger<GoogleController> log)
{
_googleSettings = options.Value;
_log = log;
}
/// <summary>
/// Returns the Google Tag Manager ID used by the frontend for analytics and tracking.
/// </summary>
/// <returns>200 OK with the Tag Manager ID as a string.</returns>
[HttpGet("tagmanager")]
[SwaggerOperation(Summary = "Get Google Tag Manager ID", Description = "Returns the Google Tag Manager ID configured for frontend analytics.")]
[SwaggerResponse(StatusCodes.Status200OK, "Tag Manager ID returned")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> GetTagManagerId(CancellationToken ct)
{
return Ok(_googleSettings.TagManagerId);
}
/// <summary>
/// Returns the Google Maps API key used by the frontend to load the
/// Maps JavaScript API. This key is expected to be restricted and
/// safe to expose for client-side usage.
/// </summary>
/// <returns>200 OK with the maps API key as a string.</returns>
[HttpGet("maps")]
[SwaggerOperation(Summary = "Get Google Maps key", Description = "Returns the Google Maps API key configured for frontend map features.")]
[SwaggerResponse(StatusCodes.Status200OK, "Maps API key returned")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> GetMapKey(CancellationToken ct)
{
return Ok(_googleSettings.MapKey);
}
}
}