61 lines
1.4 KiB
C#
61 lines
1.4 KiB
C#
using API.Authentication.Interfaces;
|
|
using API.DTO.Base;
|
|
using API.DTO.Base.Update;
|
|
using API.Services;
|
|
using DAL.Models;
|
|
using DAL.Models.Audits;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using MUser = DAL.Models.User;
|
|
|
|
namespace API.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/v1/[controller]")]
|
|
public class EventController : CRUDBase<EventController, EventDTO, EventUpdateDTO, Event, AuditEvent, IEventAuthentication, EventService>
|
|
{
|
|
public EventController(ILogger<EventController> logger, UserService userService, EventService service) : base(logger, userService, service)
|
|
{
|
|
}
|
|
|
|
//todo slow
|
|
[HttpGet("period")]
|
|
public virtual ActionResult<List<EventDTO>> getPeriod(DateTime start, DateTime end)
|
|
{
|
|
MUser? user = getUser(User);
|
|
if (user == null)
|
|
return Unauthorized();
|
|
|
|
IEnumerable<Event>? result = Service.get(user, x => x.when >= start && x.when <= end && x.hidden == false);
|
|
if (result == null)
|
|
return Forbid();
|
|
|
|
List<EventDTO> dtos = [];
|
|
|
|
List<Event> temp = result.ToList();
|
|
|
|
Parallel.ForEach(temp, item =>
|
|
{
|
|
EventDTO dto = new EventDTO();
|
|
dto.adaptFromModel(item);
|
|
dtos.Add(dto);
|
|
});
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|