From ea07ae43413b2e1ee76decb616b116e8fca90691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=95=9C=EA=B4=80=ED=9D=AC?= Date: Sat, 3 Aug 2024 11:55:10 +0900 Subject: [PATCH] =?UTF-8?q?refactor(Email):=20=EB=AF=B8=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=20API=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/email/api/EmailController.java | 53 ------------------- .../email/application/EmailService.java | 21 -------- 2 files changed, 74 deletions(-) delete mode 100644 src/main/java/page/clab/api/global/common/email/api/EmailController.java diff --git a/src/main/java/page/clab/api/global/common/email/api/EmailController.java b/src/main/java/page/clab/api/global/common/email/api/EmailController.java deleted file mode 100644 index 0e08f541e..000000000 --- a/src/main/java/page/clab/api/global/common/email/api/EmailController.java +++ /dev/null @@ -1,53 +0,0 @@ -package page.clab.api.global.common.email.api; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.http.MediaType; -import org.springframework.security.access.annotation.Secured; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; -import page.clab.api.global.common.dto.ApiResponse; -import page.clab.api.global.common.email.application.EmailService; -import page.clab.api.global.common.email.dto.request.EmailDto; - -import java.util.List; -import java.util.concurrent.CompletableFuture; - -@RestController -@RequestMapping("/api/v1/emails") -@RequiredArgsConstructor -@Tag(name = "Email", description = "이메일") -@Slf4j -public class EmailController { - - private final EmailService emailService; - - @Operation(summary = "[A] 메일 전송", description = "ROLE_ADMIN 이상의 권한이 필요함") - @Secured({ "ROLE_ADMIN", "ROLE_SUPER" }) - @PostMapping(path = "", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public ApiResponse> broadcastEmail( - EmailDto emailDto, - @RequestParam(name = "multipartFile", required = false) List files - ) { - CompletableFuture> emailTask = CompletableFuture.supplyAsync(() -> emailService.broadcastEmail(emailDto, files)); - List successfulAddresses = emailTask.join(); - return ApiResponse.success(successfulAddresses); - } - - @Operation(summary = "[A] 전체 메일 전송", description = "ROLE_ADMIN 이상의 권한이 필요함") - @Secured({ "ROLE_ADMIN", "ROLE_SUPER" }) - @PostMapping(path = "/all", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public ApiResponse> broadcastEmailToAllMember( - EmailDto emailDto, - @RequestParam(name = "multipartFile", required = false) List files - ) { - CompletableFuture> emailTask = CompletableFuture.supplyAsync(() -> emailService.broadcastEmailToAllMember(emailDto, files)); - List successfulEmails = emailTask.join(); - return ApiResponse.success(successfulEmails); - } -} diff --git a/src/main/java/page/clab/api/global/common/email/application/EmailService.java b/src/main/java/page/clab/api/global/common/email/application/EmailService.java index 0822a285b..b5c9985b5 100644 --- a/src/main/java/page/clab/api/global/common/email/application/EmailService.java +++ b/src/main/java/page/clab/api/global/common/email/application/EmailService.java @@ -9,7 +9,6 @@ import org.springframework.web.multipart.MultipartFile; import org.thymeleaf.context.Context; import org.thymeleaf.spring6.SpringTemplateEngine; -import page.clab.api.domain.memberManagement.member.application.dto.shared.MemberEmailInfoDto; import page.clab.api.domain.memberManagement.member.domain.Member; import page.clab.api.external.memberManagement.member.application.port.ExternalRetrieveMemberUseCase; import page.clab.api.global.common.email.domain.EmailTemplateType; @@ -55,26 +54,6 @@ public List broadcastEmail(EmailDto emailDto, List multip return successfulAddresses; } - public List broadcastEmailToAllMember(EmailDto emailDto, List multipartFiles) { - List convertedFiles = multipartFiles != null && !multipartFiles.isEmpty() ? - convertMultipartFiles(multipartFiles) : null; - - List memberInfos = externalRetrieveMemberUseCase.getMembers(); - - List successfulEmails = Collections.synchronizedList(new ArrayList<>()); - - memberInfos.parallelStream().forEach(member -> { - try { - String emailContent = generateEmailContent(emailDto, member.getMemberName()); - emailAsyncService.sendEmailAsync(member.getEmail(), emailDto.getSubject(), emailContent, convertedFiles, emailDto.getEmailTemplateType()); - successfulEmails.add(member.getEmail()); - } catch (MessagingException e) { - throw new MessageSendingFailedException(member.getEmail() + "에게 이메일을 보내는데 실패했습니다."); - } - }); - return successfulEmails; - } - public void broadcastEmailToApprovedMember(Member member, String password) { String subject = "C-Lab 계정 발급 안내"; String content = """