|
|
@@ -1,8 +1,10 @@
|
|
|
|
|
|
+using LiteDB;
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.Extensions.Options;
|
|
|
using RunnersMeet.Server.Domain;
|
|
|
+using RunnersMeet.Server.Persistence;
|
|
|
|
|
|
namespace RunnersMeet.Server.Controllers;
|
|
|
|
|
|
@@ -38,13 +40,45 @@ public class EventsController : ControllerBase
|
|
|
return Ok(new ResultPage<Event>(events, eventsRequest.Page, _settings.PageSize));
|
|
|
}
|
|
|
|
|
|
+ [HttpGet("{id}")]
|
|
|
+ public ActionResult<Event> GetEvent(string id)
|
|
|
+ {
|
|
|
+ var anEvent = _requestRouter.For(new ObjectId(id)).Process<Event>();
|
|
|
+
|
|
|
+ return Ok(anEvent);
|
|
|
+ }
|
|
|
+
|
|
|
[HttpPost]
|
|
|
public ActionResult<Event> CreateEvent([FromBody] EventData eventData)
|
|
|
{
|
|
|
+ var user = _requestRouter.For(ApiUser.Current.UserId).Process<UserProfile>();
|
|
|
var createdEvent = _requestRouter
|
|
|
- .For(new Event(eventData))
|
|
|
+ .For(new CreateEventRequest(user, eventData))
|
|
|
.Process<Event>();
|
|
|
|
|
|
return Ok(createdEvent);
|
|
|
}
|
|
|
+
|
|
|
+ [HttpPut("{id}")]
|
|
|
+ public ActionResult<Event> UpdateEvent(string id, [FromBody] Event anEvent)
|
|
|
+ {
|
|
|
+ if (id != anEvent.EventId.ToString())
|
|
|
+ {
|
|
|
+ throw new ArgumentException("Object ID in URL does not match event ID");
|
|
|
+ }
|
|
|
+
|
|
|
+ var result = _requestRouter.For(new EventUpdate(ApiUser.Current.UserId, anEvent)).Process<Event>();
|
|
|
+
|
|
|
+ return Ok(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ [HttpDelete("{id}")]
|
|
|
+ public ActionResult DeleteEvent(string id)
|
|
|
+ {
|
|
|
+ _requestRouter
|
|
|
+ .For(new EventReference(ApiUser.Current.UserId, new ObjectId(id)))
|
|
|
+ .Process<bool>();
|
|
|
+
|
|
|
+ return Ok();
|
|
|
+ }
|
|
|
}
|