-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…omain/dto,repo Refactoring voice room 객체 정리 및 미사용 코드 삭제
- Loading branch information
Showing
13 changed files
with
339 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/space/space_spring/dao/UserSpaceRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<UserSpace, Long> { | ||
@Query("SELECT r FROM UserSpace r WHERE r.user.userId = :userId AND r.space.spaceId = :spaceId AND r.status = 'ACTIVE'") | ||
Optional<UserSpace> findUserSpaceByUserAndSpace(@Param("userId") Long userId, @Param("spaceId") Long spaceId); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomEntityList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<VoiceRoom> voiceRoomEntityList; | ||
|
||
public void VoiceRoomList(List<VoiceRoom> voiceRoomEntityList) { | ||
this.voiceRoomEntityList = voiceRoomEntityList; | ||
} | ||
|
||
public List<RoomDto> convertRoomDto(){ | ||
if(this.voiceRoomEntityList==null||this.voiceRoomEntityList.isEmpty()){return null;} | ||
return this.voiceRoomEntityList.stream() | ||
.map(RoomDto::convertRoom) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/main/java/space/space_spring/dto/VoiceRoom/VoiceRoomListDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<RoomDto> roomDtoList; | ||
|
||
public VoiceRoomListDto(List<RoomDto> roomDtos){ | ||
this.roomDtoList=roomDtos; | ||
} | ||
|
||
public static VoiceRoomListDto from(List<VoiceRoom> voiceRoomEntityList){ | ||
List<RoomDto> roomDtos = convertRoomDtoListByVoiceRoom(voiceRoomEntityList); | ||
return new VoiceRoomListDto(roomDtos); | ||
} | ||
|
||
public static List<RoomDto> convertRoomDtoListByVoiceRoom(List<VoiceRoom> voiceRoomList){ | ||
if(voiceRoomList==null||voiceRoomList.isEmpty()){return null;} | ||
return voiceRoomList.stream() | ||
.map(RoomDto::convertRoom) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private void setActiveRoom(Map<String,LivekitModels.Room> 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<LivekitModels.Room> roomResponse){ | ||
Map<String,LivekitModels.Room> roomResMap=roomResponse.stream() | ||
.collect(Collectors.toMap( | ||
res->res.getName(), | ||
res->res, | ||
(oldVal,newVal)->newVal | ||
)); | ||
roomResMap = Collections.unmodifiableMap(roomResMap); | ||
setActiveRoom(roomResMap); | ||
} | ||
|
||
public List<GetVoiceRoomList.VoiceRoomInfo> convertVoicRoomInfoList(Integer limit){ | ||
if(this.roomDtoList==null||this.roomDtoList.isEmpty()){return null;} | ||
Stream<RoomDto> 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<RoomDto> processedStream = (limit != null) ? sortedStream.limit(limit) : sortedStream; | ||
|
||
return processedStream.map(GetVoiceRoomList.VoiceRoomInfo::convertRoomDto) | ||
.collect(Collectors.toList()); | ||
} | ||
public List<GetVoiceRoomList.VoiceRoomInfo> convertVoicRoomInfoList() { | ||
return convertVoicRoomInfoList( null); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.