diff --git a/Main/src/main/java/com/kusitms29/backendH/api/sync/service/SyncDetailService.java b/Main/src/main/java/com/kusitms29/backendH/api/sync/service/SyncDetailService.java index 5eb28b9..151751d 100644 --- a/Main/src/main/java/com/kusitms29/backendH/api/sync/service/SyncDetailService.java +++ b/Main/src/main/java/com/kusitms29/backendH/api/sync/service/SyncDetailService.java @@ -132,12 +132,13 @@ public List getSyncReviewList(Long syncId, int take){ public void joinSync(Long userId, Long syncId){ Sync sync = syncReader.findById(syncId); User owner = userReader.getByUserId(sync.getUser().getId()); + User joinUser = userReader.getByUserId(userId); Participation newParticipation =Participation.createParticipation(User.from(userId), Sync.from(syncId)); participationAppender.saveParticipation(newParticipation); int count = participationManager.countParticipationBySyncId(syncId); Boolean isPossible = syncManager.validateCreateRoom(sync,count); List userList = participationReader.findAllBySyncId(syncId).stream().map(participation -> userReader.getByUserId(participation.getUser().getId())).toList(); - roomAppender.createRoom(userList,isPossible,syncId,owner); + roomAppender.createRoom(userList,isPossible,syncId,owner,joinUser); } public Boolean bookmark(Long userId, SyncBookmarkRequestDto syncBookmarkRequestDto){ if(syncBookmarkRequestDto.isMarked()){ diff --git a/Main/src/main/java/com/kusitms29/backendH/domain/chat/service/RoomAppender.java b/Main/src/main/java/com/kusitms29/backendH/domain/chat/service/RoomAppender.java index 09810c9..3d3bafd 100644 --- a/Main/src/main/java/com/kusitms29/backendH/domain/chat/service/RoomAppender.java +++ b/Main/src/main/java/com/kusitms29/backendH/domain/chat/service/RoomAppender.java @@ -22,13 +22,13 @@ public class RoomAppender { private final RoomRepository roomRepository; private final PushNotificationService pushNotificationService; private final SyncReader syncReader; + private final RoomReader roomReader; @Transactional - public void createRoom(List userList, Boolean isPossible, Long syncId, User owner) { + public void createRoom(List userList, Boolean isPossible, Long syncId, User owner,User joinUser) { Room room = null; - + Sync sync = syncReader.findById(syncId); if (isPossible) { // 채팅 내용 추가 - Sync sync = syncReader.findById(syncId); List contents = new ArrayList<>(); @@ -45,22 +45,14 @@ public void createRoom(List userList, Boolean isPossible, Long syncId, Use ); for (User user : userList) { if (sync.getUser().getId().equals(user.getId())) { - ChatContent chatContent = ChatContent.createChatContent(user.getUserName(), "환영합니다", room,"https://sync-content-bucket-01.s3.ap-northeast-2.amazonaws.com/94f1a566-0072-45e9-944f-707a6e21bbbf.png"); + ChatContent chatContent = ChatContent.createChatContent(user.getUserName(), "모두 반가워요~", room,"https://sync-content-bucket-01.s3.ap-northeast-2.amazonaws.com/a2d3a182-9054-42b9-b439-616bcbba9e87.png"); contents.add(chatContent); } } roomRepository.save(room); } else { - List chatUsers = userList.stream() - .map(ChatUser::createChatUser) - .toList(); - - // 기존 채팅방에 사용자 추가 - for (ChatUser chatUser : chatUsers) { - if (!room.getChatUserList().contains(chatUser)) { - room.addChatRoom(chatUser); - } - } + room = roomReader.getRoomBySyncName(sync.getSyncName()); + room.addChatRoom(ChatUser.createChatUser(joinUser)); roomRepository.save(room); } // 채팅방 개설 알림 diff --git a/Main/src/main/java/com/kusitms29/backendH/domain/chat/service/RoomReader.java b/Main/src/main/java/com/kusitms29/backendH/domain/chat/service/RoomReader.java new file mode 100644 index 0000000..8ebbcd8 --- /dev/null +++ b/Main/src/main/java/com/kusitms29/backendH/domain/chat/service/RoomReader.java @@ -0,0 +1,19 @@ +package com.kusitms29.backendH.domain.chat.service; + +import com.kusitms29.backendH.domain.chat.entity.Room; +import lombok.RequiredArgsConstructor; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class RoomReader { + private final MongoTemplate mongoTemplate; + public Room getRoomBySyncName(String syncName){ + Query query = new Query(); + query.addCriteria(Criteria.where("syncName").is(syncName)); + return mongoTemplate.findOne(query, Room.class); + } +} diff --git a/Main/src/main/java/com/kusitms29/backendH/global/common/HealthCheckApiController.java b/Main/src/main/java/com/kusitms29/backendH/global/common/HealthCheckApiController.java index 15b5c8a..fadec09 100644 --- a/Main/src/main/java/com/kusitms29/backendH/global/common/HealthCheckApiController.java +++ b/Main/src/main/java/com/kusitms29/backendH/global/common/HealthCheckApiController.java @@ -52,10 +52,11 @@ public class HealthCheckApiController { private String KAKAO_REDIRECT_URI; private Properties promptMap = new Properties(); private final TranslateConfig translateConfig; - public HealthCheckApiController(MongoTemplate mongoTemplate, RoomRepository roomRepository, TranslateConfig translateConfig) { + public HealthCheckApiController(UserReader userReader, MongoTemplate mongoTemplate, RoomRepository roomRepository, TranslateConfig translateConfig) { this.mongoTemplate = mongoTemplate; this.roomRepository = roomRepository; this.translateConfig = translateConfig; + this.userReader = userReader; } @GetMapping("google") public ResponseEntity googleOauth(HttpServletRequest request) throws IOException {