Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion core/Controllers/OrganizerEventsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using Microsoft.AspNetCore.Mvc;
using api.core.Data.Requests;
using api.core.Data.Enums;
using api.core.Data.Exceptions;
using api.core.data.entities;

namespace api.core.Controllers;

Expand Down Expand Up @@ -73,13 +75,29 @@ public IActionResult AddEvent([FromForm] EventCreationRequestDTO dto)
logger.LogInformation($"Adding new event");

var userId = jwtUtils.GetUserIdFromAuthHeader(HttpContext.Request.Headers["Authorization"]!);
var evnt = eventService.AddEvent(userId, dto);
try
{

var evnt = eventService.AddEvent(userId, dto);
return new OkObjectResult(
new Response<EventResponseDTO>
{
Data = evnt,
});
} catch (BadParameterException<EventCreationRequestDTO> e)
{
return Ok(new Response<string>
{
Error = e.ErrorCode,
});
}
catch (BadParameterException<Event> e)
{
return Ok(new Response<string>
{
Error = e.ErrorCode,
});
}
}

[HttpDelete("{id}")]
Expand Down
4 changes: 4 additions & 0 deletions core/Misc/JwtUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ public class JwtUtils : IJwtUtils
{
public string GetUserIdFromAuthHeader(string authHeader)
{
if (!authHeader.Contains("Bearer "))
{
return authHeader;
}
var token = authHeader.Replace("Bearer ", "");
var handler = new JwtSecurityTokenHandler();
var jsonToken = handler.ReadToken(token) as JwtSecurityToken;
Expand Down
2 changes: 1 addition & 1 deletion core/Policies/OrganizerIsActive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
var identifierClaim = context.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
//var userId = Guid.Parse(identifierClaim ?? throw new UnauthorizedException());

var user = userService.GetUser(identifierClaim);

Check warning on line 19 in core/Policies/OrganizerIsActive.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'userToken' in 'UserResponseDTO IUserService.GetUser(string userToken)'.
if (user.Type != "Organizer" || !user.IsActive)
if (!user.Type.Contains("Organizer") || !user.IsActive)
throw new UnauthorizedException();
else
context.Succeed(requirement);
Expand Down
4 changes: 2 additions & 2 deletions core/Services/ImageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public void EnsureImageSizeAndStore(string directory, IFormFile imageFile, Image
try
{
using var image = Image.Load(imageFile.OpenReadStream());
int width = image.Size.Width;
int height = image.Size.Height;
double width = image.Size.Width;
double height = image.Size.Height;

if (Math.Abs((width / height) - _imageRatioAcceptance[type]) > TOLERANCE_ACCEPTABILITY)
throw new BadParameterException<Event>(nameof(image), $"Invalid image aspect ratio {width}/{height}");
Expand Down
Loading