From e656edcfee9a04040068c0d793a6c39b3103f859 Mon Sep 17 00:00:00 2001 From: kim_sang_ june <79149384+drbug2000@users.noreply.github.com> Date: Tue, 8 Oct 2024 01:22:34 +0900 Subject: [PATCH 01/15] [feat] add VoiceRoomParticipant Service --- .../service/VoiceRoomParticipantService.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/main/java/space/space_spring/service/VoiceRoomParticipantService.java diff --git a/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java b/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java new file mode 100644 index 00000000..8dab1ba1 --- /dev/null +++ b/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java @@ -0,0 +1,49 @@ +package space.space_spring.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import space.space_spring.dao.UserSpaceDao; +import space.space_spring.dao.VoiceRoomRepository; +import space.space_spring.domain.user.repository.UserDao; +import space.space_spring.dto.VoiceRoom.GetParticipantList; +import space.space_spring.dto.VoiceRoom.ParticipantDto; +import space.space_spring.entity.Space; +import space.space_spring.entity.User; +import space.space_spring.entity.UserSpace; +import space.space_spring.util.LiveKitUtils; + +import java.util.Collections; +import java.util.List; + +@Service +@RequiredArgsConstructor +public class VoiceRoomParticipantService { + final private UserSpaceDao userSpaceDao; + final private UserDao userDao; + final private VoiceRoomRepository voiceRoomRepository; + final private LiveKitUtils liveKitUtils; + public List getParticipantInfoListById(long voiceRoomId){ + return GetParticipantList.ParticipantInfo.convertParticipantDtoList( + getParticipantDtoListById(voiceRoomId) + //liveKitUtils.getParticipantInfo(findNameTagById(voiceRoomId)) + ); + } + private List getParticipantDtoListById(long voiceRoomId){ + Space space = voiceRoomRepository.findById(voiceRoomId).getSpace(); + List participantDtoList = liveKitUtils.getParticipantInfo(String.valueOf(voiceRoomId)); + if(participantDtoList==null||participantDtoList.isEmpty()){ + return Collections.emptyList(); + } + for(ParticipantDto participantDto: participantDtoList){ + //profileIamge 집어넣기 + participantDto.setProfileImage(findProfileImageByUserId(participantDto.getUserSpaceId())); + //userSpaceId 집어 넣기 + User user = userDao.findUserByUserId(participantDto.getId()); + participantDto.setUserSpaceId(userSpaceDao.findUserSpaceByUserAndSpace(user,space).get().getUserSpaceId()); + } + return participantDtoList; + } + private String findProfileImageByUserId(Long userSpaceId){ + return userSpaceDao.findProfileImageById(userSpaceId).orElse(""); + } +} From 672f8e82a07284f050b191968c1a855dd6bcc108 Mon Sep 17 00:00:00 2001 From: kim_sang_ june <79149384+drbug2000@users.noreply.github.com> Date: Tue, 8 Oct 2024 01:22:59 +0900 Subject: [PATCH 02/15] [feat] add ParticipantListDto --- .../dto/VoiceRoom/ParticipantListDto.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java b/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java new file mode 100644 index 00000000..dfd2639c --- /dev/null +++ b/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java @@ -0,0 +1,17 @@ +package space.space_spring.dto.VoiceRoom; + +import java.util.List; + +public class ParticipantListDto { + + + private List participantDtoList; + + private ParticipantListDto(List participantDtoList){ + this.participantDtoList=participantDtoList; + } + public ParticipantListDto from(List participantDtoList ){ + + return new ParticipantListDto(participantDtoList); + } +} From 220227c42d0ca03ccff978f9a1a8c7068d206818 Mon Sep 17 00:00:00 2001 From: kim_sang_ june <79149384+drbug2000@users.noreply.github.com> Date: Tue, 8 Oct 2024 18:56:25 +0900 Subject: [PATCH 03/15] [feat] add function parameter to set Participant Profile --- .../space_spring/dto/VoiceRoom/ParticipantListDto.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java b/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java index dfd2639c..fcfcee88 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java @@ -1,6 +1,7 @@ package space.space_spring.dto.VoiceRoom; import java.util.List; +import java.util.function.Function; public class ParticipantListDto { @@ -14,4 +15,11 @@ public ParticipantListDto from(List participantDtoList ){ return new ParticipantListDto(participantDtoList); } + + public void setProfileImage(Function profileFinder){ + this.participantDtoList.forEach(participantDto -> { + String profileImage = profileFinder.apply(participantDto.getUserSpaceId()); + participantDto.setProfileImage(profileImage); + }); + } } From a4d3d44a123d713eaf75d33babf7aba036a7e5ae Mon Sep 17 00:00:00 2001 From: kim_sang_ june <79149384+drbug2000@users.noreply.github.com> Date: Tue, 8 Oct 2024 19:29:53 +0900 Subject: [PATCH 04/15] [refactoring] convert Identity LiveKit token userId->userSpaceId --- .../space/space_spring/dto/VoiceRoom/GetParticipantList.java | 4 ++-- .../space/space_spring/dto/VoiceRoom/ParticipantDto.java | 5 ++++- .../space_spring/service/VoiceRoomParticipantService.java | 3 --- .../java/space/space_spring/service/VoiceRoomService.java | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/GetParticipantList.java b/src/main/java/space/space_spring/dto/VoiceRoom/GetParticipantList.java index 1162694d..bf1b4865 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/GetParticipantList.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/GetParticipantList.java @@ -28,7 +28,7 @@ public static class Response{ @Setter public static class ParticipantInfo{ private String name; - private Long userId; + private Long id; private Long userSpaceId; private boolean isMute; private String profileImage; @@ -39,7 +39,7 @@ public static ParticipantInfo convertParticipantDto(ParticipantDto participantDt .name(participantDto.getName()) .isMute(participantDto.isMicMute()) .profileImage(participantDto.getProfileImage()) - .userId(participantDto.getId()) + .id(participantDto.getId()) .userSpaceId(participantDto.getUserSpaceId()) .build(); } diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantDto.java b/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantDto.java index fde26d46..ffb2065b 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantDto.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantDto.java @@ -31,8 +31,11 @@ public void setProfileImage(String imageUrl){ public static ParticipantDto convertParticipant(LivekitModels.ParticipantInfo participantInfo){ if(participantInfo==null){return null;} + Long id = Long.valueOf(participantInfo.getIdentity()); + Long userSpaceId = id; return ParticipantDto.builder() - .id(Long.valueOf(participantInfo.getIdentity())) + .id(id) + .userSpaceId(userSpaceId) .name(participantInfo.getName()) .isMicMute(checkMicMute(participantInfo.getTracksList())) diff --git a/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java b/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java index 8dab1ba1..e05ecb83 100644 --- a/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java +++ b/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java @@ -37,9 +37,6 @@ private List getParticipantDtoListById(long voiceRoomId){ for(ParticipantDto participantDto: participantDtoList){ //profileIamge 집어넣기 participantDto.setProfileImage(findProfileImageByUserId(participantDto.getUserSpaceId())); - //userSpaceId 집어 넣기 - User user = userDao.findUserByUserId(participantDto.getId()); - participantDto.setUserSpaceId(userSpaceDao.findUserSpaceByUserAndSpace(user,space).get().getUserSpaceId()); } return participantDtoList; } diff --git a/src/main/java/space/space_spring/service/VoiceRoomService.java b/src/main/java/space/space_spring/service/VoiceRoomService.java index c831ef89..b6f60f02 100644 --- a/src/main/java/space/space_spring/service/VoiceRoomService.java +++ b/src/main/java/space/space_spring/service/VoiceRoomService.java @@ -297,7 +297,7 @@ private String findNameTagById(long id){ public String getToken(long spaceId,long userId,long userSpaceId,long voiceRoomId){ String userName=userSpaceDao.findUserNameById(userSpaceId); - String userIdentity=String.valueOf(userId); + String userIdentity=String.valueOf(userSpaceId); //Metadata에 profileImage와 userName 추가 String metadata="userProfileImage : "+userSpaceDao.findProfileImageById(userSpaceId).orElse(""); //String roomName=findNameTagById(voiceRoomId); From f87f52e69b48ca931623d476d564166e587f19e6 Mon Sep 17 00:00:00 2001 From: kim_sang_ june <79149384+drbug2000@users.noreply.github.com> Date: Tue, 8 Oct 2024 20:30:25 +0900 Subject: [PATCH 05/15] [feat] add setProfileImage func param --- .../controller/VoiceRoomController.java | 7 ++- .../dto/VoiceRoom/ParticipantListDto.java | 15 ++++- .../service/VoiceRoomParticipantService.java | 26 ++++----- .../service/VoiceRoomService.java | 55 ++++++++++--------- 4 files changed, 61 insertions(+), 42 deletions(-) diff --git a/src/main/java/space/space_spring/controller/VoiceRoomController.java b/src/main/java/space/space_spring/controller/VoiceRoomController.java index c2aad928..2926c16d 100644 --- a/src/main/java/space/space_spring/controller/VoiceRoomController.java +++ b/src/main/java/space/space_spring/controller/VoiceRoomController.java @@ -16,6 +16,7 @@ import space.space_spring.exception.CustomException; import space.space_spring.response.BaseResponse; import space.space_spring.service.LiveKitService; +import space.space_spring.service.VoiceRoomParticipantService; import space.space_spring.service.VoiceRoomService; import space.space_spring.util.space.SpaceUtils; import space.space_spring.util.user.UserUtils; @@ -40,6 +41,7 @@ public class VoiceRoomController { private final UserSpaceDao userSpaceDao; private final UserUtils userUtils; private final SpaceUtils spaceUtils; + private final VoiceRoomParticipantService voiceRoomParticipantService; //VoiceRoom 생성/수정 @PostMapping("") @@ -143,10 +145,11 @@ public BaseResponse getParticipants( //해당 voiceRoom이 해당 space에 속한것이 맞는지 확인 validateVoiceRoomInSpace(spaceId,roomId); - List participantInfoList = voiceRoomService.getParticipantInfoListById(roomId); + //List participantInfoList = voiceRoomService.getParticipantInfoListById(roomId); + List participantInfoList = voiceRoomParticipantService.getParticipantInfoListById(roomId); + return new BaseResponse(new GetParticipantList.Response(participantInfoList)); } - @PatchMapping("") public BaseResponse updateVoiceRoom( @PathVariable("spaceId") @NotNull long spaceId, diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java b/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java index fcfcee88..71c4bf7a 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java @@ -1,7 +1,9 @@ package space.space_spring.dto.VoiceRoom; +import java.util.Collections; import java.util.List; import java.util.function.Function; +import java.util.stream.Collectors; public class ParticipantListDto { @@ -11,7 +13,7 @@ public class ParticipantListDto { private ParticipantListDto(List participantDtoList){ this.participantDtoList=participantDtoList; } - public ParticipantListDto from(List participantDtoList ){ + public static ParticipantListDto from(List participantDtoList ){ return new ParticipantListDto(participantDtoList); } @@ -22,4 +24,15 @@ public void setProfileImage(Function profileFinder){ participantDto.setProfileImage(profileImage); }); } + + + + //Todo 생성/변환 책임분리 필요 + public List convertParticipantDtoList(){ + if(this.participantDtoList==null){System.out.print("\n[DEBUG] participant List is NULL\n"); return null;} + if(this.participantDtoList.isEmpty()){System.out.print("\n[DEBUG] participant List is Empty\n"); return Collections.emptyList();} + return this.participantDtoList.stream() + .map(GetParticipantList.ParticipantInfo::convertParticipantDto) + .collect(Collectors.toList()); + } } diff --git a/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java b/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java index e05ecb83..a17acff7 100644 --- a/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java +++ b/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java @@ -7,6 +7,7 @@ import space.space_spring.domain.user.repository.UserDao; import space.space_spring.dto.VoiceRoom.GetParticipantList; import space.space_spring.dto.VoiceRoom.ParticipantDto; +import space.space_spring.dto.VoiceRoom.ParticipantListDto; import space.space_spring.entity.Space; import space.space_spring.entity.User; import space.space_spring.entity.UserSpace; @@ -23,22 +24,21 @@ public class VoiceRoomParticipantService { final private VoiceRoomRepository voiceRoomRepository; final private LiveKitUtils liveKitUtils; public List getParticipantInfoListById(long voiceRoomId){ - return GetParticipantList.ParticipantInfo.convertParticipantDtoList( - getParticipantDtoListById(voiceRoomId) - //liveKitUtils.getParticipantInfo(findNameTagById(voiceRoomId)) - ); + return getParticipantDtoListById(voiceRoomId).convertParticipantDtoList(); } - private List getParticipantDtoListById(long voiceRoomId){ + private ParticipantListDto getParticipantDtoListById(long voiceRoomId){ Space space = voiceRoomRepository.findById(voiceRoomId).getSpace(); - List participantDtoList = liveKitUtils.getParticipantInfo(String.valueOf(voiceRoomId)); - if(participantDtoList==null||participantDtoList.isEmpty()){ - return Collections.emptyList(); + //Todo 다른 네이밍 고려 + List participantDtos = liveKitUtils.getParticipantInfo(String.valueOf(voiceRoomId)); + if(participantDtos==null || participantDtos.isEmpty()){ + participantDtos = Collections.emptyList(); } - for(ParticipantDto participantDto: participantDtoList){ - //profileIamge 집어넣기 - participantDto.setProfileImage(findProfileImageByUserId(participantDto.getUserSpaceId())); - } - return participantDtoList; + + ParticipantListDto participantListDto = ParticipantListDto.from(participantDtos); + + + participantListDto.setProfileImage(this::findProfileImageByUserId); + return participantListDto; } private String findProfileImageByUserId(Long userSpaceId){ return userSpaceDao.findProfileImageById(userSpaceId).orElse(""); diff --git a/src/main/java/space/space_spring/service/VoiceRoomService.java b/src/main/java/space/space_spring/service/VoiceRoomService.java index b6f60f02..73483a75 100644 --- a/src/main/java/space/space_spring/service/VoiceRoomService.java +++ b/src/main/java/space/space_spring/service/VoiceRoomService.java @@ -34,6 +34,7 @@ public class VoiceRoomService { private final UserDao userDao; private final UserSpaceDao userSpaceDao; private final TaskExecutor taskExecutor; + private final VoiceRoomParticipantService voiceRoomParticipantService; public Long createVoiceRoom(long spaceId,PostVoiceRoomDto.Request req){ Space targetSpace = spaceUtils.findSpaceBySpaceId(spaceId); @@ -65,32 +66,34 @@ public List getVoiceRoomInfoList(long spaceId,Ge for(RoomDto roomDto : roomDtoList){ roomDto.setActiveRoom(roomResponses); } + + //participant mapping - if (showParticipant) { - for(RoomDto roomDto : roomDtoList) { - if(roomDto.getNumParticipants()==0){ - //showParticipant = ture 일때, 참가자가 없으면 빈문자열[] 출력 - System.out.print("\n[DEBUG]Participant Number : 0\n"); - roomDto.setParticipantDTOList(Collections.emptyList()); - continue; - } - //participantDto List 가져오기 - List participantDtoList = getParticipantDtoListById(roomDto.getId()); - for(ParticipantDto participantDto: participantDtoList){ - //Todo profileIamge 집어넣기 - participantDto.setProfileImage(findProfileImageByUserId(participantDto.getUserSpaceId())); - } - //RoomDto에 값 집어넣기 - //showParticipant = ture 일때, 참가자가 없으면 빈문자열[] 출력 - if(participantDtoList==null||participantDtoList.isEmpty()){ - System.out.print("\n\n[DEBUG]participant response is empty or null"+participantDtoList.toString()+ - "participant number is \n\n"); - roomDto.setParticipantDTOList(Collections.emptyList()); - }else { - roomDto.setParticipantDTOList(participantDtoList); - } - } - } +// if (showParticipant) { +// for(RoomDto roomDto : roomDtoList) { +// if(roomDto.getNumParticipants()==0){ +// //showParticipant = ture 일때, 참가자가 없으면 빈문자열[] 출력 +// System.out.print("\n[DEBUG]Participant Number : 0\n"); +// roomDto.setParticipantDTOList(Collections.emptyList()); +// continue; +// } +// //participantDto List 가져오기 +// List participantDtoList = getParticipantDtoListById(roomDto.getId()); +// for(ParticipantDto participantDto: participantDtoList){ +// //Todo profileIamge 집어넣기 +// participantDto.setProfileImage(findProfileImageByUserId(participantDto.getUserSpaceId())); +// } +// //RoomDto에 값 집어넣기 +// //showParticipant = ture 일때, 참가자가 없으면 빈문자열[] 출력 +// if(participantDtoList==null||participantDtoList.isEmpty()){ +// System.out.print("\n\n[DEBUG]participant response is empty or null"+participantDtoList.toString()+ +// "participant number is \n\n"); +// roomDto.setParticipantDTOList(Collections.emptyList()); +// }else { +// roomDto.setParticipantDTOList(participantDtoList); +// } +// } +// } //ToDo Response로 convert //#1 Active/inActive 분리 @@ -136,7 +139,7 @@ public List getVoiceRoomInfoListConcurrency(long //.exceptionally(ex->{throws ex;}) ) .collect(Collectors.toList()); - + // 모든 Future의 완료를 기다림 CompletableFuture allOf = CompletableFuture.allOf( From 138efdb7dd19049a4be328cf3f909dd89f9e236d Mon Sep 17 00:00:00 2001 From: kim_sang_ june <79149384+drbug2000@users.noreply.github.com> Date: Wed, 9 Oct 2024 03:07:41 +0900 Subject: [PATCH 06/15] [refactoring] change RoomDto value RoomList->ListDto --- .../space_spring/dto/VoiceRoom/RoomDto.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java b/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java index 5183274a..b6c3415e 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java @@ -20,23 +20,28 @@ public class RoomDto { private int numParticipants; private long startTime; //time Stamp private long createdAt; - private List participantDTOList; + //private List participantDTOList; + private ParticipantListDto participantListDto; private int order; private String sid; private String metadata; - public void setParticipantDTOListByInfo(List participantInfoList){ - if(participantInfoList==null||participantInfoList.isEmpty()){return;} - this.participantDTOList = participantInfoList.stream() - .map(ParticipantDto::convertParticipant) - .collect(Collectors.toList()); - } +// public void setParticipantDTOListByInfo(List participantInfoList){ +// if(participantInfoList==null||participantInfoList.isEmpty()){return;} +// this.participantDTOList = participantInfoList.stream() +// .map(ParticipantDto::convertParticipant) +// .collect(Collectors.toList()); +// } public RoomDto setParticipantDTOList(List participantDtoList){ - this.participantDTOList = participantDtoList; + this.participantListDto= ParticipantListDto.from(participantDtoList); return this; } + public RoomDto setParticipantDTOList(ParticipantListDto participants){ + this.participantListDto = participants; + return this; + } public static RoomDto convertRoom(LivekitModels.Room room){ if(room==null){return null;} return RoomDto.builder() @@ -45,7 +50,7 @@ public static RoomDto convertRoom(LivekitModels.Room room){ .startTime(room.getCreationTime()) .sid(room.getSid()) .metadata(room.getMetadata()) - .participantDTOList(null) + .participantListDto(null) .build(); } @@ -75,7 +80,7 @@ public static RoomDto convertRoom(VoiceRoom voiceRoom){ .sid(null) .metadata(null) //.startTime() - .participantDTOList(null) + .participantListDto(null) .build(); } From e25dd7e31cc173f3c84add413a9feaa1e634cf93 Mon Sep 17 00:00:00 2001 From: kim_sang_ june <79149384+drbug2000@users.noreply.github.com> Date: Sat, 2 Nov 2024 02:57:04 +0900 Subject: [PATCH 07/15] [refac] change func name findProfileImageByUserSpaceId in VoiceRoomParticipantService findProfileImageByUserId -> findProfileImageByUserSpaceId --- .../service/VoiceRoomParticipantService.java | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java b/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java index a17acff7..95d6ab95 100644 --- a/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java +++ b/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java @@ -1,6 +1,7 @@ package space.space_spring.service; import lombok.RequiredArgsConstructor; +import org.springframework.core.task.TaskExecutor; import org.springframework.stereotype.Service; import space.space_spring.dao.UserSpaceDao; import space.space_spring.dao.VoiceRoomRepository; @@ -8,6 +9,7 @@ import space.space_spring.dto.VoiceRoom.GetParticipantList; import space.space_spring.dto.VoiceRoom.ParticipantDto; import space.space_spring.dto.VoiceRoom.ParticipantListDto; +import space.space_spring.dto.VoiceRoom.RoomDto; import space.space_spring.entity.Space; import space.space_spring.entity.User; import space.space_spring.entity.UserSpace; @@ -15,6 +17,8 @@ import java.util.Collections; import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; @Service @RequiredArgsConstructor @@ -23,6 +27,7 @@ public class VoiceRoomParticipantService { final private UserDao userDao; final private VoiceRoomRepository voiceRoomRepository; final private LiveKitUtils liveKitUtils; + private final TaskExecutor taskExecutor; public List getParticipantInfoListById(long voiceRoomId){ return getParticipantDtoListById(voiceRoomId).convertParticipantDtoList(); } @@ -35,12 +40,36 @@ private ParticipantListDto getParticipantDtoListById(long voiceRoomId){ } ParticipantListDto participantListDto = ParticipantListDto.from(participantDtos); - - - participantListDto.setProfileImage(this::findProfileImageByUserId); + participantListDto.setProfileImage(this::findProfileImageByUserSpaceId); return participantListDto; } - private String findProfileImageByUserId(Long userSpaceId){ + private String findProfileImageByUserSpaceId(Long userSpaceId){ return userSpaceDao.findProfileImageById(userSpaceId).orElse(""); } + + + + + //1. 이 함수를 VoiceRoomListDto의 parameter로 넘긴다 + //장점. 동기 처리의 책임을 service가 질 수 있음 + //단점. 굳이 이렇게까지 코드를 꼬야야하나 싶을 수 있음. 그냥 getRoomList해서 RoomList를 밖으로 빼는게 나을지도 + + //2. 이 함수를 VoiceRoomListDto 내부로 이전 + //장점. findProfileImageByUserSpaceId만 function parameter로 넘기면 됨 -> 책임과 구조가 더 명확하게 보인다고 + //단점. 비동기 병렬처리의 책임을 VoiceRoomListDto가 가져야함. + public void setParticipant(List roomDtoList){ + List> roomDtoFutureList = roomDtoList.stream() + .map(r->CompletableFuture.runAsync(()->r.setParticipantDTOList(getParticipantDtoListById(r.getId())),taskExecutor) + //.exceptionally(ex->{throws ex;}) + ) + .collect(Collectors.toList()); + + + // 모든 Future의 완료를 기다림 + CompletableFuture allOf = CompletableFuture.allOf( + roomDtoFutureList.toArray(new CompletableFuture[0])); + + // 결과 수집 및 출력 + allOf.join(); + } } From eb6a1d73561a664dd08794dd955ffe9e4d674bbb Mon Sep 17 00:00:00 2001 From: kim_sang_ june <79149384+drbug2000@users.noreply.github.com> Date: Mon, 4 Nov 2024 01:33:08 +0900 Subject: [PATCH 08/15] [refactor] add getParticipantListDto func --- .../space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java | 2 +- .../space/space_spring/dto/VoiceRoom/ParticipantListDto.java | 4 ++++ src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java b/src/main/java/space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java index e512885d..f8b730ec 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java @@ -48,7 +48,7 @@ public static VoiceRoomInfo convertRoomDto(RoomDto roomDto){ .order(roomDto.getOrder()) .metadate(roomDto.getMetadata()) .participantInfoList( - GetParticipantList.ParticipantInfo.convertParticipantDtoList(roomDto.getParticipantDTOList()) + GetParticipantList.ParticipantInfo.convertParticipantDtoList(roomDto.getParticipantListDto().getParticipantDtoList()) ) .build(); } diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java b/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java index 71c4bf7a..98c503a9 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java @@ -35,4 +35,8 @@ public List convertParticipantDtoList(){ .map(GetParticipantList.ParticipantInfo::convertParticipantDto) .collect(Collectors.toList()); } + + public List getParticipantDtoList() { + return participantDtoList; + } } diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java b/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java index b6c3415e..5a726c48 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java @@ -130,6 +130,6 @@ public String toString() { } } - + public ParticipantListDto getParticipantListDto(){return participantListDto;} } From f092595ce01ba24a2734d8a733e25de33385bb07 Mon Sep 17 00:00:00 2001 From: kim_sang_ june <79149384+drbug2000@users.noreply.github.com> Date: Mon, 4 Nov 2024 01:33:48 +0900 Subject: [PATCH 09/15] [feat] add set participant concurrency func use Map< roomId , participantList> parameter --- .../service/VoiceRoomParticipantService.java | 38 +++++++++++++++++++ .../service/VoiceRoomService.java | 20 +++++----- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java b/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java index 95d6ab95..43f8eecb 100644 --- a/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java +++ b/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java @@ -1,6 +1,7 @@ package space.space_spring.service; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.core.task.TaskExecutor; import org.springframework.stereotype.Service; import space.space_spring.dao.UserSpaceDao; @@ -17,11 +18,13 @@ import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; @Service @RequiredArgsConstructor +@Slf4j public class VoiceRoomParticipantService { final private UserSpaceDao userSpaceDao; final private UserDao userDao; @@ -72,4 +75,39 @@ public void setParticipant(List roomDtoList){ // 결과 수집 및 출력 allOf.join(); } + public Map getParticipantList(List roomIdList){ + + Map> futureMap = roomIdList.stream() + .collect(Collectors.toMap( + roomId->roomId, + roomId->CompletableFuture.supplyAsync( + ()-> getParticipantDtoListById(roomId), + taskExecutor + + ).exceptionally(throwable -> { + log.error("failed to fetch and get participantList",throwable); + return null;//empty ParticipantListDto + }) + )); + try { + // 모든 Future의 완료를 기다림 + CompletableFuture.allOf( + futureMap.values().toArray(new CompletableFuture[0])) + .exceptionally(throwable -> { + log.error("Error while waiting for all participant fetches to complete",throwable); + return null; + }) + .join(); + + return futureMap.entrySet().stream() + .collect(Collectors.toMap( + entry -> entry.getKey(), + entry->entry.getValue().getNow(ParticipantListDto.from(null)) + )); + + }catch (Exception e){ + log.error("Critical error while processing participant fetches", e); + return Collections.emptyMap(); // 심각한 오류 발생 시 빈 Map 반환 + } + } } diff --git a/src/main/java/space/space_spring/service/VoiceRoomService.java b/src/main/java/space/space_spring/service/VoiceRoomService.java index 73483a75..303f1972 100644 --- a/src/main/java/space/space_spring/service/VoiceRoomService.java +++ b/src/main/java/space/space_spring/service/VoiceRoomService.java @@ -16,8 +16,10 @@ import space.space_spring.util.LiveKitUtils; import space.space_spring.util.space.SpaceUtils; +import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.function.Function; import java.util.stream.Collectors; @@ -131,22 +133,18 @@ public List getVoiceRoomInfoListConcurrency(long * 병렬 처리 적용대상 1 */ //#2 Room과 mapping 시키기 + List roomIdList = new ArrayList<>(); for(RoomDto roomDto : roomDtoList){ roomDto.setActiveRoom(roomResponses); + roomIdList.add(roomDto.getId()); } - List> roomDtoFutureList = roomDtoList.stream() - .map(r->CompletableFuture.runAsync(()->setRoomDto(r,roomResponses,req),taskExecutor) - //.exceptionally(ex->{throws ex;}) - ) - .collect(Collectors.toList()); - - // 모든 Future의 완료를 기다림 - CompletableFuture allOf = CompletableFuture.allOf( - roomDtoFutureList.toArray(new CompletableFuture[0])); - // 결과 수집 및 출력 - allOf.join(); + Map roomIdParticipantMap=voiceRoomParticipantService.getParticipantList(roomIdList); + for(RoomDto roomDto : roomDtoList){ + roomDto.setParticipantDTOList(roomIdParticipantMap.get(roomDto.getId())); + } + //ToDo Response로 convert //#1 Active/inActive 분리 From e82c96629b4b40020d39f4bdfd2d622a1698cb35 Mon Sep 17 00:00:00 2001 From: kim_sang_ june <79149384+drbug2000@users.noreply.github.com> Date: Mon, 4 Nov 2024 01:45:52 +0900 Subject: [PATCH 10/15] [refactor] add short function getParticipantDtoList --- .../java/space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java | 2 +- src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java b/src/main/java/space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java index f8b730ec..219d7aac 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java @@ -48,7 +48,7 @@ public static VoiceRoomInfo convertRoomDto(RoomDto roomDto){ .order(roomDto.getOrder()) .metadate(roomDto.getMetadata()) .participantInfoList( - GetParticipantList.ParticipantInfo.convertParticipantDtoList(roomDto.getParticipantListDto().getParticipantDtoList()) + GetParticipantList.ParticipantInfo.convertParticipantDtoList(roomDto.getParticipantDtoList()) ) .build(); } diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java b/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java index 5a726c48..76cd00ef 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java @@ -131,5 +131,5 @@ public String toString() { } public ParticipantListDto getParticipantListDto(){return participantListDto;} - + public List getParticipantDtoList(){return participantListDto.getParticipantDtoList();} } From 52f4414f7b4a1bb744a0f33d6313380f9909695c Mon Sep 17 00:00:00 2001 From: kim_sang_ june <79149384+drbug2000@users.noreply.github.com> Date: Mon, 4 Nov 2024 03:02:13 +0900 Subject: [PATCH 11/15] [fix] fix null point error & connect participant+room --- .../dto/VoiceRoom/GetVoiceRoomList.java | 2 +- .../dto/VoiceRoom/ParticipantListDto.java | 9 ++++++++- .../space/space_spring/dto/VoiceRoom/RoomDto.java | 14 ++++++++++---- .../dto/VoiceRoom/VoiceRoomListDto.java | 6 ++++++ .../java/space/space_spring/entity/VoiceRoom.java | 2 +- .../service/VoiceRoomParticipantService.java | 2 +- .../space_spring/service/VoiceRoomService.java | 4 +--- 7 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java b/src/main/java/space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java index acbbd743..241b1174 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java @@ -48,7 +48,7 @@ public static VoiceRoomInfo convertRoomDto(RoomDto roomDto){ .order(roomDto.getOrder()) .metadate(roomDto.getMetadata()) .participantInfoList( - GetParticipantList.ParticipantInfo.convertParticipantDtoList(roomDto.getParticipantDtoList()) + GetParticipantList.ParticipantInfo.convertParticipantDtoList(roomDto.getParticipantListDto().getParticipantDtoList()) ) .build(); } diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java b/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java index 98c503a9..86e14eb5 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java @@ -13,10 +13,17 @@ public class ParticipantListDto { private ParticipantListDto(List participantDtoList){ this.participantDtoList=participantDtoList; } - public static ParticipantListDto from(List participantDtoList ){ + public static ParticipantListDto from(List participantDtoList ){ return new ParticipantListDto(participantDtoList); } + public static ParticipantListDto empty(){ + return new ParticipantListDto(Collections.emptyList()); + } + + public static ParticipantListDto nullList(){ + return new ParticipantListDto(null); + } public void setProfileImage(Function profileFinder){ this.participantDtoList.forEach(participantDto -> { diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java b/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java index 51d4f031..0d418f01 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java @@ -34,11 +34,17 @@ public class RoomDto { // .collect(Collectors.toList()); // } public RoomDto setParticipantDTOList(List participantDtoList){ - this.participantListDto= ParticipantListDto.from(participantDtoList); + if(participantDtoList==null){ + this.participantListDto = ParticipantListDto.empty(); + } + this.participantListDto = ParticipantListDto.from(participantDtoList); return this; } public RoomDto setParticipantDTOList(ParticipantListDto participants){ + if(participants==null){ + this.participantListDto = ParticipantListDto.empty(); + } this.participantListDto = participants; return this; } @@ -50,7 +56,7 @@ public static RoomDto convertRoom(LivekitModels.Room room){ .startTime(room.getCreationTime()) .sid(room.getSid()) .metadata(room.getMetadata()) - .participantListDto(null) + .participantListDto(ParticipantListDto.nullList()) .build(); } @@ -72,7 +78,7 @@ public static RoomDto convertRoom(VoiceRoom voiceRoom){ .sid(null) .metadata(null) //.startTime() - .participantListDto(null) + .participantListDto(ParticipantListDto.nullList()) .build(); } @@ -134,5 +140,5 @@ public String toString() { } public ParticipantListDto getParticipantListDto(){return participantListDto;} - public List getParticipantDtoList(){return participantListDto.getParticipantDtoList();} + //public List getParticipantDtoList(){return participantListDto.getParticipantDtoList();} } diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomListDto.java b/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomListDto.java index ffc5ad9e..f5084bf1 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomListDto.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomListDto.java @@ -65,5 +65,11 @@ public List convertVoicRoomInfoList() { return convertVoicRoomInfoList( null); } + public void serParticipantListDto(Map participantListDtoMap){ + + for(RoomDto roomDto : this.roomDtoList){ + roomDto.setParticipantDTOList(participantListDtoMap.get(roomDto.getId())); + } + } } diff --git a/src/main/java/space/space_spring/entity/VoiceRoom.java b/src/main/java/space/space_spring/entity/VoiceRoom.java index 2472dd92..eeae710f 100644 --- a/src/main/java/space/space_spring/entity/VoiceRoom.java +++ b/src/main/java/space/space_spring/entity/VoiceRoom.java @@ -63,7 +63,7 @@ public RoomDto convertRoomDto(){ .sid(null) .metadata(null) //.startTime() - .participantDTOList(null) + .participantListDto(null) .build(); } } diff --git a/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java b/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java index 43f8eecb..02b9d42e 100644 --- a/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java +++ b/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java @@ -102,7 +102,7 @@ public Map getParticipantList(List roomIdList){ return futureMap.entrySet().stream() .collect(Collectors.toMap( entry -> entry.getKey(), - entry->entry.getValue().getNow(ParticipantListDto.from(null)) + entry->entry.getValue().getNow(ParticipantListDto.empty()) )); }catch (Exception e){ diff --git a/src/main/java/space/space_spring/service/VoiceRoomService.java b/src/main/java/space/space_spring/service/VoiceRoomService.java index 1bfe480e..4dafa788 100644 --- a/src/main/java/space/space_spring/service/VoiceRoomService.java +++ b/src/main/java/space/space_spring/service/VoiceRoomService.java @@ -99,9 +99,7 @@ public List getVoiceRoomInfoListConcurrency(long Map roomIdParticipantMap=voiceRoomParticipantService.getParticipantList(roomIdList); - for(RoomDto roomDto : roomDtoList){ - roomDto.setParticipantDTOList(roomIdParticipantMap.get(roomDto.getId())); - } + //ToDo Response로 convert //#1 Active/inActive 분리 From 794090f5742905441e4da5dce833afa1d15b9e2c Mon Sep 17 00:00:00 2001 From: kim_sang_ june <79149384+drbug2000@users.noreply.github.com> Date: Mon, 4 Nov 2024 03:06:55 +0900 Subject: [PATCH 12/15] [feat] now showParticipant true work setParticipantListDto func --- .../space/space_spring/dto/VoiceRoom/VoiceRoomListDto.java | 2 +- .../java/space/space_spring/service/VoiceRoomService.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomListDto.java b/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomListDto.java index f5084bf1..9b0f6b9e 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomListDto.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomListDto.java @@ -65,7 +65,7 @@ public List convertVoicRoomInfoList() { return convertVoicRoomInfoList( null); } - public void serParticipantListDto(Map participantListDtoMap){ + public void setParticipantListDto(Map participantListDtoMap){ for(RoomDto roomDto : this.roomDtoList){ roomDto.setParticipantDTOList(participantListDtoMap.get(roomDto.getId())); diff --git a/src/main/java/space/space_spring/service/VoiceRoomService.java b/src/main/java/space/space_spring/service/VoiceRoomService.java index 4dafa788..dc735f8d 100644 --- a/src/main/java/space/space_spring/service/VoiceRoomService.java +++ b/src/main/java/space/space_spring/service/VoiceRoomService.java @@ -99,7 +99,10 @@ public List getVoiceRoomInfoListConcurrency(long Map roomIdParticipantMap=voiceRoomParticipantService.getParticipantList(roomIdList); - + + if(showParticipant){ + voiceRoomListDto.setParticipantListDto(roomIdParticipantMap); + } //ToDo Response로 convert //#1 Active/inActive 분리 From ef3f87ace251f24aac2aeebdc9bc8382e6fab368 Mon Sep 17 00:00:00 2001 From: kim_sang_ june <79149384+drbug2000@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:40:40 +0900 Subject: [PATCH 13/15] [refactor] voiceRoomRePo::findId return Optional --- .../space/space_spring/controller/VoiceRoomController.java | 3 ++- .../java/space/space_spring/dao/VoiceRoomRepository.java | 4 +++- .../space_spring/service/VoiceRoomParticipantService.java | 5 ++++- .../java/space/space_spring/service/VoiceRoomService.java | 7 +++++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/space/space_spring/controller/VoiceRoomController.java b/src/main/java/space/space_spring/controller/VoiceRoomController.java index 3a7c716f..da7fe43d 100644 --- a/src/main/java/space/space_spring/controller/VoiceRoomController.java +++ b/src/main/java/space/space_spring/controller/VoiceRoomController.java @@ -207,7 +207,8 @@ private boolean validateVoiceRoomNameExist(String voiceRoomName){ return true; } private boolean validateVoiceRoomInSpace(long spaceId,long voiceRoomId){ - if(! (voiceRoomRepository.findById(voiceRoomId).getSpace().getSpaceId().equals(spaceId))){ + if(! (voiceRoomRepository.findById(voiceRoomId).orElseThrow(()->new CustomException(VOICEROOM_NOT_EXIST)) + .getSpace().getSpaceId().equals(spaceId))){ throw new CustomException(VOICEROOM_NOT_IN_SPACE); } return true; diff --git a/src/main/java/space/space_spring/dao/VoiceRoomRepository.java b/src/main/java/space/space_spring/dao/VoiceRoomRepository.java index fc169ff7..69d4c30a 100644 --- a/src/main/java/space/space_spring/dao/VoiceRoomRepository.java +++ b/src/main/java/space/space_spring/dao/VoiceRoomRepository.java @@ -8,6 +8,8 @@ import space.space_spring.entity.VoiceRoom; import java.util.List; +import java.util.Optional; + @Repository public interface VoiceRoomRepository extends JpaRepository { @@ -24,7 +26,7 @@ public interface VoiceRoomRepository extends JpaRepository { @Query("SELECT CASE WHEN COUNT(v) > 0 THEN true ELSE false END FROM VoiceRoom v WHERE v.name = :voiceRoomName AND v.status = 'ACTIVE'") boolean existsByName(@Param("voiceRoomName") String voiceRoomName); @Query("SELECT v FROM VoiceRoom v WHERE v.voiceRoomId = :id AND v.status = 'ACTIVE'") - VoiceRoom findById(@Param("id") long Id); + Optional findById(@Param("id") long Id); @Query("SELECT v FROM VoiceRoom v WHERE v.space.id = :spaceId AND v.status = 'ACTIVE'") List findActiveVoiceRoomsBySpaceId(@Param("spaceId") Long spaceId); diff --git a/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java b/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java index 02b9d42e..00adb5de 100644 --- a/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java +++ b/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java @@ -14,6 +14,7 @@ import space.space_spring.entity.Space; import space.space_spring.entity.User; import space.space_spring.entity.UserSpace; +import space.space_spring.exception.CustomException; import space.space_spring.util.LiveKitUtils; import java.util.Collections; @@ -22,6 +23,8 @@ import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; +import static space.space_spring.response.status.BaseExceptionResponseStatus.VOICEROOM_NOT_EXIST; + @Service @RequiredArgsConstructor @Slf4j @@ -35,7 +38,7 @@ public List getParticipantInfoListById(long return getParticipantDtoListById(voiceRoomId).convertParticipantDtoList(); } private ParticipantListDto getParticipantDtoListById(long voiceRoomId){ - Space space = voiceRoomRepository.findById(voiceRoomId).getSpace(); + Space space = voiceRoomRepository.findById(voiceRoomId).orElseThrow(()->new CustomException(VOICEROOM_NOT_EXIST)).getSpace(); //Todo 다른 네이밍 고려 List participantDtos = liveKitUtils.getParticipantInfo(String.valueOf(voiceRoomId)); if(participantDtos==null || participantDtos.isEmpty()){ diff --git a/src/main/java/space/space_spring/service/VoiceRoomService.java b/src/main/java/space/space_spring/service/VoiceRoomService.java index dc735f8d..38bfc74a 100644 --- a/src/main/java/space/space_spring/service/VoiceRoomService.java +++ b/src/main/java/space/space_spring/service/VoiceRoomService.java @@ -13,6 +13,7 @@ import space.space_spring.entity.Space; import space.space_spring.entity.User; import space.space_spring.entity.VoiceRoom; +import space.space_spring.exception.CustomException; import space.space_spring.util.LiveKitUtils; import space.space_spring.util.space.SpaceUtils; @@ -25,6 +26,8 @@ import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; +import static space.space_spring.response.status.BaseExceptionResponseStatus.VOICEROOM_NOT_EXIST; + @Service @RequiredArgsConstructor public class VoiceRoomService { @@ -167,7 +170,7 @@ public boolean updateVoiceRoom(List updateRoomList){ public void deleteVoiceRoom(long voiceRoomId){ //Todo Base Entity에 일괄적으로 soft Delete를 적용하는 방법을 다같이 정하는 것이 좋아보임 - VoiceRoom voiceRoom = voiceRoomRepository.findById(voiceRoomId); + VoiceRoom voiceRoom = voiceRoomRepository.findById(voiceRoomId).orElseThrow(()->new CustomException(VOICEROOM_NOT_EXIST)); voiceRoom.updateInactive(); voiceRoomRepository.save(voiceRoom); } @@ -182,7 +185,7 @@ private String findProfileImageByUserId(Long userSpaceId){ // return voiceRoomRepository.findBySpace(space); // } private List getParticipantDtoListById(long voiceRoomId){ - Space space = voiceRoomRepository.findById(voiceRoomId).getSpace(); + Space space = voiceRoomRepository.findById(voiceRoomId).orElseThrow(()->new CustomException(VOICEROOM_NOT_EXIST)).getSpace(); List participantDtoList = liveKitUtils.getParticipantInfo(String.valueOf(voiceRoomId)); if(participantDtoList==null||participantDtoList.isEmpty()){ return Collections.emptyList(); From df42b841b2491ad032852c297400624a9823ec84 Mon Sep 17 00:00:00 2001 From: kim_sang_ june <79149384+drbug2000@users.noreply.github.com> Date: Tue, 5 Nov 2024 16:38:59 +0900 Subject: [PATCH 14/15] [refactor] add class final keyword in *DtoList class --- .../space_spring/dto/VoiceRoom/ParticipantListDto.java | 2 +- .../space_spring/dto/VoiceRoom/VoiceRoomEntityList.java | 8 +++++--- .../space_spring/dto/VoiceRoom/VoiceRoomListDto.java | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java b/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java index 86e14eb5..848dfbbd 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/ParticipantListDto.java @@ -8,7 +8,7 @@ public class ParticipantListDto { - private List participantDtoList; + final private List participantDtoList; private ParticipantListDto(List participantDtoList){ this.participantDtoList=participantDtoList; diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomEntityList.java b/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomEntityList.java index 11a30826..f3266800 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomEntityList.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomEntityList.java @@ -7,12 +7,14 @@ public class VoiceRoomEntityList { - private List voiceRoomEntityList; + final private List voiceRoomEntityList; - public void VoiceRoomList(List voiceRoomEntityList) { + private VoiceRoomEntityList(List voiceRoomEntityList) { this.voiceRoomEntityList = voiceRoomEntityList; } - + public VoiceRoomEntityList from(List voiceRoomEntityList){ + return new VoiceRoomEntityList(voiceRoomEntityList); + } public List convertRoomDto(){ if(this.voiceRoomEntityList==null||this.voiceRoomEntityList.isEmpty()){return null;} return this.voiceRoomEntityList.stream() diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomListDto.java b/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomListDto.java index 9b0f6b9e..06d5effb 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomListDto.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomListDto.java @@ -12,7 +12,7 @@ import java.util.stream.Stream; public class VoiceRoomListDto { - private List roomDtoList; + final private List roomDtoList; public VoiceRoomListDto(List roomDtos){ this.roomDtoList=roomDtos; From 20d23b34ec09b368242f22304109d84a0b84065c Mon Sep 17 00:00:00 2001 From: kim_sang_ june <79149384+drbug2000@users.noreply.github.com> Date: Thu, 9 Jan 2025 20:58:31 +0900 Subject: [PATCH 15/15] [refact] rewirte participant service import --- .../space_spring/service/VoiceRoomParticipantService.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java b/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java index 00adb5de..1fe4a208 100644 --- a/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java +++ b/src/main/java/space/space_spring/service/VoiceRoomParticipantService.java @@ -4,16 +4,15 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.core.task.TaskExecutor; import org.springframework.stereotype.Service; -import space.space_spring.dao.UserSpaceDao; + import space.space_spring.dao.VoiceRoomRepository; +import space.space_spring.domain.space.model.entity.Space; import space.space_spring.domain.user.repository.UserDao; +import space.space_spring.domain.userSpace.repository.UserSpaceDao; import space.space_spring.dto.VoiceRoom.GetParticipantList; import space.space_spring.dto.VoiceRoom.ParticipantDto; import space.space_spring.dto.VoiceRoom.ParticipantListDto; import space.space_spring.dto.VoiceRoom.RoomDto; -import space.space_spring.entity.Space; -import space.space_spring.entity.User; -import space.space_spring.entity.UserSpace; import space.space_spring.exception.CustomException; import space.space_spring.util.LiveKitUtils;