using api.Interfaces;
using Microsoft.AspNetCore.Mvc;
using models.Core;
using models.Request;
namespace api.Controllers;
///
/// Endpoints for Event Management
///
/// Event Manager Service
[ApiController]
[Route("api/[controller]")]
public class EventController(IEventManager eventManager) : ControllerBase
{
[HttpPost]
public IActionResult Post([FromBody] AddEvent request)
{
//TODO: Protect Endpoint
try
{
eventManager.AddEvent(request);
return Ok();
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
///
/// Updates an Event
///
/// New Event Information
///
[HttpPatch]
public IActionResult Patch([FromBody] PatchEvent request)
{
//TODO: Protect Endpoint
try
{
eventManager.PatchEvent(request);
return Ok();
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
///
/// Gets a list of all events between a start date and an end date.
/// If the values are null, all events are returned.
///
/// Start date for the event search
/// End date for the event search
///
[HttpGet]
public ActionResult> Get(DateTime? startDate, DateTime? endDate)
{
try
{
if (startDate == null && endDate == null)
{
return Ok(eventManager.GetAllEvents());
}
return Ok(eventManager.GetEvents(startDate, endDate));
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
}