From c37376e9b4430dcf421feadcab492611bc81ddda Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 16 Oct 2024 15:31:45 +0900 Subject: [PATCH 01/16] =?UTF-8?q?fix:=20ChatRoom=EC=9D=B4=20ChatRoomEntity?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mouda/backend/bet/domain/BetDetails.java | 60 ++++++++++--------- .../mouda/backend/bet/entity/BetEntity.java | 4 +- .../mouda/backend/chat/domain/ChatRoom.java | 21 +++---- .../mouda/backend/chat/entity/ChatEntity.java | 18 ++---- .../chat/implement/BetChatPreviewManager.java | 3 +- .../chat/implement/ChatRoomFinder.java | 12 ++-- .../chat/business/ChatRoomServiceTest.java | 4 +- .../implement/BetAttributeManagerTest.java | 2 +- .../implement/BetParticipantResolverTest.java | 7 ++- .../implement/ChatRoomDetailsFinderTest.java | 21 ++++--- .../MoimParticipantResolverTest.java | 3 +- 11 files changed, 81 insertions(+), 74 deletions(-) diff --git a/backend/src/main/java/mouda/backend/bet/domain/BetDetails.java b/backend/src/main/java/mouda/backend/bet/domain/BetDetails.java index 904f52a9e..481aaedfb 100644 --- a/backend/src/main/java/mouda/backend/bet/domain/BetDetails.java +++ b/backend/src/main/java/mouda/backend/bet/domain/BetDetails.java @@ -8,31 +8,37 @@ @Getter public class BetDetails { - private final Long id; - private final String title; - private final BettingTime bettingTime; - - @Builder - public BetDetails(Long id, String title, LocalDateTime bettingTime) { - this.id = id; - this.title = title; - this.bettingTime = new BettingTime(bettingTime); - } - - public static BetDetails create(String title, int waitingMinutes) { - LocalDateTime bettingTime = LocalDateTime.now().plusMinutes(waitingMinutes); - - return BetDetails.builder() - .title(title) - .bettingTime(bettingTime) - .build(); - } - - public LocalDateTime getBettingTime() { - return bettingTime.getBettingTime(); - } - - public long timeDifferenceInMinutesWithNow() { - return bettingTime.timeDifferenceInMinutesWithNow(); - } + private final Long id; + private final String title; + private final BettingTime bettingTime; + private final Long loserId; + + @Builder + public BetDetails(Long id, String title, LocalDateTime bettingTime, Long loserId) { + this.id = id; + this.title = title; + this.bettingTime = new BettingTime(bettingTime); + this.loserId = loserId; + } + + public static BetDetails create(String title, int waitingMinutes) { + LocalDateTime bettingTime = LocalDateTime.now().plusMinutes(waitingMinutes); + + return BetDetails.builder() + .title(title) + .bettingTime(bettingTime) + .build(); + } + + public LocalDateTime getBettingTime() { + return bettingTime.getBettingTime(); + } + + public long timeDifferenceInMinutesWithNow() { + return bettingTime.timeDifferenceInMinutesWithNow(); + } + + public boolean hasLoser() { + return loserId != null; + } } diff --git a/backend/src/main/java/mouda/backend/bet/entity/BetEntity.java b/backend/src/main/java/mouda/backend/bet/entity/BetEntity.java index ccdbb1c91..ad3195d63 100644 --- a/backend/src/main/java/mouda/backend/bet/entity/BetEntity.java +++ b/backend/src/main/java/mouda/backend/bet/entity/BetEntity.java @@ -39,7 +39,8 @@ public class BetEntity { private long moimerId; @Builder - private BetEntity(Long id, String title, LocalDateTime bettingTime, Long loserDarakbangMemberId, long darakbangId, long moimerId) { + private BetEntity(Long id, String title, LocalDateTime bettingTime, Long loserDarakbangMemberId, long darakbangId, + long moimerId) { this.id = id; this.title = title; this.bettingTime = bettingTime; @@ -74,6 +75,7 @@ public BetDetails toBetDetails() { .id(id) .title(title) .bettingTime(bettingTime) + .loserId(loserDarakbangMemberId) .build(); } } diff --git a/backend/src/main/java/mouda/backend/chat/domain/ChatRoom.java b/backend/src/main/java/mouda/backend/chat/domain/ChatRoom.java index 63e4d63b2..9e176cc5b 100644 --- a/backend/src/main/java/mouda/backend/chat/domain/ChatRoom.java +++ b/backend/src/main/java/mouda/backend/chat/domain/ChatRoom.java @@ -3,29 +3,24 @@ import java.time.LocalDateTime; import lombok.Getter; -import mouda.backend.chat.entity.ChatEntity; -import mouda.backend.chat.entity.ChatRoomEntity; @Getter public class ChatRoom { - private final Long id; + private final long id; private final long targetId; private final ChatRoomType type; private final LastChat lastChat; - public ChatRoom(ChatRoomEntity chatRoomEntity, ChatEntity lastChat) { - this.id = chatRoomEntity.getId(); - this.targetId = chatRoomEntity.getTargetId(); - this.type = chatRoomEntity.getType(); - this.lastChat = new LastChat(lastChat.getDateTime(), lastChat.getContent()); + public ChatRoom(Long id, long targetId, ChatRoomType type, LastChat lastChat) { + this.id = id; + this.targetId = targetId; + this.type = type; + this.lastChat = lastChat; } - public ChatRoom(ChatRoomEntity chatRoomEntity) { - this.id = chatRoomEntity.getId(); - this.targetId = chatRoomEntity.getTargetId(); - this.type = chatRoomEntity.getType(); - this.lastChat = LastChat.empty(); + public ChatRoom(Long id, long targetId, ChatRoomType type) { + this(id, targetId, type, LastChat.empty()); } public boolean isMoim() { diff --git a/backend/src/main/java/mouda/backend/chat/entity/ChatEntity.java b/backend/src/main/java/mouda/backend/chat/entity/ChatEntity.java index f462e6759..11bdae3c7 100644 --- a/backend/src/main/java/mouda/backend/chat/entity/ChatEntity.java +++ b/backend/src/main/java/mouda/backend/chat/entity/ChatEntity.java @@ -17,6 +17,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import mouda.backend.chat.domain.Chat; +import mouda.backend.chat.domain.LastChat; import mouda.backend.darakbangmember.domain.DarakbangMember; @Entity @@ -54,19 +55,6 @@ public ChatEntity(String content, long chatRoomId, DarakbangMember darakbangMemb this.chatType = chatType; } - public static ChatEntity empty() { - return ChatEntity.builder() - .content("") - .build(); - } - - public LocalDateTime getDateTime() { - if (date == null || time == null) { - return null; - } - return LocalDateTime.of(date, time); - } - public Chat toChat() { return Chat.builder() .id(id) @@ -77,4 +65,8 @@ public Chat toChat() { .time(time) .build(); } + + public LastChat toLastChat() { + return new LastChat(LocalDateTime.of(date, time), content); + } } diff --git a/backend/src/main/java/mouda/backend/chat/implement/BetChatPreviewManager.java b/backend/src/main/java/mouda/backend/chat/implement/BetChatPreviewManager.java index 6c3720492..69511e87e 100644 --- a/backend/src/main/java/mouda/backend/chat/implement/BetChatPreviewManager.java +++ b/backend/src/main/java/mouda/backend/chat/implement/BetChatPreviewManager.java @@ -40,7 +40,8 @@ private ChatPreview getChatPreview(BetDetails bet) { ChatRoom chatRoom = chatRoomFinder.readChatRoomByTargetId(bet.getId(), ChatRoomType.BET); long lastReadChatId = betDarakbangMemberRepository.findLastReadChatIdByBetId(targetId); List participants = betDarakbangMemberRepository.findAllByBetId(targetId).stream() - .map(betDarakbangMember -> new Participant(betDarakbangMember.getDarakbangMember().getNickname(), betDarakbangMember.getDarakbangMember().getProfile(), + .map(betDarakbangMember -> new Participant(betDarakbangMember.getDarakbangMember().getNickname(), + betDarakbangMember.getDarakbangMember().getProfile(), betDarakbangMember.getDarakbangMember().getRole().toString())) .toList(); diff --git a/backend/src/main/java/mouda/backend/chat/implement/ChatRoomFinder.java b/backend/src/main/java/mouda/backend/chat/implement/ChatRoomFinder.java index 3a60380f2..082d438ac 100644 --- a/backend/src/main/java/mouda/backend/chat/implement/ChatRoomFinder.java +++ b/backend/src/main/java/mouda/backend/chat/implement/ChatRoomFinder.java @@ -12,6 +12,7 @@ import mouda.backend.chat.domain.ChatRoom; import mouda.backend.chat.domain.ChatRoomType; import mouda.backend.chat.domain.Chats; +import mouda.backend.chat.domain.LastChat; import mouda.backend.chat.entity.ChatEntity; import mouda.backend.chat.entity.ChatRoomEntity; import mouda.backend.chat.exception.ChatErrorMessage; @@ -37,7 +38,7 @@ public ChatRoom read(long darakbangId, long chatRoomId, DarakbangMember darakban if (!isParticipated) { throw new ChatException(HttpStatus.FORBIDDEN, ChatErrorMessage.UNAUTHORIZED); } - return new ChatRoom(chatRoomEntity); + return new ChatRoom(chatRoomEntity.getId(), chatRoomEntity.getTargetId(), chatRoomEntity.getType()); } private boolean checkParticipation(ChatRoomEntity chatRoomEntity, DarakbangMember darakbangMember) { @@ -61,17 +62,18 @@ public ChatRoom readMoimChatRoom(long darakbangId, long chatRoomId) { if (type.isNotMoim()) { throw new ChatException(HttpStatus.BAD_REQUEST, ChatErrorMessage.INVALID_CHATROOM_TYPE); } - return new ChatRoom(chatRoomEntity); + return new ChatRoom(chatRoomEntity.getId(), chatRoomEntity.getTargetId(), chatRoomEntity.getType()); } public ChatRoom readChatRoomByTargetId(long targetId, ChatRoomType chatRoomType) { ChatRoomEntity chatRoomEntity = chatRoomRepository.findByTargetIdAndType(targetId, chatRoomType) .orElseThrow(() -> new ChatException(HttpStatus.NOT_FOUND, ChatErrorMessage.CHATROOM_NOT_FOUND)); - ChatEntity lastChat = chatRepository.findFirstByChatRoomIdOrderByIdDesc(chatRoomEntity.getId()) - .orElse(ChatEntity.empty()); + LastChat lastChat = chatRepository.findFirstByChatRoomIdOrderByIdDesc(chatRoomEntity.getId()) + .map(ChatEntity::toLastChat) + .orElse(LastChat.empty()); - return new ChatRoom(chatRoomEntity, lastChat); + return new ChatRoom(chatRoomEntity.getId(), chatRoomEntity.getTargetId(), chatRoomEntity.getType(), lastChat); } public Chats findAllUnloadedChats(long chatRoomId, long recentChatId) { diff --git a/backend/src/test/java/mouda/backend/chat/business/ChatRoomServiceTest.java b/backend/src/test/java/mouda/backend/chat/business/ChatRoomServiceTest.java index 84f2488d0..acdfe6290 100644 --- a/backend/src/test/java/mouda/backend/chat/business/ChatRoomServiceTest.java +++ b/backend/src/test/java/mouda/backend/chat/business/ChatRoomServiceTest.java @@ -92,14 +92,14 @@ void findMoimChatPreview() { @Test void findBetChatPreview() { // given - BetEntity betEntity = BetEntityFixture.getBetEntity(darakbang.getId(), darakbangHogee.getId()); + BetEntity betEntity = BetEntityFixture.getDrawedBetEntity(darakbang.getId(), darakbangHogee.getId()); BetEntity savedBetEntity = betRepository.save(betEntity); BetDarakbangMemberEntity betDarakbangMemberEntity = new BetDarakbangMemberEntity(darakbangHogee, savedBetEntity); betDarakbangMemberRepository.save(betDarakbangMemberEntity); - ChatRoomEntity chatRoomEntity = ChatRoomEntityFixture.getChatRoomEntityOfBet(betEntity.getId(), + ChatRoomEntity chatRoomEntity = ChatRoomEntityFixture.getChatRoomEntityOfBet(savedBetEntity.getId(), darakbang.getId()); ChatRoomEntity chatRoom = chatRoomRepository.save(chatRoomEntity); diff --git a/backend/src/test/java/mouda/backend/chat/implement/BetAttributeManagerTest.java b/backend/src/test/java/mouda/backend/chat/implement/BetAttributeManagerTest.java index 13334e5aa..6ae221649 100644 --- a/backend/src/test/java/mouda/backend/chat/implement/BetAttributeManagerTest.java +++ b/backend/src/test/java/mouda/backend/chat/implement/BetAttributeManagerTest.java @@ -83,7 +83,7 @@ void create_shouldReturnBetAttributes() { when(darakbang.getId()).thenReturn(1L); when(betFinder.find(1L, 1L)).thenReturn(bet); - when(bet.getBetDetails()).thenReturn(new BetDetails(1L, "test bet", LocalDateTime.of(2024, 6, 5, 12, 3))); + when(bet.getBetDetails()).thenReturn(new BetDetails(1L, "test bet", LocalDateTime.of(2024, 6, 5, 12, 3), null)); when(bet.isLoser(darakbangMember.getId())).thenReturn(true); when(bet.getId()).thenReturn(1L); when(bet.getLoserId()).thenReturn(2L); diff --git a/backend/src/test/java/mouda/backend/chat/implement/BetParticipantResolverTest.java b/backend/src/test/java/mouda/backend/chat/implement/BetParticipantResolverTest.java index a75971c1e..d737bb6a2 100644 --- a/backend/src/test/java/mouda/backend/chat/implement/BetParticipantResolverTest.java +++ b/backend/src/test/java/mouda/backend/chat/implement/BetParticipantResolverTest.java @@ -48,9 +48,10 @@ void resolve_shouldReturnParticipantsForGivenChatRoom() { betDarakbangMemberRepository.save(annaEntity); betDarakbangMemberRepository.save(hogeeEntity); - ChatRoomEntity chatRoomEntity = ChatRoomEntityFixture.getChatRoomEntityOfBet(betEntity.getId(), darakbang.getId()); - ChatRoomEntity savedChatRoomEntity = chatRoomRepository.save(chatRoomEntity); - ChatRoom chatRoom = new ChatRoom(savedChatRoomEntity); + ChatRoomEntity chatRoomEntity = ChatRoomEntityFixture.getChatRoomEntityOfBet(betEntity.getId(), + darakbang.getId()); + ChatRoomEntity savedChatRoom = chatRoomRepository.save(chatRoomEntity); + ChatRoom chatRoom = new ChatRoom(savedChatRoom.getId(), savedChatRoom.getTargetId(), savedChatRoom.getType()); // when List participants = betParticipantResolver.resolve(chatRoom); diff --git a/backend/src/test/java/mouda/backend/chat/implement/ChatRoomDetailsFinderTest.java b/backend/src/test/java/mouda/backend/chat/implement/ChatRoomDetailsFinderTest.java index e98515175..dfda5b9da 100644 --- a/backend/src/test/java/mouda/backend/chat/implement/ChatRoomDetailsFinderTest.java +++ b/backend/src/test/java/mouda/backend/chat/implement/ChatRoomDetailsFinderTest.java @@ -73,16 +73,19 @@ void find_moimChatRoomType() { ChatRoomEntity chatRoomEntity = ChatRoomEntityFixture.getChatRoomEntityOfMoim(moim.getId(), darakbang.getId()); ChatRoomEntity savedChatRoomEntity = chatRoomRepository.save(chatRoomEntity); - ChatRoom chatRoom = new ChatRoom(savedChatRoomEntity); + ChatRoom chatRoom = new ChatRoom(savedChatRoomEntity.getId(), savedChatRoomEntity.getTargetId(), + savedChatRoomEntity.getType()); // when - ChatRoomDetails chatRoomDetails = chatRoomDetailsFinder.find(darakbang.getId(), chatRoom.getId(), darakbangAnna); + ChatRoomDetails chatRoomDetails = chatRoomDetailsFinder.find(darakbang.getId(), chatRoom.getId(), + darakbangAnna); // then assertThat(chatRoomDetails.getChatRoomType()).isEqualTo(ChatRoomType.MOIM); assertThat(chatRoomDetails.getTitle()).isEqualTo("커피 마실 사람?"); assertThat(chatRoomDetails.getId()).isEqualTo(chatRoom.getId()); - assertThat(chatRoomDetails.getParticipants()).containsExactly(new Participant("anna", "profile", "MOIMER"), new Participant("hogee", "profile", "MOIMEE")); + assertThat(chatRoomDetails.getParticipants()).containsExactly(new Participant("anna", "profile", "MOIMER"), + new Participant("hogee", "profile", "MOIMEE")); assertThat(chatRoomDetails.getAttributes()) .containsExactlyInAnyOrderEntriesOf(getExpectedMoimAttributes(savedMoim)); } @@ -112,18 +115,22 @@ void find_betChatRoomType() { betDarakbangMemberRepository.save(annaEntity); betDarakbangMemberRepository.save(hogeeEntity); - ChatRoomEntity chatRoomEntity = ChatRoomEntityFixture.getChatRoomEntityOfBet(betEntity.getId(), darakbang.getId()); + ChatRoomEntity chatRoomEntity = ChatRoomEntityFixture.getChatRoomEntityOfBet(betEntity.getId(), + darakbang.getId()); ChatRoomEntity savedChatRoomEntity = chatRoomRepository.save(chatRoomEntity); - ChatRoom chatRoom = new ChatRoom(savedChatRoomEntity); + ChatRoom chatRoom = new ChatRoom(savedChatRoomEntity.getId(), savedChatRoomEntity.getTargetId(), + savedChatRoomEntity.getType()); // when - ChatRoomDetails chatRoomDetails = chatRoomDetailsFinder.find(darakbang.getId(), chatRoom.getId(), darakbangAnna); + ChatRoomDetails chatRoomDetails = chatRoomDetailsFinder.find(darakbang.getId(), chatRoom.getId(), + darakbangAnna); // then assertThat(chatRoomDetails.getChatRoomType()).isEqualTo(ChatRoomType.BET); assertThat(chatRoomDetails.getTitle()).isEqualTo("테바바보"); assertThat(chatRoomDetails.getId()).isEqualTo(chatRoom.getId()); - assertThat(chatRoomDetails.getParticipants()).containsExactly(new Participant("anna", "profile", "MOIMER"), new Participant("hogee", "profile", "MOIMEE")); + assertThat(chatRoomDetails.getParticipants()).containsExactly(new Participant("anna", "profile", "MOIMER"), + new Participant("hogee", "profile", "MOIMEE")); assertThat(chatRoomDetails.getAttributes()) .containsExactlyInAnyOrderEntriesOf(getExpectedBetAttributes(savedBetEntity)); } diff --git a/backend/src/test/java/mouda/backend/chat/implement/MoimParticipantResolverTest.java b/backend/src/test/java/mouda/backend/chat/implement/MoimParticipantResolverTest.java index a4eed0c84..2833892fe 100644 --- a/backend/src/test/java/mouda/backend/chat/implement/MoimParticipantResolverTest.java +++ b/backend/src/test/java/mouda/backend/chat/implement/MoimParticipantResolverTest.java @@ -59,7 +59,8 @@ void resolve_shouldReturnParticipantsForGivenChatRoom() { ChatRoomEntity chatRoomEntity = ChatRoomEntityFixture.getChatRoomEntityOfMoim(moim.getId(), darakbang.getId()); ChatRoomEntity savedChatRoomEntity = chatRoomRepository.save(chatRoomEntity); - ChatRoom chatRoom = new ChatRoom(savedChatRoomEntity); + ChatRoom chatRoom = new ChatRoom(savedChatRoomEntity.getId(), savedChatRoomEntity.getTargetId(), + savedChatRoomEntity.getType()); // when List participants = moimParticipantResolver.resolve(chatRoom); From 9541c4ba3de7e16f4e8f4ea1968b3307751dc3c7 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 16 Oct 2024 15:32:15 +0900 Subject: [PATCH 02/16] =?UTF-8?q?fix:=20=EC=B6=94=EC=B2=A8=EC=9E=90=20?= =?UTF-8?q?=EC=9E=88=EB=8A=94=20=EC=95=88=EB=82=B4=EB=A9=B4=EC=A7=84?= =?UTF-8?q?=EB=8B=A4=EB=A7=8C=20=EC=B1=84=ED=8C=85=EB=B0=A9=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20=EA=B0=80=EB=8A=A5=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/implement/BetChatPreviewManager.java | 1 + .../implement/BetChatPreviewManagerTest.java | 20 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/backend/src/main/java/mouda/backend/chat/implement/BetChatPreviewManager.java b/backend/src/main/java/mouda/backend/chat/implement/BetChatPreviewManager.java index 69511e87e..cf4aac823 100644 --- a/backend/src/main/java/mouda/backend/chat/implement/BetChatPreviewManager.java +++ b/backend/src/main/java/mouda/backend/chat/implement/BetChatPreviewManager.java @@ -30,6 +30,7 @@ public List create(DarakbangMember darakbangMember) { List myBets = betFinder.readAllMyBets(darakbangMember); return myBets.stream() + .filter(BetDetails::hasLoser) .map(this::getChatPreview) .sorted() .toList(); diff --git a/backend/src/test/java/mouda/backend/chat/implement/BetChatPreviewManagerTest.java b/backend/src/test/java/mouda/backend/chat/implement/BetChatPreviewManagerTest.java index 7136ba72c..2f44c6dd6 100644 --- a/backend/src/test/java/mouda/backend/chat/implement/BetChatPreviewManagerTest.java +++ b/backend/src/test/java/mouda/backend/chat/implement/BetChatPreviewManagerTest.java @@ -43,23 +43,19 @@ void createWithoutBet() { assertThat(chatPreviews).isEmpty(); } - @DisplayName("안내면진다 채팅방 목록을 조회한다.") + @DisplayName("채팅방 목록에서 추첨 후 채팅방이 열린 안내면진다만 조회한다.") @Test void create() { // given - BetEntity betEntity1 = BetEntityFixture.getBetEntity(darakbangAnna.getId(), 1L); + BetEntity betEntity1 = BetEntityFixture.getDrawedBetEntity(darakbangAnna.getId(), 1L); BetEntity betEntity2 = BetEntityFixture.getBetEntity(darakbangAnna.getId(), 1L); - betRepository.save(betEntity1); - betRepository.save(betEntity2); - betDarakbangMemberRepository.save(new BetDarakbangMemberEntity(darakbangHogee, betEntity1)); - betDarakbangMemberRepository.save(new BetDarakbangMemberEntity(darakbangHogee, betEntity2)); + BetEntity savedBet1 = betRepository.save(betEntity1); + BetEntity savedBet2 = betRepository.save(betEntity2); + betDarakbangMemberRepository.save(new BetDarakbangMemberEntity(darakbangHogee, savedBet1)); + betDarakbangMemberRepository.save(new BetDarakbangMemberEntity(darakbangHogee, savedBet2)); - ChatRoomEntity chatRoom1 = ChatRoomEntityFixture.getChatRoomEntityOfBet(betEntity1.getId(), - darakbang.getId()); - ChatRoomEntity chatRoom2 = ChatRoomEntityFixture.getChatRoomEntityOfBet(betEntity2.getId(), - darakbang.getId()); + ChatRoomEntity chatRoom1 = ChatRoomEntityFixture.getChatRoomEntityOfBet(savedBet1.getId(), darakbang.getId()); chatRoomRepository.save(chatRoom1); - chatRoomRepository.save(chatRoom2); // when List chatPreviews = betChatPreviewManager.create(darakbangHogee); @@ -67,6 +63,6 @@ void create() { // then assertThat(chatPreviews) .isNotEmpty() - .hasSize(2); + .hasSize(1); } } From cdcdb600b4f1c4a07a774b032556d029d446f5c6 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 16 Oct 2024 15:32:39 +0900 Subject: [PATCH 03/16] =?UTF-8?q?fix:=20targetid=20nullable=20=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/java/mouda/backend/chat/domain/Target.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/mouda/backend/chat/domain/Target.java b/backend/src/main/java/mouda/backend/chat/domain/Target.java index 0b18c66c9..3ddecc53c 100644 --- a/backend/src/main/java/mouda/backend/chat/domain/Target.java +++ b/backend/src/main/java/mouda/backend/chat/domain/Target.java @@ -7,7 +7,7 @@ @Getter public class Target { - private final Long targetId; + private final long targetId; private final String title; private final boolean isStarted; From 4a2d72040e84a0a0b79cb931ef568c202d701816 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 16 Oct 2024 15:55:53 +0900 Subject: [PATCH 04/16] =?UTF-8?q?fix:=20=EC=B1=84=ED=8C=85=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=AA=A8=EB=91=90=20=EC=9E=90=EC=8B=A0=EC=9D=98=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=ED=95=84=EB=A1=9C=20=EB=82=98=EC=98=A4?= =?UTF-8?q?=EB=8A=94=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mouda/backend/chat/domain/ChatWithAuthor.java | 4 ++-- .../main/java/mouda/backend/chat/domain/Chats.java | 6 +----- .../java/mouda/backend/chat/domain/Participant.java | 9 ++++++++- .../mouda/backend/chat/business/ChatServiceTest.java | 6 +++++- .../common/fixture/DarakbangMemberFixture.java | 11 +++++++++++ 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/backend/src/main/java/mouda/backend/chat/domain/ChatWithAuthor.java b/backend/src/main/java/mouda/backend/chat/domain/ChatWithAuthor.java index 83942ad04..db8b55191 100644 --- a/backend/src/main/java/mouda/backend/chat/domain/ChatWithAuthor.java +++ b/backend/src/main/java/mouda/backend/chat/domain/ChatWithAuthor.java @@ -9,9 +9,9 @@ public class ChatWithAuthor { private final Participant participant; private final boolean isMine; - public ChatWithAuthor(Chat chat, Participant participant,boolean isMine) { + public ChatWithAuthor(Chat chat, boolean isMine) { this.chat = chat; - this.participant = participant; + this.participant = new Participant(chat); this.isMine = isMine; } } diff --git a/backend/src/main/java/mouda/backend/chat/domain/Chats.java b/backend/src/main/java/mouda/backend/chat/domain/Chats.java index 134f70989..1174ec54a 100644 --- a/backend/src/main/java/mouda/backend/chat/domain/Chats.java +++ b/backend/src/main/java/mouda/backend/chat/domain/Chats.java @@ -16,11 +16,7 @@ public Chats(List chats) { public List getChatsWithAuthor(DarakbangMember darakbangMember) { return chats.stream() - .map(chat -> new ChatWithAuthor(chat, new Participant( - darakbangMember.getNickname(), - darakbangMember.getProfile(), - darakbangMember.getDescription()), - chat.isMyMessage(darakbangMember.getId()))) + .map(chat -> new ChatWithAuthor(chat, chat.isMyMessage(darakbangMember.getId()))) .toList(); } } diff --git a/backend/src/main/java/mouda/backend/chat/domain/Participant.java b/backend/src/main/java/mouda/backend/chat/domain/Participant.java index b804d9f8a..33add9561 100644 --- a/backend/src/main/java/mouda/backend/chat/domain/Participant.java +++ b/backend/src/main/java/mouda/backend/chat/domain/Participant.java @@ -17,6 +17,12 @@ public Participant(String nickname, String profile, String role) { this.role = role; } + public Participant(Chat chat) { + this.nickname = chat.getDarakbangMember().getNickname(); + this.profile = chat.getDarakbangMember().getProfile(); + this.role = chat.getDarakbangMember().getDescription(); + } + @Override public boolean equals(Object o) { if (this == o) @@ -24,7 +30,8 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; Participant that = (Participant)o; - return Objects.equals(nickname, that.nickname) && Objects.equals(profile, that.profile) && Objects.equals(role, that.role); + return Objects.equals(nickname, that.nickname) && Objects.equals(profile, that.profile) && Objects.equals(role, + that.role); } @Override diff --git a/backend/src/test/java/mouda/backend/chat/business/ChatServiceTest.java b/backend/src/test/java/mouda/backend/chat/business/ChatServiceTest.java index f59768fb2..fa27b5548 100644 --- a/backend/src/test/java/mouda/backend/chat/business/ChatServiceTest.java +++ b/backend/src/test/java/mouda/backend/chat/business/ChatServiceTest.java @@ -257,7 +257,7 @@ void findUnloadedChats() { ChatRoomEntityFixture.getChatRoomEntityOfMoim(savedMoim.getId(), darakbang.getId())); chatRepository.save(ChatEntityFixture.getChatEntity(darakbangHogee)); - chatRepository.save(ChatEntityFixture.getChatEntity(darakbangHogee)); + chatRepository.save(ChatEntityFixture.getChatEntity(darakbangAnna)); chatRepository.save(ChatEntityFixture.getChatEntity(darakbangHogee)); // when @@ -266,6 +266,10 @@ void findUnloadedChats() { // then assertThat(unloadedChats.chats()).hasSize(2); + assertThat(unloadedChats.chats().get(0).isMyMessage()).isFalse(); + assertThat(unloadedChats.chats().get(0).participation().nickname()).isEqualTo(darakbangAnna.getNickname()); + assertThat(unloadedChats.chats().get(1).isMyMessage()).isTrue(); + assertThat(unloadedChats.chats().get(1).participation().nickname()).isEqualTo(darakbangHogee.getNickname()); } @DisplayName("열린 채팅방이 없다면 빈 리스트를 반환한다.") diff --git a/backend/src/test/java/mouda/backend/common/fixture/DarakbangMemberFixture.java b/backend/src/test/java/mouda/backend/common/fixture/DarakbangMemberFixture.java index 7e117f8cf..f85033939 100644 --- a/backend/src/test/java/mouda/backend/common/fixture/DarakbangMemberFixture.java +++ b/backend/src/test/java/mouda/backend/common/fixture/DarakbangMemberFixture.java @@ -29,6 +29,17 @@ public static DarakbangMember getDarakbangMemberWithWooteco(Darakbang darakbang, .build(); } + public static DarakbangMember getDarakbangMemberWithWooteco(Member member) { + return DarakbangMember.builder() + .darakbang(DarakbangFixture.getDarakbangWithMouda()) + .memberId(member.getId()) + .nickname(member.getName()) + .profile("profile") + .description("description") + .role(DarakBangMemberRole.MEMBER) + .build(); + } + public static DarakbangMember getDarakbangOutsiderWithWooteco(Darakbang darakbang, Member member) { return DarakbangMember.builder() .darakbang(darakbang) From c346dd8fed88560b936f64315997831c9c0f6f23 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 16 Oct 2024 17:00:57 +0900 Subject: [PATCH 05/16] =?UTF-8?q?feat:=20Author=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 채팅 작성자 도메인 --- .../mouda/backend/chat/domain/Author.java | 19 +++++++++++++++++++ .../domain/DarakbangMember.java | 9 +++++++++ 2 files changed, 28 insertions(+) create mode 100644 backend/src/main/java/mouda/backend/chat/domain/Author.java diff --git a/backend/src/main/java/mouda/backend/chat/domain/Author.java b/backend/src/main/java/mouda/backend/chat/domain/Author.java new file mode 100644 index 000000000..75dc7f661 --- /dev/null +++ b/backend/src/main/java/mouda/backend/chat/domain/Author.java @@ -0,0 +1,19 @@ +package mouda.backend.chat.domain; + +import lombok.Builder; +import lombok.Getter; + +@Getter +public class Author { + + private final long id; + private final String nickname; + private final String profile; + + @Builder + public Author(long id, String nickname, String profile) { + this.id = id; + this.nickname = nickname; + this.profile = profile; + } +} diff --git a/backend/src/main/java/mouda/backend/darakbangmember/domain/DarakbangMember.java b/backend/src/main/java/mouda/backend/darakbangmember/domain/DarakbangMember.java index a8334020c..a9b56ac4a 100644 --- a/backend/src/main/java/mouda/backend/darakbangmember/domain/DarakbangMember.java +++ b/backend/src/main/java/mouda/backend/darakbangmember/domain/DarakbangMember.java @@ -19,6 +19,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import mouda.backend.chat.domain.Author; import mouda.backend.darakbang.domain.Darakbang; import mouda.backend.darakbangmember.exception.DarakbangMemberErrorMessage; import mouda.backend.darakbangmember.exception.DarakbangMemberException; @@ -111,6 +112,14 @@ public boolean hasImage() { return profile != null; } + public Author toAuthor() { + return Author.builder() + .id(id) + .nickname(nickname) + .profile(profile) + .build(); + } + @Override public boolean equals(Object o) { if (this == o) From e02e5b2c26ad577aa0e60fe93a3e997e7d2a4832 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 16 Oct 2024 17:13:00 +0900 Subject: [PATCH 06/16] =?UTF-8?q?refactor:=20chat=20DarakbangMember?= =?UTF-8?q?=EB=A5=BC=20Author=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/mouda/backend/chat/domain/Chat.java | 10 ++++------ .../java/mouda/backend/chat/domain/ChatWithAuthor.java | 2 -- .../java/mouda/backend/chat/entity/ChatEntity.java | 2 +- .../presentation/response/ChatFindDetailResponse.java | 6 +++--- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/backend/src/main/java/mouda/backend/chat/domain/Chat.java b/backend/src/main/java/mouda/backend/chat/domain/Chat.java index baa91f7e0..7a3c11c8f 100644 --- a/backend/src/main/java/mouda/backend/chat/domain/Chat.java +++ b/backend/src/main/java/mouda/backend/chat/domain/Chat.java @@ -6,30 +6,28 @@ import lombok.Builder; import lombok.Getter; import mouda.backend.chat.entity.ChatType; -import mouda.backend.darakbangmember.domain.DarakbangMember; @Getter public class Chat { private final long id; private final String content; - private final DarakbangMember darakbangMember; + private final Author author; private final LocalDate date; private final LocalTime time; private final ChatType chatType; @Builder - public Chat(long id, String content, DarakbangMember darakbangMember, LocalDate date, LocalTime time, - ChatType chatType) { + public Chat(long id, String content, Author author, LocalDate date, LocalTime time, ChatType chatType) { this.id = id; this.content = content; - this.darakbangMember = darakbangMember; + this.author = author; this.date = date; this.time = time; this.chatType = chatType; } public boolean isMyMessage(long darakbangMemberId) { - return darakbangMember.getId() == darakbangMemberId; + return author.getId() == darakbangMemberId; } } diff --git a/backend/src/main/java/mouda/backend/chat/domain/ChatWithAuthor.java b/backend/src/main/java/mouda/backend/chat/domain/ChatWithAuthor.java index db8b55191..b442b2d62 100644 --- a/backend/src/main/java/mouda/backend/chat/domain/ChatWithAuthor.java +++ b/backend/src/main/java/mouda/backend/chat/domain/ChatWithAuthor.java @@ -6,12 +6,10 @@ public class ChatWithAuthor { private final Chat chat; - private final Participant participant; private final boolean isMine; public ChatWithAuthor(Chat chat, boolean isMine) { this.chat = chat; - this.participant = new Participant(chat); this.isMine = isMine; } } diff --git a/backend/src/main/java/mouda/backend/chat/entity/ChatEntity.java b/backend/src/main/java/mouda/backend/chat/entity/ChatEntity.java index 11bdae3c7..eb4cdc868 100644 --- a/backend/src/main/java/mouda/backend/chat/entity/ChatEntity.java +++ b/backend/src/main/java/mouda/backend/chat/entity/ChatEntity.java @@ -58,7 +58,7 @@ public ChatEntity(String content, long chatRoomId, DarakbangMember darakbangMemb public Chat toChat() { return Chat.builder() .id(id) - .darakbangMember(darakbangMember) + .author(darakbangMember.toAuthor()) .content(content) .chatType(chatType) .date(date) diff --git a/backend/src/main/java/mouda/backend/chat/presentation/response/ChatFindDetailResponse.java b/backend/src/main/java/mouda/backend/chat/presentation/response/ChatFindDetailResponse.java index 084ee6b94..05e7e0820 100644 --- a/backend/src/main/java/mouda/backend/chat/presentation/response/ChatFindDetailResponse.java +++ b/backend/src/main/java/mouda/backend/chat/presentation/response/ChatFindDetailResponse.java @@ -4,9 +4,9 @@ import java.time.LocalTime; import lombok.Builder; +import mouda.backend.chat.domain.Author; import mouda.backend.chat.domain.Chat; import mouda.backend.chat.domain.ChatWithAuthor; -import mouda.backend.chat.domain.Participant; import mouda.backend.chat.entity.ChatType; @Builder @@ -33,7 +33,7 @@ public static ChatFindDetailResponse toResponse(ChatWithAuthor chatWithAuthor) { } private static ParticipantResponse getParticipantResponse(ChatWithAuthor chatWithAuthor) { - Participant participant = chatWithAuthor.getParticipant(); - return new ParticipantResponse(participant.getNickname(), participant.getProfile(), participant.getRole()); + Author author = chatWithAuthor.getChat().getAuthor(); + return new ParticipantResponse(author.getNickname(), author.getProfile(), null); } } From c00edbd1d0d1add2b650bc608cd6aefa3ce61e4c Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 16 Oct 2024 17:13:43 +0900 Subject: [PATCH 07/16] =?UTF-8?q?fix:=20=EC=B0=B8=EC=97=AC=EC=9E=90=20?= =?UTF-8?q?=EB=AA=A8=EC=9D=B4=EB=A8=B8=EC=9D=B8=EC=A7=80=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/mouda/backend/bet/domain/BetDetails.java | 6 ++++-- .../backend/bet/entity/BetDarakbangMemberEntity.java | 8 ++++++++ .../main/java/mouda/backend/chat/domain/Participant.java | 6 ------ .../backend/chat/implement/BetChatPreviewManager.java | 2 +- .../java/mouda/backend/chat/implement/ChatRoomFinder.java | 2 ++ .../backend/chat/implement/BetAttributeManagerTest.java | 3 ++- 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/mouda/backend/bet/domain/BetDetails.java b/backend/src/main/java/mouda/backend/bet/domain/BetDetails.java index 481aaedfb..00779a8e7 100644 --- a/backend/src/main/java/mouda/backend/bet/domain/BetDetails.java +++ b/backend/src/main/java/mouda/backend/bet/domain/BetDetails.java @@ -8,16 +8,18 @@ @Getter public class BetDetails { - private final Long id; + private final long id; private final String title; private final BettingTime bettingTime; + private final long moimerId; private final Long loserId; @Builder - public BetDetails(Long id, String title, LocalDateTime bettingTime, Long loserId) { + public BetDetails(long id, String title, LocalDateTime bettingTime, long moimerId, Long loserId) { this.id = id; this.title = title; this.bettingTime = new BettingTime(bettingTime); + this.moimerId = moimerId; this.loserId = loserId; } diff --git a/backend/src/main/java/mouda/backend/bet/entity/BetDarakbangMemberEntity.java b/backend/src/main/java/mouda/backend/bet/entity/BetDarakbangMemberEntity.java index a8809bf0a..9386c0ccc 100644 --- a/backend/src/main/java/mouda/backend/bet/entity/BetDarakbangMemberEntity.java +++ b/backend/src/main/java/mouda/backend/bet/entity/BetDarakbangMemberEntity.java @@ -10,6 +10,7 @@ import jakarta.persistence.Table; import lombok.Getter; import lombok.NoArgsConstructor; +import mouda.backend.bet.domain.BetRole; import mouda.backend.darakbangmember.domain.DarakbangMember; @Entity @@ -40,4 +41,11 @@ public BetDarakbangMemberEntity(DarakbangMember darakbangMember, BetEntity bet) public void updateLastChat(Long lastReadChatId) { this.lastReadChatId = lastReadChatId; } + + public String getRole(long moimerId) { + if (darakbangMember.getId() == moimerId) { + return BetRole.MOIMER.name(); + } + return BetRole.MOIMEE.name(); + } } diff --git a/backend/src/main/java/mouda/backend/chat/domain/Participant.java b/backend/src/main/java/mouda/backend/chat/domain/Participant.java index 33add9561..e8f9c33ea 100644 --- a/backend/src/main/java/mouda/backend/chat/domain/Participant.java +++ b/backend/src/main/java/mouda/backend/chat/domain/Participant.java @@ -17,12 +17,6 @@ public Participant(String nickname, String profile, String role) { this.role = role; } - public Participant(Chat chat) { - this.nickname = chat.getDarakbangMember().getNickname(); - this.profile = chat.getDarakbangMember().getProfile(); - this.role = chat.getDarakbangMember().getDescription(); - } - @Override public boolean equals(Object o) { if (this == o) diff --git a/backend/src/main/java/mouda/backend/chat/implement/BetChatPreviewManager.java b/backend/src/main/java/mouda/backend/chat/implement/BetChatPreviewManager.java index cf4aac823..db9e359f9 100644 --- a/backend/src/main/java/mouda/backend/chat/implement/BetChatPreviewManager.java +++ b/backend/src/main/java/mouda/backend/chat/implement/BetChatPreviewManager.java @@ -43,7 +43,7 @@ private ChatPreview getChatPreview(BetDetails bet) { List participants = betDarakbangMemberRepository.findAllByBetId(targetId).stream() .map(betDarakbangMember -> new Participant(betDarakbangMember.getDarakbangMember().getNickname(), betDarakbangMember.getDarakbangMember().getProfile(), - betDarakbangMember.getDarakbangMember().getRole().toString())) + betDarakbangMember.getRole(bet.getMoimerId()))) .toList(); return ChatPreview.builder() diff --git a/backend/src/main/java/mouda/backend/chat/implement/ChatRoomFinder.java b/backend/src/main/java/mouda/backend/chat/implement/ChatRoomFinder.java index 082d438ac..cbff50a15 100644 --- a/backend/src/main/java/mouda/backend/chat/implement/ChatRoomFinder.java +++ b/backend/src/main/java/mouda/backend/chat/implement/ChatRoomFinder.java @@ -5,6 +5,7 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; import lombok.RequiredArgsConstructor; import mouda.backend.bet.infrastructure.BetDarakbangMemberRepository; @@ -76,6 +77,7 @@ public ChatRoom readChatRoomByTargetId(long targetId, ChatRoomType chatRoomType) return new ChatRoom(chatRoomEntity.getId(), chatRoomEntity.getTargetId(), chatRoomEntity.getType(), lastChat); } + @Transactional(readOnly = true) public Chats findAllUnloadedChats(long chatRoomId, long recentChatId) { List chats = chatRepository.findAllUnloadedChats(chatRoomId, recentChatId).stream() .map(ChatEntity::toChat) diff --git a/backend/src/test/java/mouda/backend/chat/implement/BetAttributeManagerTest.java b/backend/src/test/java/mouda/backend/chat/implement/BetAttributeManagerTest.java index 6ae221649..b0a3b9041 100644 --- a/backend/src/test/java/mouda/backend/chat/implement/BetAttributeManagerTest.java +++ b/backend/src/test/java/mouda/backend/chat/implement/BetAttributeManagerTest.java @@ -83,7 +83,8 @@ void create_shouldReturnBetAttributes() { when(darakbang.getId()).thenReturn(1L); when(betFinder.find(1L, 1L)).thenReturn(bet); - when(bet.getBetDetails()).thenReturn(new BetDetails(1L, "test bet", LocalDateTime.of(2024, 6, 5, 12, 3), null)); + when(bet.getBetDetails()).thenReturn( + new BetDetails(1L, "test bet", LocalDateTime.of(2024, 6, 5, 12, 3), 1L, null)); when(bet.isLoser(darakbangMember.getId())).thenReturn(true); when(bet.getId()).thenReturn(1L); when(bet.getLoserId()).thenReturn(2L); From 0ff6a35d054cf4f0cc3624644887723af7190128 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 16 Oct 2024 20:17:03 +0900 Subject: [PATCH 08/16] =?UTF-8?q?feat:=20=EC=95=88=EB=82=B4=EB=A9=B4?= =?UTF-8?q?=EC=A7=84=EB=8B=A4=20=EC=A4=91=EB=B3=B5=EC=B0=B8=EC=97=AC=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bet/entity/BetDarakbangMemberEntity.java | 10 +- .../bet/exception/BetErrorMessage.java | 5 +- .../backend/bet/implement/BetWriter.java | 15 ++- .../backend/bet/implement/BetWriterTest.java | 60 ++++++++++++ .../common/fixture/BetEntityFixture.java | 96 +++++++++++-------- 5 files changed, 138 insertions(+), 48 deletions(-) create mode 100644 backend/src/test/java/mouda/backend/bet/implement/BetWriterTest.java diff --git a/backend/src/main/java/mouda/backend/bet/entity/BetDarakbangMemberEntity.java b/backend/src/main/java/mouda/backend/bet/entity/BetDarakbangMemberEntity.java index 9386c0ccc..ea3b6d854 100644 --- a/backend/src/main/java/mouda/backend/bet/entity/BetDarakbangMemberEntity.java +++ b/backend/src/main/java/mouda/backend/bet/entity/BetDarakbangMemberEntity.java @@ -8,6 +8,7 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; +import jakarta.persistence.UniqueConstraint; import lombok.Getter; import lombok.NoArgsConstructor; import mouda.backend.bet.domain.BetRole; @@ -16,7 +17,14 @@ @Entity @Getter @NoArgsConstructor -@Table(name = "bet_darakbang_member") +@Table( + name = "bet_darakbang_member", + uniqueConstraints = { + @UniqueConstraint( + columnNames = {"bet_id", "darakbang_member_id"} + ) + } +) public class BetDarakbangMemberEntity { @Id diff --git a/backend/src/main/java/mouda/backend/bet/exception/BetErrorMessage.java b/backend/src/main/java/mouda/backend/bet/exception/BetErrorMessage.java index e835185af..98de59a0e 100644 --- a/backend/src/main/java/mouda/backend/bet/exception/BetErrorMessage.java +++ b/backend/src/main/java/mouda/backend/bet/exception/BetErrorMessage.java @@ -9,7 +9,8 @@ public enum BetErrorMessage { BET_DARAKBANG_MEMBER_NOT_FOUND("참여하지 않은 안내면진다입니다."), BET_NOT_FOUND("안내면진다가 존재하지 않습니다."), - LOSER_NOT_FOUND("당첨자가 존재하지 않습니다."); - + LOSER_NOT_FOUND("당첨자가 존재하지 않습니다."), + ALREADY_PARTICIPATED_BET("이미 참여한 안내면진다입니다."); + private final String message; } diff --git a/backend/src/main/java/mouda/backend/bet/implement/BetWriter.java b/backend/src/main/java/mouda/backend/bet/implement/BetWriter.java index bad5228ad..3daec324f 100644 --- a/backend/src/main/java/mouda/backend/bet/implement/BetWriter.java +++ b/backend/src/main/java/mouda/backend/bet/implement/BetWriter.java @@ -2,6 +2,7 @@ import java.util.List; +import org.springframework.dao.DataIntegrityViolationException; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; @@ -21,6 +22,7 @@ public class BetWriter { private final BetRepository betRepository; private final BetDarakbangMemberRepository betDarakbangMemberRepository; + private final BetFinder betFinder; public void saveAll(List bets) { List betEntities = bets.stream() @@ -36,11 +38,18 @@ public long save(long darakbangId, Bet bet) { } public void participate(long darakbangId, long betId, DarakbangMember darakbangMember) { - BetEntity betEntity = betRepository.findByIdAndDarakbangId(betId, darakbangId) - .orElseThrow(() -> new BetException(HttpStatus.NOT_FOUND, BetErrorMessage.BET_NOT_FOUND)); + Bet bet = betFinder.find(darakbangId, betId); + participate(darakbangMember, bet); + } + private void participate(DarakbangMember darakbangMember, Bet bet) { + BetEntity betEntity = BetEntity.from(bet); BetDarakbangMemberEntity betDarakbangMemberEntity = new BetDarakbangMemberEntity(darakbangMember, betEntity); - betDarakbangMemberRepository.save(betDarakbangMemberEntity); + try { + betDarakbangMemberRepository.save(betDarakbangMemberEntity); + } catch (DataIntegrityViolationException e) { + throw new BetException(HttpStatus.BAD_REQUEST, BetErrorMessage.ALREADY_PARTICIPATED_BET); + } } public void updateLoser(Bet bet) { diff --git a/backend/src/test/java/mouda/backend/bet/implement/BetWriterTest.java b/backend/src/test/java/mouda/backend/bet/implement/BetWriterTest.java new file mode 100644 index 000000000..277c8cd6b --- /dev/null +++ b/backend/src/test/java/mouda/backend/bet/implement/BetWriterTest.java @@ -0,0 +1,60 @@ +package mouda.backend.bet.implement; + +import static org.assertj.core.api.Assertions.*; + +import java.util.List; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import mouda.backend.bet.business.BetService; +import mouda.backend.bet.entity.BetDarakbangMemberEntity; +import mouda.backend.bet.entity.BetEntity; +import mouda.backend.bet.exception.BetException; +import mouda.backend.bet.infrastructure.BetDarakbangMemberRepository; +import mouda.backend.bet.infrastructure.BetRepository; +import mouda.backend.common.fixture.BetEntityFixture; +import mouda.backend.common.fixture.DarakbangSetUp; + +@SpringBootTest +class BetWriterTest extends DarakbangSetUp { + + @Autowired + BetService betService; + + @Autowired + BetRepository betRepository; + + @Autowired + BetDarakbangMemberRepository betDarakbangMemberRepository; + + @DisplayName("중복 참여할 수 없다.") + @Test + void failToParticipate_alreadyParticipate() { + // given + BetEntity bet = betRepository.save( + BetEntityFixture.getFutureBetEntity(darakbang.getId(), darakbangAnna.getId())); + betDarakbangMemberRepository.save(new BetDarakbangMemberEntity(darakbangAnna, bet)); + + // when & then + assertThatThrownBy(() -> betService.participateBet(darakbang.getId(), bet.getId(), darakbangAnna)) + .isInstanceOf(BetException.class); + } + + @DisplayName("참여에 성공한다.") + @Test + void participate() { + // given + BetEntity bet = betRepository.save( + BetEntityFixture.getFutureBetEntity(darakbang.getId(), darakbangAnna.getId())); + + // when + betService.participateBet(darakbang.getId(), bet.getId(), darakbangHogee); + + // then + List participants = betDarakbangMemberRepository.findAllByBetId(bet.getId()); + assertThat(participants).hasSize(1); + } +} diff --git a/backend/src/test/java/mouda/backend/common/fixture/BetEntityFixture.java b/backend/src/test/java/mouda/backend/common/fixture/BetEntityFixture.java index c81c0aa32..a91ba7cfd 100644 --- a/backend/src/test/java/mouda/backend/common/fixture/BetEntityFixture.java +++ b/backend/src/test/java/mouda/backend/common/fixture/BetEntityFixture.java @@ -6,46 +6,58 @@ public class BetEntityFixture { - public static BetEntity getBetEntity(long darakbangId, long moimerId) { - return BetEntity.builder() - .title("testBet") - .bettingTime(LocalDateTime.now() - .withSecond(0) - .withNano(0)) - .darakbangId(darakbangId) - .moimerId(moimerId) - .build(); - } - - public static BetEntity getBetEntity(String title, long darakbangId, long moimerId) { - return BetEntity.builder() - .title(title) - .bettingTime(LocalDateTime.now() - .withSecond(0) - .withNano(0)) - .darakbangId(darakbangId) - .moimerId(moimerId) - .build(); - } - - public static BetEntity getBetEntity(long darakbangId, long moimerId, LocalDateTime bettingTime) { - return BetEntity.builder() - .title("테바바보") - .bettingTime(bettingTime.withSecond(0).withNano(0)) - .darakbangId(darakbangId) - .moimerId(moimerId) - .build(); - } - - public static BetEntity getDrawedBetEntity(long darakbangId, long moimerId) { - return BetEntity.builder() - .title("테바바보") - .bettingTime(LocalDateTime.now() - .withSecond(0) - .withNano(0)) - .darakbangId(darakbangId) - .moimerId(moimerId) - .loserDarakbangMemberId(moimerId) - .build(); - } + public static BetEntity getBetEntity(long darakbangId, long moimerId) { + return BetEntity.builder() + .title("testBet") + .bettingTime(LocalDateTime.now() + .withSecond(0) + .withNano(0)) + .darakbangId(darakbangId) + .moimerId(moimerId) + .build(); + } + + public static BetEntity getFutureBetEntity(long darakbangId, long moimerId) { + return BetEntity.builder() + .title("testBet") + .bettingTime(LocalDateTime.now() + .plusMinutes(10) + .withSecond(0) + .withNano(0)) + .darakbangId(darakbangId) + .moimerId(moimerId) + .build(); + } + + public static BetEntity getBetEntity(String title, long darakbangId, long moimerId) { + return BetEntity.builder() + .title(title) + .bettingTime(LocalDateTime.now() + .withSecond(0) + .withNano(0)) + .darakbangId(darakbangId) + .moimerId(moimerId) + .build(); + } + + public static BetEntity getBetEntity(long darakbangId, long moimerId, LocalDateTime bettingTime) { + return BetEntity.builder() + .title("테바바보") + .bettingTime(bettingTime.withSecond(0).withNano(0)) + .darakbangId(darakbangId) + .moimerId(moimerId) + .build(); + } + + public static BetEntity getDrawedBetEntity(long darakbangId, long moimerId) { + return BetEntity.builder() + .title("테바바보") + .bettingTime(LocalDateTime.now() + .withSecond(0) + .withNano(0)) + .darakbangId(darakbangId) + .moimerId(moimerId) + .loserDarakbangMemberId(moimerId) + .build(); + } } From d116aeb427d35bf439dc3cee07bcf2e2b71047a3 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 16 Oct 2024 20:21:01 +0900 Subject: [PATCH 09/16] =?UTF-8?q?feat:=20=EC=B6=94=EC=B2=A8=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=EC=9D=B4=20=EC=A7=80=EB=82=AC=EA=B1=B0=EB=82=98=20?= =?UTF-8?q?=EB=8B=B9=EC=B2=A8=EC=9E=90=EA=B0=80=20=EC=9D=B4=EB=AF=B8=20?= =?UTF-8?q?=EC=9E=88=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20=EC=B0=B8=EC=97=AC=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/mouda/backend/bet/domain/Bet.java | 15 +++------- .../mouda/backend/bet/domain/BetDetails.java | 4 +++ .../mouda/backend/bet/domain/BettingTime.java | 28 +++++++++++-------- .../bet/exception/BetErrorMessage.java | 1 + .../backend/bet/implement/BetWriter.java | 3 ++ .../backend/bet/business/BetServiceTest.java | 4 +-- .../backend/bet/implement/BetFinderTest.java | 9 ++++-- .../backend/bet/implement/BetWriterTest.java | 26 +++++++++++++++++ .../bet/infrastructure/BetRepositoryTest.java | 5 ++-- 9 files changed, 66 insertions(+), 29 deletions(-) diff --git a/backend/src/main/java/mouda/backend/bet/domain/Bet.java b/backend/src/main/java/mouda/backend/bet/domain/Bet.java index e9e28ff2b..7371e63ce 100644 --- a/backend/src/main/java/mouda/backend/bet/domain/Bet.java +++ b/backend/src/main/java/mouda/backend/bet/domain/Bet.java @@ -3,12 +3,8 @@ import java.util.List; import java.util.Random; -import org.springframework.http.HttpStatus; - import lombok.Builder; import lombok.Getter; -import mouda.backend.bet.exception.BetErrorMessage; -import mouda.backend.bet.exception.BetException; @Getter public class Bet { @@ -53,13 +49,6 @@ private boolean isParticipated(Long id) { .anyMatch(participant -> participant.getId() == id); } - public long getLoserId() { - if (loserId == null) { - throw new BetException(HttpStatus.NOT_FOUND, BetErrorMessage.LOSER_NOT_FOUND); - } - return loserId; - } - public boolean isLoser(long otherId) { return loserId == otherId; } @@ -75,4 +64,8 @@ public String getTitle() { public long timeDifferenceInMinutesWithNow() { return betDetails.timeDifferenceInMinutesWithNow(); } + + public boolean canNotParticipant() { + return hasLoser() || betDetails.pastBettingTime(); + } } diff --git a/backend/src/main/java/mouda/backend/bet/domain/BetDetails.java b/backend/src/main/java/mouda/backend/bet/domain/BetDetails.java index 00779a8e7..b0d9838b2 100644 --- a/backend/src/main/java/mouda/backend/bet/domain/BetDetails.java +++ b/backend/src/main/java/mouda/backend/bet/domain/BetDetails.java @@ -43,4 +43,8 @@ public long timeDifferenceInMinutesWithNow() { public boolean hasLoser() { return loserId != null; } + + public boolean pastBettingTime() { + return bettingTime.isPast(); + } } diff --git a/backend/src/main/java/mouda/backend/bet/domain/BettingTime.java b/backend/src/main/java/mouda/backend/bet/domain/BettingTime.java index 1e26db3a7..ac93468db 100644 --- a/backend/src/main/java/mouda/backend/bet/domain/BettingTime.java +++ b/backend/src/main/java/mouda/backend/bet/domain/BettingTime.java @@ -8,20 +8,24 @@ @Getter public class BettingTime { - private static final int NO_SECONDS = 0; - private static final int NO_NANOS = 0; + private static final int NO_SECONDS = 0; + private static final int NO_NANOS = 0; - private final LocalDateTime bettingTime; + private final LocalDateTime bettingTime; - public BettingTime(LocalDateTime bettingTime) { - this.bettingTime = normalize(bettingTime); - } + public BettingTime(LocalDateTime bettingTime) { + this.bettingTime = normalize(bettingTime); + } - private LocalDateTime normalize(LocalDateTime bettingTime) { - return bettingTime.withSecond(NO_SECONDS).withNano(NO_NANOS); - } + private LocalDateTime normalize(LocalDateTime bettingTime) { + return bettingTime.withSecond(NO_SECONDS).withNano(NO_NANOS); + } - public long timeDifferenceInMinutesWithNow() { - return Math.abs(ChronoUnit.MINUTES.between(normalize(LocalDateTime.now()), this.bettingTime)); - } + public long timeDifferenceInMinutesWithNow() { + return Math.abs(ChronoUnit.MINUTES.between(normalize(LocalDateTime.now()), this.bettingTime)); + } + + public boolean isPast() { + return LocalDateTime.now().isAfter(bettingTime); + } } diff --git a/backend/src/main/java/mouda/backend/bet/exception/BetErrorMessage.java b/backend/src/main/java/mouda/backend/bet/exception/BetErrorMessage.java index 98de59a0e..3a74a79ea 100644 --- a/backend/src/main/java/mouda/backend/bet/exception/BetErrorMessage.java +++ b/backend/src/main/java/mouda/backend/bet/exception/BetErrorMessage.java @@ -10,6 +10,7 @@ public enum BetErrorMessage { BET_DARAKBANG_MEMBER_NOT_FOUND("참여하지 않은 안내면진다입니다."), BET_NOT_FOUND("안내면진다가 존재하지 않습니다."), LOSER_NOT_FOUND("당첨자가 존재하지 않습니다."), + CAN_NOT_PARTICIPATE("참여할 수 없는 안내면진다입니다."), ALREADY_PARTICIPATED_BET("이미 참여한 안내면진다입니다."); private final String message; diff --git a/backend/src/main/java/mouda/backend/bet/implement/BetWriter.java b/backend/src/main/java/mouda/backend/bet/implement/BetWriter.java index 3daec324f..1f0092b2f 100644 --- a/backend/src/main/java/mouda/backend/bet/implement/BetWriter.java +++ b/backend/src/main/java/mouda/backend/bet/implement/BetWriter.java @@ -39,6 +39,9 @@ public long save(long darakbangId, Bet bet) { public void participate(long darakbangId, long betId, DarakbangMember darakbangMember) { Bet bet = betFinder.find(darakbangId, betId); + if (bet.canNotParticipant()) { + throw new BetException(HttpStatus.BAD_REQUEST, BetErrorMessage.CAN_NOT_PARTICIPATE); + } participate(darakbangMember, bet); } diff --git a/backend/src/test/java/mouda/backend/bet/business/BetServiceTest.java b/backend/src/test/java/mouda/backend/bet/business/BetServiceTest.java index 241e3aea1..36744e3da 100644 --- a/backend/src/test/java/mouda/backend/bet/business/BetServiceTest.java +++ b/backend/src/test/java/mouda/backend/bet/business/BetServiceTest.java @@ -78,7 +78,7 @@ void findAll() { void findNotDrawnBet() { // given long darakbangId = darakbang.getId(); - BetEntity drawnBetEntity = BetEntityFixture.getBetEntity(darakbangId, darakbangAnna.getId()); + BetEntity drawnBetEntity = BetEntityFixture.getFutureBetEntity(darakbangId, darakbangAnna.getId()); BetEntity savedBetEntity = betRepository.save(drawnBetEntity); // when @@ -138,7 +138,7 @@ void participateBet() { void drawBet() { // given Long darakbangId = darakbang.getId(); - BetEntity betEntity = BetEntityFixture.getBetEntity(darakbangId, darakbangAnna.getId()); + BetEntity betEntity = BetEntityFixture.getFutureBetEntity(darakbangId, darakbangAnna.getId()); BetEntity savedBetEntity = betRepository.save(betEntity); betWriter.participate(darakbangId, savedBetEntity.getId(), darakbangAnna); diff --git a/backend/src/test/java/mouda/backend/bet/implement/BetFinderTest.java b/backend/src/test/java/mouda/backend/bet/implement/BetFinderTest.java index ca95681a7..232e1f85a 100644 --- a/backend/src/test/java/mouda/backend/bet/implement/BetFinderTest.java +++ b/backend/src/test/java/mouda/backend/bet/implement/BetFinderTest.java @@ -11,8 +11,10 @@ import mouda.backend.bet.domain.Bet; import mouda.backend.bet.domain.Loser; +import mouda.backend.bet.entity.BetDarakbangMemberEntity; import mouda.backend.bet.entity.BetEntity; import mouda.backend.bet.exception.BetException; +import mouda.backend.bet.infrastructure.BetDarakbangMemberRepository; import mouda.backend.bet.infrastructure.BetRepository; import mouda.backend.common.fixture.BetEntityFixture; import mouda.backend.common.fixture.DarakbangSetUp; @@ -28,6 +30,9 @@ class BetFinderTest extends DarakbangSetUp { @Autowired BetRepository betRepository; + @Autowired + BetDarakbangMemberRepository betDarakbangMemberRepository; + @DisplayName("다락방에 존재하는 안내면진다를 조회한다.") @Test void find() { @@ -50,7 +55,7 @@ void find() { void findAllDetails() { // given long darakbangId = darakbang.getId(); - BetEntity betEntity = BetEntityFixture.getBetEntity(darakbangId, darakbangAnna.getId()); + BetEntity betEntity = BetEntityFixture.getFutureBetEntity(darakbangId, darakbangAnna.getId()); betRepository.save(betEntity); // when @@ -92,7 +97,7 @@ void findBetResult() { long darakbangId = darakbang.getId(); BetEntity betEntity = BetEntityFixture.getDrawedBetEntity(darakbangId, darakbangAnna.getId()); BetEntity savedBetEntity = betRepository.save(betEntity); - betWriter.participate(darakbangId, savedBetEntity.getId(), darakbangAnna); + betDarakbangMemberRepository.save(new BetDarakbangMemberEntity(darakbangAnna, savedBetEntity)); // when Loser loser = betFinder.findResult(darakbangId, savedBetEntity.getId()); diff --git a/backend/src/test/java/mouda/backend/bet/implement/BetWriterTest.java b/backend/src/test/java/mouda/backend/bet/implement/BetWriterTest.java index 277c8cd6b..586159514 100644 --- a/backend/src/test/java/mouda/backend/bet/implement/BetWriterTest.java +++ b/backend/src/test/java/mouda/backend/bet/implement/BetWriterTest.java @@ -2,6 +2,7 @@ import static org.assertj.core.api.Assertions.*; +import java.time.LocalDateTime; import java.util.List; import org.junit.jupiter.api.DisplayName; @@ -30,6 +31,31 @@ class BetWriterTest extends DarakbangSetUp { @Autowired BetDarakbangMemberRepository betDarakbangMemberRepository; + @DisplayName("추첨 시간 이후 참여할 수 없다.") + @Test + void failToParticipate_pastBettingTIme() { + // given + LocalDateTime pastBettingTime = LocalDateTime.now().minusSeconds(1); + BetEntity bet = betRepository.save( + BetEntityFixture.getBetEntity(darakbang.getId(), darakbangAnna.getId(), pastBettingTime)); + + // when & then + assertThatThrownBy(() -> betService.participateBet(darakbang.getId(), bet.getId(), darakbangHogee)) + .isInstanceOf(BetException.class); + } + + @DisplayName("이미 당첨자가 존재하면 참여할 수 없다.") + @Test + void failToParticipate_loserExists() { + // given + BetEntity bet = betRepository.save( + BetEntityFixture.getDrawedBetEntity(darakbang.getId(), darakbangAnna.getId())); + + // when & then + assertThatThrownBy(() -> betService.participateBet(darakbang.getId(), bet.getId(), darakbangHogee)) + .isInstanceOf(BetException.class); + } + @DisplayName("중복 참여할 수 없다.") @Test void failToParticipate_alreadyParticipate() { diff --git a/backend/src/test/java/mouda/backend/bet/infrastructure/BetRepositoryTest.java b/backend/src/test/java/mouda/backend/bet/infrastructure/BetRepositoryTest.java index da1cda6a8..aa4c984df 100644 --- a/backend/src/test/java/mouda/backend/bet/infrastructure/BetRepositoryTest.java +++ b/backend/src/test/java/mouda/backend/bet/infrastructure/BetRepositoryTest.java @@ -23,14 +23,15 @@ class BetRepositoryTest { @Test void findAllByBettingTimeAndLoserDarakbangMemberIdIsNull() { // given - BetEntity betEntity1 = BetEntityFixture.getBetEntity(1L, 1L); + BetEntity betEntity1 = BetEntityFixture.getBetEntity(1L, 1L, LocalDateTime.now()); BetEntity betEntity2 = BetEntityFixture.getDrawedBetEntity(1L, 2L); betRepository.save(betEntity1); betRepository.save(betEntity2); // when - List betEntities = betRepository.findAllByBettingTimeAndLoserDarakbangMemberIdIsNull(LocalDateTime.now().withSecond(0).withNano(0)); + List betEntities = betRepository.findAllByBettingTimeAndLoserDarakbangMemberIdIsNull( + LocalDateTime.now().withSecond(0).withNano(0)); //then assertThat(betEntities).hasSize(1); From 68acb8b8cae046f9e5b57b2225bbd87ab8c35102 Mon Sep 17 00:00:00 2001 From: hoyeonyy Date: Wed, 16 Oct 2024 21:49:28 +0900 Subject: [PATCH 10/16] =?UTF-8?q?refactor:=20AccessToken=20payload=20?= =?UTF-8?q?=EC=97=90=20OauthType=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mouda/backend/auth/implement/jwt/AccessTokenProvider.java | 2 ++ backend/src/main/java/mouda/backend/member/domain/Member.java | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/backend/src/main/java/mouda/backend/auth/implement/jwt/AccessTokenProvider.java b/backend/src/main/java/mouda/backend/auth/implement/jwt/AccessTokenProvider.java index a0d9cdf02..23af414e0 100644 --- a/backend/src/main/java/mouda/backend/auth/implement/jwt/AccessTokenProvider.java +++ b/backend/src/main/java/mouda/backend/auth/implement/jwt/AccessTokenProvider.java @@ -19,6 +19,7 @@ public class AccessTokenProvider { public static final String MEMBER_ID_CLAIM_KEY = "id"; public static final String SOCIAL_LOGIN_ID_CLAIM_KEY = "socialLoginId"; + private static final String OAUTH_TYPE = "oauthType"; @Value("${security.jwt.token.secret-key}") private String secretKey; @@ -33,6 +34,7 @@ public String provide(Member member) { return Jwts.builder() .claim(MEMBER_ID_CLAIM_KEY, member.getId()) .claim(SOCIAL_LOGIN_ID_CLAIM_KEY, member.getSocialLoginId()) + .claim(OAUTH_TYPE, member.getOauthType()) .setIssuedAt(now) .setExpiration(validity) .signWith(SignatureAlgorithm.HS256, secretKey) diff --git a/backend/src/main/java/mouda/backend/member/domain/Member.java b/backend/src/main/java/mouda/backend/member/domain/Member.java index 4df3d8e47..d80b55dbb 100644 --- a/backend/src/main/java/mouda/backend/member/domain/Member.java +++ b/backend/src/main/java/mouda/backend/member/domain/Member.java @@ -46,6 +46,10 @@ public String getSocialLoginId() { return loginDetail.getSocialLoginId(); } + public String getOauthType() { + return loginDetail.getOauthType().toString(); + } + @Override public boolean equals(Object o) { if (this == o) From b8b3e6d23c99bd379083c8bec633a9df31037acd Mon Sep 17 00:00:00 2001 From: hoyeonyy Date: Wed, 16 Oct 2024 21:55:19 +0900 Subject: [PATCH 11/16] =?UTF-8?q?refactor:=20=EC=9D=B8=ED=84=B0=EC=85=89?= =?UTF-8?q?=ED=84=B0=EC=97=90=EC=84=9C=20=ED=86=A0=ED=81=B0=EC=9D=98=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EA=B0=80=20Kakao=20=EB=9D=BC=EB=A9=B4=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=EB=A5=BC=20=EB=B0=9C=EC=83=9D=ED=95=9C?= =?UTF-8?q?=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/auth/implement/jwt/AccessTokenProvider.java | 6 +++++- .../java/mouda/backend/member/business/MemberService.java | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/mouda/backend/auth/implement/jwt/AccessTokenProvider.java b/backend/src/main/java/mouda/backend/auth/implement/jwt/AccessTokenProvider.java index 23af414e0..e9f28cff5 100644 --- a/backend/src/main/java/mouda/backend/auth/implement/jwt/AccessTokenProvider.java +++ b/backend/src/main/java/mouda/backend/auth/implement/jwt/AccessTokenProvider.java @@ -13,6 +13,7 @@ import mouda.backend.auth.exception.AuthErrorMessage; import mouda.backend.auth.exception.AuthException; import mouda.backend.member.domain.Member; +import mouda.backend.member.domain.OauthType; @Component public class AccessTokenProvider { @@ -58,12 +59,15 @@ public Claims getPayload(String token) { } } - public void validateExpiration(String token) { + public void validateToken(String token) { Claims claims = getPayload(token); if (claims.getExpiration().before(new Date())) { throw new AuthException(HttpStatus.UNAUTHORIZED, AuthErrorMessage.UNAUTHORIZED); } + if (claims.get(OAUTH_TYPE) == OauthType.KAKAO.toString()) { + throw new AuthException(HttpStatus.UNAUTHORIZED, AuthErrorMessage.UNAUTHORIZED); + } } } diff --git a/backend/src/main/java/mouda/backend/member/business/MemberService.java b/backend/src/main/java/mouda/backend/member/business/MemberService.java index 389263b4c..d18017098 100644 --- a/backend/src/main/java/mouda/backend/member/business/MemberService.java +++ b/backend/src/main/java/mouda/backend/member/business/MemberService.java @@ -22,6 +22,6 @@ public Member findMember(String token) { } public void checkAuthentication(String token) { - accessTokenProvider.validateExpiration(token); + accessTokenProvider.validateToken(token); } } From 4a6dea4f4d6329bdfdf411f2bcb93e70afb49ddb Mon Sep 17 00:00:00 2001 From: hoyeonyy Date: Thu, 17 Oct 2024 09:59:39 +0900 Subject: [PATCH 12/16] =?UTF-8?q?refactor:=20=EA=B0=92=20=EB=B9=84?= =?UTF-8?q?=EA=B5=90,=20=EC=A0=91=EA=B7=BC=EC=A0=9C=EC=96=B4=EC=9E=90=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/auth/implement/jwt/AccessTokenProvider.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/mouda/backend/auth/implement/jwt/AccessTokenProvider.java b/backend/src/main/java/mouda/backend/auth/implement/jwt/AccessTokenProvider.java index e9f28cff5..e2da74b21 100644 --- a/backend/src/main/java/mouda/backend/auth/implement/jwt/AccessTokenProvider.java +++ b/backend/src/main/java/mouda/backend/auth/implement/jwt/AccessTokenProvider.java @@ -18,8 +18,8 @@ @Component public class AccessTokenProvider { - public static final String MEMBER_ID_CLAIM_KEY = "id"; - public static final String SOCIAL_LOGIN_ID_CLAIM_KEY = "socialLoginId"; + private static final String MEMBER_ID_CLAIM_KEY = "id"; + private static final String SOCIAL_LOGIN_ID_CLAIM_KEY = "socialLoginId"; private static final String OAUTH_TYPE = "oauthType"; @Value("${security.jwt.token.secret-key}") @@ -65,7 +65,7 @@ public void validateToken(String token) { if (claims.getExpiration().before(new Date())) { throw new AuthException(HttpStatus.UNAUTHORIZED, AuthErrorMessage.UNAUTHORIZED); } - if (claims.get(OAUTH_TYPE) == OauthType.KAKAO.toString()) { + if (claims.get(OAUTH_TYPE).equals(OauthType.KAKAO.toString())) { throw new AuthException(HttpStatus.UNAUTHORIZED, AuthErrorMessage.UNAUTHORIZED); } } From 64f1b09979be5d21046aec43d534594e73eb9175 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Thu, 17 Oct 2024 15:39:41 +0900 Subject: [PATCH 13/16] =?UTF-8?q?fix:=20=EC=98=A4=ED=83=80=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/java/mouda/backend/bet/domain/Bet.java | 2 +- .../src/main/java/mouda/backend/bet/implement/BetWriter.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/mouda/backend/bet/domain/Bet.java b/backend/src/main/java/mouda/backend/bet/domain/Bet.java index 7371e63ce..11092a307 100644 --- a/backend/src/main/java/mouda/backend/bet/domain/Bet.java +++ b/backend/src/main/java/mouda/backend/bet/domain/Bet.java @@ -65,7 +65,7 @@ public long timeDifferenceInMinutesWithNow() { return betDetails.timeDifferenceInMinutesWithNow(); } - public boolean canNotParticipant() { + public boolean canNotParticipate() { return hasLoser() || betDetails.pastBettingTime(); } } diff --git a/backend/src/main/java/mouda/backend/bet/implement/BetWriter.java b/backend/src/main/java/mouda/backend/bet/implement/BetWriter.java index 1f0092b2f..49a8e1a18 100644 --- a/backend/src/main/java/mouda/backend/bet/implement/BetWriter.java +++ b/backend/src/main/java/mouda/backend/bet/implement/BetWriter.java @@ -39,7 +39,7 @@ public long save(long darakbangId, Bet bet) { public void participate(long darakbangId, long betId, DarakbangMember darakbangMember) { Bet bet = betFinder.find(darakbangId, betId); - if (bet.canNotParticipant()) { + if (bet.canNotParticipate()) { throw new BetException(HttpStatus.BAD_REQUEST, BetErrorMessage.CAN_NOT_PARTICIPATE); } participate(darakbangMember, bet); From 7507eb5a498a1021b9de60d96113050cc79fae42 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Thu, 17 Oct 2024 15:40:15 +0900 Subject: [PATCH 14/16] =?UTF-8?q?refactor:=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/java/mouda/backend/chat/domain/Chat.java | 2 +- backend/src/main/java/mouda/backend/chat/domain/Chats.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/mouda/backend/chat/domain/Chat.java b/backend/src/main/java/mouda/backend/chat/domain/Chat.java index 7a3c11c8f..0defca2a9 100644 --- a/backend/src/main/java/mouda/backend/chat/domain/Chat.java +++ b/backend/src/main/java/mouda/backend/chat/domain/Chat.java @@ -27,7 +27,7 @@ public Chat(long id, String content, Author author, LocalDate date, LocalTime ti this.chatType = chatType; } - public boolean isMyMessage(long darakbangMemberId) { + public boolean isMine(long darakbangMemberId) { return author.getId() == darakbangMemberId; } } diff --git a/backend/src/main/java/mouda/backend/chat/domain/Chats.java b/backend/src/main/java/mouda/backend/chat/domain/Chats.java index 1174ec54a..7920d4511 100644 --- a/backend/src/main/java/mouda/backend/chat/domain/Chats.java +++ b/backend/src/main/java/mouda/backend/chat/domain/Chats.java @@ -16,7 +16,7 @@ public Chats(List chats) { public List getChatsWithAuthor(DarakbangMember darakbangMember) { return chats.stream() - .map(chat -> new ChatWithAuthor(chat, chat.isMyMessage(darakbangMember.getId()))) + .map(chat -> new ChatWithAuthor(chat, chat.isMine(darakbangMember.getId()))) .toList(); } } From 913222478cc30fb768e8b8a3294d6588d5ada64a Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Thu, 17 Oct 2024 15:41:36 +0900 Subject: [PATCH 15/16] =?UTF-8?q?refactor:=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mouda/backend/chat/business/ChatService.java | 4 ++-- .../{ChatWithAuthor.java => ChatOwnership.java} | 4 ++-- .../main/java/mouda/backend/chat/domain/Chats.java | 4 ++-- .../response/ChatFindDetailResponse.java | 14 +++++++------- .../response/ChatFindUnloadedResponse.java | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) rename backend/src/main/java/mouda/backend/chat/domain/{ChatWithAuthor.java => ChatOwnership.java} (68%) diff --git a/backend/src/main/java/mouda/backend/chat/business/ChatService.java b/backend/src/main/java/mouda/backend/chat/business/ChatService.java index 3bb51cb8b..fd11d75c5 100644 --- a/backend/src/main/java/mouda/backend/chat/business/ChatService.java +++ b/backend/src/main/java/mouda/backend/chat/business/ChatService.java @@ -8,8 +8,8 @@ import org.springframework.transaction.annotation.Transactional; import lombok.RequiredArgsConstructor; +import mouda.backend.chat.domain.ChatOwnership; import mouda.backend.chat.domain.ChatRoom; -import mouda.backend.chat.domain.ChatWithAuthor; import mouda.backend.chat.domain.Chats; import mouda.backend.chat.implement.ChatRoomFinder; import mouda.backend.chat.implement.ChatWriter; @@ -59,7 +59,7 @@ public ChatFindUnloadedResponse findUnloadedChats( ChatRoom chatRoom = chatRoomFinder.read(darakbangId, chatRoomId, darakbangMember); Chats chats = chatRoomFinder.findAllUnloadedChats(chatRoom.getId(), recentChatId); - List chatsWithAuthor = chats.getChatsWithAuthor(darakbangMember); + List chatsWithAuthor = chats.getChatsWithAuthor(darakbangMember); return ChatFindUnloadedResponse.toResponse(chatsWithAuthor); } diff --git a/backend/src/main/java/mouda/backend/chat/domain/ChatWithAuthor.java b/backend/src/main/java/mouda/backend/chat/domain/ChatOwnership.java similarity index 68% rename from backend/src/main/java/mouda/backend/chat/domain/ChatWithAuthor.java rename to backend/src/main/java/mouda/backend/chat/domain/ChatOwnership.java index b442b2d62..8e9273d20 100644 --- a/backend/src/main/java/mouda/backend/chat/domain/ChatWithAuthor.java +++ b/backend/src/main/java/mouda/backend/chat/domain/ChatOwnership.java @@ -3,12 +3,12 @@ import lombok.Getter; @Getter -public class ChatWithAuthor { +public class ChatOwnership { private final Chat chat; private final boolean isMine; - public ChatWithAuthor(Chat chat, boolean isMine) { + public ChatOwnership(Chat chat, boolean isMine) { this.chat = chat; this.isMine = isMine; } diff --git a/backend/src/main/java/mouda/backend/chat/domain/Chats.java b/backend/src/main/java/mouda/backend/chat/domain/Chats.java index 7920d4511..28fcf7c67 100644 --- a/backend/src/main/java/mouda/backend/chat/domain/Chats.java +++ b/backend/src/main/java/mouda/backend/chat/domain/Chats.java @@ -14,9 +14,9 @@ public Chats(List chats) { this.chats = chats; } - public List getChatsWithAuthor(DarakbangMember darakbangMember) { + public List getChatsWithAuthor(DarakbangMember darakbangMember) { return chats.stream() - .map(chat -> new ChatWithAuthor(chat, chat.isMine(darakbangMember.getId()))) + .map(chat -> new ChatOwnership(chat, chat.isMine(darakbangMember.getId()))) .toList(); } } diff --git a/backend/src/main/java/mouda/backend/chat/presentation/response/ChatFindDetailResponse.java b/backend/src/main/java/mouda/backend/chat/presentation/response/ChatFindDetailResponse.java index 05e7e0820..c30819eb4 100644 --- a/backend/src/main/java/mouda/backend/chat/presentation/response/ChatFindDetailResponse.java +++ b/backend/src/main/java/mouda/backend/chat/presentation/response/ChatFindDetailResponse.java @@ -6,7 +6,7 @@ import lombok.Builder; import mouda.backend.chat.domain.Author; import mouda.backend.chat.domain.Chat; -import mouda.backend.chat.domain.ChatWithAuthor; +import mouda.backend.chat.domain.ChatOwnership; import mouda.backend.chat.entity.ChatType; @Builder @@ -19,21 +19,21 @@ public record ChatFindDetailResponse( LocalTime time, ChatType chatType ) { - public static ChatFindDetailResponse toResponse(ChatWithAuthor chatWithAuthor) { - Chat chat = chatWithAuthor.getChat(); + public static ChatFindDetailResponse toResponse(ChatOwnership chatOwnership) { + Chat chat = chatOwnership.getChat(); return ChatFindDetailResponse.builder() .chatId(chat.getId()) .content(chat.getContent()) - .isMyMessage(chatWithAuthor.isMine()) - .participation(getParticipantResponse(chatWithAuthor)) + .isMyMessage(chatOwnership.isMine()) + .participation(getParticipantResponse(chatOwnership)) .date(chat.getDate()) .time(chat.getTime()) .chatType(chat.getChatType()) .build(); } - private static ParticipantResponse getParticipantResponse(ChatWithAuthor chatWithAuthor) { - Author author = chatWithAuthor.getChat().getAuthor(); + private static ParticipantResponse getParticipantResponse(ChatOwnership chatOwnership) { + Author author = chatOwnership.getChat().getAuthor(); return new ParticipantResponse(author.getNickname(), author.getProfile(), null); } } diff --git a/backend/src/main/java/mouda/backend/chat/presentation/response/ChatFindUnloadedResponse.java b/backend/src/main/java/mouda/backend/chat/presentation/response/ChatFindUnloadedResponse.java index 91f9b5e41..7817caf46 100644 --- a/backend/src/main/java/mouda/backend/chat/presentation/response/ChatFindUnloadedResponse.java +++ b/backend/src/main/java/mouda/backend/chat/presentation/response/ChatFindUnloadedResponse.java @@ -2,12 +2,12 @@ import java.util.List; -import mouda.backend.chat.domain.ChatWithAuthor; +import mouda.backend.chat.domain.ChatOwnership; public record ChatFindUnloadedResponse( List chats ) { - public static ChatFindUnloadedResponse toResponse(List chats) { + public static ChatFindUnloadedResponse toResponse(List chats) { List responses = chats.stream() .map(ChatFindDetailResponse::toResponse) .toList(); From 2a55bd969c867f00f8ea70ab667c8429eacd35f6 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Thu, 17 Oct 2024 15:44:01 +0900 Subject: [PATCH 16/16] =?UTF-8?q?feat:=20role=20=ED=8F=AC=ED=95=A8?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20ParticipantResponse?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=EC=9E=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/presentation/response/ChatFindDetailResponse.java | 2 +- .../chat/presentation/response/ParticipantResponse.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/mouda/backend/chat/presentation/response/ChatFindDetailResponse.java b/backend/src/main/java/mouda/backend/chat/presentation/response/ChatFindDetailResponse.java index c30819eb4..2b1bf7bc5 100644 --- a/backend/src/main/java/mouda/backend/chat/presentation/response/ChatFindDetailResponse.java +++ b/backend/src/main/java/mouda/backend/chat/presentation/response/ChatFindDetailResponse.java @@ -34,6 +34,6 @@ public static ChatFindDetailResponse toResponse(ChatOwnership chatOwnership) { private static ParticipantResponse getParticipantResponse(ChatOwnership chatOwnership) { Author author = chatOwnership.getChat().getAuthor(); - return new ParticipantResponse(author.getNickname(), author.getProfile(), null); + return new ParticipantResponse(author.getNickname(), author.getProfile()); } } diff --git a/backend/src/main/java/mouda/backend/chat/presentation/response/ParticipantResponse.java b/backend/src/main/java/mouda/backend/chat/presentation/response/ParticipantResponse.java index 576752164..ea1d1ddcd 100644 --- a/backend/src/main/java/mouda/backend/chat/presentation/response/ParticipantResponse.java +++ b/backend/src/main/java/mouda/backend/chat/presentation/response/ParticipantResponse.java @@ -5,4 +5,8 @@ public record ParticipantResponse( String profile, String role ) { + + public ParticipantResponse(String nickname, String profile) { + this(nickname, profile, null); + } }