Skip to content

Commit

Permalink
[refactor] voiceRoomRePo::findId return Optional
Browse files Browse the repository at this point in the history
  • Loading branch information
drbug2000 committed Nov 5, 2024
1 parent 794090f commit ef3f87a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import space.space_spring.entity.VoiceRoom;

import java.util.List;
import java.util.Optional;

@Repository
public interface VoiceRoomRepository extends JpaRepository<VoiceRoom,Long> {

Expand All @@ -24,7 +26,7 @@ public interface VoiceRoomRepository extends JpaRepository<VoiceRoom,Long> {
@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<VoiceRoom> findById(@Param("id") long Id);

@Query("SELECT v FROM VoiceRoom v WHERE v.space.id = :spaceId AND v.status = 'ACTIVE'")
List<VoiceRoom> findActiveVoiceRoomsBySpaceId(@Param("spaceId") Long spaceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -35,7 +38,7 @@ public List<GetParticipantList.ParticipantInfo> 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<ParticipantDto> participantDtos = liveKitUtils.getParticipantInfo(String.valueOf(voiceRoomId));
if(participantDtos==null || participantDtos.isEmpty()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand Down Expand Up @@ -167,7 +170,7 @@ public boolean updateVoiceRoom(List<PatchVoiceRoom.UpdateRoom> 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);
}
Expand All @@ -182,7 +185,7 @@ private String findProfileImageByUserId(Long userSpaceId){
// return voiceRoomRepository.findBySpace(space);
// }
private List<ParticipantDto> getParticipantDtoListById(long voiceRoomId){
Space space = voiceRoomRepository.findById(voiceRoomId).getSpace();
Space space = voiceRoomRepository.findById(voiceRoomId).orElseThrow(()->new CustomException(VOICEROOM_NOT_EXIST)).getSpace();
List<ParticipantDto> participantDtoList = liveKitUtils.getParticipantInfo(String.valueOf(voiceRoomId));
if(participantDtoList==null||participantDtoList.isEmpty()){
return Collections.emptyList();
Expand Down

0 comments on commit ef3f87a

Please sign in to comment.