-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring voice room 객체 정리 및 미사용 코드 삭제 #162
Changes from all commits
3f509e1
8567dec
c1cd862
1ab4d97
55f682c
0d866e1
875bc1a
c47b3fd
22aa779
23b3ad7
08a841b
dfb2a27
6b9348c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 UserSpaceDao의 코드를 작성하신 UserSpaceRepository 로 넘기도록 하겠습니다 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네 다만, 꼭 id 값으로 Entity를 가져오는 것이 정답은 아닌 것 같아서 고민중입니다. |
||
} |
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()); | ||
} | ||
} |
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); | ||
} | ||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
비즈니스 로직을 전부 서비스단으로 넘겨버리니 컨트롤러의 코드가 훨씬 깔끔해진것 같습니다!!