From 86dac3beb07f8bca543c6fe834afc61088f7c94e Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Wed, 1 May 2024 19:54:15 +0900 Subject: [PATCH 01/32] =?UTF-8?q?feat=20:=20MessageController=20-=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=EB=A5=BC=20=EA=B7=B8=EB=A3=B9?= =?UTF-8?q?=EB=B3=84=EB=A1=9C=20=EB=B3=B4=EB=82=BC=20=EC=88=98=20=EC=9E=88?= =?UTF-8?q?=EB=8A=94=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A1=A4=EB=9F=AC=EB=A5=BC=20=EB=A7=8C=EB=93=A4=EC=97=88?= =?UTF-8?q?=EC=8A=B5=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../message/MessageController.java | 28 +++++++++++++++++++ src/main/resources/banner.txt | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/bamdoliro/maru/presentation/message/MessageController.java diff --git a/src/main/java/com/bamdoliro/maru/presentation/message/MessageController.java b/src/main/java/com/bamdoliro/maru/presentation/message/MessageController.java new file mode 100644 index 00000000..acc7ada0 --- /dev/null +++ b/src/main/java/com/bamdoliro/maru/presentation/message/MessageController.java @@ -0,0 +1,28 @@ +package com.bamdoliro.maru.presentation.message; + +import com.bamdoliro.maru.domain.user.domain.User; +import com.bamdoliro.maru.infrastructure.message.SendMessageService; +import com.bamdoliro.maru.presentation.message.dto.request.SendMessageRequest; +import com.bamdoliro.maru.shared.auth.AuthenticationPrincipal; +import com.bamdoliro.maru.shared.auth.Authority; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +@RequiredArgsConstructor +@RequestMapping("/message") +@RestController +public class MessageController { + + private final SendMessageService messageService; + + @ResponseStatus(HttpStatus.NO_CONTENT) + @PostMapping + public void sendMessage( + @AuthenticationPrincipal(authority = Authority.ADMIN) User user, + @RequestBody @Valid SendMessageRequest request + ){ + messageService.execute(request); + } +} diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt index 7ca35567..3e51dde1 100644 --- a/src/main/resources/banner.txt +++ b/src/main/resources/banner.txt @@ -6,7 +6,7 @@ _|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""| "`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-' -Contributors - @gimhanul, @hsem4717 +Contributors - @gimhanul, @hsem4717, @jyj1289, @cabbage16 SpringBoot - ${spring-boot.version} Java - ${java.version} From 9d04ef81db8d52b3c35a11cee15f23627a15956c Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Wed, 1 May 2024 19:57:34 +0900 Subject: [PATCH 02/32] =?UTF-8?q?feat(#75):send=20message=20by=20group=20s?= =?UTF-8?q?ervice=20-=20=EB=A9=94=EC=8B=9C=EC=A7=80=EB=A5=BC=20=EA=B7=B8?= =?UTF-8?q?=EB=A3=B9=EB=B3=84=EB=A1=9C=20=EB=B3=B4=EB=82=BC=20=EC=88=98=20?= =?UTF-8?q?=EC=9E=88=EB=8A=94=20=EB=A9=94=EC=84=B8=EC=8B=9C=EB=A5=BC=20?= =?UTF-8?q?=EB=B3=B4=EB=82=BC=20=EC=88=98=20=EC=9E=88=EB=8A=94=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=EB=A5=BC=20=EB=A7=8C=EB=93=A4=EC=97=88?= =?UTF-8?q?=EC=8A=B5=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../message/SendMessageService.java | 35 +++++++++++++++++++ .../dto/request/SendMessageRequest.java | 23 ++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/main/java/com/bamdoliro/maru/presentation/message/dto/request/SendMessageRequest.java diff --git a/src/main/java/com/bamdoliro/maru/infrastructure/message/SendMessageService.java b/src/main/java/com/bamdoliro/maru/infrastructure/message/SendMessageService.java index 43ea613b..190f2f2c 100644 --- a/src/main/java/com/bamdoliro/maru/infrastructure/message/SendMessageService.java +++ b/src/main/java/com/bamdoliro/maru/infrastructure/message/SendMessageService.java @@ -1,6 +1,9 @@ package com.bamdoliro.maru.infrastructure.message; +import com.bamdoliro.maru.domain.form.domain.Form; import com.bamdoliro.maru.infrastructure.message.exception.FailedToSendException; +import com.bamdoliro.maru.infrastructure.persistence.form.FormRepository; +import com.bamdoliro.maru.presentation.message.dto.request.SendMessageRequest; import com.bamdoliro.maru.shared.config.properties.MessageProperties; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -9,6 +12,9 @@ import net.nurigo.sdk.message.service.DefaultMessageService; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; + @Slf4j @RequiredArgsConstructor @Service @@ -16,6 +22,7 @@ public class SendMessageService { private final MessageProperties messageProperties; private final DefaultMessageService messageService; + private final FormRepository formRepository; public void execute(String to, String text) { Message message = createMessage(to, text); @@ -28,6 +35,24 @@ public void execute(String to, String text, String title) { sendOneMessage(message); } + public void execute(SendMessageRequest request){ + List
formList = formRepository.findByStatus(request.getStatus()); + List phoneNumberList = new ArrayList<>(); + List messageList = new ArrayList<>(); + + for (Form form : formList){ + phoneNumberList.add(form.getUser().getPhoneNumber()); + } + + for(String phoneNumber : phoneNumberList){ + Message message = createMessage(phoneNumber, request.getText()); + message.setSubject(request.getTitle()); + messageList.add(message); + } + + sendManyMessage(messageList); + } + private Message createMessage(String to, String text) { Message message = new Message(); message.setFrom(messageProperties.getFrom()); @@ -46,4 +71,14 @@ private void sendOneMessage(Message message) { throw new FailedToSendException(); } } + + private void sendManyMessage(List messageList){ + try{ + messageService.send(messageList, false, false); + } catch (Exception e){ + log.error(e.getMessage()); + e.printStackTrace(); + throw new FailedToSendException(); + } + } } diff --git a/src/main/java/com/bamdoliro/maru/presentation/message/dto/request/SendMessageRequest.java b/src/main/java/com/bamdoliro/maru/presentation/message/dto/request/SendMessageRequest.java new file mode 100644 index 00000000..56a24113 --- /dev/null +++ b/src/main/java/com/bamdoliro/maru/presentation/message/dto/request/SendMessageRequest.java @@ -0,0 +1,23 @@ +package com.bamdoliro.maru.presentation.message.dto.request; + +import com.bamdoliro.maru.domain.form.domain.type.FormStatus; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class SendMessageRequest { + + @NotBlank(message = "필수값입니다.") + private String title; + + @NotBlank(message = "필수값입니다.") + private String text; + + @NotNull(message = "필수값입니다.") + private FormStatus status; +} From 9b737c7df8b5dcfd2899a4c8a5a93d6a14f87165 Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Wed, 1 May 2024 20:24:00 +0900 Subject: [PATCH 03/32] =?UTF-8?q?docs:add=20cors=20url=20-=20cors=EC=97=90?= =?UTF-8?q?=20=EB=A7=88=EB=A3=A8=20=EB=B2=84=EC=85=80=20url=EC=9D=84=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=ED=96=88=EC=8A=B5=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/bamdoliro/maru/shared/config/WebConfig.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bamdoliro/maru/shared/config/WebConfig.java b/src/main/java/com/bamdoliro/maru/shared/config/WebConfig.java index 32550cef..59649041 100644 --- a/src/main/java/com/bamdoliro/maru/shared/config/WebConfig.java +++ b/src/main/java/com/bamdoliro/maru/shared/config/WebConfig.java @@ -29,7 +29,9 @@ public void addCorsMappings(CorsRegistry registry) { "http://localhost:3001", "http://localhost:3002", "https://maru.bamdoliro.com", - "https://admin.maru.bamdoliro.com" + "https://admin.maru.bamdoliro.com", + "https://maru-user.vercel.app", + "https://maru-admin.vercel.app" ) .allowedMethods( HttpMethod.GET.name(), From 71538faada09dd7a54a9c45ba831dda0a2e0ba8e Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Fri, 3 May 2024 09:37:55 +0900 Subject: [PATCH 04/32] =?UTF-8?q?feat(#75):MessageControllerTest=20-=20Mes?= =?UTF-8?q?sageControllerTest=EB=A5=BC=20=EB=A7=8C=EB=93=A4=EC=97=88?= =?UTF-8?q?=EC=96=B4=EC=9A=94.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../message/MessageControllerTest.java | 118 ++++++++++++++++++ .../maru/shared/util/ControllerTest.java | 4 +- 2 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java diff --git a/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java b/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java new file mode 100644 index 00000000..bd0a1a93 --- /dev/null +++ b/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java @@ -0,0 +1,118 @@ +package com.bamdoliro.maru.presentation.message; + +import com.bamdoliro.maru.domain.form.domain.Form; +import com.bamdoliro.maru.domain.form.domain.type.FormStatus; +import com.bamdoliro.maru.domain.form.domain.type.FormType; +import com.bamdoliro.maru.domain.user.domain.User; +import com.bamdoliro.maru.infrastructure.persistence.form.FormRepository; +import com.bamdoliro.maru.presentation.message.dto.request.SendMessageRequest; +import com.bamdoliro.maru.shared.fixture.AuthFixture; +import com.bamdoliro.maru.shared.fixture.FormFixture; +import com.bamdoliro.maru.shared.fixture.UserFixture; +import com.bamdoliro.maru.shared.util.RestDocsTestSupport; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.core.MethodParameter; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.restdocs.payload.JsonFieldType; + +import java.util.Arrays; +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.*; +import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; +import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +public class MessageControllerTest extends RestDocsTestSupport { + + @MockBean + private FormRepository formRepository; + + @BeforeEach + void setup(){ + Form form = FormFixture.createForm(FormType.REGULAR); + form.receive(); + List forms = Arrays.asList(form); + + given(formRepository.findByStatus(FormStatus.RECEIVED)).willReturn(forms); + } + + @Test + void 원서가_접수된_학생들에게_메시지를_보낸다() throws Exception{ + + User user = UserFixture.createAdminUser(); + given(authenticationArgumentResolver.supportsParameter(any(MethodParameter.class))).willReturn(true); + given(authenticationArgumentResolver.resolveArgument(any(), any(), any(), any())).willReturn(user); + + SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "배고파요..", FormStatus.RECEIVED); + doNothing().when(sendMessageService).execute(any(SendMessageRequest.class)); + + mockMvc.perform(post("/message") + .header(HttpHeaders.AUTHORIZATION, AuthFixture.createAuthHeader()) + .contentType(MediaType.APPLICATION_JSON) + .content(toJson(request))) + .andExpect(status().isNoContent()) + + .andDo(restDocs.document( + requestHeaders( + headerWithName(HttpHeaders.AUTHORIZATION) + .description("Bearer token") + ), + requestFields( + fieldWithPath("title") + .type(JsonFieldType.STRING) + .description("문자 메시지 제목"), + fieldWithPath("text") + .type(JsonFieldType.STRING) + .description("문자 메시지 내용"), + fieldWithPath("status") + .type(JsonFieldType.STRING) + .description("메시지를 보낼 원서의 상태") + ) + )); + + verify(sendMessageService, times(1)).execute(any(SendMessageRequest.class)); + } + + @Test + void 해당제출상태인_원서가_없으면_오류가난다() throws Exception { + User user = UserFixture.createAdminUser(); + given(authenticationArgumentResolver.supportsParameter(any(MethodParameter.class))).willReturn(true); + given(authenticationArgumentResolver.resolveArgument(any(), any(), any(), any())).willReturn(user); + + SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "배고파요..", FormStatus.FINAL_SUBMITTED); + + // 예외 발생 설정 + doThrow(new RuntimeException("원서를 찾을 수 없음")).when(sendMessageService).execute(any(SendMessageRequest.class)); + + mockMvc.perform(post("/message") + .header(HttpHeaders.AUTHORIZATION, AuthFixture.createAuthHeader()) + .contentType(MediaType.APPLICATION_JSON) + .content(toJson(request))) + .andExpect(status().isInternalServerError()) // 내부 서버 오류 예상 + .andDo(restDocs.document( + requestHeaders( + headerWithName(HttpHeaders.AUTHORIZATION).description("Bearer token") + ), + requestFields( + fieldWithPath("title").type(JsonFieldType.STRING).description("문자 메시지 제목"), + fieldWithPath("text").type(JsonFieldType.STRING).description("문자 메시지 내용"), + fieldWithPath("status").type(JsonFieldType.STRING).description("메시지를 보낼 원서의 상태") + ) + )); + + verify(sendMessageService, times(1)).execute(any(SendMessageRequest.class)); + } + + + + +} diff --git a/src/test/java/com/bamdoliro/maru/shared/util/ControllerTest.java b/src/test/java/com/bamdoliro/maru/shared/util/ControllerTest.java index f7fdf615..86d7ab45 100644 --- a/src/test/java/com/bamdoliro/maru/shared/util/ControllerTest.java +++ b/src/test/java/com/bamdoliro/maru/shared/util/ControllerTest.java @@ -55,6 +55,7 @@ import com.bamdoliro.maru.presentation.fair.FairController; import com.bamdoliro.maru.presentation.form.DraftFormController; import com.bamdoliro.maru.presentation.form.FormController; +import com.bamdoliro.maru.presentation.message.MessageController; import com.bamdoliro.maru.presentation.notice.NoticeController; import com.bamdoliro.maru.presentation.question.QuestionController; import com.bamdoliro.maru.presentation.school.SchoolController; @@ -81,7 +82,8 @@ FormController.class, NoticeController.class, DraftFormController.class, - FairController.class + FairController.class, + MessageController.class }) public abstract class ControllerTest { From 92012f5adbd7141b543c5a2c34aebe2f6eb6a5a6 Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Fri, 3 May 2024 09:38:32 +0900 Subject: [PATCH 05/32] =?UTF-8?q?docs(#75):MessageController=20asciidocs?= =?UTF-8?q?=20-=20MessageController=EC=97=90=20=EB=8C=80=ED=95=9C=20?= =?UTF-8?q?=EC=95=84=EC=8A=A4=ED=82=A4=20=EB=8F=85=EC=8A=A4=EB=A5=BC=20?= =?UTF-8?q?=EB=A7=8C=EB=93=A4=EC=97=88=EC=96=B4=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/index.adoc | 2 ++ src/docs/asciidoc/message.adoc | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/docs/asciidoc/message.adoc diff --git a/src/docs/asciidoc/index.adoc b/src/docs/asciidoc/index.adoc index 9072983d..4a46528e 100644 --- a/src/docs/asciidoc/index.adoc +++ b/src/docs/asciidoc/index.adoc @@ -25,4 +25,6 @@ include::form.adoc[] include::fair.adoc[] +include::message.adoc[] + include::enum.adoc[] diff --git a/src/docs/asciidoc/message.adoc b/src/docs/asciidoc/message.adoc new file mode 100644 index 00000000..80858aca --- /dev/null +++ b/src/docs/asciidoc/message.adoc @@ -0,0 +1,24 @@ +== 그룹별 메세지 보내기 + +=== 메시지 보내기 +메세지를 보낼 원서의 상태를 입력해 메시지를 보낼 수 있습니다. + +==== 요청 형식 + +===== Request Header +include::{snippets}/message-controller-test/원서가_접수된_학생들에게_메시지를_보낸다/request-headers.adoc[] + +===== Request Body +include::{snippets}/message-controller-test/원서가_접수된_학생들에게_메시지를_보낸다/request-fields.adoc[] + +==== 요청 +===== 접수된 원서를 가진 사용자에게 메시지 보내기 +include::{snippets}/message-controller-test/원서가_접수된_학생들에게_메시지를_보낸다/http-request.adoc[] + +==== 응답 + +===== 정상 응답 +include::{snippets}/message-controller-test/원서가_접수된_학생들에게_메시지를_보낸다/http-response.adoc[] + +===== 입력한 상태의 원서가 없거나 상태를 잘못 입력한 경우 +include::{snippets}/message-controller-test/해당제출상태인_원서가_없으면_오류가난다/http-response.adoc[] \ No newline at end of file From f738bac2c52064d52f56318c92e9923d8ab14fc2 Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Tue, 7 May 2024 10:51:30 +0900 Subject: [PATCH 06/32] =?UTF-8?q?fix(#75)=20:=20remove=20verify()=20-=20?= =?UTF-8?q?=ED=9A=9F=EC=88=98=20=EA=B2=80=EC=A6=9D=EC=9D=84=20=ED=95=A0=20?= =?UTF-8?q?=ED=95=84=EC=9A=94=EA=B0=80=20=EC=97=86=EC=96=B4=EC=84=9C=20ver?= =?UTF-8?q?ify()=20=ED=98=B8=EC=B6=9C=20=EC=BD=94=EB=93=9C=EB=A5=BC=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0=ED=96=88=EC=96=B4=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../maru/presentation/message/MessageControllerTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java b/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java index bd0a1a93..5e819e8d 100644 --- a/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java +++ b/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java @@ -79,7 +79,6 @@ void setup(){ ) )); - verify(sendMessageService, times(1)).execute(any(SendMessageRequest.class)); } @Test @@ -109,7 +108,6 @@ void setup(){ ) )); - verify(sendMessageService, times(1)).execute(any(SendMessageRequest.class)); } From 2e785fe1b89bfc0d40de62ed3f093b0d69f2a1a7 Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Tue, 7 May 2024 11:01:56 +0900 Subject: [PATCH 07/32] =?UTF-8?q?refactor(#75)=20:=20=EC=A3=BC=EC=84=9D=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0=20-=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C?= =?UTF-8?q?=20=EC=A3=BC=EC=84=9D=EC=9D=84=20=EC=A0=9C=EA=B1=B0=ED=96=88?= =?UTF-8?q?=EC=96=B4=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../maru/presentation/message/MessageControllerTest.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java b/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java index 5e819e8d..5cfb1c63 100644 --- a/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java +++ b/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java @@ -89,14 +89,13 @@ void setup(){ SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "배고파요..", FormStatus.FINAL_SUBMITTED); - // 예외 발생 설정 doThrow(new RuntimeException("원서를 찾을 수 없음")).when(sendMessageService).execute(any(SendMessageRequest.class)); mockMvc.perform(post("/message") .header(HttpHeaders.AUTHORIZATION, AuthFixture.createAuthHeader()) .contentType(MediaType.APPLICATION_JSON) .content(toJson(request))) - .andExpect(status().isInternalServerError()) // 내부 서버 오류 예상 + .andExpect(status().isInternalServerError()) .andDo(restDocs.document( requestHeaders( headerWithName(HttpHeaders.AUTHORIZATION).description("Bearer token") @@ -107,10 +106,5 @@ void setup(){ fieldWithPath("status").type(JsonFieldType.STRING).description("메시지를 보낼 원서의 상태") ) )); - } - - - - } From 8bc31adc0cce6964c7649f1b3bb01da876e51a96 Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Tue, 7 May 2024 11:10:25 +0900 Subject: [PATCH 08/32] =?UTF-8?q?refactor(#75)=20:=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0=20-=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EC=A4=91=EB=B3=B5=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EB=A5=BC=20=EC=A0=9C=EA=B1=B0=ED=96=88=EC=96=B4?= =?UTF-8?q?=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../maru/infrastructure/message/SendMessageService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/bamdoliro/maru/infrastructure/message/SendMessageService.java b/src/main/java/com/bamdoliro/maru/infrastructure/message/SendMessageService.java index 190f2f2c..ee287029 100644 --- a/src/main/java/com/bamdoliro/maru/infrastructure/message/SendMessageService.java +++ b/src/main/java/com/bamdoliro/maru/infrastructure/message/SendMessageService.java @@ -77,7 +77,6 @@ private void sendManyMessage(List messageList){ messageService.send(messageList, false, false); } catch (Exception e){ log.error(e.getMessage()); - e.printStackTrace(); throw new FailedToSendException(); } } From 64a20e1230091cbbdea635c3b8e8f564cea7c4ee Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Thu, 9 May 2024 19:44:33 +0900 Subject: [PATCH 09/32] =?UTF-8?q?refactor(#75)=20:=20=EC=9E=90=EB=8F=99=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC=20-=20=EC=BD=94=EB=93=9C=EB=A5=BC=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC=ED=96=88=EC=96=B4=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infrastructure/message/SendMessageService.java | 12 ++++++------ .../maru/presentation/message/MessageController.java | 2 +- .../presentation/message/MessageControllerTest.java | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/bamdoliro/maru/infrastructure/message/SendMessageService.java b/src/main/java/com/bamdoliro/maru/infrastructure/message/SendMessageService.java index ee287029..9f7be5cb 100644 --- a/src/main/java/com/bamdoliro/maru/infrastructure/message/SendMessageService.java +++ b/src/main/java/com/bamdoliro/maru/infrastructure/message/SendMessageService.java @@ -35,16 +35,16 @@ public void execute(String to, String text, String title) { sendOneMessage(message); } - public void execute(SendMessageRequest request){ + public void execute(SendMessageRequest request) { List formList = formRepository.findByStatus(request.getStatus()); List phoneNumberList = new ArrayList<>(); List messageList = new ArrayList<>(); - for (Form form : formList){ + for (Form form : formList) { phoneNumberList.add(form.getUser().getPhoneNumber()); } - for(String phoneNumber : phoneNumberList){ + for (String phoneNumber : phoneNumberList) { Message message = createMessage(phoneNumber, request.getText()); message.setSubject(request.getTitle()); messageList.add(message); @@ -72,10 +72,10 @@ private void sendOneMessage(Message message) { } } - private void sendManyMessage(List messageList){ - try{ + private void sendManyMessage(List messageList) { + try { messageService.send(messageList, false, false); - } catch (Exception e){ + } catch (Exception e) { log.error(e.getMessage()); throw new FailedToSendException(); } diff --git a/src/main/java/com/bamdoliro/maru/presentation/message/MessageController.java b/src/main/java/com/bamdoliro/maru/presentation/message/MessageController.java index acc7ada0..e480d69f 100644 --- a/src/main/java/com/bamdoliro/maru/presentation/message/MessageController.java +++ b/src/main/java/com/bamdoliro/maru/presentation/message/MessageController.java @@ -22,7 +22,7 @@ public class MessageController { public void sendMessage( @AuthenticationPrincipal(authority = Authority.ADMIN) User user, @RequestBody @Valid SendMessageRequest request - ){ + ) { messageService.execute(request); } } diff --git a/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java b/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java index 5cfb1c63..3d8c07ad 100644 --- a/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java +++ b/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java @@ -37,7 +37,7 @@ public class MessageControllerTest extends RestDocsTestSupport { private FormRepository formRepository; @BeforeEach - void setup(){ + void setup() { Form form = FormFixture.createForm(FormType.REGULAR); form.receive(); List forms = Arrays.asList(form); @@ -46,7 +46,7 @@ void setup(){ } @Test - void 원서가_접수된_학생들에게_메시지를_보낸다() throws Exception{ + void 원서가_접수된_학생들에게_메시지를_보낸다() throws Exception { User user = UserFixture.createAdminUser(); given(authenticationArgumentResolver.supportsParameter(any(MethodParameter.class))).willReturn(true); @@ -56,9 +56,9 @@ void setup(){ doNothing().when(sendMessageService).execute(any(SendMessageRequest.class)); mockMvc.perform(post("/message") - .header(HttpHeaders.AUTHORIZATION, AuthFixture.createAuthHeader()) - .contentType(MediaType.APPLICATION_JSON) - .content(toJson(request))) + .header(HttpHeaders.AUTHORIZATION, AuthFixture.createAuthHeader()) + .contentType(MediaType.APPLICATION_JSON) + .content(toJson(request))) .andExpect(status().isNoContent()) .andDo(restDocs.document( From 30cfb0ef47d11d9a256e569f6a001122a60b5fa3 Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Thu, 9 May 2024 22:34:59 +0900 Subject: [PATCH 10/32] =?UTF-8?q?feat(#75)=20:=20SendMessageUseCase=20-=20?= =?UTF-8?q?SendMessageUseCase=EB=A5=BC=20=EB=A7=8C=EB=93=A4=EC=97=88?= =?UTF-8?q?=EC=96=B4=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../message/SendMessageUseCase.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java diff --git a/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java b/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java new file mode 100644 index 00000000..b191fbc3 --- /dev/null +++ b/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java @@ -0,0 +1,24 @@ +package com.bamdoliro.maru.application.message; + +import com.bamdoliro.maru.domain.form.domain.Form; +import com.bamdoliro.maru.infrastructure.message.SendMessageService; +import com.bamdoliro.maru.infrastructure.persistence.form.FormRepository; +import com.bamdoliro.maru.presentation.message.dto.request.SendMessageRequest; +import com.bamdoliro.maru.shared.annotation.UseCase; +import lombok.RequiredArgsConstructor; + +import java.util.List; + +@RequiredArgsConstructor +@UseCase +public class SendMessageUseCase { + + private final FormRepository formRepository; + private final SendMessageService sendMessageService; + + public void execute(SendMessageRequest request) { + List formList = formRepository.findByStatus(request.getStatus()); + List phoneNumberList = formList.stream().map(form -> form.getUser().getPhoneNumber()).toList(); + sendMessageService.execute(phoneNumberList, request.getText(), request.getTitle()); + } +} From b67cec00860ea4024bc41d3ee09012419514fa6d Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Thu, 9 May 2024 22:37:44 +0900 Subject: [PATCH 11/32] =?UTF-8?q?refact(#75)=20:=20MessageUseCase=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=20-=20execute=EC=97=90=EC=84=9C=20phoneNumbe?= =?UTF-8?q?rList=EB=A5=BC=20=EC=83=9D=EC=84=B1=ED=95=98=EB=8D=98=20?= =?UTF-8?q?=EA=B2=83=EC=9D=84=20UseCase=EB=A1=9C=20=EC=9D=B4=EC=A0=84?= =?UTF-8?q?=ED=96=88=EC=96=B4=EC=9A=94.=20-=20=EA=B8=B0=EC=A1=B4=20for?= =?UTF-8?q?=EB=AC=B8=EC=9D=84=20stream=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=ED=99=98=ED=96=88=EC=96=B4=EC=9A=94.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../message/SendMessageService.java | 30 +++++-------------- .../message/MessageControllerTest.java | 7 +++-- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/bamdoliro/maru/infrastructure/message/SendMessageService.java b/src/main/java/com/bamdoliro/maru/infrastructure/message/SendMessageService.java index 9f7be5cb..237052f8 100644 --- a/src/main/java/com/bamdoliro/maru/infrastructure/message/SendMessageService.java +++ b/src/main/java/com/bamdoliro/maru/infrastructure/message/SendMessageService.java @@ -1,9 +1,7 @@ package com.bamdoliro.maru.infrastructure.message; -import com.bamdoliro.maru.domain.form.domain.Form; import com.bamdoliro.maru.infrastructure.message.exception.FailedToSendException; import com.bamdoliro.maru.infrastructure.persistence.form.FormRepository; -import com.bamdoliro.maru.presentation.message.dto.request.SendMessageRequest; import com.bamdoliro.maru.shared.config.properties.MessageProperties; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -12,7 +10,6 @@ import net.nurigo.sdk.message.service.DefaultMessageService; import org.springframework.stereotype.Service; -import java.util.ArrayList; import java.util.List; @Slf4j @@ -35,22 +32,11 @@ public void execute(String to, String text, String title) { sendOneMessage(message); } - public void execute(SendMessageRequest request) { - List formList = formRepository.findByStatus(request.getStatus()); - List phoneNumberList = new ArrayList<>(); - List messageList = new ArrayList<>(); - - for (Form form : formList) { - phoneNumberList.add(form.getUser().getPhoneNumber()); - } - - for (String phoneNumber : phoneNumberList) { - Message message = createMessage(phoneNumber, request.getText()); - message.setSubject(request.getTitle()); - messageList.add(message); - } - - sendManyMessage(messageList); + public void execute(List phoneNumberList, String text, String title) { + List messageList = phoneNumberList.stream() + .map(phoneNumber -> createMessage(phoneNumber, text)) + .peek(message -> message.setSubject(title)).toList(); + sendManyMessages(messageList); } private Message createMessage(String to, String text) { @@ -63,16 +49,14 @@ private Message createMessage(String to, String text) { private void sendOneMessage(Message message) { try { - messageService.sendOne( - new SingleMessageSendingRequest(message) - ); + messageService.sendOne(new SingleMessageSendingRequest(message)); } catch (Exception e) { log.error(e.getMessage()); throw new FailedToSendException(); } } - private void sendManyMessage(List messageList) { + private void sendManyMessages(List messageList) { try { messageService.send(messageList, false, false); } catch (Exception e) { diff --git a/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java b/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java index 3d8c07ad..987717b7 100644 --- a/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java +++ b/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java @@ -23,7 +23,8 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doThrow; import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; @@ -53,7 +54,7 @@ void setup() { given(authenticationArgumentResolver.resolveArgument(any(), any(), any(), any())).willReturn(user); SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "배고파요..", FormStatus.RECEIVED); - doNothing().when(sendMessageService).execute(any(SendMessageRequest.class)); + doNothing().when(sendMessageUseCase).execute(any(SendMessageRequest.class)); mockMvc.perform(post("/message") .header(HttpHeaders.AUTHORIZATION, AuthFixture.createAuthHeader()) @@ -89,7 +90,7 @@ void setup() { SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "배고파요..", FormStatus.FINAL_SUBMITTED); - doThrow(new RuntimeException("원서를 찾을 수 없음")).when(sendMessageService).execute(any(SendMessageRequest.class)); + doThrow(new RuntimeException("원서를 찾을 수 없음")).when(sendMessageUseCase).execute(any(SendMessageRequest.class)); mockMvc.perform(post("/message") .header(HttpHeaders.AUTHORIZATION, AuthFixture.createAuthHeader()) From de4965e7578ed6d0c74460952a4f7faa70b847cc Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Thu, 9 May 2024 22:38:12 +0900 Subject: [PATCH 12/32] =?UTF-8?q?refact(#75)=20:=20MessageUseCase=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=20-=20SendMessageService=EB=A5=BC=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EB=8D=98=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EB=93=A4=EC=9D=84=20SendMessageUseCase=EB=A5=BC=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=ED=99=98?= =?UTF-8?q?=ED=96=88=EC=96=B4=EC=9A=94.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/message/MessageController.java | 5 +++-- .../maru/shared/util/ControllerTest.java | 17 ++++------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/bamdoliro/maru/presentation/message/MessageController.java b/src/main/java/com/bamdoliro/maru/presentation/message/MessageController.java index e480d69f..da242f13 100644 --- a/src/main/java/com/bamdoliro/maru/presentation/message/MessageController.java +++ b/src/main/java/com/bamdoliro/maru/presentation/message/MessageController.java @@ -1,5 +1,6 @@ package com.bamdoliro.maru.presentation.message; +import com.bamdoliro.maru.application.message.SendMessageUseCase; import com.bamdoliro.maru.domain.user.domain.User; import com.bamdoliro.maru.infrastructure.message.SendMessageService; import com.bamdoliro.maru.presentation.message.dto.request.SendMessageRequest; @@ -15,7 +16,7 @@ @RestController public class MessageController { - private final SendMessageService messageService; + private final SendMessageUseCase sendMessageUseCase; @ResponseStatus(HttpStatus.NO_CONTENT) @PostMapping @@ -23,6 +24,6 @@ public void sendMessage( @AuthenticationPrincipal(authority = Authority.ADMIN) User user, @RequestBody @Valid SendMessageRequest request ) { - messageService.execute(request); + sendMessageUseCase.execute(request); } } diff --git a/src/test/java/com/bamdoliro/maru/shared/util/ControllerTest.java b/src/test/java/com/bamdoliro/maru/shared/util/ControllerTest.java index 86d7ab45..61d384c8 100644 --- a/src/test/java/com/bamdoliro/maru/shared/util/ControllerTest.java +++ b/src/test/java/com/bamdoliro/maru/shared/util/ControllerTest.java @@ -34,6 +34,7 @@ import com.bamdoliro.maru.application.form.UpdateSecondRoundScoreUseCase; import com.bamdoliro.maru.application.form.UploadFormUseCase; import com.bamdoliro.maru.application.form.UploadIdentificationPictureUseCase; +import com.bamdoliro.maru.application.message.SendMessageUseCase; import com.bamdoliro.maru.application.notice.CreateNoticeUseCase; import com.bamdoliro.maru.application.notice.DeleteNoticeUseCase; import com.bamdoliro.maru.application.notice.QueryNoticeListUseCase; @@ -73,18 +74,7 @@ import org.springframework.test.web.servlet.MockMvc; @Disabled -@WebMvcTest({ - UserController.class, - AuthController.class, - SharedController.class, - SchoolController.class, - QuestionController.class, - FormController.class, - NoticeController.class, - DraftFormController.class, - FairController.class, - MessageController.class -}) +@WebMvcTest({UserController.class, AuthController.class, SharedController.class, SchoolController.class, QuestionController.class, FormController.class, NoticeController.class, DraftFormController.class, FairController.class, MessageController.class}) public abstract class ControllerTest { @Autowired @@ -238,7 +228,6 @@ public abstract class ControllerTest { @MockBean protected QueryFormUrlUseCase queryFormUrlUseCase; - @MockBean protected TokenService tokenService; @@ -248,6 +237,8 @@ public abstract class ControllerTest { @MockBean protected SendMessageService sendMessageService; + @MockBean + protected SendMessageUseCase sendMessageUseCase; @MockBean protected JwtProperties jwtProperties; From 5ea895a6101069acc441c5905b16663fd3a599be Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Thu, 16 May 2024 08:01:51 +0900 Subject: [PATCH 13/32] =?UTF-8?q?refactor(#75)=20:=20stream=20=EC=BB=A8?= =?UTF-8?q?=EB=B2=A4=EC=85=98=20=EC=82=AC=EC=9A=A9=20-=20stream=20?= =?UTF-8?q?=EC=BB=A8=EB=B2=A4=EC=85=98=EC=9D=84=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=96=88=EC=96=B4=EC=9A=94.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../maru/application/message/SendMessageUseCase.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java b/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java index b191fbc3..0aad401d 100644 --- a/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java +++ b/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java @@ -18,7 +18,9 @@ public class SendMessageUseCase { public void execute(SendMessageRequest request) { List formList = formRepository.findByStatus(request.getStatus()); - List phoneNumberList = formList.stream().map(form -> form.getUser().getPhoneNumber()).toList(); + List phoneNumberList = formList.stream() + .map(form -> form.getUser().getPhoneNumber()) + .toList(); sendMessageService.execute(phoneNumberList, request.getText(), request.getTitle()); } } From 5ed2f4424a3c6f9e9984d291e8fe4fff31fae731 Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Thu, 16 May 2024 17:29:08 +0900 Subject: [PATCH 14/32] =?UTF-8?q?refactor(#75)=20:=20sendMessage=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=9D=B4=EB=A6=84=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=EB=B0=8F=20=EC=97=94=EB=93=9C=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EB=B3=80=EA=B2=BD=20-=20=EC=9B=90=EC=84=9C=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=EB=B3=84=EB=A1=9C=20=EB=A9=94=EC=8B=9C?= =?UTF-8?q?=EC=A7=80=20=EB=B3=B4=EB=82=B4=EA=B8=B0=EC=99=80=20=EC=9B=90?= =?UTF-8?q?=EC=84=9C=20=ED=83=80=EC=9E=85=EB=B3=84=EB=A1=9C=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EB=B3=B4=EB=82=B4=EA=B8=B0=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=EC=9D=84=20=EB=B6=84=EB=A6=AC=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=EC=9C=84=ED=95=B4=20=EC=9D=B4=EB=A6=84=EA=B3=BC=20=EC=97=94?= =?UTF-8?q?=EB=93=9C=ED=8F=AC=EC=9D=B8=ED=8A=B8=EB=A5=BC=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=ED=96=88=EC=96=B4=EC=9A=94.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../maru/presentation/message/MessageController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bamdoliro/maru/presentation/message/MessageController.java b/src/main/java/com/bamdoliro/maru/presentation/message/MessageController.java index da242f13..75c10a52 100644 --- a/src/main/java/com/bamdoliro/maru/presentation/message/MessageController.java +++ b/src/main/java/com/bamdoliro/maru/presentation/message/MessageController.java @@ -19,8 +19,8 @@ public class MessageController { private final SendMessageUseCase sendMessageUseCase; @ResponseStatus(HttpStatus.NO_CONTENT) - @PostMapping - public void sendMessage( + @PostMapping("/status") + public void sendMessageByStatus( @AuthenticationPrincipal(authority = Authority.ADMIN) User user, @RequestBody @Valid SendMessageRequest request ) { From 411cad34737b18f082946fd490a29f0eb18eccbc Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Thu, 16 May 2024 17:42:15 +0900 Subject: [PATCH 15/32] =?UTF-8?q?test(#75)=20:=20=EC=97=94=EB=93=9C?= =?UTF-8?q?=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20?= =?UTF-8?q?BDDMockito=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20-=20BDD=EA=B4=80=EC=A0=90=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=B4=EA=B8=B0=20=EC=9C=84=ED=95=B4=EC=84=9C=20BDDMockito?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=ED=96=88=EC=96=B4=EC=9A=94.=20-=20UseCaseTest=EC=97=90?= =?UTF-8?q?=EC=84=9C=20status=EB=B3=84=EB=A1=9C=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=B4=EC=84=9C=20?= =?UTF-8?q?=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EB=A5=BC=20=EC=88=98=EC=A0=95=ED=96=88=EC=96=B4?= =?UTF-8?q?=EC=9A=94.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../message/MessageControllerTest.java | 57 ++++--------------- 1 file changed, 12 insertions(+), 45 deletions(-) diff --git a/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java b/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java index 987717b7..972970bc 100644 --- a/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java +++ b/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java @@ -1,30 +1,19 @@ package com.bamdoliro.maru.presentation.message; -import com.bamdoliro.maru.domain.form.domain.Form; import com.bamdoliro.maru.domain.form.domain.type.FormStatus; -import com.bamdoliro.maru.domain.form.domain.type.FormType; import com.bamdoliro.maru.domain.user.domain.User; -import com.bamdoliro.maru.infrastructure.persistence.form.FormRepository; import com.bamdoliro.maru.presentation.message.dto.request.SendMessageRequest; import com.bamdoliro.maru.shared.fixture.AuthFixture; -import com.bamdoliro.maru.shared.fixture.FormFixture; import com.bamdoliro.maru.shared.fixture.UserFixture; import com.bamdoliro.maru.shared.util.RestDocsTestSupport; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.core.MethodParameter; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.restdocs.payload.JsonFieldType; -import java.util.Arrays; -import java.util.List; - import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doThrow; +import static org.mockito.BDDMockito.*; import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; @@ -34,52 +23,30 @@ public class MessageControllerTest extends RestDocsTestSupport { - @MockBean - private FormRepository formRepository; - - @BeforeEach - void setup() { - Form form = FormFixture.createForm(FormType.REGULAR); - form.receive(); - List forms = Arrays.asList(form); - - given(formRepository.findByStatus(FormStatus.RECEIVED)).willReturn(forms); - } - @Test - void 원서가_접수된_학생들에게_메시지를_보낸다() throws Exception { - - User user = UserFixture.createAdminUser(); + void 조회할_상태의_원서를_가진_학생들에게() throws Exception { + User user = UserFixture.createUser(); given(authenticationArgumentResolver.supportsParameter(any(MethodParameter.class))).willReturn(true); given(authenticationArgumentResolver.resolveArgument(any(), any(), any(), any())).willReturn(user); - SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "배고파요..", FormStatus.RECEIVED); - doNothing().when(sendMessageUseCase).execute(any(SendMessageRequest.class)); + SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "테스트임니다...", FormStatus.FINAL_SUBMITTED); + willDoNothing().given(sendMessageUseCase).execute(request); - mockMvc.perform(post("/message") + mockMvc.perform(post("/message/status") .header(HttpHeaders.AUTHORIZATION, AuthFixture.createAuthHeader()) .contentType(MediaType.APPLICATION_JSON) .content(toJson(request))) .andExpect(status().isNoContent()) - .andDo(restDocs.document( requestHeaders( - headerWithName(HttpHeaders.AUTHORIZATION) - .description("Bearer token") + headerWithName(HttpHeaders.AUTHORIZATION).description("Bearer token") ), requestFields( - fieldWithPath("title") - .type(JsonFieldType.STRING) - .description("문자 메시지 제목"), - fieldWithPath("text") - .type(JsonFieldType.STRING) - .description("문자 메시지 내용"), - fieldWithPath("status") - .type(JsonFieldType.STRING) - .description("메시지를 보낼 원서의 상태") + fieldWithPath("title").type(JsonFieldType.STRING).description("문자 메시지 제목"), + fieldWithPath("text").type(JsonFieldType.STRING).description("문자 메시지 내용"), + fieldWithPath("status").type(JsonFieldType.STRING).description("메시지를 보낼 원서의 상태") ) )); - } @Test @@ -90,9 +57,9 @@ void setup() { SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "배고파요..", FormStatus.FINAL_SUBMITTED); - doThrow(new RuntimeException("원서를 찾을 수 없음")).when(sendMessageUseCase).execute(any(SendMessageRequest.class)); + willThrow(new RuntimeException("원서를 찾을 수 없음")).given(sendMessageUseCase).execute(any(SendMessageRequest.class)); - mockMvc.perform(post("/message") + mockMvc.perform(post("/message/status") .header(HttpHeaders.AUTHORIZATION, AuthFixture.createAuthHeader()) .contentType(MediaType.APPLICATION_JSON) .content(toJson(request))) From fddf9a32036db685468ddf2dec325ca83d811f95 Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Thu, 16 May 2024 17:42:47 +0900 Subject: [PATCH 16/32] =?UTF-8?q?test(#75)=20:=20status=EB=B3=84=20?= =?UTF-8?q?=EB=8B=A8=EC=9C=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20-=20SendMessageUseCaseTest=EB=A5=BC=20=EB=A7=8C?= =?UTF-8?q?=EB=93=A4=EC=97=88=EC=96=B4=EC=9A=94.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../message/SendMessageUseCaseTest.java | 202 ++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 src/test/java/com/bamdoliro/maru/application/message/SendMessageUseCaseTest.java diff --git a/src/test/java/com/bamdoliro/maru/application/message/SendMessageUseCaseTest.java b/src/test/java/com/bamdoliro/maru/application/message/SendMessageUseCaseTest.java new file mode 100644 index 00000000..c24154fe --- /dev/null +++ b/src/test/java/com/bamdoliro/maru/application/message/SendMessageUseCaseTest.java @@ -0,0 +1,202 @@ +package com.bamdoliro.maru.application.message; + +import com.bamdoliro.maru.domain.form.domain.Form; +import com.bamdoliro.maru.domain.form.domain.type.FormStatus; +import com.bamdoliro.maru.domain.form.domain.type.FormType; +import com.bamdoliro.maru.infrastructure.message.SendMessageService; +import com.bamdoliro.maru.infrastructure.message.exception.FailedToSendException; +import com.bamdoliro.maru.infrastructure.persistence.form.FormRepository; +import com.bamdoliro.maru.presentation.message.dto.request.SendMessageRequest; +import com.bamdoliro.maru.shared.fixture.FormFixture; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; + +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.willThrow; +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) +public class SendMessageUseCaseTest { + + @InjectMocks + private SendMessageUseCase sendMessageUseCase; + + @Mock + private SendMessageService sendMessageService; + + @Mock + private FormRepository formRepository; + + @Test + void 원서를_최종제출한_학생들에게_메시지를_보낸다(){ + + //given + Form form = FormFixture.createForm(FormType.REGULAR); + form.submit("https://maru.bamdoliro.com/pdf/1"); + given(formRepository.findByStatus(FormStatus.FINAL_SUBMITTED)).willReturn(List.of(form)); + SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "테스트입니다", FormStatus.FINAL_SUBMITTED); + + //when + sendMessageUseCase.execute(request); + + //then + verify(formRepository, times(1)).findByStatus(FormStatus.FINAL_SUBMITTED); + verify(sendMessageService, times(1)).execute(List.of(form.getUser().getPhoneNumber()), request.getText(), request.getTitle()); + } + + @Test + void 원서를_승인받은_학생들에게_메시지를_보낸다(){ + + //given + Form form = FormFixture.createForm(FormType.REGULAR); + form.approve(); + given(formRepository.findByStatus(FormStatus.APPROVED)).willReturn(List.of(form)); + SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "테스트입니다", FormStatus.APPROVED); + + //when + sendMessageUseCase.execute(request); + + //then + verify(formRepository, times(1)).findByStatus(FormStatus.APPROVED); + verify(sendMessageService, times(1)).execute(List.of(form.getUser().getPhoneNumber()), request.getText(), request.getTitle()); + } + + @Test + void 원서를_반려받은_학생들에게_메시지를_보낸다(){ + + //given + Form form = FormFixture.createForm(FormType.REGULAR); + form.reject(); + given(formRepository.findByStatus(FormStatus.REJECTED)).willReturn(List.of(form)); + SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "학생들의 원서가 조건을 충족하지 못해 반려되었습니다.", FormStatus.REJECTED); + + //when + sendMessageUseCase.execute(request); + + //then + verify(formRepository, times(1)).findByStatus(FormStatus.REJECTED); + verify(sendMessageService, times(1)).execute(List.of(form.getUser().getPhoneNumber()), request.getText(), request.getTitle()); + } + + @Test + void 원서를_접수한_학생들에게_메시지를_보낸다(){ + + //given + Form form = FormFixture.createForm(FormType.REGULAR); + form.receive(); + given(formRepository.findByStatus(FormStatus.RECEIVED)).willReturn(List.of(form)); + SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "제출하신 원서가 접수되었습니다.", FormStatus.RECEIVED); + + //when + sendMessageUseCase.execute(request); + + //then + verify(formRepository, times(1)).findByStatus(FormStatus.RECEIVED); + verify(sendMessageService, times(1)).execute(List.of(form.getUser().getPhoneNumber()), request.getText(), request.getTitle()); + } + + @Test + void 제1차_합격자들에게_메시지를_보낸다(){ + + //given + Form form = FormFixture.createForm(FormType.REGULAR); + form.firstPass(); + given(formRepository.findByStatus(FormStatus.FIRST_PASSED)).willReturn(List.of(form)); + SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "1차 전형에 합격하신것을 축하드립니다. 면접 장소를 확인하시고 꼭 제시간에 방문하시길 바라겠습니다,", FormStatus.FIRST_PASSED); + + //when + sendMessageUseCase.execute(request); + + //then + verify(formRepository, times(1)).findByStatus(FormStatus.FIRST_PASSED); + verify(sendMessageService, times(1)).execute(List.of(form.getUser().getPhoneNumber()), request.getText(), request.getTitle()); + } + + @Test + void 제1차_불합격자들에게_메시지를_보낸다(){ + + //given + Form form = FormFixture.createForm(FormType.REGULAR); + form.firstFail(); + given(formRepository.findByStatus(FormStatus.FIRST_FAILED)).willReturn(List.of(form)); + SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "1차 전형에 불합격하신것에 대해 유감입니당~", FormStatus.FIRST_FAILED); + + //when + sendMessageUseCase.execute(request); + + //then + verify(formRepository, times(1)).findByStatus(FormStatus.FIRST_FAILED); + verify(sendMessageService, times(1)).execute(List.of(form.getUser().getPhoneNumber()), request.getText(), request.getTitle()); + } + + @Test + void 제2차전형에_불참한_학생들에게_메시지를_보낸다(){ + + //given + Form form = FormFixture.createForm(FormType.REGULAR); + form.noShow(); + given(formRepository.findByStatus(FormStatus.NO_SHOW)).willReturn(List.of(form)); + SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "해당 지원자들은 2차전형에 '불참'하였으므로 패널티가 있을 예정입니다.", FormStatus.NO_SHOW); + + //when + sendMessageUseCase.execute(request); + + //then + verify(formRepository, times(1)).findByStatus(FormStatus.NO_SHOW); + verify(sendMessageService, times(1)).execute(List.of(form.getUser().getPhoneNumber()), request.getText(), request.getTitle()); + } + + @Test + void 최종합격자들에게_메시지를_보낸다(){ + + //given + Form form = FormFixture.createForm(FormType.REGULAR); + form.pass(); + given(formRepository.findByStatus(FormStatus.PASSED)).willReturn(List.of(form)); + SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "합격하였습니다. 축하드립니다.", FormStatus.PASSED); + + //when + sendMessageUseCase.execute(request); + + //then + verify(formRepository, times(1)).findByStatus(FormStatus.PASSED); + verify(sendMessageService, times(1)).execute(List.of(form.getUser().getPhoneNumber()), request.getText(), request.getTitle()); + } + + @Test + void 최종불합격자들에게_메시지를_보낸다(){ + + //given + Form form = FormFixture.createForm(FormType.REGULAR); + form.fail(); + given(formRepository.findByStatus(FormStatus.FAILED)).willReturn(List.of(form)); + SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "불합격", FormStatus.FAILED); + + //when + sendMessageUseCase.execute(request); + + //then + verify(formRepository, times(1)).findByStatus(FormStatus.FAILED); + verify(sendMessageService, times(1)).execute(List.of(form.getUser().getPhoneNumber()), request.getText(), request.getTitle()); + } + + @Test + void 보낼메시지대상이_존재하지_않으면_오류가_발생한다(){ + + //given + willThrow(new FailedToSendException()).given(formRepository).findByStatus(FormStatus.SUBMITTED); + SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "제출이 완료되었습니다.", FormStatus.SUBMITTED); + + //when and then + Assertions.assertThrows(FailedToSendException.class, + () -> sendMessageUseCase.execute(request)); + verify(formRepository, times(1)).findByStatus(FormStatus.SUBMITTED); + verify(sendMessageService, never()).execute(anyList(), anyString(), anyString()); + } +} From e57d2a9f96983c62036396533c625a8cac8814e0 Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Tue, 28 May 2024 17:33:58 +0900 Subject: [PATCH 17/32] =?UTF-8?q?feat(#81)=20:=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EA=B0=9C=EC=84=A0=20?= =?UTF-8?q?-=20SendMessageService=EC=97=90=EC=84=9C=20formRepository?= =?UTF-8?q?=EB=A5=BC=20=EC=82=AC=EC=9A=A9=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EC=95=84=EC=84=9C=20=EC=A0=9C=EA=B1=B0=ED=96=88=EC=96=B4?= =?UTF-8?q?=EC=9A=94.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../maru/infrastructure/message/SendMessageService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/bamdoliro/maru/infrastructure/message/SendMessageService.java b/src/main/java/com/bamdoliro/maru/infrastructure/message/SendMessageService.java index 237052f8..6f8726c5 100644 --- a/src/main/java/com/bamdoliro/maru/infrastructure/message/SendMessageService.java +++ b/src/main/java/com/bamdoliro/maru/infrastructure/message/SendMessageService.java @@ -19,7 +19,6 @@ public class SendMessageService { private final MessageProperties messageProperties; private final DefaultMessageService messageService; - private final FormRepository formRepository; public void execute(String to, String text) { Message message = createMessage(to, text); From 53e18ec7d4645e0f47074f5402ae12b0b5ef70ce Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Thu, 30 May 2024 15:20:33 +0900 Subject: [PATCH 18/32] =?UTF-8?q?feat(#81)=20:=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80=20-=20=EB=A7=88=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=ED=84=B0=EC=A0=84=ED=98=95=EA=B3=BC,=20=EB=A7=88?= =?UTF-8?q?=EC=9D=B4=EC=8A=A4=ED=84=B0=EC=A0=84=ED=98=95=EC=9D=84=20?= =?UTF-8?q?=EC=A0=9C=EC=99=B8=ED=95=9C=20=EB=AA=A8=EB=93=A0=20=EC=A0=84?= =?UTF-8?q?=ED=98=95=EC=9D=84=20=EC=A1=B0=ED=9A=8C=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=EC=9C=84=ED=95=B4=EC=84=9C=20findMeisterTalentFirstRoundForm()?= =?UTF-8?q?=EA=B3=BC=20findNotExistsMeisterTalentFirstRoundForm()=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=EB=A5=BC=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=ED=96=88=EC=96=B4=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infrastructure/persistence/form/FormRepositoryCustom.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/bamdoliro/maru/infrastructure/persistence/form/FormRepositoryCustom.java b/src/main/java/com/bamdoliro/maru/infrastructure/persistence/form/FormRepositoryCustom.java index 77801104..ed7dec7e 100644 --- a/src/main/java/com/bamdoliro/maru/infrastructure/persistence/form/FormRepositoryCustom.java +++ b/src/main/java/com/bamdoliro/maru/infrastructure/persistence/form/FormRepositoryCustom.java @@ -12,6 +12,8 @@ public interface FormRepositoryCustom { List findReceivedSpecialForm(); List findReceivedRegularOrSupernumeraryForm(); List findFirstRoundForm(); + List findMeisterTalentFirstRoundForm(); + List findNotExistsMeisterTalentFirstRoundForm(); List findSecondRoundForm(); List findByFormIdList(List idList); List findFormUrlByFormIdList(List idList); From 626a4eeb8153591fd62229e38a0e12275ba41b67 Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Thu, 30 May 2024 15:20:51 +0900 Subject: [PATCH 19/32] =?UTF-8?q?feat(#81)=20:=20formRepository=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC=ED=98=84=20-=20?= =?UTF-8?q?=EB=A7=88=EC=9D=B4=EC=8A=A4=ED=84=B0=EC=A0=84=ED=98=95=EA=B3=BC?= =?UTF-8?q?,=20=EB=A7=88=EC=9D=B4=EC=8A=A4=ED=84=B0=EC=A0=84=ED=98=95?= =?UTF-8?q?=EC=9D=84=20=EC=A0=9C=EC=99=B8=ED=95=9C=20=EB=AA=A8=EB=93=A0=20?= =?UTF-8?q?=EC=A0=84=ED=98=95=EC=9D=84=20=EC=A1=B0=ED=9A=8C=ED=95=98?= =?UTF-8?q?=EA=B8=B0=20=EC=9C=84=ED=95=B4=EC=84=9C=20findMeisterTalentFirs?= =?UTF-8?q?tRoundForm()=EA=B3=BC=20findNotExistsMeisterTalentFirstRoundFor?= =?UTF-8?q?m()=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=A5=BC=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=ED=96=88=EC=96=B4=EC=9A=94.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/form/FormRepositoryImpl.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/com/bamdoliro/maru/infrastructure/persistence/form/FormRepositoryImpl.java b/src/main/java/com/bamdoliro/maru/infrastructure/persistence/form/FormRepositoryImpl.java index e70765f8..f78df470 100644 --- a/src/main/java/com/bamdoliro/maru/infrastructure/persistence/form/FormRepositoryImpl.java +++ b/src/main/java/com/bamdoliro/maru/infrastructure/persistence/form/FormRepositoryImpl.java @@ -86,6 +86,26 @@ public List findFirstRoundForm() { .fetch(); } + @Override + public List findMeisterTalentFirstRoundForm() { + return queryFactory + .selectFrom(form) + .where(form.status.eq(FormStatus.FIRST_PASSED) + .and(form.type.eq(FormType.MEISTER_TALENT)) + ) + .fetch(); + } + + @Override + public List findNotExistsMeisterTalentFirstRoundForm() { + return queryFactory + .selectFrom(form) + .where(form.status.eq(FormStatus.FIRST_PASSED) + .and(form.type.ne(FormType.MEISTER_TALENT)) + ) + .fetch(); + } + @Override public List findSecondRoundForm() { return queryFactory From 1eb26e2a6fd4a014cf6106ce3653c841f5cc3dd7 Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Thu, 30 May 2024 15:21:27 +0900 Subject: [PATCH 20/32] =?UTF-8?q?feat(#81)=20:=20=EC=A0=84=ED=98=95?= =?UTF-8?q?=EB=B3=84=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80=20-=20=EC=A0=84=ED=98=95?= =?UTF-8?q?=EB=B3=84=EB=A1=9C=20=EB=A9=94=EC=8B=9C=EC=A7=80=EB=A5=BC=20?= =?UTF-8?q?=EB=B3=B4=EB=82=B4=EA=B8=B0=20=EC=9C=84=ED=95=B4=EC=84=9C=20?= =?UTF-8?q?=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=EC=97=90=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=EB=A5=BC=20=EC=B6=94=EA=B0=80=ED=96=88?= =?UTF-8?q?=EC=96=B4=EC=9A=94.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/message/MessageController.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/bamdoliro/maru/presentation/message/MessageController.java b/src/main/java/com/bamdoliro/maru/presentation/message/MessageController.java index 75c10a52..362569de 100644 --- a/src/main/java/com/bamdoliro/maru/presentation/message/MessageController.java +++ b/src/main/java/com/bamdoliro/maru/presentation/message/MessageController.java @@ -2,8 +2,8 @@ import com.bamdoliro.maru.application.message.SendMessageUseCase; import com.bamdoliro.maru.domain.user.domain.User; -import com.bamdoliro.maru.infrastructure.message.SendMessageService; -import com.bamdoliro.maru.presentation.message.dto.request.SendMessageRequest; +import com.bamdoliro.maru.presentation.message.dto.request.SendMessageByStatusRequest; +import com.bamdoliro.maru.presentation.message.dto.request.SendMessageByTypeRequest; import com.bamdoliro.maru.shared.auth.AuthenticationPrincipal; import com.bamdoliro.maru.shared.auth.Authority; import jakarta.validation.Valid; @@ -22,7 +22,16 @@ public class MessageController { @PostMapping("/status") public void sendMessageByStatus( @AuthenticationPrincipal(authority = Authority.ADMIN) User user, - @RequestBody @Valid SendMessageRequest request + @RequestBody @Valid SendMessageByStatusRequest request + ) { + sendMessageUseCase.execute(request); + } + + @ResponseStatus(HttpStatus.NO_CONTENT) + @PostMapping("/type") + public void sendMessageByType( + @AuthenticationPrincipal(authority = Authority.ADMIN) User user, + @RequestBody @Valid SendMessageByTypeRequest request ) { sendMessageUseCase.execute(request); } From d6e12fde2dc7c5c1f752ccb4de11e8deba8aaa86 Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Thu, 30 May 2024 16:45:41 +0900 Subject: [PATCH 21/32] =?UTF-8?q?refactor(#81)=20:=20DTO=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EB=B3=80=EA=B2=BD=20-=20SendMessageByStatusRequest?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EB=A6=84=EC=9D=84=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=ED=96=88=EC=96=B4=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...t.java => SendMessageByStatusRequest.java} | 2 +- .../message/SendMessageUseCaseTest.java | 22 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) rename src/main/java/com/bamdoliro/maru/presentation/message/dto/request/{SendMessageRequest.java => SendMessageByStatusRequest.java} (93%) diff --git a/src/main/java/com/bamdoliro/maru/presentation/message/dto/request/SendMessageRequest.java b/src/main/java/com/bamdoliro/maru/presentation/message/dto/request/SendMessageByStatusRequest.java similarity index 93% rename from src/main/java/com/bamdoliro/maru/presentation/message/dto/request/SendMessageRequest.java rename to src/main/java/com/bamdoliro/maru/presentation/message/dto/request/SendMessageByStatusRequest.java index 56a24113..9874ea0d 100644 --- a/src/main/java/com/bamdoliro/maru/presentation/message/dto/request/SendMessageRequest.java +++ b/src/main/java/com/bamdoliro/maru/presentation/message/dto/request/SendMessageByStatusRequest.java @@ -10,7 +10,7 @@ @Getter @NoArgsConstructor @AllArgsConstructor -public class SendMessageRequest { +public class SendMessageByStatusRequest { @NotBlank(message = "필수값입니다.") private String title; diff --git a/src/test/java/com/bamdoliro/maru/application/message/SendMessageUseCaseTest.java b/src/test/java/com/bamdoliro/maru/application/message/SendMessageUseCaseTest.java index c24154fe..d2163a11 100644 --- a/src/test/java/com/bamdoliro/maru/application/message/SendMessageUseCaseTest.java +++ b/src/test/java/com/bamdoliro/maru/application/message/SendMessageUseCaseTest.java @@ -6,7 +6,7 @@ import com.bamdoliro.maru.infrastructure.message.SendMessageService; import com.bamdoliro.maru.infrastructure.message.exception.FailedToSendException; import com.bamdoliro.maru.infrastructure.persistence.form.FormRepository; -import com.bamdoliro.maru.presentation.message.dto.request.SendMessageRequest; +import com.bamdoliro.maru.presentation.message.dto.request.SendMessageByStatusRequest; import com.bamdoliro.maru.shared.fixture.FormFixture; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -40,7 +40,7 @@ public class SendMessageUseCaseTest { Form form = FormFixture.createForm(FormType.REGULAR); form.submit("https://maru.bamdoliro.com/pdf/1"); given(formRepository.findByStatus(FormStatus.FINAL_SUBMITTED)).willReturn(List.of(form)); - SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "테스트입니다", FormStatus.FINAL_SUBMITTED); + SendMessageByStatusRequest request = new SendMessageByStatusRequest("부산소마고 공지사항", "테스트입니다", FormStatus.FINAL_SUBMITTED); //when sendMessageUseCase.execute(request); @@ -57,7 +57,7 @@ public class SendMessageUseCaseTest { Form form = FormFixture.createForm(FormType.REGULAR); form.approve(); given(formRepository.findByStatus(FormStatus.APPROVED)).willReturn(List.of(form)); - SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "테스트입니다", FormStatus.APPROVED); + SendMessageByStatusRequest request = new SendMessageByStatusRequest("부산소마고 공지사항", "테스트입니다", FormStatus.APPROVED); //when sendMessageUseCase.execute(request); @@ -74,7 +74,7 @@ public class SendMessageUseCaseTest { Form form = FormFixture.createForm(FormType.REGULAR); form.reject(); given(formRepository.findByStatus(FormStatus.REJECTED)).willReturn(List.of(form)); - SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "학생들의 원서가 조건을 충족하지 못해 반려되었습니다.", FormStatus.REJECTED); + SendMessageByStatusRequest request = new SendMessageByStatusRequest("부산소마고 공지사항", "학생들의 원서가 조건을 충족하지 못해 반려되었습니다.", FormStatus.REJECTED); //when sendMessageUseCase.execute(request); @@ -91,7 +91,7 @@ public class SendMessageUseCaseTest { Form form = FormFixture.createForm(FormType.REGULAR); form.receive(); given(formRepository.findByStatus(FormStatus.RECEIVED)).willReturn(List.of(form)); - SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "제출하신 원서가 접수되었습니다.", FormStatus.RECEIVED); + SendMessageByStatusRequest request = new SendMessageByStatusRequest("부산소마고 공지사항", "제출하신 원서가 접수되었습니다.", FormStatus.RECEIVED); //when sendMessageUseCase.execute(request); @@ -108,7 +108,7 @@ public class SendMessageUseCaseTest { Form form = FormFixture.createForm(FormType.REGULAR); form.firstPass(); given(formRepository.findByStatus(FormStatus.FIRST_PASSED)).willReturn(List.of(form)); - SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "1차 전형에 합격하신것을 축하드립니다. 면접 장소를 확인하시고 꼭 제시간에 방문하시길 바라겠습니다,", FormStatus.FIRST_PASSED); + SendMessageByStatusRequest request = new SendMessageByStatusRequest("부산소마고 공지사항", "1차 전형에 합격하신것을 축하드립니다. 면접 장소를 확인하시고 꼭 제시간에 방문하시길 바라겠습니다,", FormStatus.FIRST_PASSED); //when sendMessageUseCase.execute(request); @@ -125,7 +125,7 @@ public class SendMessageUseCaseTest { Form form = FormFixture.createForm(FormType.REGULAR); form.firstFail(); given(formRepository.findByStatus(FormStatus.FIRST_FAILED)).willReturn(List.of(form)); - SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "1차 전형에 불합격하신것에 대해 유감입니당~", FormStatus.FIRST_FAILED); + SendMessageByStatusRequest request = new SendMessageByStatusRequest("부산소마고 공지사항", "1차 전형에 불합격하신것에 대해 유감입니당~", FormStatus.FIRST_FAILED); //when sendMessageUseCase.execute(request); @@ -142,7 +142,7 @@ public class SendMessageUseCaseTest { Form form = FormFixture.createForm(FormType.REGULAR); form.noShow(); given(formRepository.findByStatus(FormStatus.NO_SHOW)).willReturn(List.of(form)); - SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "해당 지원자들은 2차전형에 '불참'하였으므로 패널티가 있을 예정입니다.", FormStatus.NO_SHOW); + SendMessageByStatusRequest request = new SendMessageByStatusRequest("부산소마고 공지사항", "해당 지원자들은 2차전형에 '불참'하였으므로 패널티가 있을 예정입니다.", FormStatus.NO_SHOW); //when sendMessageUseCase.execute(request); @@ -159,7 +159,7 @@ public class SendMessageUseCaseTest { Form form = FormFixture.createForm(FormType.REGULAR); form.pass(); given(formRepository.findByStatus(FormStatus.PASSED)).willReturn(List.of(form)); - SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "합격하였습니다. 축하드립니다.", FormStatus.PASSED); + SendMessageByStatusRequest request = new SendMessageByStatusRequest("부산소마고 공지사항", "합격하였습니다. 축하드립니다.", FormStatus.PASSED); //when sendMessageUseCase.execute(request); @@ -176,7 +176,7 @@ public class SendMessageUseCaseTest { Form form = FormFixture.createForm(FormType.REGULAR); form.fail(); given(formRepository.findByStatus(FormStatus.FAILED)).willReturn(List.of(form)); - SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "불합격", FormStatus.FAILED); + SendMessageByStatusRequest request = new SendMessageByStatusRequest("부산소마고 공지사항", "불합격", FormStatus.FAILED); //when sendMessageUseCase.execute(request); @@ -191,7 +191,7 @@ public class SendMessageUseCaseTest { //given willThrow(new FailedToSendException()).given(formRepository).findByStatus(FormStatus.SUBMITTED); - SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "제출이 완료되었습니다.", FormStatus.SUBMITTED); + SendMessageByStatusRequest request = new SendMessageByStatusRequest("부산소마고 공지사항", "제출이 완료되었습니다.", FormStatus.SUBMITTED); //when and then Assertions.assertThrows(FailedToSendException.class, From 13a9a704dcd8665ae13973f370806d543978e0aa Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Thu, 30 May 2024 16:47:30 +0900 Subject: [PATCH 22/32] =?UTF-8?q?feat(#81)=20:=20execute=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EA=B0=9C?= =?UTF-8?q?=EC=84=A0=20-=20=EC=A0=84=ED=98=95=EB=B3=84=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EB=B3=B4=EB=82=B4=EA=B8=B0=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=EB=A5=BC=20=EB=A7=8C=EB=93=A4=EC=97=88?= =?UTF-8?q?=EC=96=B4=EC=9A=94.=20-=20=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=EC=9D=84=20private=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=A1=9C=20=EB=B0=94=EA=BE=B8=EC=97=88=EC=96=B4?= =?UTF-8?q?=EC=9A=94.=20-=20=EA=B2=B9=EC=B9=98=EB=8A=94=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=EC=9D=84=20=ED=95=98=EB=82=98=EC=9D=98=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=EB=A1=9C=20=EA=B0=9C=EC=84=A0=ED=96=88?= =?UTF-8?q?=EC=96=B4=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../message/SendMessageUseCase.java | 42 +++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java b/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java index 0aad401d..c3c3050a 100644 --- a/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java +++ b/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java @@ -1,9 +1,11 @@ package com.bamdoliro.maru.application.message; import com.bamdoliro.maru.domain.form.domain.Form; +import com.bamdoliro.maru.domain.form.domain.type.FormType; import com.bamdoliro.maru.infrastructure.message.SendMessageService; import com.bamdoliro.maru.infrastructure.persistence.form.FormRepository; -import com.bamdoliro.maru.presentation.message.dto.request.SendMessageRequest; +import com.bamdoliro.maru.presentation.message.dto.request.SendMessageByStatusRequest; +import com.bamdoliro.maru.presentation.message.dto.request.SendMessageByTypeRequest; import com.bamdoliro.maru.shared.annotation.UseCase; import lombok.RequiredArgsConstructor; @@ -16,11 +18,43 @@ public class SendMessageUseCase { private final FormRepository formRepository; private final SendMessageService sendMessageService; - public void execute(SendMessageRequest request) { + public void execute(SendMessageByStatusRequest request) { List formList = formRepository.findByStatus(request.getStatus()); - List phoneNumberList = formList.stream() + List phoneNumberList = phoneNumberListConvert(formList); + + sendMessageService.execute(phoneNumberList, request.getText(), request.getTitle()); + } + + public void execute(SendMessageByTypeRequest request) { + List formList = formListFilter(request.getFormType(), request.isChangeToRegular()); + List phoneNumberList = phoneNumberListConvert(formList); + + sendMessageService.execute(phoneNumberList, request.getText(), request.getTitle()); + } + + private List formListFilter(FormType formType, boolean isChangeToRegular) { + List formList; + if (formType.isMeister()) { + formList = formRepository.findMeisterTalentFirstRoundForm(); + } else { + formList = formRepository.findNotExistsMeisterTalentFirstRoundForm(); + if (isChangeToRegular) { + formList = formList.stream() + .filter(Form::getChangedToRegular) + .toList(); + } else { + formList = formList.stream() + .filter(form -> !form.getChangedToRegular()) + .toList(); + } + } + + return formList; + } + + private List phoneNumberListConvert(List formList) { + return formList.stream() .map(form -> form.getUser().getPhoneNumber()) .toList(); - sendMessageService.execute(phoneNumberList, request.getText(), request.getTitle()); } } From 7126186db86feb6c6140c627072ff45df4cb5970 Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Thu, 30 May 2024 17:58:51 +0900 Subject: [PATCH 23/32] =?UTF-8?q?docs=20:=20message.adoc=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/message.adoc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/docs/asciidoc/message.adoc b/src/docs/asciidoc/message.adoc index 80858aca..6835679e 100644 --- a/src/docs/asciidoc/message.adoc +++ b/src/docs/asciidoc/message.adoc @@ -6,19 +6,19 @@ ==== 요청 형식 ===== Request Header -include::{snippets}/message-controller-test/원서가_접수된_학생들에게_메시지를_보낸다/request-headers.adoc[] +include::{snippets}/message-controller-test/조회할_상태의_원서를_가진_학생들에게/request-headers.adoc[] ===== Request Body -include::{snippets}/message-controller-test/원서가_접수된_학생들에게_메시지를_보낸다/request-fields.adoc[] +include::{snippets}/message-controller-test/조회할_상태의_원서를_가진_학생들에게/request-fields.adoc[] ==== 요청 ===== 접수된 원서를 가진 사용자에게 메시지 보내기 -include::{snippets}/message-controller-test/원서가_접수된_학생들에게_메시지를_보낸다/http-request.adoc[] +include::{snippets}/message-controller-test/조회할_상태의_원서를_가진_학생들에게/http-request.adoc[] ==== 응답 ===== 정상 응답 -include::{snippets}/message-controller-test/원서가_접수된_학생들에게_메시지를_보낸다/http-response.adoc[] +include::{snippets}/message-controller-test/조회할_상태의_원서를_가진_학생들에게/http-response.adoc[] ===== 입력한 상태의 원서가 없거나 상태를 잘못 입력한 경우 include::{snippets}/message-controller-test/해당제출상태인_원서가_없으면_오류가난다/http-response.adoc[] \ No newline at end of file From 68b8f9a7226f9c2c5bada53fb82176fbd9f9d8da Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Thu, 30 May 2024 19:22:57 +0900 Subject: [PATCH 24/32] =?UTF-8?q?feat(#81)=20:=20SendMessageByTypeRequest?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=20-=20SendMessageByTypeRequest=20DTO?= =?UTF-8?q?=EB=A5=BC=20=EC=B6=94=EA=B0=80=ED=96=88=EC=96=B4=EC=9A=94.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/SendMessageByTypeRequest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/com/bamdoliro/maru/presentation/message/dto/request/SendMessageByTypeRequest.java diff --git a/src/main/java/com/bamdoliro/maru/presentation/message/dto/request/SendMessageByTypeRequest.java b/src/main/java/com/bamdoliro/maru/presentation/message/dto/request/SendMessageByTypeRequest.java new file mode 100644 index 00000000..f1794b0d --- /dev/null +++ b/src/main/java/com/bamdoliro/maru/presentation/message/dto/request/SendMessageByTypeRequest.java @@ -0,0 +1,27 @@ +package com.bamdoliro.maru.presentation.message.dto.request; + +import com.bamdoliro.maru.domain.form.domain.type.FormType; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class SendMessageByTypeRequest { + + @NotBlank(message = "필수값입니다.") + private String title; + + @NotBlank(message = "필수값입니다.") + private String text; + + @NotNull(message = "필수값입니다.") + private FormType formType; + + @NotNull(message = "필수값입니다.") + private boolean isChangeToRegular; +} + From 135cf3625430131fe77d9e1d7a4a61523af7b663 Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Thu, 30 May 2024 19:24:49 +0900 Subject: [PATCH 25/32] =?UTF-8?q?fix(#81)=20:=20SendMessageRequest=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD=20-=20SendMessageReques?= =?UTF-8?q?t=EB=A5=BC=20SendMessageByStatusRequest=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=ED=96=88=EC=96=B4=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../maru/presentation/message/MessageControllerTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java b/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java index 972970bc..f69681b7 100644 --- a/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java +++ b/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java @@ -2,6 +2,7 @@ import com.bamdoliro.maru.domain.form.domain.type.FormStatus; import com.bamdoliro.maru.domain.user.domain.User; +import com.bamdoliro.maru.presentation.message.dto.request.SendMessageByStatusRequest; import com.bamdoliro.maru.presentation.message.dto.request.SendMessageRequest; import com.bamdoliro.maru.shared.fixture.AuthFixture; import com.bamdoliro.maru.shared.fixture.UserFixture; @@ -29,7 +30,7 @@ public class MessageControllerTest extends RestDocsTestSupport { given(authenticationArgumentResolver.supportsParameter(any(MethodParameter.class))).willReturn(true); given(authenticationArgumentResolver.resolveArgument(any(), any(), any(), any())).willReturn(user); - SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "테스트임니다...", FormStatus.FINAL_SUBMITTED); + SendMessageByStatusRequest request = new SendMessageByStatusRequest("부산소마고 공지사항", "테스트임니다...", FormStatus.FINAL_SUBMITTED); willDoNothing().given(sendMessageUseCase).execute(request); mockMvc.perform(post("/message/status") @@ -55,9 +56,9 @@ public class MessageControllerTest extends RestDocsTestSupport { given(authenticationArgumentResolver.supportsParameter(any(MethodParameter.class))).willReturn(true); given(authenticationArgumentResolver.resolveArgument(any(), any(), any(), any())).willReturn(user); - SendMessageRequest request = new SendMessageRequest("부산소마고 공지사항", "배고파요..", FormStatus.FINAL_SUBMITTED); + SendMessageByStatusRequest request = new SendMessageByStatusRequest("부산소마고 공지사항", "배고파요..", FormStatus.FINAL_SUBMITTED); - willThrow(new RuntimeException("원서를 찾을 수 없음")).given(sendMessageUseCase).execute(any(SendMessageRequest.class)); + willThrow(new RuntimeException("원서를 찾을 수 없음")).given(sendMessageUseCase).execute(any(SendMessageByStatusRequest.class)); mockMvc.perform(post("/message/status") .header(HttpHeaders.AUTHORIZATION, AuthFixture.createAuthHeader()) From 79cec340334d25784249c8bbb74e0d6df5088653 Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Thu, 30 May 2024 19:25:17 +0900 Subject: [PATCH 26/32] =?UTF-8?q?refactor(#81)=20:=20import=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=20-=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20import?= =?UTF-8?q?=EB=A5=BC=20=EC=A0=9C=EA=B1=B0=ED=96=88=EC=96=B4=EC=9A=94.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../maru/presentation/message/MessageControllerTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java b/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java index f69681b7..a57e5a86 100644 --- a/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java +++ b/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java @@ -3,7 +3,6 @@ import com.bamdoliro.maru.domain.form.domain.type.FormStatus; import com.bamdoliro.maru.domain.user.domain.User; import com.bamdoliro.maru.presentation.message.dto.request.SendMessageByStatusRequest; -import com.bamdoliro.maru.presentation.message.dto.request.SendMessageRequest; import com.bamdoliro.maru.shared.fixture.AuthFixture; import com.bamdoliro.maru.shared.fixture.UserFixture; import com.bamdoliro.maru.shared.util.RestDocsTestSupport; From 2c1470fd8d3b780c215ca3c2b43e5cc4bb0c5a32 Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Fri, 31 May 2024 02:55:48 +0900 Subject: [PATCH 27/32] =?UTF-8?q?fix(#81)=20:=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20-=20=EB=A7=88=EC=9D=B4=EC=8A=A4=ED=84=B0?= =?UTF-8?q?=20=EC=A0=84=ED=98=95=EC=97=90=EC=84=9C=20=EC=9D=BC=EB=B0=98?= =?UTF-8?q?=EC=A0=84=ED=98=95=EC=9C=BC=EB=A1=9C=20=EB=B0=94=EB=80=90=20?= =?UTF-8?q?=EC=9B=90=EC=84=9C=EB=8A=94=20getType()=EC=9D=84=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=96=88=EC=9D=84=20=EB=95=8C=EB=A7=8C=20REGULAR?= =?UTF-8?q?=EB=A1=9C=20=EB=82=98=EC=98=A4=EA=B3=A0=20=EC=8B=A4=EC=A0=9C=20?= =?UTF-8?q?=EB=94=94=EB=B9=84=EC=97=90=EB=8A=94=20MEISTER=5FTALENT?= =?UTF-8?q?=EB=A1=9C=20=EB=93=A4=EC=96=B4=EA=B0=80=EC=84=9C=20=EA=B7=B8?= =?UTF-8?q?=EB=A3=B9=EB=B3=84=20=EB=A9=94=EC=8B=9C=EC=A7=80=EB=A5=BC=20?= =?UTF-8?q?=EB=B3=B4=EB=82=BC=20=EB=95=8C=20=EB=B2=88=EA=B1=B0=EB=A1=9C?= =?UTF-8?q?=EC=9B=80=EC=9D=B4=20=EC=9E=88=EC=96=B4=EC=84=9C=20=EC=9B=90?= =?UTF-8?q?=EC=84=9C=20=EC=A0=84=ED=98=95=20=EC=9E=90=EC=B2=B4=EB=A5=BC=20?= =?UTF-8?q?REGULAR=EB=A1=9C=20=EB=B0=94=EA=BE=B8=EA=B8=B0=EB=A1=9C=20?= =?UTF-8?q?=EA=B2=B0=EC=A0=95=ED=96=88=EC=96=B4=EC=9A=94.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/bamdoliro/maru/domain/form/domain/Form.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/bamdoliro/maru/domain/form/domain/Form.java b/src/main/java/com/bamdoliro/maru/domain/form/domain/Form.java index 24af92b1..793ee92c 100644 --- a/src/main/java/com/bamdoliro/maru/domain/form/domain/Form.java +++ b/src/main/java/com/bamdoliro/maru/domain/form/domain/Form.java @@ -195,6 +195,7 @@ public boolean isFailedNow() { public void changeToRegular(CalculateFormScoreService calculateFormScoreService) { this.changedToRegular = true; + this.type = FormType.REGULAR; Double subjectGradeScore = calculateFormScoreService.calculateSubjectGradeScore(this); this.score.updateSubjectScore(subjectGradeScore); From 48f997e74e54149b8defef1f49501912c6805e42 Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Fri, 31 May 2024 02:56:24 +0900 Subject: [PATCH 28/32] =?UTF-8?q?fix(#81)=20:=20boolean=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=20=EB=B3=80=EA=B2=BD=20-=20=EC=9A=94=EC=B2=AD?= =?UTF-8?q?=ED=95=A0=20=EB=95=8C=20=EC=9D=B8=EC=8B=9D=EC=9D=B4=20=EB=90=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EC=95=84=EC=84=9C=20boolean=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=EC=97=90=EC=84=9C=20Boolean=20=ED=83=80=EC=9E=85?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B0=94=EA=BE=B8=EC=97=88=EC=96=B4?= =?UTF-8?q?=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../maru/application/message/SendMessageUseCase.java | 9 +++++++-- .../message/dto/request/SendMessageByTypeRequest.java | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java b/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java index c3c3050a..3be58871 100644 --- a/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java +++ b/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java @@ -26,13 +26,13 @@ public void execute(SendMessageByStatusRequest request) { } public void execute(SendMessageByTypeRequest request) { - List formList = formListFilter(request.getFormType(), request.isChangeToRegular()); + List formList = formListFilter(request.getFormType(), request.getIsChangeToRegular()); List phoneNumberList = phoneNumberListConvert(formList); sendMessageService.execute(phoneNumberList, request.getText(), request.getTitle()); } - private List formListFilter(FormType formType, boolean isChangeToRegular) { + private List formListFilter(FormType formType, Boolean isChangeToRegular) { List formList; if (formType.isMeister()) { formList = formRepository.findMeisterTalentFirstRoundForm(); @@ -49,6 +49,11 @@ private List formListFilter(FormType formType, boolean isChangeToRegular) } } + System.out.println("-------------------------------------------------------------------"); + for(Form form : formList){ + System.out.println("form id : " + form.getId() + "form type : " + form.getType() + "isChangeToRegular : " + form.getChangedToRegular()); + } + return formList; } diff --git a/src/main/java/com/bamdoliro/maru/presentation/message/dto/request/SendMessageByTypeRequest.java b/src/main/java/com/bamdoliro/maru/presentation/message/dto/request/SendMessageByTypeRequest.java index f1794b0d..b33b7ba7 100644 --- a/src/main/java/com/bamdoliro/maru/presentation/message/dto/request/SendMessageByTypeRequest.java +++ b/src/main/java/com/bamdoliro/maru/presentation/message/dto/request/SendMessageByTypeRequest.java @@ -22,6 +22,6 @@ public class SendMessageByTypeRequest { private FormType formType; @NotNull(message = "필수값입니다.") - private boolean isChangeToRegular; + private Boolean isChangeToRegular; } From 1fe3954514395fe41c1b63eed306e567c836520f Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Fri, 31 May 2024 17:13:19 +0900 Subject: [PATCH 29/32] =?UTF-8?q?docs(#81)=20:=20message.adoc=20-=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=ED=95=A0=20=EB=95=8C=20=EC=9D=B8=EC=8B=9D?= =?UTF-8?q?=EC=9D=B4=20=EB=90=98=EC=A7=80=20=EC=95=8A=EC=95=84=EC=84=9C=20?= =?UTF-8?q?boolean=20=ED=83=80=EC=9E=85=EC=97=90=EC=84=9C=20Boolean=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=EC=9C=BC=EB=A1=9C=20=EB=B0=94=EA=BE=B8?= =?UTF-8?q?=EC=97=88=EC=96=B4=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/message.adoc | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/docs/asciidoc/message.adoc b/src/docs/asciidoc/message.adoc index 6835679e..5d47a65f 100644 --- a/src/docs/asciidoc/message.adoc +++ b/src/docs/asciidoc/message.adoc @@ -1,6 +1,6 @@ == 그룹별 메세지 보내기 -=== 메시지 보내기 +=== 상태에 따른 메시지 보내기 메세지를 보낼 원서의 상태를 입력해 메시지를 보낼 수 있습니다. ==== 요청 형식 @@ -21,4 +21,25 @@ include::{snippets}/message-controller-test/조회할_상태의_원서를_가진 include::{snippets}/message-controller-test/조회할_상태의_원서를_가진_학생들에게/http-response.adoc[] ===== 입력한 상태의 원서가 없거나 상태를 잘못 입력한 경우 -include::{snippets}/message-controller-test/해당제출상태인_원서가_없으면_오류가난다/http-response.adoc[] \ No newline at end of file +include::{snippets}/message-controller-test/해당제출상태인_원서가_없으면_오류가난다/http-response.adoc[] + +=== 전형에 따른 메시지 보내기 +메세지를 보낼 원서의 전형을 입력해 메시지를 보낼 수 있습니다. + +=== 요청 형식 + +==== Request Header +include::{snippets}/message-controller-test/마이스터전형과_마이스터에서_일반전형으로_바뀐_합격자를_제외한_1차_합격자들에게_메시지를_보낸다/request-headers.adoc[] + +==== Request Body +include::{snippets}/message-controller-test/마이스터전형과_마이스터에서_일반전형으로_바뀐_합격자를_제외한_1차_합격자들에게_메시지를_보낸다/request-fields.adoc[] + +==== 요청 +===== 일반전형(마이스터전형 & 마이스터 -> 일반을 제외한 모든 전형) 1차 합격자에게 메시지를 보내는 경우 +include::{snippets}/message-controller-test/마이스터전형과_마이스터에서_일반전형으로_바뀐_합격자를_제외한_1차_합격자들에게_메시지를_보낸다/http-request.adoc[] + +===== 마이스터 -> 일반 전형으로 바뀐 1차 합격자들에게 메시지를 보내는 경우 +include::{snippets}/message-controller-test/마이스터전형에서_일반전형으로_바뀐_1차_합격자들에게_메시지를_보낸다/http-request.adoc[] + +===== 마이스터전형 1차 합격자들에게 메시지를 보내는 경우 +include::{snippets}/message-controller-test/마이스터_전형_1차_합격자들에게_메시지를_보낸다/http-request.adoc[]https://xxx[] \ No newline at end of file From 7d8f19e26a8ea5784cce5c3862c4a306baca6996 Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Fri, 31 May 2024 17:14:32 +0900 Subject: [PATCH 30/32] =?UTF-8?q?feat(#81)=20:=20messageControllerTest=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20-=20/message/type=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EB=A5=BC=20=EC=B6=94=EA=B0=80=ED=96=88=EC=96=B4?= =?UTF-8?q?=EC=9A=94.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../message/MessageControllerTest.java | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java b/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java index a57e5a86..103367f4 100644 --- a/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java +++ b/src/test/java/com/bamdoliro/maru/presentation/message/MessageControllerTest.java @@ -1,8 +1,10 @@ package com.bamdoliro.maru.presentation.message; import com.bamdoliro.maru.domain.form.domain.type.FormStatus; +import com.bamdoliro.maru.domain.form.domain.type.FormType; import com.bamdoliro.maru.domain.user.domain.User; import com.bamdoliro.maru.presentation.message.dto.request.SendMessageByStatusRequest; +import com.bamdoliro.maru.presentation.message.dto.request.SendMessageByTypeRequest; import com.bamdoliro.maru.shared.fixture.AuthFixture; import com.bamdoliro.maru.shared.fixture.UserFixture; import com.bamdoliro.maru.shared.util.RestDocsTestSupport; @@ -75,4 +77,95 @@ public class MessageControllerTest extends RestDocsTestSupport { ) )); } + + @Test + void 마이스터전형과_마이스터에서_일반전형으로_바뀐_합격자를_제외한_1차_합격자들에게_메시지를_보낸다() throws Exception { + User user = UserFixture.createAdminUser(); + given(authenticationArgumentResolver.supportsParameter(any(MethodParameter.class))).willReturn(true); + given(authenticationArgumentResolver.resolveArgument(any(), any(), any(), any())).willReturn(user); + + SendMessageByTypeRequest request = new SendMessageByTypeRequest("부산소마고 공지사항", "추카추카", FormType.REGULAR, false); + willDoNothing().given(sendMessageUseCase).execute(request); + + mockMvc.perform(post("/message/type") + .header(HttpHeaders.AUTHORIZATION, AuthFixture.createAuthHeader()) + .contentType(MediaType.APPLICATION_JSON) + .content(toJson(request))) + .andExpect(status().isNoContent()) + .andDo(restDocs.document( + requestHeaders( + headerWithName(HttpHeaders.AUTHORIZATION).description("Bearer token") + ), + requestFields( + fieldWithPath("title").type(JsonFieldType.STRING).description("문자 메시지 제목"), + fieldWithPath("text").type(JsonFieldType.STRING).description("문자 메시지 내용"), + fieldWithPath("formType").type(JsonFieldType.STRING).description("메시지를 보낼 원서 전형(MEISTER_TALENT, REGULAR)"), + fieldWithPath("isChangeToRegular").type(JsonFieldType.BOOLEAN).description("만약 마이스터 -> 일반 전형이면 true 아니면 false") + ) + )); + } + + @Test + void 마이스터_전형_1차_합격자들에게_메시지를_보낸다() throws Exception { + User user = UserFixture.createAdminUser(); + given(authenticationArgumentResolver.supportsParameter(any(MethodParameter.class))).willReturn(true); + given(authenticationArgumentResolver.resolveArgument(any(), any(), any(), any())).willReturn(user); + + SendMessageByTypeRequest request = new SendMessageByTypeRequest("부산소마고 공지사항", "추카추카", FormType.MEISTER_TALENT, false); + willDoNothing().given(sendMessageUseCase).execute(request); + + mockMvc.perform(post("/message/type") + .header(HttpHeaders.AUTHORIZATION, AuthFixture.createAuthHeader()) + .contentType(MediaType.APPLICATION_JSON) + .content(toJson(request))) + .andExpect(status().isNoContent()) + + .andDo(restDocs.document()); + } + + @Test + void 마이스터전형에서_일반전형으로_바뀐_1차_합격자들에게_메시지를_보낸다() throws Exception { + User user = UserFixture.createAdminUser(); + given(authenticationArgumentResolver.supportsParameter(any(MethodParameter.class))).willReturn(true); + given(authenticationArgumentResolver.resolveArgument(any(), any(), any(), any())).willReturn(user); + + SendMessageByTypeRequest request = new SendMessageByTypeRequest("부산소마고 공지사항", "추카추카", FormType.REGULAR, true); + willDoNothing().given(sendMessageUseCase).execute(request); + + mockMvc.perform(post("/message/type") + .header(HttpHeaders.AUTHORIZATION, AuthFixture.createAuthHeader()) + .contentType(MediaType.APPLICATION_JSON) + .content(toJson(request))) + .andExpect(status().isNoContent()) + + .andDo(restDocs.document()); + } + + @Test + void 해당전형의_원서가_없다면_오류가_발생한다() throws Exception { + User user = UserFixture.createAdminUser(); + given(authenticationArgumentResolver.supportsParameter(any(MethodParameter.class))).willReturn(true); + given(authenticationArgumentResolver.resolveArgument(any(), any(), any(), any())).willReturn(user); + + SendMessageByTypeRequest request = new SendMessageByTypeRequest("부산소마고 공지사항", "오류가 발생하겠죠?", FormType.REGULAR, false); + + willThrow(new RuntimeException("원서를 찾을 수 없음")).given(sendMessageUseCase).execute(any(SendMessageByTypeRequest.class)); + + mockMvc.perform(post("/message/type") + .header(HttpHeaders.AUTHORIZATION, AuthFixture.createAuthHeader()) + .contentType(MediaType.APPLICATION_JSON) + .content(toJson(request))) + .andExpect(status().isInternalServerError()) + .andDo(restDocs.document( + requestHeaders( + headerWithName(HttpHeaders.AUTHORIZATION).description("Bearer token") + ), + requestFields( + fieldWithPath("title").type(JsonFieldType.STRING).description("문자 메시지 제목"), + fieldWithPath("text").type(JsonFieldType.STRING).description("문자 메시지 내용"), + fieldWithPath("formType").type(JsonFieldType.STRING).description("메시지를 보낼 원서 전형(MEISTER_TALENT, REGULAR)"), + fieldWithPath("isChangeToRegular").type(JsonFieldType.BOOLEAN).description("만약 마이스터 -> 일반 전형이면 true 아니면 false") + ) + )); + } } From dc71040e12282355aa94120fffd77152a865d23a Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Fri, 31 May 2024 17:21:41 +0900 Subject: [PATCH 31/32] =?UTF-8?q?fix(#81)=20:=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C=20-=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EB=A5=BC=20=EC=9C=84=ED=95=9C=20pri?= =?UTF-8?q?ntln=EC=BD=94=EB=93=9C=EB=A5=BC=20=EC=82=AD=EC=A0=9C=ED=96=88?= =?UTF-8?q?=EC=96=B4=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../maru/application/message/SendMessageUseCase.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java b/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java index 3be58871..814e0745 100644 --- a/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java +++ b/src/main/java/com/bamdoliro/maru/application/message/SendMessageUseCase.java @@ -49,11 +49,6 @@ private List formListFilter(FormType formType, Boolean isChangeToRegular) } } - System.out.println("-------------------------------------------------------------------"); - for(Form form : formList){ - System.out.println("form id : " + form.getId() + "form type : " + form.getType() + "isChangeToRegular : " + form.getChangedToRegular()); - } - return formList; } From ce3304eb9951d94fe776693080837ab6ecd1172d Mon Sep 17 00:00:00 2001 From: jyj1289 Date: Fri, 31 May 2024 17:35:39 +0900 Subject: [PATCH 32/32] =?UTF-8?q?feat(#81)=20:=20=EC=A0=84=ED=98=95?= =?UTF-8?q?=EB=B3=84=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EB=B3=B4=EB=82=B4?= =?UTF-8?q?=EA=B8=B0=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=20-=20=EC=A0=84=ED=98=95=EB=B3=84=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=20=EB=B3=B4=EB=82=B4=EA=B8=B0=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=EB=A5=BC=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=ED=96=88=EC=96=B4=EC=9A=94.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../message/SendMessageUseCaseTest.java | 95 +++++++++++++++++-- 1 file changed, 85 insertions(+), 10 deletions(-) diff --git a/src/test/java/com/bamdoliro/maru/application/message/SendMessageUseCaseTest.java b/src/test/java/com/bamdoliro/maru/application/message/SendMessageUseCaseTest.java index d2163a11..8eba4f93 100644 --- a/src/test/java/com/bamdoliro/maru/application/message/SendMessageUseCaseTest.java +++ b/src/test/java/com/bamdoliro/maru/application/message/SendMessageUseCaseTest.java @@ -3,10 +3,12 @@ import com.bamdoliro.maru.domain.form.domain.Form; import com.bamdoliro.maru.domain.form.domain.type.FormStatus; import com.bamdoliro.maru.domain.form.domain.type.FormType; +import com.bamdoliro.maru.domain.form.service.CalculateFormScoreService; import com.bamdoliro.maru.infrastructure.message.SendMessageService; import com.bamdoliro.maru.infrastructure.message.exception.FailedToSendException; import com.bamdoliro.maru.infrastructure.persistence.form.FormRepository; import com.bamdoliro.maru.presentation.message.dto.request.SendMessageByStatusRequest; +import com.bamdoliro.maru.presentation.message.dto.request.SendMessageByTypeRequest; import com.bamdoliro.maru.shared.fixture.FormFixture; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -33,8 +35,11 @@ public class SendMessageUseCaseTest { @Mock private FormRepository formRepository; + @Mock + private CalculateFormScoreService calculateFormScoreService; + @Test - void 원서를_최종제출한_학생들에게_메시지를_보낸다(){ + void 원서를_최종제출한_학생들에게_메시지를_보낸다() { //given Form form = FormFixture.createForm(FormType.REGULAR); @@ -51,7 +56,7 @@ public class SendMessageUseCaseTest { } @Test - void 원서를_승인받은_학생들에게_메시지를_보낸다(){ + void 원서를_승인받은_학생들에게_메시지를_보낸다() { //given Form form = FormFixture.createForm(FormType.REGULAR); @@ -68,7 +73,7 @@ public class SendMessageUseCaseTest { } @Test - void 원서를_반려받은_학생들에게_메시지를_보낸다(){ + void 원서를_반려받은_학생들에게_메시지를_보낸다() { //given Form form = FormFixture.createForm(FormType.REGULAR); @@ -85,7 +90,7 @@ public class SendMessageUseCaseTest { } @Test - void 원서를_접수한_학생들에게_메시지를_보낸다(){ + void 원서를_접수한_학생들에게_메시지를_보낸다() { //given Form form = FormFixture.createForm(FormType.REGULAR); @@ -102,7 +107,7 @@ public class SendMessageUseCaseTest { } @Test - void 제1차_합격자들에게_메시지를_보낸다(){ + void 제1차_합격자들에게_메시지를_보낸다() { //given Form form = FormFixture.createForm(FormType.REGULAR); @@ -119,7 +124,7 @@ public class SendMessageUseCaseTest { } @Test - void 제1차_불합격자들에게_메시지를_보낸다(){ + void 제1차_불합격자들에게_메시지를_보낸다() { //given Form form = FormFixture.createForm(FormType.REGULAR); @@ -136,7 +141,7 @@ public class SendMessageUseCaseTest { } @Test - void 제2차전형에_불참한_학생들에게_메시지를_보낸다(){ + void 제2차전형에_불참한_학생들에게_메시지를_보낸다() { //given Form form = FormFixture.createForm(FormType.REGULAR); @@ -153,7 +158,7 @@ public class SendMessageUseCaseTest { } @Test - void 최종합격자들에게_메시지를_보낸다(){ + void 최종합격자들에게_메시지를_보낸다() { //given Form form = FormFixture.createForm(FormType.REGULAR); @@ -170,7 +175,7 @@ public class SendMessageUseCaseTest { } @Test - void 최종불합격자들에게_메시지를_보낸다(){ + void 최종불합격자들에게_메시지를_보낸다() { //given Form form = FormFixture.createForm(FormType.REGULAR); @@ -187,7 +192,63 @@ public class SendMessageUseCaseTest { } @Test - void 보낼메시지대상이_존재하지_않으면_오류가_발생한다(){ + void 마이스터전형과_마이스터전형에서_일반전형으로_바뀐_합격자를_제외한_1차_전형_합격자들에게_메시지를_보낸다() { + + //given + Form form = FormFixture.createForm(FormType.REGULAR); + form.firstPass(); + given(formRepository.findNotExistsMeisterTalentFirstRoundForm()).willReturn(List.of(form)); + SendMessageByTypeRequest request = new SendMessageByTypeRequest("부산소마고 공지사항", "살려줘요..", FormType.REGULAR, false); + + //when + sendMessageUseCase.execute(request); + + //then + verify(formRepository, times(1)).findNotExistsMeisterTalentFirstRoundForm(); + verify(sendMessageService, times(1)).execute(List.of(form.getUser().getPhoneNumber()), request.getText(), request.getTitle()); + } + + @Test + void 마이스터전형_1차_합격자들에게_메시지를_보낸다() { + + //given + Form form = FormFixture.createForm(FormType.MEISTER_TALENT); + form.firstPass(); + given(formRepository.findMeisterTalentFirstRoundForm()).willReturn(List.of(form)); + SendMessageByTypeRequest request = new SendMessageByTypeRequest("부산소마고 공지사항", "배고파요...", FormType.MEISTER_TALENT, false); + + //when + sendMessageUseCase.execute(request); + + //then + verify(formRepository, times(1)).findMeisterTalentFirstRoundForm(); + verify(sendMessageService, times(1)).execute(List.of(form.getUser().getPhoneNumber()), request.getText(), request.getTitle()); + } + + @Test + void 마이스터전형에서_일반전형으로_바뀐_1차_합격자들에게_메시지를_보낸다() { + + //given + Form form = FormFixture.createForm(FormType.MEISTER_TALENT); + + when(calculateFormScoreService.calculateSubjectGradeScore(any())).thenReturn(100.0); + when(formRepository.findNotExistsMeisterTalentFirstRoundForm()).thenReturn(List.of(form)); + + form.firstPass(); + form.changeToRegular(calculateFormScoreService); + SendMessageByTypeRequest request = new SendMessageByTypeRequest("부산소마고 공지사항", "헤헤", FormType.REGULAR, true); + + //when + sendMessageUseCase.execute(request); + System.out.println(form.getUser().getPhoneNumber()); + + //then + verify(formRepository, times(1)).findNotExistsMeisterTalentFirstRoundForm(); + verify(sendMessageService, times(1)).execute(List.of(form.getUser().getPhoneNumber()), request.getText(), request.getTitle()); + } + + @Test + void 상태에_따라_메시지를_보낼_대상이_존재하지_않으면_오류가_발생한다() { //given willThrow(new FailedToSendException()).given(formRepository).findByStatus(FormStatus.SUBMITTED); @@ -199,4 +260,18 @@ public class SendMessageUseCaseTest { verify(formRepository, times(1)).findByStatus(FormStatus.SUBMITTED); verify(sendMessageService, never()).execute(anyList(), anyString(), anyString()); } + + @Test + void 조회할_전형대상이_없으면_오류가_발생한다() { + + //given + willThrow(new FailedToSendException()).given(formRepository).findMeisterTalentFirstRoundForm(); + SendMessageByTypeRequest request = new SendMessageByTypeRequest("부산소마고 공지사항", "오늘은 꼭 롯데가..!", FormType.MEISTER_TALENT, false); + + //when and then + Assertions.assertThrows(FailedToSendException.class, + () -> sendMessageUseCase.execute(request)); + verify(formRepository, times(1)).findMeisterTalentFirstRoundForm(); + verify(sendMessageService, never()).execute(anyList(), anyString(), anyString()); + } }