97 lines
2.5 KiB
C#
97 lines
2.5 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("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);
|
|
}
|
|
}
|
|
|
|
/// <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>
|
|
/// <param name="seasonId">Season to find events for</param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public ActionResult<List<Event>> Get(DateTime? startDate, DateTime? endDate, string? seasonId)
|
|
{
|
|
try
|
|
{
|
|
if (startDate == null && endDate == null)
|
|
{
|
|
return Ok(seasonId == null ? eventManager.GetAllEvents() : eventManager.GetBySeason(new Guid(seasonId)));
|
|
}
|
|
return Ok(eventManager.GetEvents(startDate, endDate));
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return BadRequest(e.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deletes an event
|
|
/// </summary>
|
|
/// <param name="eventId">Event to delete</param>
|
|
/// <returns></returns>
|
|
[HttpDelete]
|
|
public IActionResult Delete(Guid eventId)
|
|
{
|
|
// TODO: Protect Endpoint
|
|
try
|
|
{
|
|
eventManager.DeleteEvent(eventId);
|
|
return Ok();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return BadRequest(e.Message);
|
|
}
|
|
}
|
|
} |