using Models.Settings; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using Swashbuckle.AspNetCore.Annotations; namespace Api.Controllers { /// /// 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. /// [ApiController] [Route("api/[controller]")] [EnableCors("FrontendOnly")] public sealed class GoogleController : ControllerBase { private readonly GoogleSettings _googleSettings; private readonly ILogger _log; public GoogleController(IOptions options, ILogger log) { _googleSettings = options.Value; _log = log; } /// /// Returns the Google Tag Manager ID used by the frontend for analytics and tracking. /// /// 200 OK with the Tag Manager ID as a string. [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 GetTagManagerId(CancellationToken ct) { return Ok(_googleSettings.TagManagerId); } /// /// 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. /// /// 200 OK with the maps API key as a string. [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 GetMapKey(CancellationToken ct) { return Ok(_googleSettings.MapKey); } } }