Skip to content

Commit

Permalink
PS-155 Get activity area (#37)
Browse files Browse the repository at this point in the history
* First draft

* get activity area

* Add activityArea migration

* Add fix for fetching activityArea

* Fix some tests

* Fix last test

* fix tests build

* ajust tolerance

* remove whiteline

* fix organizer return
  • Loading branch information
MysticFragilist authored Apr 5, 2024
1 parent 3c3f8c2 commit c0a416f
Show file tree
Hide file tree
Showing 34 changed files with 1,079 additions and 100 deletions.
32 changes: 32 additions & 0 deletions core/Controllers/ActivityAreaController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using api.core.Data;
using api.core.Data.Responses;
using api.core.Services.Abstractions;

using Microsoft.AspNetCore.Mvc;

namespace api.core.Controllers;

[ApiController]
[Route("api/activity-areas")]
public class ActivityAreaController(IActivityAreaService activityAreaService) : ControllerBase
{
[HttpGet]
public IActionResult GetAllActivityAreas([FromQuery] string? search)
{
var activityAreas = activityAreaService.GetAllActivityAreas(search);
return Ok(new Response<IEnumerable<ActivityAreaResponseDTO>>
{
Data = activityAreas
});
}

[HttpGet("{id}")]
public IActionResult GetAllActivityAreas(Guid id)
{
var activityArea = activityAreaService.GetActivityArea(id);
return Ok(new Response<ActivityAreaResponseDTO>
{
Data = activityArea
});
}
}
10 changes: 6 additions & 4 deletions core/Controllers/EventsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ActionResult<IEnumerable<EventResponseDTO>> GetEvents(
[FromQuery] DateTime? endDate,
[FromQuery] Guid? organizerId,
[FromQuery] string? title,
[FromQuery] IEnumerable<string>? activityAreas,
[FromQuery] IEnumerable<Guid>? activityAreas,
[FromQuery] IEnumerable<Guid>? tags,
[FromQuery] PaginationRequest pagination)
{
Expand All @@ -49,12 +49,14 @@ public ActionResult<IEnumerable<EventResponseDTO>> GetEvents(
var paginatedRes = events
.Skip((pagination.PageNumber - 1) * pagination.PageSize)
.Take(pagination.PageSize)
.ToList()
.Select((e) =>
{
var organizer = userService.GetUser(e.Organizer.Id);
e.Organizer = organizer;
var url = userService.GetUserAvatarUrl(e.Organizer.Id);
e.Organizer.AvatarUrl = url;
return e;
}).ToList();
})
.ToList();

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

Expand Down
7 changes: 4 additions & 3 deletions core/Controllers/ModeratorEventsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public IActionResult UpdateEventState(Guid id, [FromQuery] State newState, [From
public ActionResult<IEnumerable<EventModeratorResponseDTO>> GetEventsModerator(
[FromQuery] DateTime? startDate,
[FromQuery] DateTime? endDate,
[FromQuery] IEnumerable<string>? activityAreas,
[FromQuery] IEnumerable<Guid>? activityAreas,
[FromQuery] IEnumerable<Guid>? tags,
[FromQuery] string? title,
[FromQuery] OrderingRequest ordering,
Expand All @@ -53,10 +53,11 @@ public ActionResult<IEnumerable<EventModeratorResponseDTO>> GetEventsModerator(
var paginatedRes = events
.Skip((pagination.PageNumber - 1) * pagination.PageSize)
.Take(pagination.PageSize)
.ToList()
.Select((e) =>
{
var organizer = userService.GetUser(e.Organizer.Id);
e.Organizer = organizer;
var url = userService.GetUserAvatarUrl(e.Organizer.Id);
e.Organizer.AvatarUrl = url;
return e;
})
.ToList();
Expand Down
2 changes: 1 addition & 1 deletion core/Controllers/OrganizerEventsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class OrganizerEventsController(ILogger<OrganizerEventsController> logger
public IActionResult MyEvents(
[FromQuery] DateTime? startDate,
[FromQuery] DateTime? endDate,
[FromQuery] IEnumerable<string>? activityAreas,
[FromQuery] IEnumerable<Guid>? activityAreas,
[FromQuery] IEnumerable<Guid>? tags,
[FromQuery] string? title,
[FromQuery] OrderingRequest ordering,
Expand Down
10 changes: 8 additions & 2 deletions core/Controllers/OrganizersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,18 @@ await emailService.SendEmailAsync(
public IActionResult GetUsers(string? search, [FromQuery] PaginationRequest pagination)
{
var validFilter = new PaginationRequest(pagination.PageNumber, pagination.PageSize);
var users = userService.GetUsers(search);
var users = userService.GetUsers(search, out int totalRecords);

var totalRecords = users.Count();
var paginatedRes = users
.Skip((pagination.PageNumber - 1) * pagination.PageSize)
.Take(pagination.PageSize)
.ToList()
.Select((e) =>
{
var url = userService.GetUserAvatarUrl(e.Id);
e.AvatarUrl = url;
return e;
})
.ToList();

var response = PaginationHelper.CreatePaginatedReponse(paginatedRes, validFilter, totalRecords);
Expand Down
20 changes: 20 additions & 0 deletions core/Data/Entities/ActivityArea.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.ComponentModel.DataAnnotations.Schema;

using api.core.Data.Entities;


namespace api.core.data.entities;

[Table("ActivityArea")]
public partial class ActivityArea : BaseEntity
{
public string NameFr { get; set; } = null!;

public string NameEn { get; set; } = null!;

[InverseProperty("ActivityArea")]
public virtual ICollection<Organizer> Organizers { get; set; } = new List<Organizer>();

[InverseProperty("ActivityArea")]
public virtual ICollection<Moderator> Moderators { get; set; } = new List<Moderator>();
}
4 changes: 4 additions & 0 deletions core/Data/Entities/Moderator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ public partial class Moderator : User
{
[InverseProperty("Moderator")]
public virtual ICollection<Publication> Publications { get; set; } = new List<Publication>();

[ForeignKey("ActivityAreaId")]
[InverseProperty("Moderators")]
public virtual ActivityArea? ActivityArea { get; set; }
}
9 changes: 5 additions & 4 deletions core/Data/Entities/Organizer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations.Schema;

using api.core.Data.Entities;

Expand All @@ -10,8 +9,6 @@ public partial class Organizer : User
{
public string Organization { get; set; } = null!;

public string ActivityArea { get; set; } = null!;

public string ProfileDescription { get; set; } = null!;

public bool IsActive { get; set; }
Expand All @@ -36,4 +33,8 @@ public partial class Organizer : User

[InverseProperty("Organizer")]
public virtual ICollection<Publication> Publications { get; set; } = new List<Publication>();

[ForeignKey("ActivityAreaId")]
[InverseProperty("Organizers")]
public virtual ActivityArea? ActivityArea { get; set; }
}
1 change: 1 addition & 0 deletions core/Data/Entities/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public class User : BaseEntity
{
public string Email { get; set; } = null!;

public Guid? ActivityAreaId { get; set; }
}
2 changes: 2 additions & 0 deletions core/Data/EventManagementContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public EventManagementContext(DbContextOptions<EventManagementContext> options)

public virtual DbSet<Tag> Tags { get; set; }

public virtual DbSet<ActivityArea> ActivityAreas { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Event>(entity =>
Expand Down
2 changes: 1 addition & 1 deletion core/Data/Requests/UserRequestDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class UserCreateDTO

public string? Organization { get; set; } = null!;

public string? ActivityArea { get; set; } = null!;
public Guid? ActivityAreaId { get; set; } = null!;
}

public class UserUpdateDTO : UserCreateDTO
Expand Down
28 changes: 28 additions & 0 deletions core/Data/Responses/ActivityAreaResponseDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using api.core.data.entities;

namespace api.core.Data.Responses;

public class ActivityAreaResponseDTO
{
public Guid Id { get; set; }

public string? NameFr { get; set; } = null!;

public string? NameEn { get; set; } = null!;

public DateTime CreatedAt { get; set; }

public DateTime UpdatedAt { get; set; }

public static ActivityAreaResponseDTO Map(ActivityArea aArea)
{
return new ActivityAreaResponseDTO
{
Id = aArea.Id,
NameFr = aArea.NameFr,
NameEn = aArea.NameEn,
CreatedAt = aArea.CreatedAt,
UpdatedAt = aArea.UpdatedAt,
};
}
}
2 changes: 1 addition & 1 deletion core/Data/Responses/EventResponseDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class EventResponseDTO

public string? ImageUrl { get; set; }

public string ImageAltText { get; set; } = null!;
public string? ImageAltText { get; set; } = null!;

public State State { get; set; }

Expand Down
6 changes: 4 additions & 2 deletions core/Data/Responses/UserResponseDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class UserResponseDTO

public string? Organization { get; set; }

public string? ActivityArea { get; set; }
public ActivityAreaResponseDTO? ActivityArea { get; set; }

public bool IsActive { get; set; }

Expand Down Expand Up @@ -52,7 +52,9 @@ public static UserResponseDTO Map(Organizer organizer)
Email = organizer.Email,
Type = "Organizer",
Organization = organizer.Organization,
ActivityArea = organizer.ActivityArea,
ActivityArea = organizer.ActivityArea != null ?
ActivityAreaResponseDTO.Map(organizer.ActivityArea) :
null,
IsActive = organizer.IsActive,
HasLoggedIn = organizer.HasLoggedIn,
ProfileDescription = organizer.ProfileDescription,
Expand Down
3 changes: 3 additions & 0 deletions core/Extensions/DependencyInjectionExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using api.core.repositories.abstractions;
using api.core.services.abstractions;
using api.core.Services;
using api.core.Services.Abstractions;
using api.emails.Services;
using api.emails.Services.Abstractions;
using api.files.Services;
Expand All @@ -27,6 +28,7 @@ public static IServiceCollection AddDependencyInjection(this IServiceCollection
services.AddTransient<IEventRepository, EventRepository>();
services.AddTransient<IModeratorRepository, ModeratorRepository>();
services.AddTransient<IReportRepository, ReportRepository>();
services.AddTransient<IActivityAreaRepository, ActivityAreaRepository>();

// Services
services.AddTransient<IUserService, UserService>();
Expand All @@ -36,6 +38,7 @@ public static IServiceCollection AddDependencyInjection(this IServiceCollection
services.AddTransient<ITagService, TagService>();
services.AddTransient<IAuthService, AuthService>();
services.AddTransient<IReportService, ReportService>();
services.AddTransient<IActivityAreaService, ActivityAreaService>();
services.AddTransient<IModeratorService, ModeratorService>();

return services;
Expand Down
Loading

0 comments on commit c0a416f

Please sign in to comment.