Skip to content

Commit

Permalink
fix events
Browse files Browse the repository at this point in the history
  • Loading branch information
MysticFragilist committed Apr 3, 2024
1 parent 429a091 commit ae003dc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
9 changes: 8 additions & 1 deletion core/Controllers/ModeratorEventsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using api.core.Data.Responses;
using api.core.Misc;
using api.core.services.abstractions;
using api.core.Services;

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -13,7 +14,7 @@ namespace api.core.Controllers;
[ApiController]
[Authorize(Policy = AuthPolicies.IsModerator)]
[Route("api/moderator/events")]
public class ModeratorEventsController(ILogger<ModeratorEventsController> logger, IEventService eventService, IReportService reportService) : ControllerBase
public class ModeratorEventsController(ILogger<ModeratorEventsController> logger, IEventService eventService, IReportService reportService, IUserService userService) : ControllerBase
{
[HttpPatch("{id}/state")]
public IActionResult UpdateEventState(Guid id, [FromQuery] State newState, [FromQuery] string? reason)
Expand Down Expand Up @@ -52,6 +53,12 @@ public ActionResult<IEnumerable<EventModeratorResponseDTO>> GetEventsModerator(
var paginatedRes = events
.Skip((pagination.PageNumber - 1) * pagination.PageSize)
.Take(pagination.PageSize)
.Select((e) =>
{
var organizer = userService.GetUser(e.Organizer.Id);
e.Organizer = organizer;
return e;
})
.ToList();

var response = PaginationHelper.CreatePaginatedReponse(paginatedRes, validFilter, totalRecords);
Expand Down
17 changes: 14 additions & 3 deletions core/Controllers/OrganizersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using api.core.Data;
using api.core.Data.Exceptions;
using api.core.Data.requests;
using api.core.Data.Requests;
using api.core.Data.Responses;
using api.core.Misc;
using api.core.services.abstractions;
Expand All @@ -10,6 +11,7 @@

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace api.core.controllers;

Expand Down Expand Up @@ -59,10 +61,19 @@ await emailService.SendEmailAsync(
}

[HttpGet]
public IActionResult GetUsers()
public IActionResult GetUsers(string? search, [FromQuery] PaginationRequest pagination)
{
var users = userService.GetUsers();
return Ok(new Response<IEnumerable<UserResponseDTO>> { Data = users });
var validFilter = new PaginationRequest(pagination.PageNumber, pagination.PageSize);
var users = userService.GetUsers(search);

var totalRecords = users.Count();
var paginatedRes = users
.Skip((pagination.PageNumber - 1) * pagination.PageSize)
.Take(pagination.PageSize)
.ToList();

var response = PaginationHelper.CreatePaginatedReponse(paginatedRes, validFilter, totalRecords);
return Ok(response);
}

[HttpPatch("{organizerId}/toggle")]
Expand Down
2 changes: 1 addition & 1 deletion core/Services/Abstractions/IUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface IUserService

public UserResponseDTO GetUser(Guid id);

public IEnumerable<UserResponseDTO> GetUsers();
public IEnumerable<UserResponseDTO> GetUsers(string? search);

public bool UpdateUser(Guid id, UserUpdateDTO dto);

Expand Down
11 changes: 7 additions & 4 deletions core/Services/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using api.core.services.abstractions;
using api.files.Services.Abstractions;

using Microsoft.OpenApi.Validations;

using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;

Expand Down Expand Up @@ -65,9 +63,14 @@ public UserResponseDTO GetUser(Guid id)
throw new Exception("No users associated with this ID");
}

public IEnumerable<UserResponseDTO> GetUsers()
public IEnumerable<UserResponseDTO> GetUsers(string? search)
{
var organizers = organizerRepository.GetAll();
var organizers = organizerRepository.GetAll()
.Where(x =>
x.ActivityArea.ToLower().Contains(search?.ToLower() ?? "") ||
x.Organization.ToLower().Contains(search?.ToLower() ?? "") ||
x.Email.ToLower().Contains(search?.ToLower() ?? "")
);
return organizers.Select(UserResponseDTO.Map);
}

Expand Down

0 comments on commit ae003dc

Please sign in to comment.