76 lines
1.9 KiB
C#
76 lines
1.9 KiB
C#
using api.Interfaces;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using models.Core;
|
|
using models.Request;
|
|
|
|
namespace api.Controllers;
|
|
|
|
/// <summary>
|
|
/// Endpoints for Event Management
|
|
/// </summary>
|
|
/// <param name="eventManager">Event Manager Service</param>
|
|
[ApiController]
|
|
[Route("[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);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates an Event
|
|
/// </summary>
|
|
/// <param name="request">New Event Information</param>
|
|
/// <returns></returns>
|
|
[HttpPatch]
|
|
public IActionResult Patch([FromBody] PatchEvent request)
|
|
{
|
|
//TODO: Protect Endpoint
|
|
|
|
try
|
|
{
|
|
eventManager.PatchEvent(request);
|
|
return Ok();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return BadRequest(e.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets a list of all events between a start date and an end date.
|
|
/// If the values are null, all events are returned.
|
|
/// </summary>
|
|
/// <param name="startDate">Start date for the event search</param>
|
|
/// <param name="endDate">End date for the event search</param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public ActionResult<List<Event>> 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);
|
|
}
|
|
}
|
|
} |