event isSignedUp

This commit is contained in:
quentin 2024-08-31 18:38:43 -05:00
parent f212f85d00
commit 787cdf5c6d
4 changed files with 30 additions and 1 deletions

View File

@ -41,5 +41,10 @@ namespace API.Authentication
return _grantManager.hasGrant(user.permissionId, EventGrantNames.CanDeleteAny) || return _grantManager.hasGrant(user.permissionId, EventGrantNames.CanDeleteAny) ||
_grantManager.getULongValues(user.permissionId, EventGrantNames.CanDelete).Exists(x => x == model.id); _grantManager.getULongValues(user.permissionId, EventGrantNames.CanDelete).Exists(x => x == model.id);
} }
public bool canCheckSelfSignup(User user)
{
//todo grants
return true;
}
} }
} }

View File

@ -5,5 +5,6 @@ namespace API.Authentication.Interfaces
{ {
public interface IEventAuthentication : IGenericAuthentication<EventDTO, Event> public interface IEventAuthentication : IGenericAuthentication<EventDTO, Event>
{ {
bool canCheckSelfSignup(User user);
} }
} }

View File

@ -17,6 +17,7 @@ namespace API.Controllers
{ {
} }
//todo slow
[HttpGet("period")] [HttpGet("period")]
public virtual ActionResult<List<EventDTO>> getPeriod(DateTime start, DateTime end) public virtual ActionResult<List<EventDTO>> getPeriod(DateTime start, DateTime end)
{ {
@ -30,7 +31,7 @@ namespace API.Controllers
List<EventDTO> dtos = []; List<EventDTO> dtos = [];
Parallel.ForEach(result, item => Parallel.ForEach(result.ToList(), item =>
{ {
EventDTO dto = new EventDTO(); EventDTO dto = new EventDTO();
dto.adaptFromModel(item); dto.adaptFromModel(item);
@ -39,5 +40,19 @@ namespace API.Controllers
return Ok(dtos); return Ok(dtos);
} }
[HttpGet("{eventId}/isSignedUp")]
public ActionResult<bool> 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;
}
} }
} }

View File

@ -11,5 +11,13 @@ namespace API.Services
public EventService(ILogger<EventService> logger, SASGContext context, IEventAuthentication auth) : base(logger, context, auth) public EventService(ILogger<EventService> 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<Signup>().Any(x => x.userId == user.id && x.eventId == eventId);
}
} }
} }