Skip to content

Commit

Permalink
Merge pull request #165 from Kusitms-29th-MeetUp-H/feat/157-room
Browse files Browse the repository at this point in the history
[fix]:Main 채팅방 유저 추가 로직 수정
  • Loading branch information
qogustj authored May 23, 2024
2 parents d1e1223 + 49be1eb commit 8092816
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,13 @@ public List<SyncReviewResponseDto> 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<User> 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()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<User> userList, Boolean isPossible, Long syncId, User owner) {
public void createRoom(List<User> 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<ChatContent> contents = new ArrayList<>();

Expand All @@ -45,22 +45,14 @@ public void createRoom(List<User> 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<ChatUser> 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);
}
// 채팅방 개설 알림
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> googleOauth(HttpServletRequest request) throws IOException {
Expand Down

0 comments on commit 8092816

Please sign in to comment.