using System.Net; using FindAndDrive.Domain.Interfaces.Services; using FindAndDrive.Domain.Models.DTO; using FindAndDrive.Domain.Models.DTO.Request; using FindAndDrive.Domain.Models.DTO.Response; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace FindAndDrive.API.Controllers; [ApiExplorerSettings(IgnoreApi = true)] [Authorize(nameof(Permissions.ApiKey))] [ApiController] [Route("api/[controller]")] public class ApiKeyController : ControllerBase { private readonly IApiKeyService _apiKeyService; public ApiKeyController(IApiKeyService apiKeyService) { _apiKeyService = apiKeyService; } [HttpPost] [ProducesResponseType(typeof(ApiKeyCreateResponse), (int)HttpStatusCode.OK)] public async Task CreateApiKey([FromBody] CreateApiKeyRequest request) { var response = await _apiKeyService.CreateApiKey(request.ClientId, request.RoleId); return Ok(response); } [HttpGet("{clientId:guid}")] public async Task GetApiKeys([FromRoute] Guid clientId) { var keys = _apiKeyService.GetApiKeys(clientId); return Ok(keys); } [HttpPost("revoke")] public async Task RevokeApiKey([FromBody] RevokeApiKeyRequest request) { await _apiKeyService.RevokeApiKey(request.ApiKeyId); return Ok(); } [HttpPost("reinstate")] public async Task ReinstateApiKey([FromBody] ReinstateApiKeyRequest request) { await _apiKeyService.ReinstateApiKey(request.ApiKeyId); return Ok(); } }