From ced3c290ee5fff783cb5e5752eaf2ba68c69c318 Mon Sep 17 00:00:00 2001 From: java-saeng Date: Thu, 5 Oct 2023 16:31:27 +0900 Subject: [PATCH 1/3] =?UTF-8?q?refactor=20:=20RequestNotification=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../emmsale/RequestNotificationApiTest.java | 327 ------------------ .../api/RequestNotificationApi.java | 89 ----- .../FirebaseCloudMessageClient.java | 9 - .../RequestNotificationCommandService.java | 132 ------- .../RequestNotificationQueryService.java | 51 --- .../RequestNotificationExistedRequest.java | 19 - .../dto/RequestNotificationMessage.java | 35 -- .../dto/RequestNotificationModifyRequest.java | 16 - .../dto/RequestNotificationRequest.java | 14 - .../dto/RequestNotificationResponse.java | 49 --- .../RequestNotificationMessageGenerator.java | 57 --- .../domain/RequestNotification.java | 68 ---- .../domain/RequestNotificationRepository.java | 13 - .../domain/RequestNotificationStatus.java | 8 - .../application/ReportCommandService.java | 15 - ...RequestNotificationCommandServiceTest.java | 281 --------------- .../RequestNotificationQueryServiceTest.java | 75 ---- .../RequestNotificationRepositoryTest.java | 38 -- .../application/ReportCommandServiceTest.java | 6 - 19 files changed, 1302 deletions(-) delete mode 100644 backend/emm-sale/src/documentTest/java/com/emmsale/RequestNotificationApiTest.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/api/RequestNotificationApi.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/application/RequestNotificationCommandService.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/application/RequestNotificationQueryService.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/RequestNotificationExistedRequest.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/RequestNotificationMessage.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/RequestNotificationModifyRequest.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/RequestNotificationRequest.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/RequestNotificationResponse.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/application/generator/RequestNotificationMessageGenerator.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/domain/RequestNotification.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/domain/RequestNotificationRepository.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/domain/RequestNotificationStatus.java delete mode 100644 backend/emm-sale/src/test/java/com/emmsale/notification/application/RequestNotificationCommandServiceTest.java delete mode 100644 backend/emm-sale/src/test/java/com/emmsale/notification/application/RequestNotificationQueryServiceTest.java delete mode 100644 backend/emm-sale/src/test/java/com/emmsale/notification/domain/RequestNotificationRepositoryTest.java diff --git a/backend/emm-sale/src/documentTest/java/com/emmsale/RequestNotificationApiTest.java b/backend/emm-sale/src/documentTest/java/com/emmsale/RequestNotificationApiTest.java deleted file mode 100644 index cecd5988e..000000000 --- a/backend/emm-sale/src/documentTest/java/com/emmsale/RequestNotificationApiTest.java +++ /dev/null @@ -1,327 +0,0 @@ -package com.emmsale; - -import static com.emmsale.notification.exception.NotificationExceptionType.NO_CONTENT_BLOCKED_MEMBER; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.when; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.patch; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; -import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; -import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; -import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; -import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; -import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; -import static org.springframework.restdocs.request.RequestDocumentation.requestParameters; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import com.emmsale.notification.api.RequestNotificationApi; -import com.emmsale.notification.application.dto.RequestNotificationModifyRequest; -import com.emmsale.notification.application.dto.RequestNotificationRequest; -import com.emmsale.notification.application.dto.RequestNotificationResponse; -import com.emmsale.notification.domain.RequestNotificationStatus; -import com.emmsale.notification.exception.NotificationException; -import java.time.LocalDateTime; -import java.util.List; -import java.util.Optional; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.restdocs.payload.RequestFieldsSnippet; -import org.springframework.restdocs.payload.ResponseFieldsSnippet; -import org.springframework.restdocs.request.PathParametersSnippet; -import org.springframework.restdocs.request.RequestParametersSnippet; - -@WebMvcTest(RequestNotificationApi.class) -class RequestNotificationApiTest extends MockMvcTestHelper { - - - private static final ResponseFieldsSnippet RESPONSE_FIELDS = responseFields( - fieldWithPath("notificationId").description("저장된 알림 ID"), - fieldWithPath("senderId").description("보내는 사람 ID"), - fieldWithPath("receiverId").description("받는 사람 ID"), - fieldWithPath("message").description("알림 보낼 때 메시지"), - fieldWithPath("eventId").description("행사 ID"), - fieldWithPath("isRead").description("읽은 상태"), - fieldWithPath("status").description("ACCEPTED/REJECTED/IN_PROGRESS 상태"), - fieldWithPath("createdAt").description("알림 생성 시간") - ); - private static final RequestFieldsSnippet REQUEST_FIELDS = requestFields( - fieldWithPath("senderId").description("보내는 사람 ID"), - fieldWithPath("receiverId").description("받는 사람 ID"), - fieldWithPath("message").description("알림 보낼 때 메시지"), - fieldWithPath("eventId").description("행사 ID") - ); - - @Test - @DisplayName("create() : 알림을 성공적으로 생성한다면 201 Created를 반환할 수 있다.") - void test_create() throws Exception { - //given - - final RequestFieldsSnippet requestFields = requestFields( - fieldWithPath("senderId").description("보내는 사람 ID"), - fieldWithPath("receiverId").description("받는 사람 ID"), - fieldWithPath("message").description("알림 보낼 때 메시지"), - fieldWithPath("eventId").description("행사 ID") - ); - - final long senderId = 1L; - final long receiverId = 2L; - final long eventId = 3L; - final String message = "알림 메시지야"; - final long notificationId = 1L; - - final RequestNotificationResponse response = new RequestNotificationResponse( - notificationId, - senderId, - receiverId, - message, - eventId, - false, - RequestNotificationStatus.IN_PROGRESS, - LocalDateTime.now() - ); - - final RequestNotificationRequest request = new RequestNotificationRequest( - senderId, - receiverId, - message, - eventId - ); - - when(requestNotificationCommandService.create(any())) - .thenReturn(Optional.of(response)); - - //when & then - mockMvc.perform(post("/request-notifications") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(request))) - .andExpect(status().isCreated()) - .andDo(print()) - .andDo(document("create-request-notification", requestFields, RESPONSE_FIELDS)); - } - - @Test - @DisplayName("create() : 차단된 사용자에게 알림을 보낼 경우 204 NO_CONTENT를 반환한다.") - void test_createWithBlockedSender() throws Exception { - //given - final long senderId = 1L; - final long receiverId = 2L; - final long eventId = 3L; - final String message = "알림 메시지야"; - - final RequestNotificationRequest request = new RequestNotificationRequest( - senderId, - receiverId, - message, - eventId - ); - - when(requestNotificationCommandService.create(any())) - .thenThrow(new NotificationException(NO_CONTENT_BLOCKED_MEMBER)); - - //when & then - mockMvc.perform(post("/request-notifications") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(request))) - .andExpect(status().isNoContent()) - .andDo(print()) - .andDo(document("create-blocked-member-requestNotification", REQUEST_FIELDS)); - } - - - @Test - @DisplayName("modify() : 알림 상태를 성공적으로 변경되면 204 No Content를 반환할 수 있다.") - void test_modify() throws Exception { - //given - final RequestNotificationModifyRequest request = - new RequestNotificationModifyRequest(RequestNotificationStatus.IN_PROGRESS); - - final RequestFieldsSnippet requestFields = requestFields( - fieldWithPath("updatedStatus").description("변화시킬 상태(ACCEPTED 또는 REJECTED)") - ); - - final PathParametersSnippet pathParameters = pathParameters( - parameterWithName("request-notification-id").description("상태변화 시킬 알림 ID") - ); - - final long notificationId = 1L; - - doNothing().when(requestNotificationCommandService).modify(request, 3L); - - //when & then - mockMvc.perform(patch("/request-notifications/{request-notification-id}/status", notificationId) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(request))) - .andExpect(status().isNoContent()) - .andDo(print()) - .andDo(document("modify-request-notification", requestFields, pathParameters)); - } - - @Test - @DisplayName("find() : 알림 id를 통해 성공적으로 조회할 수 있다면 200 OK 를 반환할 수 있다.") - void test_find() throws Exception { - //given - final PathParametersSnippet pathParameters = pathParameters( - parameterWithName("request-notification-id").description("상태변화 시킬 알림 ID") - ); - - final ResponseFieldsSnippet responseFields = responseFields( - fieldWithPath("notificationId").description("저장된 알림 ID"), - fieldWithPath("senderId").description("보내는 사람 ID"), - fieldWithPath("receiverId").description("받는 사람 ID"), - fieldWithPath("message").description("알림 보낼 때 메시지"), - fieldWithPath("eventId").description("행사 ID"), - fieldWithPath("isRead").description("읽은 상태"), - fieldWithPath("status").description("ACCEPTED/REJECTED/IN_PROGRESS 상태"), - fieldWithPath("createdAt").description("알림 생성 시간") - ); - - final long senderId = 1L; - final long receiverId = 2L; - final long eventId = 3L; - final String message = "알림 메시지야"; - final long notificationId = 1L; - - final RequestNotificationResponse response = new RequestNotificationResponse( - notificationId, - senderId, - receiverId, - message, - eventId, - true, - RequestNotificationStatus.IN_PROGRESS, - LocalDateTime.now() - ); - - //when - when(requestNotificationQueryService.findNotificationBy(anyLong())) - .thenReturn(response); - - //then - mockMvc.perform(get("/request-notifications/{request-notification-id}", notificationId)) - .andExpect(status().isOk()) - .andDo(print()) - .andDo(document("find-request-notification", responseFields, pathParameters)); - } - - @Test - @DisplayName("사용자가 받은 알림의 목록을 성공적으로 반환하면 200 OK를 반환한다.") - void test_findAll() throws Exception { - //given - final String accessToken = "Bearer access_token"; - - final long memberId = 1L; - - final List expectResponses = List.of( - new RequestNotificationResponse( - 931L, 3342L, - memberId, "같이 가요~", - 312L, false, - RequestNotificationStatus.REJECTED, - LocalDateTime.now() - ), - new RequestNotificationResponse( - 932L, 1345L, - memberId, "소통해요~", - 123L, true, - RequestNotificationStatus.ACCEPTED, - LocalDateTime.now() - ) - ); - - when(requestNotificationCommandService.findAllNotifications(any())) - .thenReturn(expectResponses); - - final ResponseFieldsSnippet responseFields = responseFields( - fieldWithPath("[].notificationId").description("저장된 알림 ID"), - fieldWithPath("[].senderId").description("보내는 사람 ID"), - fieldWithPath("[].receiverId").description("받는 사람 ID"), - fieldWithPath("[].message").description("알림 보낼 때 메시지"), - fieldWithPath("[].eventId").description("행사 ID"), - fieldWithPath("[].isRead").description("읽은 상태"), - fieldWithPath("[].status").description("ACCEPTED/REJECTED/IN_PROGRESS 상태"), - fieldWithPath("[].createdAt").description("알림 생성 시간") - ); - - //when & then - mockMvc.perform(get("/request-notifications") - .header(HttpHeaders.AUTHORIZATION, accessToken)) - .andExpect(status().isOk()) - .andDo(print()) - .andDo(document("find-all-request-notification", responseFields)); - } - - @Test - @DisplayName("delete() : 알림 상태를 성공적으로 변경되면 204 No Content를 반환할 수 있다.") - void test_delete() throws Exception { - //given - final PathParametersSnippet pathParameters = pathParameters( - parameterWithName("request-notification-id").description("삭제할 알림 ID") - ); - - final long notificationId = 1L; - - doNothing().when(requestNotificationCommandService).delete(any(), any()); - - //when & then - mockMvc.perform(delete("/request-notifications/{request-notification-id}", notificationId) - .header(HttpHeaders.AUTHORIZATION, "Bearer AccessToken") - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isNoContent()) - .andDo(print()) - .andDo(document("delete-request-notification", pathParameters)); - } - - @Test - @DisplayName("read() : 알림의 읽음 상태가 성공적으로 읽은 상태가 되면 204 No Content를 반환할 수 있다.") - void test_read() throws Exception { - //given - final PathParametersSnippet pathParameters = pathParameters( - parameterWithName("request-notification-id").description("읽은 알림 ID") - ); - - final long notificationId = 1L; - - doNothing().when(requestNotificationCommandService).read(anyLong(), any()); - - //when & then - mockMvc.perform(patch("/request-notifications/{request-notification-id}/read", notificationId) - .header(HttpHeaders.AUTHORIZATION, "Bearer AccessToken")) - .andExpect(status().isNoContent()) - .andDo(print()) - .andDo(document("read-request-notification", pathParameters)); - } - - @Test - @DisplayName("isAlreadyExisted() : 현재 사용자가 행사에서 같이 가기 요청을 이미 보냈는지 제대로 확인할 수 있다면 200 OK 를 반환할 수 있다.") - void test_isAlreadyExisted() throws Exception { - //given - final String accessToken = "Bearer access_token"; - - final RequestParametersSnippet requestParam = requestParameters( - parameterWithName("receiverId").description("알림 받을 사람 id"), - parameterWithName("senderId").description("알림 보낸 사람 id"), - parameterWithName("eventId").description("행사 id") - ); - - when(requestNotificationQueryService.isAlreadyExisted(any(), any())) - .thenReturn(true); - - //when & then - mockMvc.perform(get("/request-notifications/existed") - .queryParam("receiverId", "1") - .queryParam("senderId", "2") - .queryParam("eventId", "3") - .header(HttpHeaders.AUTHORIZATION, accessToken)) - .andExpect(status().isOk()) - .andDo(print()) - .andDo(document("already-existed-request-notification", requestParam)); - } -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/api/RequestNotificationApi.java b/backend/emm-sale/src/main/java/com/emmsale/notification/api/RequestNotificationApi.java deleted file mode 100644 index 196df66e8..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/api/RequestNotificationApi.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.emmsale.notification.api; - -import com.emmsale.member.domain.Member; -import com.emmsale.notification.application.RequestNotificationCommandService; -import com.emmsale.notification.application.RequestNotificationQueryService; -import com.emmsale.notification.application.dto.RequestNotificationExistedRequest; -import com.emmsale.notification.application.dto.RequestNotificationModifyRequest; -import com.emmsale.notification.application.dto.RequestNotificationRequest; -import com.emmsale.notification.application.dto.RequestNotificationResponse; -import java.util.List; -import java.util.Optional; -import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PatchMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequiredArgsConstructor -public class RequestNotificationApi { - - private final RequestNotificationCommandService requestNotificationCommandService; - private final RequestNotificationQueryService requestNotificationQueryService; - - @PostMapping("/request-notifications") - public ResponseEntity create( - @RequestBody final RequestNotificationRequest requestNotificationRequest) { - final Optional requestNotificationResponse = requestNotificationCommandService.create( - requestNotificationRequest); - - return requestNotificationResponse.map( - response -> new ResponseEntity<>(response, HttpStatus.CREATED) - ).orElseGet(() -> new ResponseEntity<>(null, HttpStatus.NO_CONTENT)); - } - - @PatchMapping("/request-notifications/{request-notification-id}/status") - @ResponseStatus(HttpStatus.NO_CONTENT) - public void modify( - @RequestBody final RequestNotificationModifyRequest requestNotificationModifyRequest, - @PathVariable("request-notification-id") final Long notificationId - ) { - requestNotificationCommandService.modify(requestNotificationModifyRequest, notificationId); - } - - @PatchMapping("/request-notifications/{request-notification-id}/read") - @ResponseStatus(HttpStatus.NO_CONTENT) - public void read( - @PathVariable("request-notification-id") final Long notificationId, - final Member member - ) { - requestNotificationCommandService.read(notificationId, member); - } - - @GetMapping("/request-notifications/{request-notification-id}") - public RequestNotificationResponse find( - @PathVariable("request-notification-id") final Long notificationId - ) { - return requestNotificationQueryService.findNotificationBy(notificationId); - } - - @GetMapping("/request-notifications") - @ResponseStatus(HttpStatus.OK) - public List findAll(final Member member) { - return requestNotificationCommandService.findAllNotifications(member); - } - - @DeleteMapping("/request-notifications/{request-notification-id}") - @ResponseStatus(HttpStatus.NO_CONTENT) - public void delete( - final Member member, - @PathVariable("request-notification-id") final Long notificationId - ) { - requestNotificationCommandService.delete(member, notificationId); - } - - @GetMapping("/request-notifications/existed") - public boolean isAlreadyExisted( - final Member member, - final RequestNotificationExistedRequest existedRequest - ) { - return requestNotificationQueryService.isAlreadyExisted(member, existedRequest); - } -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/FirebaseCloudMessageClient.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/FirebaseCloudMessageClient.java index 2f53a4e67..d4131e5d8 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/application/FirebaseCloudMessageClient.java +++ b/backend/emm-sale/src/main/java/com/emmsale/notification/application/FirebaseCloudMessageClient.java @@ -10,13 +10,11 @@ import com.emmsale.notification.application.generator.EventNotificationMessageGenerator; import com.emmsale.notification.application.generator.MessageNotificationMessageGenerator; import com.emmsale.notification.application.generator.NotificationMessageGenerator; -import com.emmsale.notification.application.generator.RequestNotificationMessageGenerator; import com.emmsale.notification.application.generator.UpdateNotificationMessageGenerator; import com.emmsale.notification.domain.FcmToken; import com.emmsale.notification.domain.FcmTokenRepository; import com.emmsale.notification.domain.Notification; import com.emmsale.notification.domain.NotificationType; -import com.emmsale.notification.domain.RequestNotification; import com.emmsale.notification.domain.UpdateNotification; import com.emmsale.notification.exception.NotificationException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -62,13 +60,6 @@ public class FirebaseCloudMessageClient { @Value("${firebase.project.id}") private String projectId; - public void sendMessageTo(final RequestNotification requestNotification) { - sendMessageTo( - requestNotification.getReceiverId(), - new RequestNotificationMessageGenerator(requestNotification) - ); - } - public void sendMessageTo(final UpdateNotification updateNotification) { sendMessageTo( updateNotification.getReceiverId(), diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/RequestNotificationCommandService.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/RequestNotificationCommandService.java deleted file mode 100644 index 1ebb3fb3f..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/application/RequestNotificationCommandService.java +++ /dev/null @@ -1,132 +0,0 @@ -package com.emmsale.notification.application; - -import static com.emmsale.notification.exception.NotificationExceptionType.ALREADY_EXIST_NOTIFICATION; -import static com.emmsale.notification.exception.NotificationExceptionType.BAD_REQUEST_MEMBER_ID; -import static com.emmsale.notification.exception.NotificationExceptionType.NOT_FOUND_NOTIFICATION; -import static com.emmsale.notification.exception.NotificationExceptionType.NOT_OWNER; - -import com.emmsale.block.domain.BlockRepository; -import com.emmsale.member.domain.Member; -import com.emmsale.member.domain.MemberRepository; -import com.emmsale.notification.application.dto.RequestNotificationModifyRequest; -import com.emmsale.notification.application.dto.RequestNotificationRequest; -import com.emmsale.notification.application.dto.RequestNotificationResponse; -import com.emmsale.notification.domain.RequestNotification; -import com.emmsale.notification.domain.RequestNotificationRepository; -import com.emmsale.notification.exception.NotificationException; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@Transactional -@RequiredArgsConstructor -public class RequestNotificationCommandService { - - private final RequestNotificationRepository requestNotificationRepository; - private final MemberRepository memberRepository; - private final FirebaseCloudMessageClient firebaseCloudMessageClient; - private final BlockRepository blockRepository; - - public Optional create( - final RequestNotificationRequest requestNotificationRequest - ) { - final Long senderId = requestNotificationRequest.getSenderId(); - final Long receiverId = requestNotificationRequest.getReceiverId(); - final Long eventId = requestNotificationRequest.getEventId(); - - validateAlreadyExistedNotification(senderId, receiverId, eventId); - validateExistedSenderOrReceiver(List.of(senderId, receiverId)); - if (isBlockedSender(receiverId, senderId)) { - return Optional.empty(); - } - - final RequestNotification savedRequestNotification = requestNotificationRepository.save( - new RequestNotification( - senderId, - receiverId, - eventId, - requestNotificationRequest.getMessage() - )); - - firebaseCloudMessageClient.sendMessageTo(savedRequestNotification); - - return Optional.of(RequestNotificationResponse.from(savedRequestNotification)); - } - - private boolean isBlockedSender(final Long receiverId, final Long senderId) { - return blockRepository.existsByRequestMemberIdAndBlockMemberId(receiverId, senderId); - } - - private void validateAlreadyExistedNotification( - final Long senderId, - final Long receiverId, - final Long eventId - ) { - if (requestNotificationRepository.existsBySenderIdAndReceiverIdAndEventId( - senderId, receiverId, eventId - )) { - throw new NotificationException(ALREADY_EXIST_NOTIFICATION); - } - } - - private void validateExistedSenderOrReceiver(final List memberIds) { - if (isNotExistedSenderOrReceiver(memberIds)) { - throw new NotificationException(BAD_REQUEST_MEMBER_ID); - } - } - - private boolean isNotExistedSenderOrReceiver(final List memberIds) { - return memberIds.size() != memberRepository.countMembersById(memberIds); - } - - public void modify( - final RequestNotificationModifyRequest requestNotificationModifyRequest, - final Long notificationId - ) { - final RequestNotification savedRequestNotification = requestNotificationRepository.findById( - notificationId) - .orElseThrow(() -> new NotificationException(NOT_FOUND_NOTIFICATION)); - - savedRequestNotification.modifyStatus(requestNotificationModifyRequest.getUpdatedStatus()); - } - - public List findAllNotifications(final Member member) { - final List requestNotifications = requestNotificationRepository.findAllByReceiverId( - member.getId()); - - return requestNotifications.stream() - .map(RequestNotificationResponse::from) - .collect(Collectors.toList()); - } - - public void delete(final Member member, final Long notificationId) { - final RequestNotification notification = requestNotificationRepository.findById(notificationId) - .orElseThrow(() -> new NotificationException(NOT_FOUND_NOTIFICATION)); - - validateNotificationOwner(notification, member); - - requestNotificationRepository.delete(notification); - } - - private void validateNotificationOwner( - final RequestNotification notification, - final Member member - ) { - if (notification.isNotOwner(member.getId())) { - throw new NotificationException(NOT_OWNER); - } - } - - public void read(final Long notificationId, final Member member) { - final RequestNotification notification = requestNotificationRepository.findById(notificationId) - .orElseThrow(() -> new NotificationException(NOT_FOUND_NOTIFICATION)); - - validateNotificationOwner(notification, member); - - notification.read(); - } -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/RequestNotificationQueryService.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/RequestNotificationQueryService.java deleted file mode 100644 index ee8604eb6..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/application/RequestNotificationQueryService.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.emmsale.notification.application; - -import static com.emmsale.member.exception.MemberExceptionType.NOT_MATCHING_TOKEN_AND_LOGIN_MEMBER; -import static com.emmsale.notification.exception.NotificationExceptionType.NOT_FOUND_NOTIFICATION; - -import com.emmsale.member.domain.Member; -import com.emmsale.member.exception.MemberException; -import com.emmsale.notification.application.dto.RequestNotificationExistedRequest; -import com.emmsale.notification.application.dto.RequestNotificationResponse; -import com.emmsale.notification.domain.RequestNotification; -import com.emmsale.notification.domain.RequestNotificationRepository; -import com.emmsale.notification.exception.NotificationException; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@Transactional(readOnly = true) -@RequiredArgsConstructor -public class RequestNotificationQueryService { - - private final RequestNotificationRepository requestNotificationRepository; - - public RequestNotificationResponse findNotificationBy(final Long notificationId) { - final RequestNotification savedRequestNotification = requestNotificationRepository.findById( - notificationId) - .orElseThrow(() -> new NotificationException(NOT_FOUND_NOTIFICATION)); - - return RequestNotificationResponse.from(savedRequestNotification); - } - - public boolean isAlreadyExisted( - final Member member, - final RequestNotificationExistedRequest existedRequest - ) { - final Long senderId = existedRequest.getSenderId(); - validateSameSender(member, senderId); - - return requestNotificationRepository.existsBySenderIdAndReceiverIdAndEventId( - senderId, - existedRequest.getReceiverId(), - existedRequest.getEventId() - ); - } - - private void validateSameSender(final Member member, final Long senderId) { - if (member.isNotMe(senderId)) { - throw new MemberException(NOT_MATCHING_TOKEN_AND_LOGIN_MEMBER); - } - } -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/RequestNotificationExistedRequest.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/RequestNotificationExistedRequest.java deleted file mode 100644 index b0f22ef4e..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/RequestNotificationExistedRequest.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.emmsale.notification.application.dto; - -import javax.validation.constraints.NotNull; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; - -@Setter -@Getter -@RequiredArgsConstructor -public class RequestNotificationExistedRequest { - - @NotNull - private final Long receiverId; - @NotNull - private final Long senderId; - @NotNull - private final Long eventId; -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/RequestNotificationMessage.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/RequestNotificationMessage.java deleted file mode 100644 index bced3506b..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/RequestNotificationMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.emmsale.notification.application.dto; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -@Getter -public class RequestNotificationMessage { - - @JsonProperty("validate_only") - private final boolean validateOnly; - private final Message message; - - @RequiredArgsConstructor - @Getter - public static class Message { - - private final Data data; - private final String token; - } - - @RequiredArgsConstructor - @Getter - public static class Data { - - private final String senderName; - private final String senderId; - private final String receiverId; - private final String message; - private final String openProfileUrl; - private final String notificationType; - private final String createdAt; - } -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/RequestNotificationModifyRequest.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/RequestNotificationModifyRequest.java deleted file mode 100644 index 543c5b02d..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/RequestNotificationModifyRequest.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.emmsale.notification.application.dto; - -import com.emmsale.notification.domain.RequestNotificationStatus; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -@Getter -public class RequestNotificationModifyRequest { - - private final RequestNotificationStatus updatedStatus; - - private RequestNotificationModifyRequest() { - this(null); - } -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/RequestNotificationRequest.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/RequestNotificationRequest.java deleted file mode 100644 index 836518fd5..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/RequestNotificationRequest.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.emmsale.notification.application.dto; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -@Getter -public class RequestNotificationRequest { - - private final Long senderId; - private final Long receiverId; - private final String message; - private final Long eventId; -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/RequestNotificationResponse.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/RequestNotificationResponse.java deleted file mode 100644 index a88b9f76f..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/RequestNotificationResponse.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.emmsale.notification.application.dto; - -import com.emmsale.notification.domain.RequestNotification; -import com.emmsale.notification.domain.RequestNotificationStatus; -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.time.LocalDateTime; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.ToString; - -@RequiredArgsConstructor -@Getter -@ToString -public class RequestNotificationResponse { - - private final Long notificationId; - private final Long senderId; - private final Long receiverId; - private final String message; - private final Long eventId; - @JsonProperty(value = "isRead") - private final boolean isRead; - private final RequestNotificationStatus status; - @JsonFormat(pattern = "yyyy:MM:dd:HH:mm:ss") - private final LocalDateTime createdAt; - - public static RequestNotificationResponse from(final RequestNotification requestNotification) { - return new RequestNotificationResponse( - requestNotification.getId(), - requestNotification.getSenderId(), - requestNotification.getReceiverId(), - requestNotification.getMessage(), - requestNotification.getEventId(), - requestNotification.isRead(), - requestNotification.getStatus(), - requestNotification.getCreatedAt() - ); - } - - /** - * Rest docs 에서 isRead 로 표현하기 위해 사용 - *
- * 해당 메서드가 없으면 read 로 역직렬화 됨 - */ - private boolean getIsRead() { - return isRead; - } -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/generator/RequestNotificationMessageGenerator.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/generator/RequestNotificationMessageGenerator.java deleted file mode 100644 index 41ced4d5f..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/application/generator/RequestNotificationMessageGenerator.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.emmsale.notification.application.generator; - -import static com.emmsale.notification.exception.NotificationExceptionType.CONVERTING_JSON_ERROR; -import static com.emmsale.notification.exception.NotificationExceptionType.NOT_FOUND_OPEN_PROFILE_URL; - -import com.emmsale.member.domain.Member; -import com.emmsale.member.domain.MemberRepository; -import com.emmsale.member.exception.MemberException; -import com.emmsale.member.exception.MemberExceptionType; -import com.emmsale.notification.application.dto.RequestNotificationMessage; -import com.emmsale.notification.application.dto.RequestNotificationMessage.Data; -import com.emmsale.notification.application.dto.RequestNotificationMessage.Message; -import com.emmsale.notification.domain.RequestNotification; -import com.emmsale.notification.exception.NotificationException; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -public class RequestNotificationMessageGenerator implements NotificationMessageGenerator { - - private static final String REQUEST_NOTIFICATION_TYPE = "REQUEST"; - - private final RequestNotification requestNotification; - - @Override - public String makeMessage( - final String targetToken, - final ObjectMapper objectMapper, - final MemberRepository memberRepository - ) { - - final Long senderId = requestNotification.getSenderId(); - final Member sender = memberRepository.findById(senderId) - .orElseThrow(() -> new MemberException(MemberExceptionType.NOT_FOUND_MEMBER)); - - final String openProfileUrl = sender.getOptionalOpenProfileUrl() - .orElseThrow(() -> new NotificationException(NOT_FOUND_OPEN_PROFILE_URL)); - - final Data messageData = new Data( - sender.getName(), senderId.toString(), - requestNotification.getReceiverId().toString(), requestNotification.getMessage(), - openProfileUrl, REQUEST_NOTIFICATION_TYPE, - requestNotification.getCreatedAt().format(DATE_TIME_FORMATTER) - ); - - final RequestNotificationMessage requestNotificationMessage = new RequestNotificationMessage( - DEFAULT_VALIDATE_ONLY, new Message(messageData, targetToken) - ); - - try { - return objectMapper.writeValueAsString(requestNotificationMessage); - } catch (JsonProcessingException e) { - throw new NotificationException(CONVERTING_JSON_ERROR); - } - } -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/domain/RequestNotification.java b/backend/emm-sale/src/main/java/com/emmsale/notification/domain/RequestNotification.java deleted file mode 100644 index 0938ad07e..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/domain/RequestNotification.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.emmsale.notification.domain; - -import com.emmsale.base.BaseEntity; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Entity -@Getter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@Table(name = "request_notification") -public class RequestNotification extends BaseEntity { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - @Column(nullable = false) - private Long senderId; - @Column(nullable = false) - private Long receiverId; - @Column(nullable = false) - private Long eventId; - @Column(nullable = false) - private String message; - @Enumerated(EnumType.STRING) - @Column(nullable = false) - private RequestNotificationStatus status; - @Column(nullable = false) - private boolean isRead; - - public RequestNotification( - final Long senderId, - final Long receiverId, - final Long eventId, - final String message - ) { - this.senderId = senderId; - this.receiverId = receiverId; - this.eventId = eventId; - this.message = message; - this.status = RequestNotificationStatus.IN_PROGRESS; - this.isRead = false; - } - - public boolean isNotOwner(final Long memberId) { - return !receiverId.equals(memberId); - } - - public boolean isNotSender(final Long memberId) { - return !senderId.equals(memberId); - } - - public void modifyStatus(final RequestNotificationStatus status) { - this.status = status; - } - - public void read() { - isRead = true; - } -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/domain/RequestNotificationRepository.java b/backend/emm-sale/src/main/java/com/emmsale/notification/domain/RequestNotificationRepository.java deleted file mode 100644 index 3a51a052c..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/domain/RequestNotificationRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.emmsale.notification.domain; - -import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface RequestNotificationRepository extends JpaRepository { - - List findAllByReceiverId(Long memberId); - - boolean existsBySenderIdAndReceiverIdAndEventId( - final Long senderId, final Long receiverId, final Long eventId - ); -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/domain/RequestNotificationStatus.java b/backend/emm-sale/src/main/java/com/emmsale/notification/domain/RequestNotificationStatus.java deleted file mode 100644 index a5fadab02..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/domain/RequestNotificationStatus.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.emmsale.notification.domain; - -public enum RequestNotificationStatus { - - ACCEPTED, - REJECTED, - IN_PROGRESS -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/report/application/ReportCommandService.java b/backend/emm-sale/src/main/java/com/emmsale/report/application/ReportCommandService.java index 6c2a96a7f..9df02b3cf 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/report/application/ReportCommandService.java +++ b/backend/emm-sale/src/main/java/com/emmsale/report/application/ReportCommandService.java @@ -6,8 +6,6 @@ import com.emmsale.event.domain.repository.RecruitmentPostRepository; import com.emmsale.member.domain.Member; import com.emmsale.member.domain.MemberRepository; -import com.emmsale.notification.domain.RequestNotification; -import com.emmsale.notification.domain.RequestNotificationRepository; import com.emmsale.report.application.dto.ReportCreateRequest; import com.emmsale.report.application.dto.ReportCreateResponse; import com.emmsale.report.domain.Report; @@ -28,7 +26,6 @@ public class ReportCommandService { private final MemberRepository memberRepository; private final CommentRepository commentRepository; private final RecruitmentPostRepository recruitmentPostRepository; - private final RequestNotificationRepository requestNotificationRepository; public ReportCreateResponse create(final ReportCreateRequest reportRequest, final Member member) { validateReportRequest(reportRequest, member); @@ -78,9 +75,6 @@ private void validateContent(final ReportCreateRequest reportRequest) { if (reportRequest.getType() == ReportType.RECRUITMENT_POST) { validateRecruitmentPost(reportRequest); } - if (reportRequest.getType() == ReportType.REQUEST_NOTIFICATION) { - validateRequestNotification(reportRequest); - } } private void validateComment(final ReportCreateRequest reportRequest) { @@ -99,13 +93,4 @@ private void validateRecruitmentPost(final ReportCreateRequest reportRequest) { throw new ReportException(ReportExceptionType.REPORTED_MISMATCH_WRITER); } } - - private void validateRequestNotification(final ReportCreateRequest reportCreateRequest) { - RequestNotification requestNotification = requestNotificationRepository.findById( - reportCreateRequest.getContentId()) - .orElseThrow(() -> new ReportException(ReportExceptionType.NOT_FOUND_CONTENT)); - if (requestNotification.isNotSender(reportCreateRequest.getReportedId())) { - throw new ReportException(ReportExceptionType.REPORTED_MISMATCH_WRITER); - } - } } diff --git a/backend/emm-sale/src/test/java/com/emmsale/notification/application/RequestNotificationCommandServiceTest.java b/backend/emm-sale/src/test/java/com/emmsale/notification/application/RequestNotificationCommandServiceTest.java deleted file mode 100644 index 530861f61..000000000 --- a/backend/emm-sale/src/test/java/com/emmsale/notification/application/RequestNotificationCommandServiceTest.java +++ /dev/null @@ -1,281 +0,0 @@ -package com.emmsale.notification.application; - -import static com.emmsale.notification.exception.NotificationExceptionType.NOT_OWNER; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertThrowsExactly; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mock; - -import com.emmsale.block.domain.Block; -import com.emmsale.block.domain.BlockRepository; -import com.emmsale.helper.ServiceIntegrationTestHelper; -import com.emmsale.member.domain.Member; -import com.emmsale.member.domain.MemberRepository; -import com.emmsale.notification.application.dto.RequestNotificationModifyRequest; -import com.emmsale.notification.application.dto.RequestNotificationRequest; -import com.emmsale.notification.application.dto.RequestNotificationResponse; -import com.emmsale.notification.domain.RequestNotification; -import com.emmsale.notification.domain.RequestNotificationRepository; -import com.emmsale.notification.domain.RequestNotificationStatus; -import com.emmsale.notification.exception.NotificationException; -import com.emmsale.notification.exception.NotificationExceptionType; -import java.time.LocalDateTime; -import java.util.List; -import java.util.Optional; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; -import org.springframework.beans.factory.annotation.Autowired; - -class RequestNotificationCommandServiceTest extends ServiceIntegrationTestHelper { - - @Autowired - private RequestNotificationCommandService requestNotificationCommandService; - @Autowired - private RequestNotificationRepository requestNotificationRepository; - @Autowired - private MemberRepository memberRepository; - @Autowired - private BlockRepository blockRepository; - private RequestNotificationCommandService mockingRequestNotificationCommandService; - private FirebaseCloudMessageClient firebaseCloudMessageClient; - - @BeforeEach - void setUp() { - firebaseCloudMessageClient = mock(FirebaseCloudMessageClient.class); - - mockingRequestNotificationCommandService = new RequestNotificationCommandService( - requestNotificationRepository, - memberRepository, - firebaseCloudMessageClient, - blockRepository - ); - } - - @Test - @DisplayName("create() : 알림을 새로 생성할 수 있다.") - void test_create() throws Exception { - //given - final long senderId = 1L; - final long receiverId = 2L; - final long eventId = 3L; - final String message = "알림 메시지야"; - final long notificationId = 1L; - - final RequestNotificationRequest request = new RequestNotificationRequest( - senderId, - receiverId, - message, - eventId - ); - - final RequestNotificationResponse expected = new RequestNotificationResponse( - notificationId, senderId, - receiverId, message, - eventId, false, - RequestNotificationStatus.IN_PROGRESS, - LocalDateTime.now() - ); - - doNothing().when(firebaseCloudMessageClient).sendMessageTo((RequestNotification) any()); - - //when - final RequestNotificationResponse actual = mockingRequestNotificationCommandService.create( - request).get(); - - //then - assertThat(actual) - .usingRecursiveComparison() - .ignoringCollectionOrder() - .ignoringFields("createdAt") - .isEqualTo(expected); - } - - @ParameterizedTest - @DisplayName("create() : sender나 receiver가 한명이라도 존재하지 않는다면 BAD_REQUEST_MEMBER_ID 를 반환할 수 있다.") - @CsvSource({ - "1,3", - "3,1", - "4,5" - }) - void test_createToken_badRequestMemberId(final Long senderId, final Long receiverId) - throws Exception { - //given - final long eventId = 3L; - final String message = "알림 메시지야"; - - final RequestNotificationRequest request = new RequestNotificationRequest( - senderId, - receiverId, - message, - eventId - ); - - //when & then - assertThatThrownBy(() -> requestNotificationCommandService.create(request)) - .isInstanceOf(NotificationException.class) - .hasMessage(NotificationExceptionType.BAD_REQUEST_MEMBER_ID.errorMessage()); - } - - @Test - @DisplayName("modify() : 알림의 상태를 변경할 수 있다.") - void test_modify() throws Exception { - //given - final long senderId = 1L; - final long receiverId = 2L; - final long eventId = 3L; - final String message = "알림 메시지야"; - - final RequestNotificationModifyRequest request = - new RequestNotificationModifyRequest(RequestNotificationStatus.IN_PROGRESS); - final RequestNotification savedRequestNotification = - requestNotificationRepository.save( - new RequestNotification(senderId, receiverId, eventId, message)); - - //when - requestNotificationCommandService.modify(request, savedRequestNotification.getId()); - - final RequestNotification updatedRequestNotification = - requestNotificationRepository.findById(savedRequestNotification.getId()).get(); - - //then - assertEquals(request.getUpdatedStatus(), updatedRequestNotification.getStatus()); - } - - @Test - @DisplayName("Member가 받은 모든 알림 목록을 조회한다.") - void test_findAllNotifications() { - //given - final Member sender = memberRepository.findById(1L).get(); - final Member receiver = memberRepository.findById(2L).get(); - - final String message1 = "message123"; - final String message2 = "message321"; - - requestNotificationRepository.save( - new RequestNotification(sender.getId(), receiver.getId(), 123L, message1) - ); - requestNotificationRepository.save( - new RequestNotification(sender.getId(), receiver.getId(), 321L, message2) - ); - - //when - final List notifications = requestNotificationCommandService.findAllNotifications( - receiver); - - //then - assertThat(notifications).extracting("message", String.class) - .containsExactly(message1, message2); - } - - @Test - @DisplayName("알림을 삭제한다.") - void test_delete() { - //given - final Member sender = memberRepository.findById(1L).get(); - final Member receiver = memberRepository.findById(2L).get(); - - final String message = "message"; - final long eventId = 123L; - - final RequestNotification notification = requestNotificationRepository.save( - new RequestNotification(sender.getId(), receiver.getId(), eventId, message) - ); - final Long notificationId = notification.getId(); - - //when - requestNotificationCommandService.delete(receiver, notificationId); - - //then - assertFalse(requestNotificationRepository.findById(notificationId).isPresent()); - } - - @Test - @DisplayName("알림의 소유자가 아닐 경우 NOT_OWNER 타입의 NotificationException이 발생한다.") - void test_deleteByNotOwner() { - //given - final Member sender = memberRepository.findById(1L).get(); - final Member receiver = memberRepository.findById(2L).get(); - - final String message = "message"; - final long eventId = 123L; - - final RequestNotification notification = requestNotificationRepository.save( - new RequestNotification(sender.getId(), receiver.getId(), eventId, message) - ); - final Long notificationId = notification.getId(); - - final NotificationExceptionType expectExceptionType = NOT_OWNER; - - //when - final NotificationException actualException = assertThrowsExactly( - NotificationException.class, - () -> requestNotificationCommandService.delete(sender, notificationId) - ); - - //then - assertEquals(expectExceptionType, actualException.exceptionType()); - } - - @Test - @DisplayName("read() : 사용자가 자신의 알림을 읽었다면 isRead는 true가 될 수 있다.") - void test_read() throws Exception { - //given - final long senderId = 1L; - final long receiverId = 2L; - final Member member = memberRepository.findById(receiverId).get(); - final long eventId = 3L; - final String message = "알림 메시지야"; - - final RequestNotification savedRequestNotification = - requestNotificationRepository.save( - new RequestNotification( - senderId, - receiverId, - eventId, - message) - ); - - //when - requestNotificationCommandService.read(savedRequestNotification.getId(), member); - - //then - final RequestNotification readNotification = requestNotificationRepository.findById( - savedRequestNotification.getId()).get(); - - assertTrue(readNotification.isRead()); - } - - @Test - @DisplayName("차단된 사용자에게 알림을 보낼 경우 Optional.empty()가 반환된다.") - void createWithBlockedSender() { - //given - final long senderId = 1L; - final long receiverId = 2L; - final long eventId = 3L; - final String message = "알림 메시지야"; - - blockRepository.save(new Block(receiverId, senderId)); - - final RequestNotificationRequest request = new RequestNotificationRequest( - senderId, - receiverId, - message, - eventId - ); - - //when - final Optional response = requestNotificationCommandService.create( - request); - - //then - assertFalse(response.isPresent()); - } -} diff --git a/backend/emm-sale/src/test/java/com/emmsale/notification/application/RequestNotificationQueryServiceTest.java b/backend/emm-sale/src/test/java/com/emmsale/notification/application/RequestNotificationQueryServiceTest.java deleted file mode 100644 index b7acdcb75..000000000 --- a/backend/emm-sale/src/test/java/com/emmsale/notification/application/RequestNotificationQueryServiceTest.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.emmsale.notification.application; - -import static com.emmsale.member.exception.MemberExceptionType.NOT_MATCHING_TOKEN_AND_LOGIN_MEMBER; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import com.emmsale.helper.ServiceIntegrationTestHelper; -import com.emmsale.member.domain.Member; -import com.emmsale.member.domain.MemberRepository; -import com.emmsale.member.exception.MemberException; -import com.emmsale.notification.application.dto.RequestNotificationExistedRequest; -import com.emmsale.notification.domain.RequestNotification; -import com.emmsale.notification.domain.RequestNotificationRepository; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -class RequestNotificationQueryServiceTest extends ServiceIntegrationTestHelper { - - @Autowired - private RequestNotificationQueryService requestNotificationQueryService; - @Autowired - private MemberRepository memberRepository; - @Autowired - private RequestNotificationRepository requestNotificationRepository; - - @Test - @DisplayName("isAlreadyExisted() : 행사에서 이미 알림을 보낸 적이 있다면 true를 반환할 수 있다.") - void test_isAlreadyExisted() throws Exception { - //given - final long senderId = 1L; - final Member member = memberRepository.findById(senderId).get(); - final long eventId = 3L; - final long receiverId = 2L; - - final RequestNotification notification = - new RequestNotification(senderId, receiverId, eventId, "알림"); - requestNotificationRepository.save(notification); - - final RequestNotificationExistedRequest request = - new RequestNotificationExistedRequest( - receiverId, - member.getId(), - eventId - ); - - //when - final boolean actual = requestNotificationQueryService - .isAlreadyExisted(member, request); - - //then - assertTrue(actual); - } - - @Test - @DisplayName("isAlreadyExisted() : 토큰의 주인과 로그인 한 사용자가 다르면 NOT_MATCHING_TOKEN_AND_LOGIN_MEMBER 가 발생한다.") - void test_isAlreadyExisted_not_matching_token_and_login_member() throws Exception { - //given - final long senderId = 1L; - final Member member = memberRepository.findById(senderId).get(); - final long eventId = 3L; - final long receiverId = 2L; - final RequestNotificationExistedRequest request = - new RequestNotificationExistedRequest( - receiverId, - 4L, - eventId - ); - - //when & then - assertThatThrownBy(() -> requestNotificationQueryService.isAlreadyExisted(member, request)) - .isInstanceOf(MemberException.class) - .hasMessage(NOT_MATCHING_TOKEN_AND_LOGIN_MEMBER.errorMessage()); - } -} diff --git a/backend/emm-sale/src/test/java/com/emmsale/notification/domain/RequestNotificationRepositoryTest.java b/backend/emm-sale/src/test/java/com/emmsale/notification/domain/RequestNotificationRepositoryTest.java deleted file mode 100644 index 0d083da47..000000000 --- a/backend/emm-sale/src/test/java/com/emmsale/notification/domain/RequestNotificationRepositoryTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.emmsale.notification.domain; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.emmsale.helper.JpaRepositorySliceTestHelper; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; -import org.springframework.beans.factory.annotation.Autowired; - -class RequestNotificationRepositoryTest extends JpaRepositorySliceTestHelper { - - @Autowired - private RequestNotificationRepository requestNotificationRepository; - - private RequestNotification 알림1; - - @BeforeEach - void init() { - 알림1 = new RequestNotification(1L, 2L, 1L, "알림1"); - requestNotificationRepository.save(알림1); - } - - @ParameterizedTest - @CsvSource({ - "1,2,1,true", - "1,2,2,false" - }) - @DisplayName("existsBySenderIdAndReceiverIdAndEventId() : receiverId, senderId, EventId를 통해서 알림이 존재하는지 확인할 수 있다.") - void test_existsBySenderIdAndReceiverIdAndEventId( - final Long senderId, final Long receiverId, final Long eventId, final boolean result - ) throws Exception { - //when & then - assertEquals(requestNotificationRepository.existsBySenderIdAndReceiverIdAndEventId( - senderId, receiverId, eventId), result); - } -} diff --git a/backend/emm-sale/src/test/java/com/emmsale/report/application/ReportCommandServiceTest.java b/backend/emm-sale/src/test/java/com/emmsale/report/application/ReportCommandServiceTest.java index 395de3305..2f4ee11fa 100644 --- a/backend/emm-sale/src/test/java/com/emmsale/report/application/ReportCommandServiceTest.java +++ b/backend/emm-sale/src/test/java/com/emmsale/report/application/ReportCommandServiceTest.java @@ -15,8 +15,6 @@ import com.emmsale.helper.ServiceIntegrationTestHelper; import com.emmsale.member.domain.Member; import com.emmsale.member.domain.MemberRepository; -import com.emmsale.notification.domain.RequestNotification; -import com.emmsale.notification.domain.RequestNotificationRepository; import com.emmsale.report.application.dto.ReportCreateRequest; import com.emmsale.report.application.dto.ReportCreateResponse; import com.emmsale.report.domain.ReportType; @@ -47,8 +45,6 @@ class ReportCommandServiceTest extends ServiceIntegrationTestHelper { private CommentRepository commentRepository; @Autowired private RecruitmentPostRepository recruitmentPostRepository; - @Autowired - private RequestNotificationRepository requestNotificationRepository; @BeforeEach void init() { @@ -62,8 +58,6 @@ void init() { commentRepository.save(Comment.createRoot(feed, 신고_대상자, "상대방에게 불쾌감을 줄 수 있는 내용")); commentRepository.save(Comment.createRoot(feed, 신고자, "그냥 댓글")); recruitmentPostRepository.save(new RecruitmentPost(신고_대상자, event, "사회적 논란을 불러일으킬 수 있는 내용")); - requestNotificationRepository.save( - new RequestNotification(신고_대상자_ID, 신고자_ID, event.getId(), "모욕감을 줄 수 있는 내용")); } @Nested From 46ef5c38da95eaf3ccf0dbec057f77201d6d5ef9 Mon Sep 17 00:00:00 2001 From: java-saeng Date: Thu, 5 Oct 2023 17:05:54 +0900 Subject: [PATCH 2/3] =?UTF-8?q?refactor=20:=20UpdateNotification=20=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/emmsale/MockMvcTestHelper.java | 12 -- .../emmsale/UpdateNotificationApiTest.java | 150 ------------------ .../UpdateNotificationEvent.java | 38 ----- .../api/UpdateNotificationApi.java | 53 ------- .../FirebaseCloudMessageClient.java | 9 -- .../NotificationEventListener.java | 25 --- .../UpdateNotificationCommandService.java | 63 -------- .../UpdateNotificationQueryService.java | 60 ------- .../dto/UpdateNotificationDeleteRequest.java | 16 -- .../dto/UpdateNotificationMessage.java | 32 ---- .../dto/UpdateNotificationResponse.java | 69 -------- .../UpdateNotificationMessageGenerator.java | 54 ------- .../domain/UpdateNotification.java | 64 -------- .../domain/UpdateNotificationRepository.java | 18 --- .../domain/UpdateNotificationType.java | 25 --- ...entCommandServiceEventIntegrationTest.java | 8 +- .../CommentCommandServiceTest.java | 7 +- .../event/application/EventServiceTest.java | 9 +- .../event_publisher/EventPublisherTest.java | 10 +- .../NotificationCommandServiceTest.java | 1 - .../UpdateNotificationCommandServiceTest.java | 136 ---------------- .../UpdateNotificationQueryServiceTest.java | 111 ------------- ...pdateNotificationMessageGeneratorTest.java | 64 -------- .../UpdateNotificationRepositoryTest.java | 109 ------------- .../domain/UpdateNotificationTest.java | 51 ------ .../domain/UpdateNotificationTypeTest.java | 37 ----- 26 files changed, 16 insertions(+), 1215 deletions(-) delete mode 100644 backend/emm-sale/src/documentTest/java/com/emmsale/UpdateNotificationApiTest.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/event_publisher/UpdateNotificationEvent.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/api/UpdateNotificationApi.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/application/UpdateNotificationCommandService.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/application/UpdateNotificationQueryService.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/UpdateNotificationDeleteRequest.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/UpdateNotificationMessage.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/UpdateNotificationResponse.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/application/generator/UpdateNotificationMessageGenerator.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/domain/UpdateNotification.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/domain/UpdateNotificationRepository.java delete mode 100644 backend/emm-sale/src/main/java/com/emmsale/notification/domain/UpdateNotificationType.java delete mode 100644 backend/emm-sale/src/test/java/com/emmsale/notification/application/UpdateNotificationCommandServiceTest.java delete mode 100644 backend/emm-sale/src/test/java/com/emmsale/notification/application/UpdateNotificationQueryServiceTest.java delete mode 100644 backend/emm-sale/src/test/java/com/emmsale/notification/application/generator/UpdateNotificationMessageGeneratorTest.java delete mode 100644 backend/emm-sale/src/test/java/com/emmsale/notification/domain/UpdateNotificationRepositoryTest.java delete mode 100644 backend/emm-sale/src/test/java/com/emmsale/notification/domain/UpdateNotificationTest.java delete mode 100644 backend/emm-sale/src/test/java/com/emmsale/notification/domain/UpdateNotificationTypeTest.java diff --git a/backend/emm-sale/src/documentTest/java/com/emmsale/MockMvcTestHelper.java b/backend/emm-sale/src/documentTest/java/com/emmsale/MockMvcTestHelper.java index 23c3c0f9c..003ba7104 100644 --- a/backend/emm-sale/src/documentTest/java/com/emmsale/MockMvcTestHelper.java +++ b/backend/emm-sale/src/documentTest/java/com/emmsale/MockMvcTestHelper.java @@ -24,10 +24,6 @@ import com.emmsale.notification.application.FcmTokenRegisterService; import com.emmsale.notification.application.NotificationCommandService; import com.emmsale.notification.application.NotificationQueryService; -import com.emmsale.notification.application.RequestNotificationCommandService; -import com.emmsale.notification.application.RequestNotificationQueryService; -import com.emmsale.notification.application.UpdateNotificationCommandService; -import com.emmsale.notification.application.UpdateNotificationQueryService; import com.emmsale.report.application.ReportCommandService; import com.emmsale.report.application.ReportQueryService; import com.emmsale.resolver.MemberArgumentResolver; @@ -69,14 +65,6 @@ abstract class MockMvcTestHelper { @MockBean protected ReportQueryService reportQueryService; @MockBean - protected UpdateNotificationQueryService updateNotificationQueryService; - @MockBean - protected UpdateNotificationCommandService updateNotificationCommandService; - @MockBean - protected RequestNotificationCommandService requestNotificationCommandService; - @MockBean - protected RequestNotificationQueryService requestNotificationQueryService; - @MockBean protected FcmTokenRegisterService fcmTokenRegisterService; @MockBean protected MemberActivityService memberActivityService; diff --git a/backend/emm-sale/src/documentTest/java/com/emmsale/UpdateNotificationApiTest.java b/backend/emm-sale/src/documentTest/java/com/emmsale/UpdateNotificationApiTest.java deleted file mode 100644 index a4359df89..000000000 --- a/backend/emm-sale/src/documentTest/java/com/emmsale/UpdateNotificationApiTest.java +++ /dev/null @@ -1,150 +0,0 @@ -package com.emmsale; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Mockito.doNothing; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.put; -import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; -import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; -import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; -import static org.springframework.restdocs.request.RequestDocumentation.requestParameters; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import com.emmsale.notification.api.UpdateNotificationApi; -import com.emmsale.notification.application.dto.UpdateNotificationDeleteRequest; -import com.emmsale.notification.application.dto.UpdateNotificationResponse; -import com.emmsale.notification.application.dto.UpdateNotificationResponse.CommentTypeNotification; -import com.emmsale.notification.domain.UpdateNotificationType; -import java.time.LocalDateTime; -import java.util.List; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.http.MediaType; -import org.springframework.restdocs.payload.RequestFieldsSnippet; -import org.springframework.restdocs.payload.ResponseFieldsSnippet; -import org.springframework.restdocs.request.PathParametersSnippet; -import org.springframework.restdocs.request.RequestDocumentation; -import org.springframework.restdocs.request.RequestParametersSnippet; - -@WebMvcTest(UpdateNotificationApi.class) -class UpdateNotificationApiTest extends MockMvcTestHelper { - - @Test - @DisplayName("find() : 현재 로그인 한 사용자가 받은 댓글 & 피드 알림들을 성공적으로 조회한다면 200 OK를 반환할 수 있다.") - void test_find() throws Exception { - //given - final String accessToken = "Bearer Token"; - - final RequestParametersSnippet requestParam = requestParameters( - RequestDocumentation.parameterWithName("member-id").description("알림을 조회할 멤버 ID")); - - final ResponseFieldsSnippet responseFields = responseFields( - fieldWithPath("[].updateNotificationId").description("알림 ID"), - fieldWithPath("[].receiverId").description("수신자 ID"), - fieldWithPath("[].redirectId").description("리다이렉션 ID"), - fieldWithPath("[].createdAt").description("알림 생성 날짜"), - fieldWithPath("[].type").description("알림 타입"), - fieldWithPath("[].isRead").description("읽음 상태 유무"), - fieldWithPath("[].commentTypeNotification").description("피드 알림일 경우 null, 댓글 알림일 경우 내용 존재") - .optional(), - fieldWithPath("[].commentTypeNotification.content").description("(댓글 알림일 경우) 댓글 내용") - .optional(), - fieldWithPath("[].commentTypeNotification.feedTitle").description("(댓글 알림일 경우)피드 제목") - .optional(), - fieldWithPath("[].commentTypeNotification.parentId").description("(댓글 알림일 경우)부모 댓글 ID") - .optional(), - fieldWithPath("[].commentTypeNotification.feedId").description("(댓글 알림일 경우)피드 ID") - .optional(), - fieldWithPath("[].commentTypeNotification.commenterImageUrl").description( - "(댓글 알림일 경우) 댓글 작성자 이미지 Url") - .optional() - ); - - final CommentTypeNotification commentTypeNotification = new CommentTypeNotification( - "대댓글 내용", - "피드 제목", - "대댓글 단 사용자의 이미지 URL", - 3L, - 5L - ); - - final List responses = List.of( - new UpdateNotificationResponse( - 1L, 2L, - 3L, LocalDateTime.now(), - UpdateNotificationType.EVENT, true, - null), - new UpdateNotificationResponse( - 1L, 2L, - 3L, LocalDateTime.now(), - UpdateNotificationType.COMMENT, false, - commentTypeNotification - ) - ); - - //when - Mockito.when(updateNotificationQueryService.findAll(any(), anyLong())) - .thenReturn(responses); - - //then - mockMvc.perform(get("/update-notifications") - .queryParam("member-id", "1") - .header("Authorization", accessToken)) - .andExpect(status().isOk()) - .andDo(print()) - .andDo(document("get-update-notifications", requestParam, responseFields)); - } - - @Test - @DisplayName("read() : 댓글 & 피드 알림의 읽음 상태를 성공적으로 변경시켰다면 204 No Content를 반환할 수 있다.") - void test_read() throws Exception { - //given - final PathParametersSnippet pathParams = RequestDocumentation.pathParameters( - RequestDocumentation.parameterWithName("update-notifications-id") - .description("읽음 상태 변경 시킬 알림 ID") - ); - final String accessToken = "Bearer Token"; - - //when - doNothing().when(updateNotificationCommandService).read(any(), anyLong()); - - //then - mockMvc.perform(put("/update-notifications/{update-notifications-id}/read", 1L) - .header("Authorization", accessToken)) - .andExpect(status().isNoContent()) - .andDo(print()) - .andDo(document("put-update-notifications-read", pathParams)); - } - - @Test - @DisplayName("deleteBatch() : 댓글 & 피드 알림을 성공적으로 삭제했다면 204 No Content 를 반환할 수 있다.") - void test_deleteBatch() throws Exception { - //given - final RequestFieldsSnippet requestFields = requestFields( - fieldWithPath("deleteIds").description("삭제할 댓글 & 피드 알림 ID들") - ); - - final UpdateNotificationDeleteRequest request = - new UpdateNotificationDeleteRequest(List.of(1L, 2L, 3L)); - - final String accessToken = "Bearer Token"; - - //when - doNothing().when(updateNotificationCommandService).deleteBatch(any(), any()); - - //then - mockMvc.perform(delete("/update-notifications") - .content(objectMapper.writeValueAsString(request)) - .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", accessToken)) - .andExpect(status().isNoContent()) - .andDo(print()) - .andDo(document("delete-update-notifications", requestFields)); - } -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/event_publisher/UpdateNotificationEvent.java b/backend/emm-sale/src/main/java/com/emmsale/event_publisher/UpdateNotificationEvent.java deleted file mode 100644 index 6b9c17b09..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/event_publisher/UpdateNotificationEvent.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.emmsale.event_publisher; - -import com.emmsale.comment.domain.Comment; -import com.emmsale.event.domain.Event; -import java.time.LocalDateTime; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public class UpdateNotificationEvent { - - private static final String UPDATE_NOTIFICATION_COMMENT_TYPE = "comment"; - private static final String UPDATE_NOTIFICATION_EVENT_TYPE = "event"; - - private final Long receiverId; - private final Long redirectId; - private final String updateNotificationType; - private final LocalDateTime createdAt; - - public static UpdateNotificationEvent of(final Comment comment, final Long redirectId) { - return new UpdateNotificationEvent( - comment.getMember().getId(), - redirectId, - UPDATE_NOTIFICATION_COMMENT_TYPE, - LocalDateTime.now() - ); - } - - public static UpdateNotificationEvent of(final Event event, final Long receiverId) { - return new UpdateNotificationEvent( - receiverId, - event.getId(), - UPDATE_NOTIFICATION_EVENT_TYPE, - LocalDateTime.now() - ); - } -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/api/UpdateNotificationApi.java b/backend/emm-sale/src/main/java/com/emmsale/notification/api/UpdateNotificationApi.java deleted file mode 100644 index 0941bf202..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/api/UpdateNotificationApi.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.emmsale.notification.api; - -import com.emmsale.member.domain.Member; -import com.emmsale.notification.application.UpdateNotificationCommandService; -import com.emmsale.notification.application.UpdateNotificationQueryService; -import com.emmsale.notification.application.dto.UpdateNotificationDeleteRequest; -import com.emmsale.notification.application.dto.UpdateNotificationResponse; -import java.util.List; -import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequiredArgsConstructor -public class UpdateNotificationApi { - - private final UpdateNotificationQueryService updateNotificationQueryService; - private final UpdateNotificationCommandService updateNotificationCommandService; - - @GetMapping("/update-notifications") - public List find( - final Member authMember, - @RequestParam("member-id") final Long loginMemberId - ) { - return updateNotificationQueryService.findAll(authMember, loginMemberId); - } - - @PutMapping("/update-notifications/{update-notifications-id}/read") - @ResponseStatus(HttpStatus.NO_CONTENT) - public void read( - final Member authMember, - @PathVariable("update-notifications-id") final Long notificationId - ) { - updateNotificationCommandService.read(authMember, notificationId); - } - - @DeleteMapping("/update-notifications") - @ResponseStatus(HttpStatus.NO_CONTENT) - public void deleteBatch( - final Member authMember, - @RequestBody final UpdateNotificationDeleteRequest updateNotificationDeleteRequest - ) { - - updateNotificationCommandService.deleteBatch(authMember, updateNotificationDeleteRequest); - } -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/FirebaseCloudMessageClient.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/FirebaseCloudMessageClient.java index d4131e5d8..2b36a08d7 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/application/FirebaseCloudMessageClient.java +++ b/backend/emm-sale/src/main/java/com/emmsale/notification/application/FirebaseCloudMessageClient.java @@ -10,12 +10,10 @@ import com.emmsale.notification.application.generator.EventNotificationMessageGenerator; import com.emmsale.notification.application.generator.MessageNotificationMessageGenerator; import com.emmsale.notification.application.generator.NotificationMessageGenerator; -import com.emmsale.notification.application.generator.UpdateNotificationMessageGenerator; import com.emmsale.notification.domain.FcmToken; import com.emmsale.notification.domain.FcmTokenRepository; import com.emmsale.notification.domain.Notification; import com.emmsale.notification.domain.NotificationType; -import com.emmsale.notification.domain.UpdateNotification; import com.emmsale.notification.exception.NotificationException; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.auth.oauth2.GoogleCredentials; @@ -60,13 +58,6 @@ public class FirebaseCloudMessageClient { @Value("${firebase.project.id}") private String projectId; - public void sendMessageTo(final UpdateNotification updateNotification) { - sendMessageTo( - updateNotification.getReceiverId(), - new UpdateNotificationMessageGenerator(updateNotification) - ); - } - public void sendMessageTo(final MessageNotificationEvent messageNotificationEvent) { sendMessageTo( messageNotificationEvent.getReceiverId(), diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/NotificationEventListener.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/NotificationEventListener.java index 4165d85a9..e81b7b729 100644 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/application/NotificationEventListener.java +++ b/backend/emm-sale/src/main/java/com/emmsale/notification/application/NotificationEventListener.java @@ -2,13 +2,9 @@ import com.emmsale.event_publisher.MessageNotificationEvent; import com.emmsale.event_publisher.NotificationEvent; -import com.emmsale.event_publisher.UpdateNotificationEvent; import com.emmsale.notification.domain.Notification; import com.emmsale.notification.domain.NotificationRepository; import com.emmsale.notification.domain.NotificationType; -import com.emmsale.notification.domain.UpdateNotification; -import com.emmsale.notification.domain.UpdateNotificationRepository; -import com.emmsale.notification.domain.UpdateNotificationType; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.RequiredArgsConstructor; @@ -23,31 +19,10 @@ @RequiredArgsConstructor public class NotificationEventListener { - private final UpdateNotificationRepository updateNotificationRepository; private final FirebaseCloudMessageClient firebaseCloudMessageClient; private final NotificationRepository notificationRepository; private final ObjectMapper objectMapper; - @Transactional(propagation = Propagation.REQUIRES_NEW) - @TransactionalEventListener - public void createUpdateNotification(final UpdateNotificationEvent updateNotificationEvent) { - final UpdateNotification updateNotification = new UpdateNotification( - updateNotificationEvent.getReceiverId(), - updateNotificationEvent.getRedirectId(), - UpdateNotificationType.from(updateNotificationEvent.getUpdateNotificationType()), - updateNotificationEvent.getCreatedAt() - ); - - final UpdateNotification savedNotification = - updateNotificationRepository.save(updateNotification); - - try { - firebaseCloudMessageClient.sendMessageTo(savedNotification); - } catch (Exception e) { - log.error("파이어베이스 관련 에러, 알림 재요청 필요, {}", e.getMessage(), e); - } - } - @Transactional(propagation = Propagation.REQUIRES_NEW) @TransactionalEventListener public void createNotification(final NotificationEvent notificationEvent) { diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/UpdateNotificationCommandService.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/UpdateNotificationCommandService.java deleted file mode 100644 index 8dc7b77b5..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/application/UpdateNotificationCommandService.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.emmsale.notification.application; - -import static com.emmsale.member.exception.MemberExceptionType.NOT_MATCHING_TOKEN_AND_LOGIN_MEMBER; -import static com.emmsale.notification.exception.NotificationExceptionType.NOT_FOUND_NOTIFICATION; - -import com.emmsale.member.domain.Member; -import com.emmsale.member.exception.MemberException; -import com.emmsale.notification.application.dto.UpdateNotificationDeleteRequest; -import com.emmsale.notification.domain.UpdateNotification; -import com.emmsale.notification.domain.UpdateNotificationRepository; -import com.emmsale.notification.exception.NotificationException; -import java.util.List; -import java.util.stream.Collectors; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@RequiredArgsConstructor -@Transactional -public class UpdateNotificationCommandService { - - private final UpdateNotificationRepository updateNotificationRepository; - - public void read(final Member authMember, final Long notificationId) { - final UpdateNotification savedNotification = - updateNotificationRepository.findById(notificationId) - .orElseThrow(() -> new NotificationException(NOT_FOUND_NOTIFICATION)); - - validateSameMember(authMember, savedNotification.getReceiverId()); - - savedNotification.read(); - } - - private void validateSameMember(final Member authMember, final Long loginMemberId) { - if (authMember.isNotMe(loginMemberId)) { - throw new MemberException(NOT_MATCHING_TOKEN_AND_LOGIN_MEMBER); - } - } - - public void deleteBatch( - final Member authMember, - final UpdateNotificationDeleteRequest updateNotificationDeleteRequest - ) { - final List deleteIds = updateNotificationDeleteRequest.getDeleteIds(); - - final List deleteIdsOwnMember = updateNotificationRepository.findAllByIdIn(deleteIds) - .stream() - .filter(it -> it.isOwner(authMember.getId())) - .map(UpdateNotification::getId) - .collect(Collectors.toList()); - - if (hasNoNotificationToDeleteBy(deleteIdsOwnMember)) { - return; - } - - updateNotificationRepository.deleteBatchByIdsIn(deleteIdsOwnMember); - } - - private boolean hasNoNotificationToDeleteBy(final List deleteIds) { - return deleteIds.isEmpty(); - } -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/UpdateNotificationQueryService.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/UpdateNotificationQueryService.java deleted file mode 100644 index 85af175f5..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/application/UpdateNotificationQueryService.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.emmsale.notification.application; - -import static com.emmsale.comment.exception.CommentExceptionType.NOT_FOUND_COMMENT; -import static com.emmsale.member.exception.MemberExceptionType.NOT_MATCHING_TOKEN_AND_LOGIN_MEMBER; - -import com.emmsale.comment.domain.Comment; -import com.emmsale.comment.domain.CommentRepository; -import com.emmsale.comment.exception.CommentException; -import com.emmsale.member.domain.Member; -import com.emmsale.member.exception.MemberException; -import com.emmsale.notification.application.dto.UpdateNotificationResponse; -import com.emmsale.notification.domain.UpdateNotification; -import com.emmsale.notification.domain.UpdateNotificationRepository; -import java.util.Comparator; -import java.util.List; -import java.util.stream.Collectors; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@RequiredArgsConstructor -@Transactional(readOnly = true) -public class UpdateNotificationQueryService { - - private final UpdateNotificationRepository updateNotificationRepository; - private final CommentRepository commentRepository; - - public List findAll( - final Member authMember, - final Long loginMemberId - ) { - validateSameMember(authMember, loginMemberId); - - final List notifications = - updateNotificationRepository.findAllByReceiverId(authMember.getId()); - - return notifications.stream() - .sorted(Comparator.comparing(UpdateNotification::getCreatedAt)) - .map(this::convertToResponse) - .collect(Collectors.toList()); - } - - private void validateSameMember(final Member authMember, final Long loginMemberId) { - if (authMember.isNotMe(loginMemberId)) { - throw new MemberException(NOT_MATCHING_TOKEN_AND_LOGIN_MEMBER); - } - } - - private UpdateNotificationResponse convertToResponse(final UpdateNotification notification) { - if (notification.isCommentNotification()) { - final Comment savedComment = commentRepository.findById(notification.getRedirectId()) - .orElseThrow(() -> new CommentException(NOT_FOUND_COMMENT)); - - return UpdateNotificationResponse.convertCommentNotification(notification, savedComment); - } - - return UpdateNotificationResponse.convertEventNotification(notification); - } -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/UpdateNotificationDeleteRequest.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/UpdateNotificationDeleteRequest.java deleted file mode 100644 index 02d9c9c6f..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/UpdateNotificationDeleteRequest.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.emmsale.notification.application.dto; - -import java.util.List; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -@Getter -public class UpdateNotificationDeleteRequest { - - private final List deleteIds; - - private UpdateNotificationDeleteRequest() { - this(null); - } -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/UpdateNotificationMessage.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/UpdateNotificationMessage.java deleted file mode 100644 index 1a1439476..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/UpdateNotificationMessage.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.emmsale.notification.application.dto; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -@Getter -public class UpdateNotificationMessage { - - @JsonProperty("validate_only") - private final boolean validateOnly; - private final Message message; - - @RequiredArgsConstructor - @Getter - public static class Message { - - private final Data data; - private final String token; - } - - @RequiredArgsConstructor - @Getter - public static class Data { - - private final String receiverId; - private final String redirectId; - private final String notificationType; - private final String createdAt; - } -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/UpdateNotificationResponse.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/UpdateNotificationResponse.java deleted file mode 100644 index d447f031f..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/application/dto/UpdateNotificationResponse.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.emmsale.notification.application.dto; - -import com.emmsale.comment.domain.Comment; -import com.emmsale.notification.domain.UpdateNotification; -import com.emmsale.notification.domain.UpdateNotificationType; -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.time.LocalDateTime; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public class UpdateNotificationResponse { - - private final Long updateNotificationId; - private final Long receiverId; - private final Long redirectId; - @JsonFormat(pattern = "yyyy:MM:dd:HH:mm:ss") - private final LocalDateTime createdAt; - private final UpdateNotificationType type; - @JsonProperty(value = "isRead") - private final boolean isRead; - private final CommentTypeNotification commentTypeNotification; - - public static UpdateNotificationResponse convertCommentNotification( - final UpdateNotification notification, - final Comment comment - ) { - return new UpdateNotificationResponse( - notification.getId(), notification.getReceiverId(), - notification.getRedirectId(), notification.getCreatedAt(), - notification.getUpdateNotificationType(), notification.isRead(), - new CommentTypeNotification( - comment.getContent(), - comment.getFeed().getTitle(), - comment.getMember().getImageUrl(), - comment.getParentIdOrSelfId(), - comment.getFeed().getId() - ) - ); - } - - public static UpdateNotificationResponse convertEventNotification( - final UpdateNotification notification - ) { - return new UpdateNotificationResponse( - notification.getId(), notification.getReceiverId(), - notification.getRedirectId(), notification.getCreatedAt(), - notification.getUpdateNotificationType(), notification.isRead(), - null - ); - } - - private boolean getIsRead() { - return isRead; - } - - @RequiredArgsConstructor - @Getter - public static class CommentTypeNotification { - - private final String content; - private final String feedTitle; - private final String commenterImageUrl; - private final Long parentId; - private final Long feedId; - } -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/application/generator/UpdateNotificationMessageGenerator.java b/backend/emm-sale/src/main/java/com/emmsale/notification/application/generator/UpdateNotificationMessageGenerator.java deleted file mode 100644 index 6625b5396..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/application/generator/UpdateNotificationMessageGenerator.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.emmsale.notification.application.generator; - -import static com.emmsale.notification.application.dto.UpdateNotificationMessage.Data; -import static com.emmsale.notification.application.dto.UpdateNotificationMessage.Message; -import static com.emmsale.notification.exception.NotificationExceptionType.BAD_REQUEST_MEMBER_ID; -import static com.emmsale.notification.exception.NotificationExceptionType.CONVERTING_JSON_ERROR; - -import com.emmsale.member.domain.MemberRepository; -import com.emmsale.notification.application.dto.UpdateNotificationMessage; -import com.emmsale.notification.domain.UpdateNotification; -import com.emmsale.notification.exception.NotificationException; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -public class UpdateNotificationMessageGenerator implements NotificationMessageGenerator { - - private final UpdateNotification updateNotification; - - @Override - public String makeMessage( - final String targetToken, - final ObjectMapper objectMapper, - final MemberRepository memberRepository - ) { - final Long receiverId = updateNotification.getReceiverId(); - - validateIsExistedReceiver(memberRepository, receiverId); - - final Data data = new Data( - receiverId.toString(), - updateNotification.getRedirectId().toString(), - updateNotification.getUpdateNotificationType().toString(), - updateNotification.getCreatedAt().format(DATE_TIME_FORMATTER) - ); - - final UpdateNotificationMessage updateNotificationMessage = - new UpdateNotificationMessage(DEFAULT_VALIDATE_ONLY, new Message(data, targetToken)); - - try { - return objectMapper.writeValueAsString(updateNotificationMessage); - } catch (final JsonProcessingException e) { - throw new NotificationException(CONVERTING_JSON_ERROR); - } - } - - private void validateIsExistedReceiver(final MemberRepository memberRepository, - final Long receiverId) { - if (!memberRepository.existsById(receiverId)) { - throw new NotificationException(BAD_REQUEST_MEMBER_ID); - } - } -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/domain/UpdateNotification.java b/backend/emm-sale/src/main/java/com/emmsale/notification/domain/UpdateNotification.java deleted file mode 100644 index 87a5266a4..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/domain/UpdateNotification.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.emmsale.notification.domain; - -import java.time.LocalDateTime; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Table(name = "update_notification") -@Entity -@Getter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class UpdateNotification { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - @Column(nullable = false) - private Long receiverId; - @Column(nullable = false) - private Long redirectId; - @Enumerated(EnumType.STRING) - @Column(name = "type", nullable = false) - private UpdateNotificationType updateNotificationType; - private LocalDateTime createdAt; - @Column(nullable = false) - private boolean isRead; - - public UpdateNotification( - final Long receiverId, - final Long redirectId, - final UpdateNotificationType updateNotificationType, - final LocalDateTime createdAt - ) { - this.receiverId = receiverId; - this.redirectId = redirectId; - this.updateNotificationType = updateNotificationType; - this.createdAt = createdAt; - this.isRead = false; - } - - public boolean isCommentNotification() { - return updateNotificationType == UpdateNotificationType.COMMENT; - } - - public boolean isEventNotification() { - return updateNotificationType == UpdateNotificationType.EVENT; - } - - public boolean isOwner(final Long memberId) { - return receiverId.equals(memberId); - } - - public void read() { - isRead = true; - } -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/domain/UpdateNotificationRepository.java b/backend/emm-sale/src/main/java/com/emmsale/notification/domain/UpdateNotificationRepository.java deleted file mode 100644 index 34e76687f..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/domain/UpdateNotificationRepository.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.emmsale.notification.domain; - -import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -public interface UpdateNotificationRepository extends JpaRepository { - - List findAllByReceiverId(final Long receiverId); - - List findAllByIdIn(final List notificationIds); - - @Modifying - @Query("delete from UpdateNotification un where un.id in :ids") - void deleteBatchByIdsIn(@Param("ids") final List notificationIds); -} diff --git a/backend/emm-sale/src/main/java/com/emmsale/notification/domain/UpdateNotificationType.java b/backend/emm-sale/src/main/java/com/emmsale/notification/domain/UpdateNotificationType.java deleted file mode 100644 index c8fea4895..000000000 --- a/backend/emm-sale/src/main/java/com/emmsale/notification/domain/UpdateNotificationType.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.emmsale.notification.domain; - -import static com.emmsale.notification.exception.NotificationExceptionType.NOT_FOUND_NOTIFICATION_TYPE; - -import com.emmsale.notification.exception.NotificationException; -import java.util.Arrays; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public enum UpdateNotificationType { - - COMMENT("comment"), - EVENT("event"); - - private final String notificationType; - - public static UpdateNotificationType from(final String notificationType) { - return Arrays.stream(values()) - .filter(it -> it.notificationType.equals(notificationType)) - .findAny() - .orElseThrow(() -> new NotificationException(NOT_FOUND_NOTIFICATION_TYPE)); - } -} diff --git a/backend/emm-sale/src/test/java/com/emmsale/comment/application/CommentCommandServiceEventIntegrationTest.java b/backend/emm-sale/src/test/java/com/emmsale/comment/application/CommentCommandServiceEventIntegrationTest.java index 137c57626..ca257f068 100644 --- a/backend/emm-sale/src/test/java/com/emmsale/comment/application/CommentCommandServiceEventIntegrationTest.java +++ b/backend/emm-sale/src/test/java/com/emmsale/comment/application/CommentCommandServiceEventIntegrationTest.java @@ -22,8 +22,6 @@ import com.emmsale.member.domain.MemberRepository; import com.emmsale.notification.domain.Notification; import com.emmsale.notification.domain.NotificationRepository; -import com.emmsale.notification.domain.UpdateNotification; -import com.emmsale.notification.domain.UpdateNotificationRepository; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -42,8 +40,6 @@ class CommentCommandServiceEventIntegrationTest extends ServiceIntegrationTestHe @Autowired private MemberRepository memberRepository; @Autowired - private UpdateNotificationRepository updateNotificationRepository; - @Autowired private NotificationRepository notificationRepository; private Member 댓글_작성자1; private Member 댓글_작성자2; @@ -64,7 +60,7 @@ void test_publish_comment() throws Exception { //given final Comment 부모_댓글 = commentRepository.save(Comment.createRoot(feed, 댓글_작성자1, "내용1")); - doNothing().when(firebaseCloudMessageClient).sendMessageTo(any(UpdateNotification.class)); + doNothing().when(firebaseCloudMessageClient).sendMessageTo(any(Notification.class), anyLong()); final CommentAddRequest 알림_트리거_댓글_요청 = new CommentAddRequest("내용2", feed.getId(), 부모_댓글.getId()); @@ -87,7 +83,7 @@ void test_publish_comment_error_firebase() throws Exception { final Comment 부모_댓글 = commentRepository.save(Comment.createRoot(feed, 댓글_작성자1, "내용1")); doThrow(new IllegalArgumentException("파이어베이스 에러")) - .when(firebaseCloudMessageClient).sendMessageTo(any(UpdateNotification.class)); + .when(firebaseCloudMessageClient).sendMessageTo(any(Notification.class), anyLong()); final CommentAddRequest 알림_트리거_댓글_요청 = new CommentAddRequest("내용2", feed.getId(), 부모_댓글.getId()); diff --git a/backend/emm-sale/src/test/java/com/emmsale/comment/application/CommentCommandServiceTest.java b/backend/emm-sale/src/test/java/com/emmsale/comment/application/CommentCommandServiceTest.java index 60b07b6f4..134942cfa 100644 --- a/backend/emm-sale/src/test/java/com/emmsale/comment/application/CommentCommandServiceTest.java +++ b/backend/emm-sale/src/test/java/com/emmsale/comment/application/CommentCommandServiceTest.java @@ -6,6 +6,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doNothing; import com.emmsale.comment.application.dto.CommentAddRequest; @@ -25,7 +26,7 @@ import com.emmsale.helper.ServiceIntegrationTestHelper; import com.emmsale.member.domain.Member; import com.emmsale.member.domain.MemberRepository; -import com.emmsale.notification.domain.UpdateNotification; +import com.emmsale.notification.domain.Notification; import java.time.LocalDateTime; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -82,7 +83,7 @@ void test_create() throws Exception { final CommentAddRequest 부모_댓글_요청 = new CommentAddRequest(content, feed.getId(), null); - doNothing().when(firebaseCloudMessageClient).sendMessageTo(any(UpdateNotification.class)); + doNothing().when(firebaseCloudMessageClient).sendMessageTo(any(Notification.class), anyLong()); //when final CommentResponse 부모_댓글_응답 = commentCommandService.create(부모_댓글_요청, 댓글_작성자); @@ -105,7 +106,7 @@ void test_create_child() throws Exception { final CommentResponse 부모_댓글_응답 = commentCommandService.create(부모_댓글_요청, 댓글_작성자); final CommentAddRequest 자식_댓글_요청 = new CommentAddRequest(content, feed.getId(), 1L); - doNothing().when(firebaseCloudMessageClient).sendMessageTo(any(UpdateNotification.class)); + doNothing().when(firebaseCloudMessageClient).sendMessageTo(any(Notification.class), anyLong()); //when final CommentResponse 자식_댓글_응답 = commentCommandService.create(자식_댓글_요청, 댓글_작성자); diff --git a/backend/emm-sale/src/test/java/com/emmsale/event/application/EventServiceTest.java b/backend/emm-sale/src/test/java/com/emmsale/event/application/EventServiceTest.java index 3de8d1caa..616a567dc 100644 --- a/backend/emm-sale/src/test/java/com/emmsale/event/application/EventServiceTest.java +++ b/backend/emm-sale/src/test/java/com/emmsale/event/application/EventServiceTest.java @@ -27,6 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrowsExactly; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doNothing; import com.emmsale.event.application.dto.EventDetailRequest; @@ -45,7 +46,7 @@ import com.emmsale.image.domain.Image; import com.emmsale.image.domain.ImageType; import com.emmsale.image.domain.repository.ImageRepository; -import com.emmsale.notification.domain.UpdateNotification; +import com.emmsale.notification.domain.Notification; import com.emmsale.tag.application.dto.TagRequest; import com.emmsale.tag.domain.Tag; import com.emmsale.tag.domain.TagRepository; @@ -546,7 +547,7 @@ void addEventTest() { organization ); - doNothing().when(firebaseCloudMessageClient).sendMessageTo(any(UpdateNotification.class)); + doNothing().when(firebaseCloudMessageClient).sendMessageTo(any(Notification.class), anyLong()); //when final EventDetailResponse response = eventService.addEvent(request, mockMultipartFiles, now); @@ -591,7 +592,7 @@ void addEventWithStartDateTimeAfterBeforeDateTimeTest() { organization ); - doNothing().when(firebaseCloudMessageClient).sendMessageTo(any(UpdateNotification.class)); + doNothing().when(firebaseCloudMessageClient).sendMessageTo(any(Notification.class), anyLong()); //when & then final EventException exception = assertThrowsExactly(EventException.class, @@ -626,7 +627,7 @@ void addEventWithNotExistTagTest() { organization ); - doNothing().when(firebaseCloudMessageClient).sendMessageTo(any(UpdateNotification.class)); + doNothing().when(firebaseCloudMessageClient).sendMessageTo(any(Notification.class), anyLong()); //when & then final EventException exception = assertThrowsExactly(EventException.class, diff --git a/backend/emm-sale/src/test/java/com/emmsale/event_publisher/EventPublisherTest.java b/backend/emm-sale/src/test/java/com/emmsale/event_publisher/EventPublisherTest.java index fef2a5e4d..01622e6d1 100644 --- a/backend/emm-sale/src/test/java/com/emmsale/event_publisher/EventPublisherTest.java +++ b/backend/emm-sale/src/test/java/com/emmsale/event_publisher/EventPublisherTest.java @@ -15,9 +15,9 @@ import com.emmsale.event.EventFixture; import com.emmsale.event.domain.Event; import com.emmsale.event.domain.repository.EventRepository; -import com.emmsale.helper.ServiceIntegrationTestHelper; import com.emmsale.feed.domain.Feed; import com.emmsale.feed.domain.repository.FeedRepository; +import com.emmsale.helper.ServiceIntegrationTestHelper; import com.emmsale.member.MemberFixture; import com.emmsale.member.domain.InterestTag; import com.emmsale.member.domain.InterestTagRepository; @@ -139,7 +139,7 @@ void test_publish_event_no_notification_event_has_no_interest_tag() throws Excep //then verify(applicationEventPublisher, times(0)) - .publishEvent(any(UpdateNotificationEvent.class)); + .publishEvent(any(EventNotificationEvent.class)); } @Test @@ -161,7 +161,7 @@ void test_publish_event_no_notification_member_has_no_interest_tag() throws Exce //then verify(applicationEventPublisher, times(0)) - .publishEvent(any(UpdateNotificationEvent.class)); + .publishEvent(any(EventNotificationEvent.class)); } /** @@ -216,7 +216,7 @@ void test_publish_comment_parent_children_not_notification() throws Exception { //then verify(applicationEventPublisher, times(0)) - .publishEvent(any(UpdateNotificationEvent.class)); + .publishEvent(any(EventNotificationEvent.class)); } @Test @@ -235,7 +235,7 @@ void test_publish_root_comment_no_notification() throws Exception { //then verify(applicationEventPublisher, times(0)) - .publishEvent(any(UpdateNotificationEvent.class)); + .publishEvent(any(EventNotificationEvent.class)); } @Test diff --git a/backend/emm-sale/src/test/java/com/emmsale/notification/application/NotificationCommandServiceTest.java b/backend/emm-sale/src/test/java/com/emmsale/notification/application/NotificationCommandServiceTest.java index c75fa35d0..75d82c637 100644 --- a/backend/emm-sale/src/test/java/com/emmsale/notification/application/NotificationCommandServiceTest.java +++ b/backend/emm-sale/src/test/java/com/emmsale/notification/application/NotificationCommandServiceTest.java @@ -9,7 +9,6 @@ import com.emmsale.member.domain.Member; import com.emmsale.member.domain.MemberRepository; import com.emmsale.notification.application.dto.NotificationDeleteRequest; -import com.emmsale.notification.application.dto.UpdateNotificationDeleteRequest; import com.emmsale.notification.domain.Notification; import com.emmsale.notification.domain.NotificationRepository; import com.emmsale.notification.domain.NotificationType; diff --git a/backend/emm-sale/src/test/java/com/emmsale/notification/application/UpdateNotificationCommandServiceTest.java b/backend/emm-sale/src/test/java/com/emmsale/notification/application/UpdateNotificationCommandServiceTest.java deleted file mode 100644 index c78c6d6ab..000000000 --- a/backend/emm-sale/src/test/java/com/emmsale/notification/application/UpdateNotificationCommandServiceTest.java +++ /dev/null @@ -1,136 +0,0 @@ -package com.emmsale.notification.application; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import com.emmsale.event.EventFixture; -import com.emmsale.event.domain.Event; -import com.emmsale.event.domain.repository.EventRepository; -import com.emmsale.helper.ServiceIntegrationTestHelper; -import com.emmsale.member.domain.Member; -import com.emmsale.member.domain.MemberRepository; -import com.emmsale.member.exception.MemberException; -import com.emmsale.member.exception.MemberExceptionType; -import com.emmsale.notification.application.dto.UpdateNotificationDeleteRequest; -import com.emmsale.notification.domain.UpdateNotification; -import com.emmsale.notification.domain.UpdateNotificationRepository; -import com.emmsale.notification.domain.UpdateNotificationType; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -class UpdateNotificationCommandServiceTest extends ServiceIntegrationTestHelper { - - @Autowired - private UpdateNotificationCommandService updateNotificationCommandService; - @Autowired - private UpdateNotificationRepository updateNotificationRepository; - @Autowired - private EventRepository eventRepository; - @Autowired - private MemberRepository memberRepository; - - private UpdateNotification 이벤트_알림; - private Member member; - private UpdateNotification notification1, notification2, notification3; - - @BeforeEach - void setUp() { - final Event event = eventRepository.save(EventFixture.인프콘_2023()); - member = memberRepository.findById(1L).get(); - - 이벤트_알림 = updateNotificationRepository.save( - new UpdateNotification( - member.getId(), - event.getId(), - UpdateNotificationType.EVENT, - LocalDateTime.now() - ) - ); - - final Long receiverId = member.getId(); - - notification1 = new UpdateNotification( - receiverId, 2L, - UpdateNotificationType.COMMENT, LocalDateTime.now() - ); - notification2 = new UpdateNotification( - receiverId, 3L, - UpdateNotificationType.EVENT, LocalDateTime.now() - ); - notification3 = new UpdateNotification( - 2L, 4L, - UpdateNotificationType.COMMENT, LocalDateTime.now() - ); - - updateNotificationRepository.saveAll(List.of(notification1, notification2, notification3)); - } - - @Test - @DisplayName("read() : 로그인 한 사용자와 알림 받는 사람이 일치할 때, 해당 알림을 읽음 상태로 변경할 수 있다.") - void test_read() throws Exception { - //when - final Long notificationId = 이벤트_알림.getId(); - updateNotificationCommandService.read(member, notificationId); - - //then - final UpdateNotification updatedNotification = - updateNotificationRepository.findById(notificationId).get(); - - assertAll( - () -> assertEquals(notificationId, updatedNotification.getId()), - () -> assertTrue(updatedNotification.isRead()) - ); - } - - @Test - @DisplayName("read() : 토큰 주인과 로그인 한 사용자가 다르면 읽음 상태를 변경할 수 없다.") - void test_read_not_matching_token_and_login() throws Exception { - //given - final Member otherMember = memberRepository.findById(2L).get(); - - //when & then - assertThatThrownBy(() -> updateNotificationCommandService.read(otherMember, 이벤트_알림.getId())) - .isInstanceOf(MemberException.class) - .hasMessage(MemberExceptionType.NOT_MATCHING_TOKEN_AND_LOGIN_MEMBER.errorMessage()); - } - - @Test - @DisplayName("deleteBatch() : 댓글 & 행사 알림을 삭제할 ID로 본인의 알림들만을 삭제할 수 있다.") - void test_deleteBatch() throws Exception { - //given - final List nonExistedNotificationIds = List.of(4L, 5L, 6L); - final List deletedIds = new ArrayList<>(); - deletedIds.addAll(nonExistedNotificationIds); - deletedIds.addAll(List.of( - notification1.getId(), - notification2.getId(), - notification3.getId() - )); - - final UpdateNotificationDeleteRequest request = - new UpdateNotificationDeleteRequest(deletedIds); - - final List expected = List.of(notification3); - - //when - updateNotificationCommandService.deleteBatch(member, request); - - //then - final List actual = - updateNotificationRepository.findAllByIdIn(request.getDeleteIds()); - - assertThat(actual) - .usingRecursiveComparison() - .ignoringCollectionOrder() - .ignoringFields("createdAt") - .isEqualTo(expected); - } -} diff --git a/backend/emm-sale/src/test/java/com/emmsale/notification/application/UpdateNotificationQueryServiceTest.java b/backend/emm-sale/src/test/java/com/emmsale/notification/application/UpdateNotificationQueryServiceTest.java deleted file mode 100644 index cf2058064..000000000 --- a/backend/emm-sale/src/test/java/com/emmsale/notification/application/UpdateNotificationQueryServiceTest.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.emmsale.notification.application; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.emmsale.comment.domain.Comment; -import com.emmsale.comment.domain.CommentRepository; -import com.emmsale.event.EventFixture; -import com.emmsale.event.domain.Event; -import com.emmsale.event.domain.repository.EventRepository; -import com.emmsale.feed.domain.Feed; -import com.emmsale.feed.domain.repository.FeedRepository; -import com.emmsale.helper.ServiceIntegrationTestHelper; -import com.emmsale.member.domain.Member; -import com.emmsale.member.domain.MemberRepository; -import com.emmsale.notification.application.dto.UpdateNotificationResponse; -import com.emmsale.notification.application.dto.UpdateNotificationResponse.CommentTypeNotification; -import com.emmsale.notification.domain.UpdateNotification; -import com.emmsale.notification.domain.UpdateNotificationRepository; -import com.emmsale.notification.domain.UpdateNotificationType; -import java.time.LocalDateTime; -import java.util.List; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -class UpdateNotificationQueryServiceTest extends ServiceIntegrationTestHelper { - - @Autowired - private UpdateNotificationQueryService updateNotificationQueryService; - @Autowired - private MemberRepository memberRepository; - @Autowired - private UpdateNotificationRepository updateNotificationRepository; - @Autowired - private EventRepository eventRepository; - @Autowired - private FeedRepository feedRepository; - @Autowired - private CommentRepository commentRepository; - - private UpdateNotification 이벤트_알림; - private UpdateNotification 댓글_알림; - private Member member; - private Comment comment; - private Feed feed; - - @BeforeEach - void setUp() { - final Event event = eventRepository.save(EventFixture.인프콘_2023()); - member = memberRepository.findById(1L).get(); - feed = feedRepository.save(new Feed(event, member, "피드 제목", "피드 내용")); - - 이벤트_알림 = updateNotificationRepository.save( - new UpdateNotification( - member.getId(), - event.getId(), - UpdateNotificationType.EVENT, - LocalDateTime.now() - ) - ); - - comment = commentRepository.save( - Comment.createRoot(feed, member, "내용") - ); - - 댓글_알림 = updateNotificationRepository.save( - new UpdateNotification( - member.getId(), - comment.getId(), - UpdateNotificationType.COMMENT, - LocalDateTime.now() - ) - ); - } - - @Test - @DisplayName("findAll() : 현재 사용자가 받은 댓글 & 행사 알림들을 모두 조회할 수 있다.") - void test_findAll() throws Exception { - //given - final List expected = List.of( - new UpdateNotificationResponse( - 이벤트_알림.getId(), member.getId(), - 이벤트_알림.getRedirectId(), LocalDateTime.now(), - UpdateNotificationType.EVENT, false, - null), - new UpdateNotificationResponse( - 댓글_알림.getId(), member.getId(), - 댓글_알림.getRedirectId(), LocalDateTime.now(), - UpdateNotificationType.COMMENT, false, - new CommentTypeNotification( - comment.getContent(), - comment.getFeed().getTitle(), - comment.getMember().getImageUrl(), - comment.getParentIdOrSelfId(), - comment.getFeed().getId() - ) - ) - ); - - //when - final List actual = - updateNotificationQueryService.findAll(member, member.getId()); - - //then - assertThat(actual) - .usingRecursiveComparison() - .ignoringFields("createdAt") - .isEqualTo(expected); - } -} diff --git a/backend/emm-sale/src/test/java/com/emmsale/notification/application/generator/UpdateNotificationMessageGeneratorTest.java b/backend/emm-sale/src/test/java/com/emmsale/notification/application/generator/UpdateNotificationMessageGeneratorTest.java deleted file mode 100644 index e02207ec6..000000000 --- a/backend/emm-sale/src/test/java/com/emmsale/notification/application/generator/UpdateNotificationMessageGeneratorTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.emmsale.notification.application.generator; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.emmsale.helper.ServiceIntegrationTestHelper; -import com.emmsale.member.domain.Member; -import com.emmsale.member.domain.MemberRepository; -import com.emmsale.notification.application.dto.UpdateNotificationMessage; -import com.emmsale.notification.domain.UpdateNotification; -import com.emmsale.notification.domain.UpdateNotificationType; -import com.fasterxml.jackson.databind.ObjectMapper; -import java.time.LocalDateTime; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -class UpdateNotificationMessageGeneratorTest extends ServiceIntegrationTestHelper { - - @Autowired - private MemberRepository memberRepository; - @Autowired - private ObjectMapper objectMapper; - private UpdateNotificationMessageGenerator messageGenerator; - private Member member; - private UpdateNotificationType type; - - @BeforeEach - void setUp() { - member = memberRepository.findById(1L).get(); - type = UpdateNotificationType.COMMENT; - final long redirectId = 2L; - - final UpdateNotification updateNotification = new UpdateNotification( - member.getId(), - redirectId, - type, - LocalDateTime.now() - ); - - messageGenerator = new UpdateNotificationMessageGenerator(updateNotification); - } - - @Test - @DisplayName("makeMessage() : Message 포맷에 맞게 Message를 생성할 수 있다.") - void test_makeMessage() throws Exception { - //given - final String targetToken = "token"; - - //when - final String expected = messageGenerator.makeMessage( - targetToken, - objectMapper, - memberRepository - ); - - //then - final UpdateNotificationMessage expectedMessage = objectMapper.readValue( - expected, UpdateNotificationMessage.class - ); - - assertEquals(type.toString(), expectedMessage.getMessage().getData().getNotificationType()); - } -} diff --git a/backend/emm-sale/src/test/java/com/emmsale/notification/domain/UpdateNotificationRepositoryTest.java b/backend/emm-sale/src/test/java/com/emmsale/notification/domain/UpdateNotificationRepositoryTest.java deleted file mode 100644 index 4eb1818d2..000000000 --- a/backend/emm-sale/src/test/java/com/emmsale/notification/domain/UpdateNotificationRepositoryTest.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.emmsale.notification.domain; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.emmsale.helper.JpaRepositorySliceTestHelper; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -class UpdateNotificationRepositoryTest extends JpaRepositorySliceTestHelper { - - @Autowired - private UpdateNotificationRepository updateNotificationRepository; - - private UpdateNotification notification1; - private UpdateNotification notification2; - private UpdateNotification notification3; - private Long receiverId; - - @BeforeEach - void init() { - receiverId = 1L; - - notification1 = new UpdateNotification( - receiverId, 2L, - UpdateNotificationType.COMMENT, LocalDateTime.now() - ); - notification2 = new UpdateNotification( - receiverId, 3L, - UpdateNotificationType.EVENT, LocalDateTime.now() - ); - notification3 = new UpdateNotification( - 2L, 4L, - UpdateNotificationType.COMMENT, LocalDateTime.now() - ); - - updateNotificationRepository.saveAll(List.of(notification1, notification2, notification3)); - } - - @Test - @DisplayName("findAllByReceiverId() : 현재 접속해 있는 사용자가 받은 행사&댓글 알림들을 조회할 수 있다.") - void test_findAllByReceiverId() throws Exception { - //given - final List expected = List.of(notification1, notification2); - - //when - final List actual = - updateNotificationRepository.findAllByReceiverId(receiverId); - - //then - assertThat(actual) - .usingRecursiveComparison() - .ignoringCollectionOrder() - .ignoringFields("createdAt") - .isEqualTo(expected); - } - - @Test - @DisplayName("findAllByIdIn() : 해당 id들을 가진 Notification들을 조회할 수 있다.") - void test_findAllByIdsIn() throws Exception { - //given - final List expected = List.of(notification1, notification2); - - final List notificationIds = List.of(notification1.getId(), notification2.getId()); - - //when - final List actual = - updateNotificationRepository.findAllByIdIn(notificationIds); - - //then - assertThat(actual) - .usingRecursiveComparison() - .ignoringCollectionOrder() - .ignoringFields("createdAt") - .isEqualTo(expected); - } - - @Test - @DisplayName("deleteBatchByIdsIn() : IN 쿼리를 통해 알림들을 배치 삭제할 수 있다.") - void test_deleteBatchByIdsIn() throws Exception { - //given - //존재하지 않는 알림 ID - final List nonExistedNotificationIds = List.of(3L, 4L, 5L); - final List existedNotificationIds = List.of(notification1.getId(), notification2.getId()); - final List deleteIds = new ArrayList<>(); - deleteIds.addAll(nonExistedNotificationIds); - deleteIds.addAll(existedNotificationIds); - - final List actual = Collections.emptyList(); - - //when - updateNotificationRepository.deleteBatchByIdsIn(deleteIds); - - //then - final List expected = - updateNotificationRepository.findAllByIdIn(deleteIds); - - assertThat(actual) - .usingRecursiveComparison() - .ignoringCollectionOrder() - .ignoringFields("createdAt") - .isEqualTo(expected); - } -} diff --git a/backend/emm-sale/src/test/java/com/emmsale/notification/domain/UpdateNotificationTest.java b/backend/emm-sale/src/test/java/com/emmsale/notification/domain/UpdateNotificationTest.java deleted file mode 100644 index 5110331d6..000000000 --- a/backend/emm-sale/src/test/java/com/emmsale/notification/domain/UpdateNotificationTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.emmsale.notification.domain; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.time.LocalDateTime; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; - -class UpdateNotificationTest { - - @ParameterizedTest - @CsvSource({ - "EVENT, false", - "COMMENT, true" - }) - @DisplayName("isCommentNotification() : COMMENT 관련 알림일 경우 true를 반환한다.") - void test_isCommentNotification(final UpdateNotificationType type, final boolean result) - throws Exception { - //given - final UpdateNotification notification = new UpdateNotification( - 1L, - 2L, - type, - LocalDateTime.now() - ); - - //when & then - assertEquals(notification.isCommentNotification(), result); - } - - @ParameterizedTest - @CsvSource({ - "EVENT, true", - "COMMENT, false" - }) - @DisplayName("isEventNotification() : EVENT 관련 알림일 경우 true를 반환한다.") - void test_isEventNotification(final UpdateNotificationType type, final boolean result) - throws Exception { - //given - final UpdateNotification notification = new UpdateNotification( - 1L, - 2L, - type, - LocalDateTime.now() - ); - - //when & then - assertEquals(notification.isEventNotification(), result); - } -} diff --git a/backend/emm-sale/src/test/java/com/emmsale/notification/domain/UpdateNotificationTypeTest.java b/backend/emm-sale/src/test/java/com/emmsale/notification/domain/UpdateNotificationTypeTest.java deleted file mode 100644 index 8e33c3623..000000000 --- a/backend/emm-sale/src/test/java/com/emmsale/notification/domain/UpdateNotificationTypeTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.emmsale.notification.domain; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.emmsale.comment.domain.Comment; -import com.emmsale.event.domain.Event; -import java.util.stream.Stream; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -class UpdateNotificationTypeTest { - - static Stream convertClassTypeToEnum() { - - final String notificationType1 = "event"; - final UpdateNotificationType type1 = UpdateNotificationType.EVENT; - - final String notificationType2 = "comment"; - final UpdateNotificationType type2 = UpdateNotificationType.COMMENT; - - return Stream.of( - Arguments.of(notificationType1, type1), - Arguments.of(notificationType2, type2) - ); - } - - @ParameterizedTest - @MethodSource("convertClassTypeToEnum") - @DisplayName("from() : 클래스 타입을 통해서 어떤 알림의 종류인지 알 수 있다.") - void test_from(final String notificationType, final UpdateNotificationType type) - throws Exception { - //when & then - assertEquals(UpdateNotificationType.from(notificationType), type); - } -} From 0c58c636850d03f6bc4dde9f3464b9235d53f1a0 Mon Sep 17 00:00:00 2001 From: java-saeng Date: Thu, 5 Oct 2023 17:12:46 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor=20:=20request=5Fnotification,=20up?= =?UTF-8?q?date=5Fnotification=20table=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/emm-sale/src/main/resources/data.sql | 2 -- backend/emm-sale/src/main/resources/schema.sql | 4 ++++ backend/emm-sale/src/test/resources/data-test.sql | 2 -- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/emm-sale/src/main/resources/data.sql b/backend/emm-sale/src/main/resources/data.sql index 7f8a7e80e..16b6f9a49 100644 --- a/backend/emm-sale/src/main/resources/data.sql +++ b/backend/emm-sale/src/main/resources/data.sql @@ -7,9 +7,7 @@ truncate table tag; truncate table event_tag; truncate table member_tag; truncate table event_member; -truncate table request_notification; truncate table fcm_token; -truncate table update_notification; truncate table block; truncate table report; truncate table scrap; diff --git a/backend/emm-sale/src/main/resources/schema.sql b/backend/emm-sale/src/main/resources/schema.sql index 41625829d..40a8e6200 100644 --- a/backend/emm-sale/src/main/resources/schema.sql +++ b/backend/emm-sale/src/main/resources/schema.sql @@ -268,3 +268,7 @@ alter table notification alter table notification add column created_at datetime(6) default current_timestamp(6); +-- 2023-10-05 17:06 +drop table update_notification; + +drop table request_notification; diff --git a/backend/emm-sale/src/test/resources/data-test.sql b/backend/emm-sale/src/test/resources/data-test.sql index ee8870afb..d444322e1 100644 --- a/backend/emm-sale/src/test/resources/data-test.sql +++ b/backend/emm-sale/src/test/resources/data-test.sql @@ -7,8 +7,6 @@ truncate table tag; truncate table event_tag; truncate table member_tag; truncate table event_member; -truncate table request_notification; -truncate table update_notification; truncate table block; truncate table fcm_token; truncate table report;