Skip to content

Commit

Permalink
feat: instead of just returning clubMembers, sort them in clubOwners,…
Browse files Browse the repository at this point in the history
… clubModerators, clubMembers
  • Loading branch information
peageon committed Jul 23, 2024
1 parent 5ece368 commit a935cec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.runningmate.backend.club.Club;
import com.runningmate.backend.club.ClubMemberEntity;
import com.runningmate.backend.club.ClubRole;
import com.runningmate.backend.member.dto.MemberDto;
import com.runningmate.backend.route.dto.CoordinateDto;
import com.runningmate.backend.schedule.Schedule;
Expand All @@ -11,6 +12,7 @@
import org.locationtech.jts.geom.Point;

import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;

Expand All @@ -27,10 +29,22 @@ public class ClubResponseDto {
private CoordinateDto locationCoordinate;
private String profilePic;
private String backgroundPic;
private List<MemberDto> clubOwners;
private List<MemberDto> clubModerators;
private List<MemberDto> clubMembers;
private List<ClubScheduleEntityResponseDto> schedules;

public static ClubResponseDto fromEntity(Club club) {
Map<ClubRole, List<MemberDto>> groupedMembers = club.getMembers().stream()
.collect(Collectors.groupingBy(
ClubMemberEntity::getRole,
Collectors.mapping(clubMember -> MemberDto.fromEntity(clubMember.getMember()), Collectors.toList())
));

List<MemberDto> owners = groupedMembers.getOrDefault(ClubRole.OWNER, List.of());
List<MemberDto> moderators = groupedMembers.getOrDefault(ClubRole.MODERATOR, List.of());
List<MemberDto> members = groupedMembers.getOrDefault(ClubRole.MEMBER, List.of());

return ClubResponseDto.builder()
.id(club.getId())
.title(club.getTitle())
Expand All @@ -39,10 +53,9 @@ public static ClubResponseDto fromEntity(Club club) {
.locationCoordinate(PointCreator.toCoordinateDto(club.getLocationCoordinate()))
.profilePic(club.getProfile_pic())
.backgroundPic(club.getBackground_pic())
.clubMembers(club.getMembers().stream()
.map(ClubMemberEntity::getMember)
.map(MemberDto::fromEntity)
.collect(Collectors.toList()))
.clubOwners(owners)
.clubModerators(moderators)
.clubMembers(members)
.schedules(club.getSchedules().stream()
.map(clubScheduleEntity -> ClubScheduleEntityResponseDto.fromEntity(clubScheduleEntity))
.collect(Collectors.toList()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static Point createPoint(double longitude, double latitude) {

public static CoordinateDto toCoordinateDto(Point point) {
if (point == null) {
throw new IllegalArgumentException("Point cannot be null");
return null;
}
return new CoordinateDto(point.getY(), point.getX());
}
Expand Down

0 comments on commit a935cec

Please sign in to comment.