diff --git a/src/main/java/space/space_spring/controller/VoiceRoomController.java b/src/main/java/space/space_spring/controller/VoiceRoomController.java index c2aad928..5b7dd483 100644 --- a/src/main/java/space/space_spring/controller/VoiceRoomController.java +++ b/src/main/java/space/space_spring/controller/VoiceRoomController.java @@ -85,26 +85,16 @@ public BaseResponse getRoomListNonConCurrent( @JwtLoginAuth Long userId, //@RequestBody GetVoiceRoomList.Request voiceRoomList, @RequestParam(required = false,defaultValue = "0") Integer limit, - @RequestParam(required = false,defaultValue = "false") Boolean showParticipant, - @PathVariable("version") Integer version){ + @RequestParam(required = false,defaultValue = "false") Boolean showParticipant + ){ boolean showParticipantValue = (showParticipant != null) ? showParticipant : false; GetVoiceRoomList.Request voiceRoomList=new GetVoiceRoomList.Request(limit, showParticipant); List roomInfoList; - if(version==null){ - version =1; - } - if(version==1){ - roomInfoList= voiceRoomService.getVoiceRoomInfoListConcurrency(spaceId,voiceRoomList); - } - if(version==2){ - roomInfoList = voiceRoomService.getVoiceRoomInfoList(spaceId,voiceRoomList); - } - else{ - roomInfoList= voiceRoomService.getVoiceRoomInfoListConcurrency(spaceId,voiceRoomList); - } + + roomInfoList= voiceRoomService.getVoiceRoomInfoListConcurrency(spaceId,voiceRoomList); return new BaseResponse(new GetVoiceRoomList.Response(roomInfoList)); } diff --git a/src/main/java/space/space_spring/dao/UserSpaceRepository.java b/src/main/java/space/space_spring/dao/UserSpaceRepository.java new file mode 100644 index 00000000..6e3383c9 --- /dev/null +++ b/src/main/java/space/space_spring/dao/UserSpaceRepository.java @@ -0,0 +1,16 @@ +package space.space_spring.dao; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import space.space_spring.entity.UserSpace; +import space.space_spring.entity.VoiceRoom; + +import java.util.List; +import java.util.Optional; + +public interface UserSpaceRepository extends JpaRepository { + @Query("SELECT r FROM UserSpace r WHERE r.user.userId = :userId AND r.space.spaceId = :spaceId AND r.status = 'ACTIVE'") + Optional findUserSpaceByUserAndSpace(@Param("userId") Long userId, @Param("spaceId") Long spaceId); + +} diff --git a/src/main/java/space/space_spring/dao/VoiceRoomRepository.java b/src/main/java/space/space_spring/dao/VoiceRoomRepository.java index d3cea243..fc169ff7 100644 --- a/src/main/java/space/space_spring/dao/VoiceRoomRepository.java +++ b/src/main/java/space/space_spring/dao/VoiceRoomRepository.java @@ -16,10 +16,16 @@ public interface VoiceRoomRepository extends JpaRepository { List findBySpace(@Param("space")Space space); @Query("SELECT MAX(r.order) FROM VoiceRoom r WHERE r.space = :space AND r.status = 'ACTIVE'") Integer findMaxOrderBySpace(@Param("space") Space space); + + @Query("SELECT MAX(r.order) FROM VoiceRoom r WHERE r.space.id = :spaceId AND r.status = 'ACTIVE'") + Integer findMaxOrderBySpaceId(@Param("spaceId") Long spaceId); @Query("SELECT CASE WHEN COUNT(v) > 0 THEN true ELSE false END FROM VoiceRoom v WHERE v.voiceRoomId = :id AND v.status = 'ACTIVE'") boolean existsByVoiceRoomId(@Param("id")long voiceRoomId); @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); + + @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/dto/VoiceRoom/GetVoiceRoomList.java b/src/main/java/space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java index e512885d..40661862 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/GetVoiceRoomList.java @@ -52,21 +52,5 @@ public static VoiceRoomInfo convertRoomDto(RoomDto roomDto){ ) .build(); } - public static List convertRoomDtoList(List roomDtoList,Integer limit){ - if(roomDtoList==null||roomDtoList.isEmpty()){return null;} - Stream sortedStream = roomDtoList.stream() - .sorted(Comparator - .comparing((RoomDto r) -> r.getNumParticipants() == 0) // Active rooms first - .thenComparing(RoomDto::getOrder)) ;// Then by order - System.out.print("limit input:"+limit); - Stream processedStream = (limit != null) ? sortedStream.limit(limit) : sortedStream; - - return processedStream.map(VoiceRoomInfo::convertRoomDto) - .collect(Collectors.toList()); - - } - public static List convertRoomDtoList(List roomDtoList) { - return convertRoomDtoList(roomDtoList, null); - } } } diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/PostVoiceRoomDto.java b/src/main/java/space/space_spring/dto/VoiceRoom/PostVoiceRoomDto.java index a3c0dc41..0395b5c6 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/PostVoiceRoomDto.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/PostVoiceRoomDto.java @@ -2,10 +2,15 @@ import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; public class PostVoiceRoomDto { @Getter + //@Builder + @AllArgsConstructor + @NoArgsConstructor public static class Request{ @NotNull(message = "name is mandatory") private String name; 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..9e0a530c 100644 --- a/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java +++ b/src/main/java/space/space_spring/dto/VoiceRoom/RoomDto.java @@ -49,22 +49,14 @@ public static RoomDto convertRoom(LivekitModels.Room room){ .build(); } + //Todo VoiceRoomDtoList 로 이전 예정 public static List convertRoomDtoListByVoiceRoom(List voiceRoomList){ if(voiceRoomList==null||voiceRoomList.isEmpty()){return null;} return voiceRoomList.stream() .map(RoomDto::convertRoom) .collect(Collectors.toList()); } -// public static Room convertRoom(LiveKitSession session){ -// return Room.builder() -// .name(session.) -// .numParticipants(room.getNumParticipants()) -// .creationTime(room.getCreationTime()) -// .sid(room.getSid()) -// .metadata(room.getMetadata()) -// .participantList(null) -// .build(); -// } + public static RoomDto convertRoom(VoiceRoom voiceRoom){ if(voiceRoom==null){return null;} return RoomDto.builder() @@ -99,10 +91,7 @@ public void setActiveRoom(List liveKitRoomList){ boolean find = false; for(LivekitModels.Room resRoom : liveKitRoomList){ if(String.valueOf(this.id).equals( resRoom.getName() )){ - this.numParticipants = resRoom.getNumParticipants(); - this.sid = resRoom.getSid(); - this.metadata = resRoom.getMetadata(); - this.startTime= resRoom.getCreationTime(); + setActiveRoom(resRoom,true); find = true; break; } @@ -111,6 +100,20 @@ public void setActiveRoom(List liveKitRoomList){ if(!find){this.numParticipants=0;} //return this; } + + public void setActiveRoom(LivekitModels.Room resRoom,boolean checkId){ + //null에 대한 예외 처리 + if(checkId || String.valueOf(this.id).equals( resRoom.getName() )){ + this.numParticipants = resRoom.getNumParticipants(); + this.sid = resRoom.getSid(); + this.metadata = resRoom.getMetadata(); + this.startTime= resRoom.getCreationTime(); + + } + } + public void setActiveRoom(LivekitModels.Room resRoom){ + setActiveRoom(resRoom,false); + } private static boolean EqualRoomIdByNameTag(String roomName,long Id){ return roomName.endsWith("#"+String.valueOf(Id)); } diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomEntityList.java b/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomEntityList.java new file mode 100644 index 00000000..11a30826 --- /dev/null +++ b/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomEntityList.java @@ -0,0 +1,22 @@ +package space.space_spring.dto.VoiceRoom; + +import space.space_spring.entity.VoiceRoom; + +import java.util.List; +import java.util.stream.Collectors; + +public class VoiceRoomEntityList { + + private List voiceRoomEntityList; + + public void VoiceRoomList(List voiceRoomEntityList) { + this.voiceRoomEntityList = voiceRoomEntityList; + } + + public List convertRoomDto(){ + if(this.voiceRoomEntityList==null||this.voiceRoomEntityList.isEmpty()){return null;} + return this.voiceRoomEntityList.stream() + .map(RoomDto::convertRoom) + .collect(Collectors.toList()); + } +} \ No newline at end of file diff --git a/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomListDto.java b/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomListDto.java new file mode 100644 index 00000000..ffc5ad9e --- /dev/null +++ b/src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomListDto.java @@ -0,0 +1,69 @@ +package space.space_spring.dto.VoiceRoom; + +import livekit.LivekitModels; +import space.space_spring.entity.VoiceRoom; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; + +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class VoiceRoomListDto { + private List roomDtoList; + + public VoiceRoomListDto(List roomDtos){ + this.roomDtoList=roomDtos; + } + + public static VoiceRoomListDto from(List voiceRoomEntityList){ + List roomDtos = convertRoomDtoListByVoiceRoom(voiceRoomEntityList); + return new VoiceRoomListDto(roomDtos); + } + + public static List convertRoomDtoListByVoiceRoom(List voiceRoomList){ + if(voiceRoomList==null||voiceRoomList.isEmpty()){return null;} + return voiceRoomList.stream() + .map(RoomDto::convertRoom) + .collect(Collectors.toList()); + } + + private void setActiveRoom(Map roomResponse){ + for(RoomDto room : this.roomDtoList){ + LivekitModels.Room resRoom= roomResponse.get(String.valueOf(room.getId())); + if(resRoom==null){continue;} + room.setActiveRoom(resRoom); + } + + } + public void setActiveRoom(List roomResponse){ + Map roomResMap=roomResponse.stream() + .collect(Collectors.toMap( + res->res.getName(), + res->res, + (oldVal,newVal)->newVal + )); + roomResMap = Collections.unmodifiableMap(roomResMap); + setActiveRoom(roomResMap); + } + + public List convertVoicRoomInfoList(Integer limit){ + if(this.roomDtoList==null||this.roomDtoList.isEmpty()){return null;} + Stream sortedStream = this.roomDtoList.stream() + .sorted(Comparator + .comparing((RoomDto r) -> r.getNumParticipants() == 0) // Active rooms first + .thenComparing(RoomDto::getOrder)) ;// Then by order + System.out.print("limit input:"+limit); + Stream processedStream = (limit != null) ? sortedStream.limit(limit) : sortedStream; + + return processedStream.map(GetVoiceRoomList.VoiceRoomInfo::convertRoomDto) + .collect(Collectors.toList()); + } + public List convertVoicRoomInfoList() { + return convertVoicRoomInfoList( null); + } + + +} diff --git a/src/main/java/space/space_spring/entity/VoiceRoom.java b/src/main/java/space/space_spring/entity/VoiceRoom.java index aa93d303..2472dd92 100644 --- a/src/main/java/space/space_spring/entity/VoiceRoom.java +++ b/src/main/java/space/space_spring/entity/VoiceRoom.java @@ -6,6 +6,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import space.space_spring.dto.VoiceRoom.GetVoiceRoomList; +import space.space_spring.dto.VoiceRoom.RoomDto; @Entity @Table(name = "VoiceRoom") @@ -52,4 +53,17 @@ public void update(String name,Integer order){ } this.onUpdate(); } + + public RoomDto convertRoomDto(){ + return RoomDto.builder() + .name(this.getName()) + //.createdAt(voiceRoom.) + .id(this.getVoiceRoomId()) + .order(this.getOrder()) + .sid(null) + .metadata(null) + //.startTime() + .participantDTOList(null) + .build(); + } } diff --git a/src/main/java/space/space_spring/service/VoiceRoomService.java b/src/main/java/space/space_spring/service/VoiceRoomService.java index c831ef89..09ab1d90 100644 --- a/src/main/java/space/space_spring/service/VoiceRoomService.java +++ b/src/main/java/space/space_spring/service/VoiceRoomService.java @@ -18,8 +18,8 @@ import java.util.Collections; import java.util.List; + import java.util.concurrent.CompletableFuture; -import java.util.function.Function; import java.util.stream.Collectors; @Service @@ -38,6 +38,7 @@ public class VoiceRoomService { public Long createVoiceRoom(long spaceId,PostVoiceRoomDto.Request req){ Space targetSpace = spaceUtils.findSpaceBySpaceId(spaceId); Integer orderInt = voiceRoomRepository.findMaxOrderBySpace(targetSpace); + //Space currentSpace=voiceRoomRepository.findActiveVoiceRoomsBySpaceId(spaceId); int order; if(orderInt==null||orderInt==0){ order=1; @@ -49,61 +50,6 @@ public Long createVoiceRoom(long spaceId,PostVoiceRoomDto.Request req){ return voiceRoomDao.createVoiceRoom(name, order, targetSpace); } - public List getVoiceRoomInfoList(long spaceId,GetVoiceRoomList.Request req){ - Integer limit = req.getLimit(); - boolean showParticipant =req.isShowParticipant(); - - - //해당 space VoiceRoom 가져오기 (VoiceRoom List) - //Todo 가져오기에 limit 적용 - List voiceRoomDataList = findBySpaceId(spaceId); - List roomDtoList = RoomDto.convertRoomDtoListByVoiceRoom(voiceRoomDataList); - //VoiceRoom과 Room mapping - //#1 Response 받아오기 - List roomResponses = liveKitUtils.getRoomList(); - //#2 Room과 mapping 시키기 - 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); - } - } - } - //ToDo Response로 convert - //#1 Active/inActive 분리 - - //#2 convert - if(limit==null||limit<=0) { - return GetVoiceRoomList.VoiceRoomInfo.convertRoomDtoList(roomDtoList); - }else{ - return GetVoiceRoomList.VoiceRoomInfo.convertRoomDtoList(roomDtoList,limit); - } - //return null; - } - - /** @@ -116,21 +62,26 @@ public List getVoiceRoomInfoListConcurrency(long //해당 space VoiceRoom 가져오기 (VoiceRoom List) //Todo 가져오기에 limit 적용 - List voiceRoomDataList = findBySpaceId(spaceId); + //todo 일급 객체 `voiceRoomEntityList`로 변경 + //List voiceRoomDataList = findBySpaceId(spaceId); + List voiceRoomDataList = voiceRoomRepository.findActiveVoiceRoomsBySpaceId(spaceId); + //todo voiceRoomEntityList 객체에 책임 위임 + //todo RoomDtoList 일급 객체 생성 List roomDtoList = RoomDto.convertRoomDtoListByVoiceRoom(voiceRoomDataList); + //VoiceRoom과 Room mapping //#1 Response 받아오기 List roomResponsesTemp = liveKitUtils.getRoomList(); //불변 list로 변환 List roomResponses = Collections.unmodifiableList(roomResponsesTemp); - /** - * 병렬 처리 적용대상 1 - */ - //#2 Room과 mapping 시키기 - for(RoomDto roomDto : roomDtoList){ - roomDto.setActiveRoom(roomResponses); - } + + VoiceRoomListDto voiceRoomListDto = VoiceRoomListDto.from(voiceRoomDataList); + voiceRoomListDto.setActiveRoom(roomResponsesTemp); + + + //ToDo setRoomDto 함수를 RoomDtoList 객체로 이동 + //todo 책임을 위임해도 이 병렬처리 코드가 잘 동작할까? List> roomDtoFutureList = roomDtoList.stream() .map(r->CompletableFuture.runAsync(()->setRoomDto(r,roomResponses,req),taskExecutor) //.exceptionally(ex->{throws ex;}) @@ -149,13 +100,16 @@ public List getVoiceRoomInfoListConcurrency(long //#2 convert if(limit==null||limit<=0) { - return GetVoiceRoomList.VoiceRoomInfo.convertRoomDtoList(roomDtoList); + return voiceRoomListDto.convertVoicRoomInfoList(); + //return GetVoiceRoomList.VoiceRoomInfo.convertRoomDtoList(roomDtoList); }else{ - return GetVoiceRoomList.VoiceRoomInfo.convertRoomDtoList(roomDtoList,limit); + return voiceRoomListDto.convertVoicRoomInfoList(limit); + //return GetVoiceRoomList.VoiceRoomInfo.convertRoomDtoList(roomDtoList,limit); } //return null; } + //todo 해당 함수의 책임을 RoomDto에게 위임 private void setRoomDto(RoomDto roomDto,List roomResponses,GetVoiceRoomList.Request req){ roomDto.setActiveRoom(roomResponses); @@ -185,39 +139,11 @@ private void setRoomDto(RoomDto roomDto,List roomResponses,G } - - private Function setActiveParticipant= roomDto->{ - - if(roomDto.getNumParticipants()==0){ - //showParticipant = ture 일때, 참가자가 없으면 빈문자열[] 출력 - System.out.print("\n[DEBUG]Participant Number : 0\n"); - roomDto.setParticipantDTOList(Collections.emptyList()); - - } - //participantDto List 가져오기 - List participantDtoList = this.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); - } - return roomDto; - - }; - public boolean updateVoiceRoom(List updateRoomList){ //Todo 입력된 order가 유효한지 확인 필요 - + //Todo 병렬적으로 update하도록 수정 for(PatchVoiceRoom.UpdateRoom updateRoom : updateRoomList){ VoiceRoom voiceRoom = voiceRoomRepository.findById(updateRoom.getRoomId()).get(); String newName =updateRoom.getName(); @@ -235,19 +161,17 @@ public void deleteVoiceRoom(long voiceRoomId){ VoiceRoom voiceRoom = voiceRoomRepository.findById(voiceRoomId); voiceRoom.updateInactive(); voiceRoomRepository.save(voiceRoom); - - } private String findProfileImageByUserId(Long userSpaceId){ return userSpaceDao.findProfileImageById(userSpaceId).orElse(""); } - public List findBySpaceId(long spaceId){ - return findBySpace(spaceUtils.findSpaceBySpaceId(spaceId)); - } - private List findBySpace(Space space){ - return voiceRoomRepository.findBySpace(space); - } +// public List findBySpaceId(long spaceId){ +// return findBySpace(spaceUtils.findSpaceBySpaceId(spaceId)); +// } +// private List findBySpace(Space space){ +// return voiceRoomRepository.findBySpace(space); +// } private List getParticipantDtoListById(long voiceRoomId){ Space space = voiceRoomRepository.findById(voiceRoomId).getSpace(); List participantDtoList = liveKitUtils.getParticipantInfo(String.valueOf(voiceRoomId)); @@ -263,24 +187,7 @@ private List getParticipantDtoListById(long voiceRoomId){ } return participantDtoList; } -// -// private static 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; -// } + public List getParticipantInfoListById(long voiceRoomId){ return GetParticipantList.ParticipantInfo.convertParticipantDtoList( @@ -288,12 +195,6 @@ public List getParticipantInfoListById(long //liveKitUtils.getParticipantInfo(findNameTagById(voiceRoomId)) ); } - private String findNameTagById(long id){ - VoiceRoom voiceRoom =voiceRoomRepository.findById(id); - //null pointer error 처리 - String name = voiceRoom.getName(); - return name+" #"+String.valueOf(id); - } public String getToken(long spaceId,long userId,long userSpaceId,long voiceRoomId){ String userName=userSpaceDao.findUserNameById(userSpaceId); diff --git a/src/main/java/space/space_spring/util/LiveKitUtils.java b/src/main/java/space/space_spring/util/LiveKitUtils.java index 8984ec69..f9c36e88 100644 --- a/src/main/java/space/space_spring/util/LiveKitUtils.java +++ b/src/main/java/space/space_spring/util/LiveKitUtils.java @@ -28,13 +28,13 @@ public class LiveKitUtils { private final RestTemplate restTemplate; - public List getRoomList() { + public List getRoomList(List roomNameList) { String liveKitHost = hostUrl; System.out.print("[liveKit Url]:"+hostUrl); RoomServiceClient roomServiceClient = RoomServiceClient.createClient(liveKitHost, apiKey, apiSecretKey); try { - Response> response = roomServiceClient.listRooms().execute(); + Response> response = roomServiceClient.listRooms(roomNameList).execute(); System.out.print(response.body()); //response.body().get(0). @@ -48,6 +48,10 @@ public List getRoomList() { } + public List getRoomList(){ + return getRoomList(null); + } + public List getParticipantInfo(String roomName) { String liveKitHost = hostUrl; RoomServiceClient roomServiceClient = RoomServiceClient.createClient(liveKitHost, apiKey, apiSecretKey); diff --git a/src/test/java/space/space_spring/concurrency/completableFutureTest.java b/src/test/java/space/space_spring/concurrency/completableFutureTest.java index fadcb118..db951e46 100644 --- a/src/test/java/space/space_spring/concurrency/completableFutureTest.java +++ b/src/test/java/space/space_spring/concurrency/completableFutureTest.java @@ -81,6 +81,17 @@ public static List> processStringsAsync(List .collect(Collectors.toList()); } + @Test + void supplyAsyncb() throws ExecutionException, InterruptedException { + + CompletableFuture future = CompletableFuture.supplyAsync(() -> { + System.out.println("Thread task start"); + return "Thread: " + Thread.currentThread().getName(); + }); + + //System.out.println(future.get()); + System.out.println("Thread: " + Thread.currentThread().getName()); + } diff --git a/src/test/java/space/space_spring/domain/VoiceRoom/VoiceRoomServiceTest.java b/src/test/java/space/space_spring/domain/VoiceRoom/VoiceRoomServiceTest.java new file mode 100644 index 00000000..b7c88409 --- /dev/null +++ b/src/test/java/space/space_spring/domain/VoiceRoom/VoiceRoomServiceTest.java @@ -0,0 +1,141 @@ +package space.space_spring.domain.VoiceRoom; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito.*; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.test.util.ReflectionTestUtils; +import space.space_spring.dao.UserSpaceDao; +import space.space_spring.dao.VoiceRoomDao; +import space.space_spring.dao.VoiceRoomRepository; +import space.space_spring.dto.VoiceRoom.PostVoiceRoomDto; +import space.space_spring.entity.*; +import space.space_spring.entity.enumStatus.UserSignupType; +import space.space_spring.service.VoiceRoomService; +import space.space_spring.util.LiveKitUtils; +import space.space_spring.util.space.SpaceUtils; + + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +public class VoiceRoomServiceTest { + @InjectMocks + private VoiceRoomService voiceRoomService; + + @Mock + private VoiceRoomRepository voiceRoomRepository; + + @Mock + private VoiceRoomDao voiceRoomDao; + + @Mock + // 삭제 예정 + private SpaceUtils spaceUtils; + + @Mock + private LiveKitUtils liveKitUtils; + + + + @Mock + private UserSpaceDao userSpaceDao; + + + private User user1; + private User user2; + private User user3; + private User user4; + private User user5; + private User user6; + private User user7; + private Space testSpace; + private PayRequest testPayRequest_user1; + private PayRequest testPayRequest_user2; + private PayRequestTarget testPayRequestTarget_user1; + private PayRequestTarget testPayRequestTarget_user2; + private PayRequestTarget testPayRequestTarget_user3; + private PayRequestTarget testPayRequestTarget_user4; + + @BeforeEach + public void 테스트_셋업() { + /** + * : user2, 3은 정산 완료 X & user4는 정산 완료 + * : user1은 정산 완료 + */ + user1 = new User(); + user1.saveUser("test1@test.com", "abcDEF123!@", "user1", UserSignupType.LOCAL); + + user2 = new User(); + user2.saveUser("test2@test.com", "abcDEF123!@", "user2", UserSignupType.LOCAL); + + user3 = new User(); + user3.saveUser("test3@test.com", "abcDEF123!@", "user3", UserSignupType.LOCAL); + + user4 = new User(); + user4.saveUser("test4@test.com", "abcDEF123!@", "user4", UserSignupType.LOCAL); + + testSpace = new Space(); + testSpace.saveSpace("testSpace", "test_profile_img_url"); + + testPayRequest_user1 = new PayRequest(); + testPayRequest_user1.savePayRequest(user1, testSpace, 30000, "우리은행", "111-111-111", 0, false); + + testPayRequestTarget_user2 = new PayRequestTarget(); + testPayRequestTarget_user2.savePayRequestTarget(testPayRequest_user1, user2.getUserId(), 10000, false); + + testPayRequestTarget_user3 = new PayRequestTarget(); + testPayRequestTarget_user3.savePayRequestTarget(testPayRequest_user1, user3.getUserId(), 10000, false); + + testPayRequestTarget_user4 = new PayRequestTarget(); + testPayRequestTarget_user4.savePayRequestTarget(testPayRequest_user1, user4.getUserId(), 10000, true); + + testPayRequest_user2 = new PayRequest(); + testPayRequest_user2.savePayRequest(user2, testSpace, 10000, "국민은행", "111-111-111", 0, true); + + testPayRequestTarget_user1 = new PayRequestTarget(); + testPayRequestTarget_user1.savePayRequestTarget(testPayRequest_user2, user1.getUserId(), 10000, true); + + /** + * 추가로 user5,6,7 생성 + */ + user5 = new User(); + user6 = new User(); + user7 = new User(); + user5.saveUser("test5@test.com", "abcDEF123!@", "user5", UserSignupType.LOCAL); + user6.saveUser("test6@test.com", "abcDEF123!@", "user6", UserSignupType.LOCAL); + user7.saveUser("test7@test.com", "abcDEF123!@", "user7", UserSignupType.LOCAL); + + } + + @Test + @DisplayName("create VoiceRoom test") + void voiceRoom_create_test(){ + //given + int spaceOrder =1; + String voiceRoomName = "voiceRoom"; + Long spaceId = 2L; + //when + //when(testSpace.getSpaceId()).thenReturn(1L); + //testSpace. + ReflectionTestUtils.setField(testSpace,"spaceId",spaceId); + when(spaceUtils.findSpaceBySpaceId(testSpace.getSpaceId())).thenReturn(testSpace); + when(voiceRoomRepository.findMaxOrderBySpace(testSpace)).thenReturn(spaceOrder); + when(voiceRoomDao.createVoiceRoom(voiceRoomName,spaceOrder+1,testSpace)).thenReturn(1L); + + + PostVoiceRoomDto.Request request = new PostVoiceRoomDto.Request(voiceRoomName); + Long voiceRoomId = voiceRoomService.createVoiceRoom(testSpace.getSpaceId(),request); + + //then + assertThat(voiceRoomId).isEqualTo(1L); + + } +}