diff --git a/API/Authentication/EventAuthentication.cs b/API/Authentication/EventAuthentication.cs index b98d4a6..12ebb2a 100644 --- a/API/Authentication/EventAuthentication.cs +++ b/API/Authentication/EventAuthentication.cs @@ -41,5 +41,10 @@ namespace API.Authentication return _grantManager.hasGrant(user.permissionId, EventGrantNames.CanDeleteAny) || _grantManager.getULongValues(user.permissionId, EventGrantNames.CanDelete).Exists(x => x == model.id); } + public bool canCheckSelfSignup(User user) + { + //todo grants + return true; + } } } diff --git a/API/Authentication/Interfaces/IEventAuthentication.cs b/API/Authentication/Interfaces/IEventAuthentication.cs index 9681ea5..a73f42d 100644 --- a/API/Authentication/Interfaces/IEventAuthentication.cs +++ b/API/Authentication/Interfaces/IEventAuthentication.cs @@ -5,5 +5,6 @@ namespace API.Authentication.Interfaces { public interface IEventAuthentication : IGenericAuthentication { + bool canCheckSelfSignup(User user); } } diff --git a/API/Controllers/EventController.cs b/API/Controllers/EventController.cs index 14e6638..03e3257 100644 --- a/API/Controllers/EventController.cs +++ b/API/Controllers/EventController.cs @@ -17,6 +17,7 @@ namespace API.Controllers { } + //todo slow [HttpGet("period")] public virtual ActionResult> getPeriod(DateTime start, DateTime end) { @@ -30,7 +31,7 @@ namespace API.Controllers List dtos = []; - Parallel.ForEach(result, item => + Parallel.ForEach(result.ToList(), item => { EventDTO dto = new EventDTO(); dto.adaptFromModel(item); @@ -39,5 +40,19 @@ namespace API.Controllers return Ok(dtos); } + + [HttpGet("{eventId}/isSignedUp")] + public ActionResult isSignedUp(ulong eventId) + { + MUser? user = getUser(User); + if (user == null) + return Unauthorized(); + + bool? isSignedUp = Service.isSignedUp(user, eventId); + if (isSignedUp == null) + return Forbid(); + + return isSignedUp; + } } } diff --git a/API/Services/EventService.cs b/API/Services/EventService.cs index 86495a5..29ee953 100644 --- a/API/Services/EventService.cs +++ b/API/Services/EventService.cs @@ -11,5 +11,13 @@ namespace API.Services public EventService(ILogger logger, SASGContext context, IEventAuthentication auth) : base(logger, context, auth) { } + + public bool? isSignedUp(User user, ulong eventId) + { + if (!_auth.canCheckSelfSignup(user)) + return null; + + return Context.Set().Any(x => x.userId == user.id && x.eventId == eventId); + } } }