From c67cdf8dd89bf93c7a7d928d0ebaa113081238e6 Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Sun, 22 Feb 2026 16:02:34 +0100 Subject: [PATCH] Endpoints to see groups --- BeReadyBackend/BeReadyBackend.csproj | 1 - .../DTO/Groups/GetGroupDetailsDto.cs | 17 +++++++++++++ BeReadyBackend/DTO/Groups/GetGroupDto.cs | 8 +++++++ BeReadyBackend/DTO/Messages/GetMessageDto.cs | 10 ++++++++ .../Endpoints/Groups/GetAllGroupsEndpoint.cs | 23 ++++++++++++++++++ .../Groups/GetGroupDetailsEndpoint.cs | 24 +++++++++++++++++++ .../MappingProfiles/EntityToDtoMappings.cs | 13 ++++++++++ .../Specifications/Groups/GetGroupByIdSpec.cs | 4 +++- .../Groups/GetGroupsByUserIdSpec.cs | 14 +++++++++++ 9 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 BeReadyBackend/DTO/Groups/GetGroupDetailsDto.cs create mode 100644 BeReadyBackend/DTO/Groups/GetGroupDto.cs create mode 100644 BeReadyBackend/DTO/Messages/GetMessageDto.cs create mode 100644 BeReadyBackend/Endpoints/Groups/GetAllGroupsEndpoint.cs create mode 100644 BeReadyBackend/Endpoints/Groups/GetGroupDetailsEndpoint.cs create mode 100644 BeReadyBackend/Specifications/Groups/GetGroupsByUserIdSpec.cs diff --git a/BeReadyBackend/BeReadyBackend.csproj b/BeReadyBackend/BeReadyBackend.csproj index 90499a8..1697993 100644 --- a/BeReadyBackend/BeReadyBackend.csproj +++ b/BeReadyBackend/BeReadyBackend.csproj @@ -27,7 +27,6 @@ - diff --git a/BeReadyBackend/DTO/Groups/GetGroupDetailsDto.cs b/BeReadyBackend/DTO/Groups/GetGroupDetailsDto.cs new file mode 100644 index 0000000..254b17c --- /dev/null +++ b/BeReadyBackend/DTO/Groups/GetGroupDetailsDto.cs @@ -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? Messages { get; set; } + public List? Users { get; set; } +} \ No newline at end of file diff --git a/BeReadyBackend/DTO/Groups/GetGroupDto.cs b/BeReadyBackend/DTO/Groups/GetGroupDto.cs new file mode 100644 index 0000000..b1a108a --- /dev/null +++ b/BeReadyBackend/DTO/Groups/GetGroupDto.cs @@ -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; } +} \ No newline at end of file diff --git a/BeReadyBackend/DTO/Messages/GetMessageDto.cs b/BeReadyBackend/DTO/Messages/GetMessageDto.cs new file mode 100644 index 0000000..76bceac --- /dev/null +++ b/BeReadyBackend/DTO/Messages/GetMessageDto.cs @@ -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; } +} \ No newline at end of file diff --git a/BeReadyBackend/Endpoints/Groups/GetAllGroupsEndpoint.cs b/BeReadyBackend/Endpoints/Groups/GetAllGroupsEndpoint.cs new file mode 100644 index 0000000..7915b5a --- /dev/null +++ b/BeReadyBackend/Endpoints/Groups/GetAllGroupsEndpoint.cs @@ -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> +{ + public override void Configure() + { + Get("/Groups/Users/"); + } + + public override async Task HandleAsync(CancellationToken ct) + { + int userId = userService.GetUserIdFromToken(); + + List groups = await userGroupsRepository.ProjectToListAsync(new GetGroupsByUserIdSpec(userId), ct); + await Send.OkAsync(groups, ct); + } +} \ No newline at end of file diff --git a/BeReadyBackend/Endpoints/Groups/GetGroupDetailsEndpoint.cs b/BeReadyBackend/Endpoints/Groups/GetGroupDetailsEndpoint.cs new file mode 100644 index 0000000..58f5dce --- /dev/null +++ b/BeReadyBackend/Endpoints/Groups/GetGroupDetailsEndpoint.cs @@ -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 +{ + 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(new GetGroupByIdSpec(req.Id), ct), ct); + } +} \ No newline at end of file diff --git a/BeReadyBackend/MappingProfiles/EntityToDtoMappings.cs b/BeReadyBackend/MappingProfiles/EntityToDtoMappings.cs index 5b74d83..0d03362 100644 --- a/BeReadyBackend/MappingProfiles/EntityToDtoMappings.cs +++ b/BeReadyBackend/MappingProfiles/EntityToDtoMappings.cs @@ -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() + .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() + .ForMember(dest => dest.Users, opt => opt.MapFrom(src => src.UserGroups)) + .ForMember(dest => dest.Messages, opt => opt.MapFrom(src => src.Messages)); + + CreateMap() + .ForMember(dest => dest.Username, opt => opt.MapFrom(src => src.User!.Username)); } } \ No newline at end of file diff --git a/BeReadyBackend/Specifications/Groups/GetGroupByIdSpec.cs b/BeReadyBackend/Specifications/Groups/GetGroupByIdSpec.cs index 12851ab..97afd11 100644 --- a/BeReadyBackend/Specifications/Groups/GetGroupByIdSpec.cs +++ b/BeReadyBackend/Specifications/Groups/GetGroupByIdSpec.cs @@ -8,7 +8,9 @@ public class GetGroupByIdSpec : SingleResultSpecification 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); } } \ No newline at end of file diff --git a/BeReadyBackend/Specifications/Groups/GetGroupsByUserIdSpec.cs b/BeReadyBackend/Specifications/Groups/GetGroupsByUserIdSpec.cs new file mode 100644 index 0000000..63efa85 --- /dev/null +++ b/BeReadyBackend/Specifications/Groups/GetGroupsByUserIdSpec.cs @@ -0,0 +1,14 @@ +using Ardalis.Specification; +using BeReadyBackend.Models; + +namespace BeReadyBackend.Specifications.Groups; + +public class GetGroupsByUserIdSpec : Specification +{ + public GetGroupsByUserIdSpec(int userId) + { + Query + .Include(x => x.Group) + .Where(x => x.UserId == userId); + } +} \ No newline at end of file