Endpoints to see groups
This commit is contained in:
@@ -27,7 +27,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="DTO\Messages\" />
|
||||
<Folder Include="DTO\RandomChallenges\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using BeReadyBackend.DTO.Messages;
|
||||
|
||||
namespace BeReadyBackend.DTO.Groups;
|
||||
|
||||
public class GetGroupDetailsDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? Label { get; set; }
|
||||
public bool IsFinished { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public int Duration { get; set; }
|
||||
public DateTime CreationDate { get; set; }
|
||||
|
||||
public List<GetMessageDto>? Messages { get; set; }
|
||||
public List<GetUserGroupDto>? Users { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace BeReadyBackend.DTO.Groups;
|
||||
|
||||
public class GetGroupDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? Label { get; set; }
|
||||
public bool IsFinished { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace BeReadyBackend.DTO.Messages;
|
||||
|
||||
public class GetMessageDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? Libelle { get; set; }
|
||||
public DateTime SendDate { get; set; }
|
||||
public int UserId { get; set; }
|
||||
public string? Username { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using BeReadyBackend.DTO.Groups;
|
||||
using BeReadyBackend.Repositories;
|
||||
using BeReadyBackend.Services;
|
||||
using BeReadyBackend.Specifications.Groups;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace BeReadyBackend.Endpoints.Groups;
|
||||
|
||||
public class GetAllGroupsEndpoint(UserGroupsRepository userGroupsRepository, UserService userService) : EndpointWithoutRequest<List<GetGroupDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/Groups/Users/");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
int userId = userService.GetUserIdFromToken();
|
||||
|
||||
List<GetGroupDto> groups = await userGroupsRepository.ProjectToListAsync<GetGroupDto>(new GetGroupsByUserIdSpec(userId), ct);
|
||||
await Send.OkAsync(groups, ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using BeReadyBackend.DTO.Groups;
|
||||
using BeReadyBackend.Repositories;
|
||||
using BeReadyBackend.Specifications.Groups;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace BeReadyBackend.Endpoints.Groups;
|
||||
|
||||
public class GroupRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetGroupDetailsEndpoint(GroupsRepository groupsRepository) : Endpoint<GroupRequest, GetGroupDetailsDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/Groups/{@Id}/", x => new { x.Id });
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GroupRequest req, CancellationToken ct)
|
||||
{
|
||||
await Send.OkAsync(await groupsRepository.ProjectToSingleAsync<GetGroupDetailsDto>(new GetGroupByIdSpec(req.Id), ct), ct);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using BeReadyBackend.DTO.Achievements;
|
||||
using BeReadyBackend.DTO.Friends;
|
||||
using BeReadyBackend.DTO.Groups;
|
||||
using BeReadyBackend.DTO.Messages;
|
||||
using BeReadyBackend.DTO.Users;
|
||||
using BeReadyBackend.Models;
|
||||
using NSwag.Generation.Processors;
|
||||
@@ -51,5 +52,17 @@ public class EntityToDtoMappings : Profile
|
||||
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.UserId))
|
||||
.ForMember(dest => dest.Username, opt => opt.MapFrom(src => src.User!.Username))
|
||||
.ForMember(dest => dest.Score, opt => opt.MapFrom(src => src.User!.Score));
|
||||
|
||||
CreateMap<UserGroup, GetGroupDto>()
|
||||
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.GroupId))
|
||||
.ForMember(dest => dest.Label, opt => opt.MapFrom(src => src.Group!.Label))
|
||||
.ForMember(dest => dest.IsFinished, opt => opt.MapFrom(src => src.Group!.IsFinished));
|
||||
|
||||
CreateMap<Group, GetGroupDetailsDto>()
|
||||
.ForMember(dest => dest.Users, opt => opt.MapFrom(src => src.UserGroups))
|
||||
.ForMember(dest => dest.Messages, opt => opt.MapFrom(src => src.Messages));
|
||||
|
||||
CreateMap<Message, GetMessageDto>()
|
||||
.ForMember(dest => dest.Username, opt => opt.MapFrom(src => src.User!.Username));
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,9 @@ public class GetGroupByIdSpec : SingleResultSpecification<Group>
|
||||
public GetGroupByIdSpec(int groupId)
|
||||
{
|
||||
Query
|
||||
.Include(x => x.UserGroups)
|
||||
.Include(x => x.UserGroups!)
|
||||
.ThenInclude(x => x.User)
|
||||
.Include(x => x.Messages)
|
||||
.Where(x => x.Id == groupId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Ardalis.Specification;
|
||||
using BeReadyBackend.Models;
|
||||
|
||||
namespace BeReadyBackend.Specifications.Groups;
|
||||
|
||||
public class GetGroupsByUserIdSpec : Specification<UserGroup>
|
||||
{
|
||||
public GetGroupsByUserIdSpec(int userId)
|
||||
{
|
||||
Query
|
||||
.Include(x => x.Group)
|
||||
.Where(x => x.UserId == userId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user