diff --git a/backend/src/main/java/com/happy/friendogly/chat/service/ChatCommandService.java b/backend/src/main/java/com/happy/friendogly/chat/service/ChatCommandService.java index 37a6369b8..67290f50e 100644 --- a/backend/src/main/java/com/happy/friendogly/chat/service/ChatCommandService.java +++ b/backend/src/main/java/com/happy/friendogly/chat/service/ChatCommandService.java @@ -12,6 +12,8 @@ import com.happy.friendogly.chat.dto.response.ChatMessageSocketResponse; import com.happy.friendogly.chat.repository.ChatMessageRepository; import com.happy.friendogly.chat.repository.ChatRoomRepository; +import com.happy.friendogly.club.domain.Club; +import com.happy.friendogly.club.repository.ClubRepository; import com.happy.friendogly.exception.FriendoglyException; import com.happy.friendogly.member.domain.Member; import com.happy.friendogly.member.repository.MemberRepository; @@ -29,6 +31,7 @@ public class ChatCommandService { private final MemberRepository memberRepository; private final ChatRoomRepository chatRoomRepository; private final ChatMessageRepository chatMessageRepository; + private final ClubRepository clubRepository; private final NotificationService notificationService; private final ChatTemplate chatTemplate; @@ -36,12 +39,14 @@ public ChatCommandService( MemberRepository memberRepository, ChatRoomRepository chatRoomRepository, ChatMessageRepository chatMessageRepository, + ClubRepository clubRepository, NotificationService notificationService, ChatTemplate chatTemplate ) { this.memberRepository = memberRepository; this.chatRoomRepository = chatRoomRepository; this.chatMessageRepository = chatMessageRepository; + this.clubRepository = clubRepository; this.notificationService = notificationService; this.chatTemplate = chatTemplate; } @@ -70,9 +75,10 @@ public void sendLeave(Long senderMemberId, Long chatRoomId) { } private void sendAndSave(MessageType messageType, String content, ChatRoom chatRoom, Member senderMember) { - ChatMessageSocketResponse chat = new ChatMessageSocketResponse(messageType, content, senderMember, - LocalDateTime.now()); - notificationService.sendChatNotification(chatRoom.getId(), chat); + ChatMessageSocketResponse chat = new ChatMessageSocketResponse( + messageType, content, senderMember, LocalDateTime.now()); + Club club = clubRepository.getByChatRoomId(chatRoom.getId()); + notificationService.sendChatNotification(chatRoom.getId(), chat, club); chatTemplate.convertAndSend(chatRoom.getId(), chat); chatMessageRepository.save(new ChatMessage(chatRoom, messageType, senderMember, content)); } diff --git a/backend/src/main/java/com/happy/friendogly/notification/service/FakeNotificationService.java b/backend/src/main/java/com/happy/friendogly/notification/service/FakeNotificationService.java index 55e09043a..c194617e7 100644 --- a/backend/src/main/java/com/happy/friendogly/notification/service/FakeNotificationService.java +++ b/backend/src/main/java/com/happy/friendogly/notification/service/FakeNotificationService.java @@ -1,6 +1,7 @@ package com.happy.friendogly.notification.service; import com.happy.friendogly.chat.dto.response.ChatMessageSocketResponse; +import com.happy.friendogly.club.domain.Club; import java.util.List; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Service; @@ -20,7 +21,7 @@ public void sendFootprintNotification(String title, String content, List } @Override - public void sendChatNotification(Long chatRoomId, ChatMessageSocketResponse response) { + public void sendChatNotification(Long chatRoomId, ChatMessageSocketResponse response, Club club) { } diff --git a/backend/src/main/java/com/happy/friendogly/notification/service/FcmNotificationService.java b/backend/src/main/java/com/happy/friendogly/notification/service/FcmNotificationService.java index 81bd7b5b3..133916a9c 100644 --- a/backend/src/main/java/com/happy/friendogly/notification/service/FcmNotificationService.java +++ b/backend/src/main/java/com/happy/friendogly/notification/service/FcmNotificationService.java @@ -10,6 +10,7 @@ import com.google.firebase.messaging.FirebaseMessagingException; import com.google.firebase.messaging.MulticastMessage; import com.happy.friendogly.chat.dto.response.ChatMessageSocketResponse; +import com.happy.friendogly.club.domain.Club; import com.happy.friendogly.exception.FriendoglyException; import com.happy.friendogly.notification.domain.NotificationType; import com.happy.friendogly.notification.repository.DeviceTokenRepository; @@ -55,7 +56,7 @@ public void sendFootprintNotification(String title, String content, List } @Override - public void sendChatNotification(Long chatRoomId, ChatMessageSocketResponse response) { + public void sendChatNotification(Long chatRoomId, ChatMessageSocketResponse response, Club club) { List receiverTokens = deviceTokenRepository .findAllByChatRoomIdWithoutMine(chatRoomId, response.senderMemberId()); @@ -66,7 +67,9 @@ public void sendChatNotification(Long chatRoomId, ChatMessageSocketResponse resp "senderName", response.senderName(), "content", response.content(), "createdAt", response.createdAt().toString(), - "profilePictureUrl", response.profilePictureUrl() + "profilePictureUrl", response.profilePictureUrl(), + "clubPictureUrl", club.getImageUrl(), + "clubTitle", club.getTitle().getValue() ); sendNotificationWithType(CHAT, "채팅", data, receiverTokens); diff --git a/backend/src/main/java/com/happy/friendogly/notification/service/NotificationService.java b/backend/src/main/java/com/happy/friendogly/notification/service/NotificationService.java index 5e166a309..0f541d371 100644 --- a/backend/src/main/java/com/happy/friendogly/notification/service/NotificationService.java +++ b/backend/src/main/java/com/happy/friendogly/notification/service/NotificationService.java @@ -1,6 +1,7 @@ package com.happy.friendogly.notification.service; import com.happy.friendogly.chat.dto.response.ChatMessageSocketResponse; +import com.happy.friendogly.club.domain.Club; import java.util.List; public interface NotificationService { @@ -9,7 +10,7 @@ public interface NotificationService { void sendFootprintNotification(String title, String content, List receiverTokens); - void sendChatNotification(Long chatRoomId, ChatMessageSocketResponse response); + void sendChatNotification(Long chatRoomId, ChatMessageSocketResponse response, Club club); void sendPlaygroundJoinNotification(String title, String content, List receiverTokens); } diff --git a/backend/src/test/java/com/happy/friendogly/chat/service/ChatCommandServiceTest.java b/backend/src/test/java/com/happy/friendogly/chat/service/ChatCommandServiceTest.java index 54d8da490..0d370dfdc 100644 --- a/backend/src/test/java/com/happy/friendogly/chat/service/ChatCommandServiceTest.java +++ b/backend/src/test/java/com/happy/friendogly/chat/service/ChatCommandServiceTest.java @@ -8,9 +8,15 @@ import com.happy.friendogly.chat.domain.ChatMessage; import com.happy.friendogly.chat.domain.ChatRoom; import com.happy.friendogly.chat.dto.request.ChatMessageSocketRequest; +import com.happy.friendogly.club.domain.Club; import com.happy.friendogly.member.domain.Member; +import com.happy.friendogly.pet.domain.Gender; +import com.happy.friendogly.pet.domain.Pet; +import com.happy.friendogly.pet.domain.SizeType; import com.happy.friendogly.support.ServiceTest; +import java.time.LocalDate; import java.util.List; +import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -28,8 +34,14 @@ class ChatCommandServiceTest extends ServiceTest { @BeforeEach void setUp() { member = memberRepository.save(new Member("트레", "abcdef12", "https://image.com/image.jpg")); - chatRoom = chatRoomRepository.save(ChatRoom.createGroup(5)); - chatRoom.addMember(member); + Pet pet = petRepository.save( + new Pet(member, "asda", "asfdfdsa", LocalDate.now().minusYears(1), SizeType.SMALL, Gender.MALE, + "https://image.com")); + Club club = clubRepository.save(Club.create( + "모임", "모임입니다.", "서울특별시", "구구구", "동동동", + 5, member, Set.of(Gender.MALE), Set.of(SizeType.SMALL), "https://image.com", List.of(pet) + )); + chatRoom = club.getChatRoom(); } @DisplayName("채팅 입장 메시지를 DB에 저장한다.") diff --git a/backend/src/test/java/com/happy/friendogly/chat/service/ChatRoomCommandServiceTest.java b/backend/src/test/java/com/happy/friendogly/chat/service/ChatRoomCommandServiceTest.java index e5ca88c32..f933f578b 100644 --- a/backend/src/test/java/com/happy/friendogly/chat/service/ChatRoomCommandServiceTest.java +++ b/backend/src/test/java/com/happy/friendogly/chat/service/ChatRoomCommandServiceTest.java @@ -12,8 +12,10 @@ import com.happy.friendogly.chat.dto.request.SaveChatRoomRequest; import com.happy.friendogly.chat.dto.response.SaveChatRoomResponse; import com.happy.friendogly.club.domain.Club; +import com.happy.friendogly.club.dto.request.SaveClubMemberRequest; import com.happy.friendogly.club.service.ClubCommandService; import com.happy.friendogly.member.domain.Member; +import com.happy.friendogly.pet.domain.Gender; import com.happy.friendogly.pet.domain.Pet; import com.happy.friendogly.pet.domain.SizeType; import com.happy.friendogly.support.ServiceTest; @@ -79,12 +81,22 @@ void save_AlreadyExists() { @Test void leave() { // given - ChatRoom chatRoom = chatRoomRepository.save(ChatRoom.createGroup(5)); - Member member3 = memberRepository.save(new Member("john", "aaa111ab", "https://image.com")); + Pet pet = petRepository.save( + new Pet(member1, "asda", "asfdfdsa", LocalDate.now().minusYears(1), SizeType.SMALL, Gender.MALE, + "https://image.com")); + + Club club = clubRepository.save(Club.create( + "모임", "모임입니다.", "서울특별시", "구구구", "동동동", + 5, member1, Set.of(Gender.MALE), Set.of(SizeType.SMALL), "https://image.com", List.of(pet) + )); - chatRoom.addMember(member1); - chatRoom.addMember(member2); - chatRoom.addMember(member3); + Pet pet2 = petRepository.save( + new Pet(member2, "asda", "asfdfdsa", LocalDate.now().minusYears(1), SizeType.SMALL, Gender.MALE, + "https://image.com")); + + clubCommandService.joinClub(club.getId(), member2.getId(), new SaveClubMemberRequest(List.of(pet2.getId()))); + + ChatRoom chatRoom = club.getChatRoom(); // when chatRoomCommandService.leave(member2.getId(), chatRoom.getId()); @@ -93,8 +105,7 @@ void leave() { ChatRoom foundChatRoom = chatRoomRepository.getById(chatRoom.getId()); assertAll( () -> assertThat(foundChatRoom.containsMember(member1)).isTrue(), - () -> assertThat(foundChatRoom.containsMember(member2)).isFalse(), - () -> assertThat(foundChatRoom.containsMember(member3)).isTrue() + () -> assertThat(foundChatRoom.containsMember(member2)).isFalse() ); }