From 3e6e2f7779c0ddf7c073b8cc4e92cf60c4e3da44 Mon Sep 17 00:00:00 2001 From: MingyeomKim Date: Wed, 31 Jul 2024 14:03:46 +0900 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20=EC=B1=84=ED=8C=85=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EC=83=9D=EC=84=B1=20API=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/controller/ChatController.java | 29 +++++++++++++++++++ .../java/mouda/backend/chat/domain/Chat.java | 10 +++++++ .../chat/dto/request/ChatCreateRequest.java | 25 ++++++++++++++++ .../chat/repository/ChatRepository.java | 8 +++++ .../backend/chat/service/ChatService.java | 26 +++++++++++++++++ 5 files changed, 98 insertions(+) create mode 100644 backend/src/main/java/mouda/backend/chat/controller/ChatController.java create mode 100644 backend/src/main/java/mouda/backend/chat/dto/request/ChatCreateRequest.java create mode 100644 backend/src/main/java/mouda/backend/chat/repository/ChatRepository.java create mode 100644 backend/src/main/java/mouda/backend/chat/service/ChatService.java diff --git a/backend/src/main/java/mouda/backend/chat/controller/ChatController.java b/backend/src/main/java/mouda/backend/chat/controller/ChatController.java new file mode 100644 index 000000000..81ed8c208 --- /dev/null +++ b/backend/src/main/java/mouda/backend/chat/controller/ChatController.java @@ -0,0 +1,29 @@ +package mouda.backend.chat.controller; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import lombok.RequiredArgsConstructor; +import mouda.backend.chat.dto.request.ChatCreateRequest; +import mouda.backend.chat.service.ChatService; +import mouda.backend.member.domain.Member; + +@RestController +@RequestMapping("/v1/chat") +@RequiredArgsConstructor +public class ChatController { + + private final ChatService chatService; + + @PostMapping + public ResponseEntity createChat( + @RequestBody ChatCreateRequest chatCreateRequest, + Member member + ) { + chatService.createChat(chatCreateRequest, member); + return ResponseEntity.ok().build(); + } +} 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 14b4da05e..fe07b088c 100644 --- a/backend/src/main/java/mouda/backend/chat/domain/Chat.java +++ b/backend/src/main/java/mouda/backend/chat/domain/Chat.java @@ -8,6 +8,7 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.ManyToOne; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import mouda.backend.member.domain.Member; @@ -33,4 +34,13 @@ public class Chat { private LocalDate date; private LocalTime time; + + @Builder + public Chat(String content, Moim moim, Member member, LocalDate date, LocalTime time) { + this.content = content; + this.moim = moim; + this.member = member; + this.date = date; + this.time = time; + } } diff --git a/backend/src/main/java/mouda/backend/chat/dto/request/ChatCreateRequest.java b/backend/src/main/java/mouda/backend/chat/dto/request/ChatCreateRequest.java new file mode 100644 index 000000000..d91e59d2f --- /dev/null +++ b/backend/src/main/java/mouda/backend/chat/dto/request/ChatCreateRequest.java @@ -0,0 +1,25 @@ +package mouda.backend.chat.dto.request; + +import java.time.LocalDate; +import java.time.LocalTime; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import mouda.backend.chat.domain.Chat; +import mouda.backend.member.domain.Member; +import mouda.backend.moim.domain.Moim; + +public record ChatCreateRequest( + @NotNull Long moimId, + @NotBlank String content +) { + public Chat toEntity(Moim moim, Member member) { + return Chat.builder() + .content(content) + .date(LocalDate.now()) + .time(LocalTime.now()) + .member(member) + .moim(moim) + .build(); + } +} diff --git a/backend/src/main/java/mouda/backend/chat/repository/ChatRepository.java b/backend/src/main/java/mouda/backend/chat/repository/ChatRepository.java new file mode 100644 index 000000000..df8b38cf8 --- /dev/null +++ b/backend/src/main/java/mouda/backend/chat/repository/ChatRepository.java @@ -0,0 +1,8 @@ +package mouda.backend.chat.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import mouda.backend.chat.domain.Chat; + +public interface ChatRepository extends JpaRepository { +} diff --git a/backend/src/main/java/mouda/backend/chat/service/ChatService.java b/backend/src/main/java/mouda/backend/chat/service/ChatService.java new file mode 100644 index 000000000..28182759c --- /dev/null +++ b/backend/src/main/java/mouda/backend/chat/service/ChatService.java @@ -0,0 +1,26 @@ +package mouda.backend.chat.service; + +import org.springframework.stereotype.Service; + +import lombok.RequiredArgsConstructor; +import mouda.backend.chat.domain.Chat; +import mouda.backend.chat.dto.request.ChatCreateRequest; +import mouda.backend.chat.repository.ChatRepository; +import mouda.backend.member.domain.Member; +import mouda.backend.moim.domain.Moim; +import mouda.backend.moim.repository.MoimRepository; + +@Service +@RequiredArgsConstructor +public class ChatService { + + private final ChatRepository chatRepository; + private final MoimRepository moimRepository; + + public void createChat(ChatCreateRequest chatCreateRequest, Member member) { + Moim moim = moimRepository.findById(chatCreateRequest.moimId()) + .orElseThrow(); + Chat chat = chatCreateRequest.toEntity(moim, member); + chatRepository.save(chat); + } +} From e44a3e55f3c12c84e9dda00c392e5df5ad08274d Mon Sep 17 00:00:00 2001 From: MingyeomKim Date: Wed, 31 Jul 2024 15:22:20 +0900 Subject: [PATCH 2/6] =?UTF-8?q?feat:=20=EC=B5=9C=EA=B7=BC=20=EC=B1=84?= =?UTF-8?q?=ED=8C=85=20=EC=9D=B4=ED=9B=84=EB=A1=9C=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EB=90=9C=20=EC=B1=84=ED=8C=85=EC=9D=84=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/controller/ChatController.java | 17 ++++- .../dto/response/ChatFindDetailResponse.java | 28 ++++++++ .../response/ChatFindUnloadedResponse.java | 9 +++ .../chat/repository/ChatRepository.java | 7 ++ .../backend/chat/service/ChatService.java | 16 ++++- .../chat/repository/ChatRepositoryTest.java | 71 +++++++++++++++++++ 6 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 backend/src/main/java/mouda/backend/chat/dto/response/ChatFindDetailResponse.java create mode 100644 backend/src/main/java/mouda/backend/chat/dto/response/ChatFindUnloadedResponse.java create mode 100644 backend/src/test/java/mouda/backend/chat/repository/ChatRepositoryTest.java diff --git a/backend/src/main/java/mouda/backend/chat/controller/ChatController.java b/backend/src/main/java/mouda/backend/chat/controller/ChatController.java index 81ed8c208..a0be67282 100644 --- a/backend/src/main/java/mouda/backend/chat/controller/ChatController.java +++ b/backend/src/main/java/mouda/backend/chat/controller/ChatController.java @@ -1,14 +1,19 @@ package mouda.backend.chat.controller; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import mouda.backend.chat.dto.request.ChatCreateRequest; +import mouda.backend.chat.dto.response.ChatFindUnloadedResponse; import mouda.backend.chat.service.ChatService; +import mouda.backend.common.RestResponse; import mouda.backend.member.domain.Member; @RestController @@ -20,10 +25,20 @@ public class ChatController { @PostMapping public ResponseEntity createChat( - @RequestBody ChatCreateRequest chatCreateRequest, + @Valid @RequestBody ChatCreateRequest chatCreateRequest, Member member ) { chatService.createChat(chatCreateRequest, member); return ResponseEntity.ok().build(); } + + @GetMapping + public ResponseEntity> findUnloadedChats( + @RequestParam Long recentChatId, + @RequestParam Long moimId, + Member member + ) { + ChatFindUnloadedResponse unloadedChats = chatService.findUnloadedChats(recentChatId, moimId, member); + return ResponseEntity.ok(new RestResponse<>(unloadedChats)); + } } diff --git a/backend/src/main/java/mouda/backend/chat/dto/response/ChatFindDetailResponse.java b/backend/src/main/java/mouda/backend/chat/dto/response/ChatFindDetailResponse.java new file mode 100644 index 000000000..7ac1a898f --- /dev/null +++ b/backend/src/main/java/mouda/backend/chat/dto/response/ChatFindDetailResponse.java @@ -0,0 +1,28 @@ +package mouda.backend.chat.dto.response; + +import java.time.LocalDate; +import java.time.LocalTime; + +import lombok.Builder; +import mouda.backend.chat.domain.Chat; + +@Builder +public record ChatFindDetailResponse( + long chatId, + String content, + long memberId, + String nickname, + LocalDate date, + LocalTime time +) { + public static ChatFindDetailResponse toResponse(Chat chat) { + return ChatFindDetailResponse.builder() + .chatId(chat.getId()) + .content(chat.getContent()) + .memberId(chat.getMember().getId()) + .nickname(chat.getMember().getNickname()) + .date(chat.getDate()) + .time(chat.getTime()) + .build(); + } +} diff --git a/backend/src/main/java/mouda/backend/chat/dto/response/ChatFindUnloadedResponse.java b/backend/src/main/java/mouda/backend/chat/dto/response/ChatFindUnloadedResponse.java new file mode 100644 index 000000000..d813522d0 --- /dev/null +++ b/backend/src/main/java/mouda/backend/chat/dto/response/ChatFindUnloadedResponse.java @@ -0,0 +1,9 @@ +package mouda.backend.chat.dto.response; + +import java.util.List; + +public record ChatFindUnloadedResponse( + long loginMemberId, + List chats +) { +} diff --git a/backend/src/main/java/mouda/backend/chat/repository/ChatRepository.java b/backend/src/main/java/mouda/backend/chat/repository/ChatRepository.java index df8b38cf8..c50d086a8 100644 --- a/backend/src/main/java/mouda/backend/chat/repository/ChatRepository.java +++ b/backend/src/main/java/mouda/backend/chat/repository/ChatRepository.java @@ -1,8 +1,15 @@ package mouda.backend.chat.repository; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import mouda.backend.chat.domain.Chat; public interface ChatRepository extends JpaRepository { + + @Query("SELECT c FROM Chat c WHERE c.moim.id = :moimId AND c.id > :chatId") + List findAllUnloadedChats(@Param("moimId") long moimId, @Param("chatId") long chatId); } diff --git a/backend/src/main/java/mouda/backend/chat/service/ChatService.java b/backend/src/main/java/mouda/backend/chat/service/ChatService.java index 28182759c..4e634cf0b 100644 --- a/backend/src/main/java/mouda/backend/chat/service/ChatService.java +++ b/backend/src/main/java/mouda/backend/chat/service/ChatService.java @@ -1,10 +1,17 @@ package mouda.backend.chat.service; +import java.util.List; + +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import lombok.RequiredArgsConstructor; import mouda.backend.chat.domain.Chat; import mouda.backend.chat.dto.request.ChatCreateRequest; +import mouda.backend.chat.dto.response.ChatFindDetailResponse; +import mouda.backend.chat.dto.response.ChatFindUnloadedResponse; +import mouda.backend.chat.exception.ChatErrorMessage; +import mouda.backend.chat.exception.ChatException; import mouda.backend.chat.repository.ChatRepository; import mouda.backend.member.domain.Member; import mouda.backend.moim.domain.Moim; @@ -19,8 +26,15 @@ public class ChatService { public void createChat(ChatCreateRequest chatCreateRequest, Member member) { Moim moim = moimRepository.findById(chatCreateRequest.moimId()) - .orElseThrow(); + .orElseThrow(() -> new ChatException(HttpStatus.BAD_REQUEST, ChatErrorMessage.MOIM_NOT_FOUND)); Chat chat = chatCreateRequest.toEntity(moim, member); chatRepository.save(chat); } + + public ChatFindUnloadedResponse findUnloadedChats(long recentChatId, long moimId, Member member) { + List chats = chatRepository.findAllUnloadedChats(moimId, recentChatId).stream() + .map(ChatFindDetailResponse::toResponse) + .toList(); + return new ChatFindUnloadedResponse(member.getId(), chats); + } } diff --git a/backend/src/test/java/mouda/backend/chat/repository/ChatRepositoryTest.java b/backend/src/test/java/mouda/backend/chat/repository/ChatRepositoryTest.java new file mode 100644 index 000000000..446003435 --- /dev/null +++ b/backend/src/test/java/mouda/backend/chat/repository/ChatRepositoryTest.java @@ -0,0 +1,71 @@ +package mouda.backend.chat.repository; + +import static org.assertj.core.api.Assertions.*; + +import java.time.LocalDate; +import java.time.LocalTime; +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.autoconfigure.orm.jpa.DataJpaTest; + +import mouda.backend.chat.domain.Chat; +import mouda.backend.member.domain.Member; +import mouda.backend.member.repository.MemberRepository; +import mouda.backend.moim.domain.Moim; +import mouda.backend.moim.repository.MoimRepository; + +@DataJpaTest +class ChatRepositoryTest { + + @Autowired + private ChatRepository chatRepository; + + @Autowired + private MoimRepository moimRepository; + + @Autowired + private MemberRepository memberRepository; + + @DisplayName("모임 아이디가 동일하고 채팅 아이디가 더 큰 채팅 리스트가 조회된다.") + @Test + void test() { + Moim moim = Moim.builder() + .place("asdf") + .maxPeople(1) + .description("123") + .time(LocalTime.now()) + .date(LocalDate.now()) + .title("sdfsdfsd") + .build(); + moimRepository.save(moim); + + Member member = Member.builder() + .nickname("hogee") + .build(); + memberRepository.save(member); + + Chat chat1 = Chat.builder() + .moim(moim) + .member(member) + .content("콘텐트") + .date(LocalDate.now()) + .time(LocalTime.now()) + .build(); + Chat chat2 = Chat.builder() + .moim(moim) + .member(member) + .content("콘텐트") + .date(LocalDate.now()) + .time(LocalTime.now()) + .build(); + chatRepository.save(chat1); + chatRepository.save(chat2); + + List chats = chatRepository.findAllUnloadedChats(1L, 1L); + + assertThat(chats).hasSize(1); + } +} From b7a12dbc6fa07f9942f5a4492b18d5e78950fbe9 Mon Sep 17 00:00:00 2001 From: MingyeomKim Date: Wed, 31 Jul 2024 15:22:48 +0900 Subject: [PATCH 3/6] =?UTF-8?q?feat:=20=EC=B1=84=ED=8C=85=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/chat/exception/ChatErrorMessage.java | 12 ++++++++++++ .../mouda/backend/chat/exception/ChatException.java | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 backend/src/main/java/mouda/backend/chat/exception/ChatErrorMessage.java create mode 100644 backend/src/main/java/mouda/backend/chat/exception/ChatException.java diff --git a/backend/src/main/java/mouda/backend/chat/exception/ChatErrorMessage.java b/backend/src/main/java/mouda/backend/chat/exception/ChatErrorMessage.java new file mode 100644 index 000000000..ea234c4f2 --- /dev/null +++ b/backend/src/main/java/mouda/backend/chat/exception/ChatErrorMessage.java @@ -0,0 +1,12 @@ +package mouda.backend.chat.exception; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum ChatErrorMessage { + MOIM_NOT_FOUND("존재하지 않는 모임에 채팅할 수 없습니다."); + + private final String message; +} diff --git a/backend/src/main/java/mouda/backend/chat/exception/ChatException.java b/backend/src/main/java/mouda/backend/chat/exception/ChatException.java new file mode 100644 index 000000000..1c4646128 --- /dev/null +++ b/backend/src/main/java/mouda/backend/chat/exception/ChatException.java @@ -0,0 +1,12 @@ +package mouda.backend.chat.exception; + +import org.springframework.http.HttpStatus; + +import mouda.backend.exception.MoudaException; + +public class ChatException extends MoudaException { + + public ChatException(HttpStatus httpStatus, ChatErrorMessage chatErrorMessage) { + super(httpStatus, chatErrorMessage.getMessage()); + } +} From bd6ea7a057908cfde280172e46c3f7e9aa0b2b5a Mon Sep 17 00:00:00 2001 From: MingyeomKim Date: Wed, 31 Jul 2024 17:14:00 +0900 Subject: [PATCH 4/6] =?UTF-8?q?test:=20=EB=AA=A8=EC=9E=84=EC=9D=84=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8A=94=20=EB=A0=88=ED=8F=AC?= =?UTF-8?q?=EC=A7=80=ED=86=A0=EB=A6=AC=20=EB=A1=9C=EC=A7=81=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/repository/ChatRepositoryTest.java | 43 ++++++------------- .../mouda/backend/fixture/ChatFixture.java | 10 +++++ .../mouda/backend/fixture/MoimFixture.java | 2 +- 3 files changed, 24 insertions(+), 31 deletions(-) diff --git a/backend/src/test/java/mouda/backend/chat/repository/ChatRepositoryTest.java b/backend/src/test/java/mouda/backend/chat/repository/ChatRepositoryTest.java index 446003435..7341964f4 100644 --- a/backend/src/test/java/mouda/backend/chat/repository/ChatRepositoryTest.java +++ b/backend/src/test/java/mouda/backend/chat/repository/ChatRepositoryTest.java @@ -2,8 +2,6 @@ import static org.assertj.core.api.Assertions.*; -import java.time.LocalDate; -import java.time.LocalTime; import java.util.List; import org.junit.jupiter.api.DisplayName; @@ -12,6 +10,9 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import mouda.backend.chat.domain.Chat; +import mouda.backend.fixture.ChatFixture; +import mouda.backend.fixture.MemberFixture; +import mouda.backend.fixture.MoimFixture; import mouda.backend.member.domain.Member; import mouda.backend.member.repository.MemberRepository; import mouda.backend.moim.domain.Moim; @@ -32,37 +33,19 @@ class ChatRepositoryTest { @DisplayName("모임 아이디가 동일하고 채팅 아이디가 더 큰 채팅 리스트가 조회된다.") @Test void test() { - Moim moim = Moim.builder() - .place("asdf") - .maxPeople(1) - .description("123") - .time(LocalTime.now()) - .date(LocalDate.now()) - .title("sdfsdfsd") - .build(); + Moim moim = MoimFixture.getCoffeeMoim(); moimRepository.save(moim); - Member member = Member.builder() - .nickname("hogee") - .build(); - memberRepository.save(member); + Member member1 = MemberFixture.getAnna(); + Member member2 = MemberFixture.getHogee(); - Chat chat1 = Chat.builder() - .moim(moim) - .member(member) - .content("콘텐트") - .date(LocalDate.now()) - .time(LocalTime.now()) - .build(); - Chat chat2 = Chat.builder() - .moim(moim) - .member(member) - .content("콘텐트") - .date(LocalDate.now()) - .time(LocalTime.now()) - .build(); - chatRepository.save(chat1); - chatRepository.save(chat2); + memberRepository.save(member1); + memberRepository.save(member2); + + Chat hogee = ChatFixture.getChatWithHogeeAtCoffeeMoim(); + chatRepository.save(hogee); + Chat anna = ChatFixture.getChatWithAnnaAtCoffeeMoim(); + chatRepository.save(anna); List chats = chatRepository.findAllUnloadedChats(1L, 1L); diff --git a/backend/src/test/java/mouda/backend/fixture/ChatFixture.java b/backend/src/test/java/mouda/backend/fixture/ChatFixture.java index 0f8dd8644..08f74711c 100644 --- a/backend/src/test/java/mouda/backend/fixture/ChatFixture.java +++ b/backend/src/test/java/mouda/backend/fixture/ChatFixture.java @@ -27,6 +27,16 @@ public static Chat getChatWithAnnaAtCoffeeMoim() { .build(); } + public static Chat getChatWithHogeeAtCoffeeMoim() { + return Chat.builder() + .time(LocalTime.now()) + .date(LocalDate.now()) + .content("반갑읍니다") + .member(MemberFixture.getHogee()) + .moim(MoimFixture.getCoffeeMoim()) + .build(); + } + public static Chat getChatWithTebahAtSoccerMoim() { return Chat.builder() .time(LocalTime.now()) diff --git a/backend/src/test/java/mouda/backend/fixture/MoimFixture.java b/backend/src/test/java/mouda/backend/fixture/MoimFixture.java index f2401878f..9a5b9fc7f 100644 --- a/backend/src/test/java/mouda/backend/fixture/MoimFixture.java +++ b/backend/src/test/java/mouda/backend/fixture/MoimFixture.java @@ -36,7 +36,7 @@ public static Moim getCoffeeMoim() { .date(LocalDate.now().plusDays(1)) .place("안나 집") .description("커피 머신 들고와라") - .maxPeople(100) + .maxPeople(60) .build(); } } From 532836c1324565f19694cf2db7d006f6b5850993 Mon Sep 17 00:00:00 2001 From: MingyeomKim Date: Wed, 31 Jul 2024 17:29:28 +0900 Subject: [PATCH 5/6] =?UTF-8?q?test:=20=EA=B0=9D=EC=B2=B4=EA=B0=80=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=EB=90=98=EC=A7=80=20=EC=95=8A=EC=95=84?= =?UTF-8?q?=EC=84=9C=20=EC=8B=A4=ED=8C=A8=ED=95=98=EB=8A=94=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/repository/ChatRepositoryTest.java | 6 +-- .../mouda/backend/fixture/ChatFixture.java | 40 +++---------------- 2 files changed, 9 insertions(+), 37 deletions(-) diff --git a/backend/src/test/java/mouda/backend/chat/repository/ChatRepositoryTest.java b/backend/src/test/java/mouda/backend/chat/repository/ChatRepositoryTest.java index 7341964f4..90b593abe 100644 --- a/backend/src/test/java/mouda/backend/chat/repository/ChatRepositoryTest.java +++ b/backend/src/test/java/mouda/backend/chat/repository/ChatRepositoryTest.java @@ -42,10 +42,10 @@ void test() { memberRepository.save(member1); memberRepository.save(member2); - Chat hogee = ChatFixture.getChatWithHogeeAtCoffeeMoim(); - chatRepository.save(hogee); - Chat anna = ChatFixture.getChatWithAnnaAtCoffeeMoim(); + Chat anna = ChatFixture.getChatWithMemberAtMoim(member1, moim); chatRepository.save(anna); + Chat hogee = ChatFixture.getChatWithMemberAtMoim(member2, moim); + chatRepository.save(hogee); List chats = chatRepository.findAllUnloadedChats(1L, 1L); diff --git a/backend/src/test/java/mouda/backend/fixture/ChatFixture.java b/backend/src/test/java/mouda/backend/fixture/ChatFixture.java index 08f74711c..0854117fa 100644 --- a/backend/src/test/java/mouda/backend/fixture/ChatFixture.java +++ b/backend/src/test/java/mouda/backend/fixture/ChatFixture.java @@ -4,46 +4,18 @@ import java.time.LocalTime; import mouda.backend.chat.domain.Chat; +import mouda.backend.member.domain.Member; +import mouda.backend.moim.domain.Moim; public class ChatFixture { - public static Chat getChatWithHogeeAtBasketballMoim() { + public static Chat getChatWithMemberAtMoim(Member member, Moim moim) { return Chat.builder() .time(LocalTime.now()) .date(LocalDate.now()) - .content("ㅎㅇㅎㅇ") - .member(MemberFixture.getHogee()) - .moim(MoimFixture.getBasketballMoim()) - .build(); - } - - public static Chat getChatWithAnnaAtCoffeeMoim() { - return Chat.builder() - .time(LocalTime.now()) - .date(LocalDate.now()) - .content("반갑읍니다") - .member(MemberFixture.getAnna()) - .moim(MoimFixture.getCoffeeMoim()) - .build(); - } - - public static Chat getChatWithHogeeAtCoffeeMoim() { - return Chat.builder() - .time(LocalTime.now()) - .date(LocalDate.now()) - .content("반갑읍니다") - .member(MemberFixture.getHogee()) - .moim(MoimFixture.getCoffeeMoim()) - .build(); - } - - public static Chat getChatWithTebahAtSoccerMoim() { - return Chat.builder() - .time(LocalTime.now()) - .date(LocalDate.now()) - .content("ㅎㅇㅎㅇ") - .member(MemberFixture.getTebah()) - .moim(MoimFixture.getSoccerMoim()) + .content("안녕하쎄요") + .member(member) + .moim(moim) .build(); } } From 6372ef4629731a621e2b596e56b097392a906e0b Mon Sep 17 00:00:00 2001 From: MingyeomKim Date: Thu, 1 Aug 2024 11:19:42 +0900 Subject: [PATCH 6/6] =?UTF-8?q?style:=20=EA=B0=9C=ED=96=89=20=EC=BB=A8?= =?UTF-8?q?=EB=B2=A4=EC=85=98=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mouda/backend/chat/dto/request/ChatCreateRequest.java | 7 +++++-- .../mouda/backend/chat/exception/ChatErrorMessage.java | 4 +++- .../main/java/mouda/backend/chat/service/ChatService.java | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/mouda/backend/chat/dto/request/ChatCreateRequest.java b/backend/src/main/java/mouda/backend/chat/dto/request/ChatCreateRequest.java index d91e59d2f..8564b25bd 100644 --- a/backend/src/main/java/mouda/backend/chat/dto/request/ChatCreateRequest.java +++ b/backend/src/main/java/mouda/backend/chat/dto/request/ChatCreateRequest.java @@ -10,8 +10,11 @@ import mouda.backend.moim.domain.Moim; public record ChatCreateRequest( - @NotNull Long moimId, - @NotBlank String content + @NotNull + Long moimId, + + @NotBlank + String content ) { public Chat toEntity(Moim moim, Member member) { return Chat.builder() diff --git a/backend/src/main/java/mouda/backend/chat/exception/ChatErrorMessage.java b/backend/src/main/java/mouda/backend/chat/exception/ChatErrorMessage.java index ea234c4f2..bcb82caf3 100644 --- a/backend/src/main/java/mouda/backend/chat/exception/ChatErrorMessage.java +++ b/backend/src/main/java/mouda/backend/chat/exception/ChatErrorMessage.java @@ -6,7 +6,9 @@ @Getter @AllArgsConstructor public enum ChatErrorMessage { - MOIM_NOT_FOUND("존재하지 않는 모임에 채팅할 수 없습니다."); + + MOIM_NOT_FOUND("존재하지 않는 모임에 채팅할 수 없습니다."), + ; private final String message; } diff --git a/backend/src/main/java/mouda/backend/chat/service/ChatService.java b/backend/src/main/java/mouda/backend/chat/service/ChatService.java index 4e634cf0b..c11e2e298 100644 --- a/backend/src/main/java/mouda/backend/chat/service/ChatService.java +++ b/backend/src/main/java/mouda/backend/chat/service/ChatService.java @@ -35,6 +35,7 @@ public ChatFindUnloadedResponse findUnloadedChats(long recentChatId, long moimId List chats = chatRepository.findAllUnloadedChats(moimId, recentChatId).stream() .map(ChatFindDetailResponse::toResponse) .toList(); + return new ChatFindUnloadedResponse(member.getId(), chats); } }