using System; using System.Threading.Tasks; using System.Linq; using System.Collections.Generic; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Serilog; using LCU.Api.Internal.MaidBotApi.Services; using LCU.Api.Internal.MaidBotLib.Models; using LCU.Library.Internal.Exceptions; namespace LCU.API.Internal.MaidBotApi.Controllers; [ApiController] [Route("api/[controller]")] public class EventLogController : ControllerBase { private readonly IEventLogService _eventLogService; public EventLogController(IEventLogService eventLogService) { _eventLogService = eventLogService; } [HttpGet] [ProducesResponseType(200)] [ProducesResponseType(204)] [ProducesResponseType(typeof(EventLog), 400)] [ProducesResponseType(500)] public async Task Get() { try { var results = await _eventLogService.GetAsync(); if (results == null || !results.Any()) { return NoContent(); } return Ok(results); } catch (ServiceException exception) { return StatusCode(StatusCodes.Status500InternalServerError, exception.Message); } catch (Exception exception) { Log.Error(exception, "Unexpected Exception"); return StatusCode(StatusCodes.Status500InternalServerError); } } [HttpDelete()] [ProducesResponseType(200)] [ProducesResponseType(500)] public IActionResult DeleteMany([FromBody] List eventLogs) { try { _eventLogService.DeleteMany(eventLogs); return Ok(); } catch (ServiceException exception) { return StatusCode(StatusCodes.Status500InternalServerError, exception.Message); } catch (Exception exception) { Log.Error(exception, "Unexpected Exception"); return StatusCode(StatusCodes.Status500InternalServerError); } } }