diff --git a/mashup-admin/src/main/java/kr/mashup/branding/config/security/SecurityConfig.java b/mashup-admin/src/main/java/kr/mashup/branding/config/security/SecurityConfig.java index 3dea662ad..ef9653b8c 100644 --- a/mashup-admin/src/main/java/kr/mashup/branding/config/security/SecurityConfig.java +++ b/mashup-admin/src/main/java/kr/mashup/branding/config/security/SecurityConfig.java @@ -1,13 +1,18 @@ package kr.mashup.branding.config.security; -import java.util.Arrays; -import java.util.stream.Collectors; - +import com.fasterxml.jackson.databind.ObjectMapper; +import kr.mashup.branding.config.jwt.JwtService; +import kr.mashup.branding.domain.ResultCode; +import kr.mashup.branding.domain.adminmember.entity.Position; +import kr.mashup.branding.service.adminmember.AdminMemberService; +import kr.mashup.branding.ui.ApiResponse; +import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.security.authentication.ProviderManager; +import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.WebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; @@ -17,17 +22,12 @@ import org.springframework.web.cors.CorsConfigurationSource; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; -import com.fasterxml.jackson.databind.ObjectMapper; - -import kr.mashup.branding.config.jwt.JwtService; -import kr.mashup.branding.domain.ResultCode; -import kr.mashup.branding.service.adminmember.AdminMemberService; -import kr.mashup.branding.domain.adminmember.entity.Position; -import kr.mashup.branding.ui.ApiResponse; -import lombok.RequiredArgsConstructor; +import java.util.Arrays; +import java.util.stream.Collectors; @RequiredArgsConstructor @Configuration +@EnableMethodSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { public static final String[] AUTHORITY_NAMES = Arrays.stream(Position.values()).map(Enum::name) .collect(Collectors.toList()).toArray(new String[Position.values().length]); @@ -111,4 +111,4 @@ public CorsConfigurationSource corsConfigurationSource() { source.registerCorsConfiguration("/**", configuration); return source; } -} \ No newline at end of file +} diff --git a/mashup-admin/src/main/java/kr/mashup/branding/facade/application/AdminApplicationFacadeService.java b/mashup-admin/src/main/java/kr/mashup/branding/facade/application/AdminApplicationFacadeService.java index a6e64b2d6..3961a75d5 100644 --- a/mashup-admin/src/main/java/kr/mashup/branding/facade/application/AdminApplicationFacadeService.java +++ b/mashup-admin/src/main/java/kr/mashup/branding/facade/application/AdminApplicationFacadeService.java @@ -7,12 +7,10 @@ import kr.mashup.branding.domain.application.result.UpdateApplicationResultVo; import kr.mashup.branding.domain.email.EmailRequest; import kr.mashup.branding.domain.generation.Generation; -import kr.mashup.branding.domain.notification.sms.SmsRequest; import kr.mashup.branding.service.adminmember.AdminMemberService; import kr.mashup.branding.service.application.ApplicationService; import kr.mashup.branding.service.email.EmailNotificationService; import kr.mashup.branding.service.generation.GenerationService; -import kr.mashup.branding.service.notification.NotificationService; import kr.mashup.branding.ui.application.vo.ApplicationDetailResponse; import kr.mashup.branding.ui.application.vo.ApplicationSimpleResponse; import lombok.RequiredArgsConstructor; @@ -34,7 +32,6 @@ public class AdminApplicationFacadeService { private final AdminMemberService adminMemberService; private final ApplicationService applicationService; private final GenerationService generationService; - private final NotificationService notificationService; private final EmailNotificationService emailNotificationService; public Page getApplications(Long adminMemberId, ApplicationQueryRequest applicationQueryRequest) { @@ -52,13 +49,10 @@ public ApplicationDetailResponse getApplicationDetail(Long adminMemberId, Long a final AdminMember adminMember = adminMemberService.getByAdminMemberId(adminMemberId); final Application application = applicationService.getApplicationFromAdmin(adminMember, applicationId); - final List smsRequests - = notificationService.getSmsRequestsByApplicantId(application.getApplicant().getApplicantId()); - final List emailRequests = emailNotificationService.getEmailRequestsByApplicationId(application.getApplicationId()); - return ApplicationDetailResponse.of(application, smsRequests, emailRequests); + return ApplicationDetailResponse.of(application, emailRequests); } @Transactional diff --git a/mashup-admin/src/main/java/kr/mashup/branding/facade/application/ApplicationDetailVo.java b/mashup-admin/src/main/java/kr/mashup/branding/facade/application/ApplicationDetailVo.java deleted file mode 100644 index 0f255da3c..000000000 --- a/mashup-admin/src/main/java/kr/mashup/branding/facade/application/ApplicationDetailVo.java +++ /dev/null @@ -1,13 +0,0 @@ -package kr.mashup.branding.facade.application; - -import java.util.List; - -import kr.mashup.branding.domain.application.Application; -import kr.mashup.branding.domain.notification.sms.SmsRequest; -import lombok.Value; - -@Value(staticConstructor = "of") -public class ApplicationDetailVo { - Application application; - List smsRequests; -} diff --git a/mashup-admin/src/main/java/kr/mashup/branding/facade/notification/NotificationFacadeService.java b/mashup-admin/src/main/java/kr/mashup/branding/facade/notification/NotificationFacadeService.java deleted file mode 100644 index 7a32ea194..000000000 --- a/mashup-admin/src/main/java/kr/mashup/branding/facade/notification/NotificationFacadeService.java +++ /dev/null @@ -1,107 +0,0 @@ -package kr.mashup.branding.facade.notification; - -import kr.mashup.branding.domain.adminmember.entity.AdminMember; -import kr.mashup.branding.domain.applicant.Applicant; -import kr.mashup.branding.domain.application.Application; -import kr.mashup.branding.domain.generation.Generation; -import kr.mashup.branding.domain.notification.Notification; -import kr.mashup.branding.domain.notification.sms.SmsRequest; -import kr.mashup.branding.domain.notification.sms.vo.SmsSendRequestVo; -import kr.mashup.branding.domain.notification.sms.vo.SmsSendResultVo; -import kr.mashup.branding.service.adminmember.AdminMemberService; -import kr.mashup.branding.service.applicant.ApplicantService; -import kr.mashup.branding.service.application.ApplicationService; -import kr.mashup.branding.service.generation.GenerationService; -import kr.mashup.branding.service.notification.NotificationEvent; -import kr.mashup.branding.service.notification.NotificationEventPublisher; -import kr.mashup.branding.service.notification.NotificationEventType; -import kr.mashup.branding.service.notification.NotificationService; -import kr.mashup.branding.ui.notification.vo.NotificationDetailResponse; -import kr.mashup.branding.ui.notification.vo.NotificationSimpleResponse; -import kr.mashup.branding.ui.notification.vo.SmsSendRequest; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.Assert; - -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -@Slf4j -@Service -@Transactional -@RequiredArgsConstructor -public class NotificationFacadeService { - private final AdminMemberService adminMemberService; - private final NotificationService notificationService; - private final ApplicantService applicantService; - private final GenerationService generationService; - private final NotificationEventPublisher notificationEventPublisher; - private final ApplicationService applicationService; - - public void createSmsNotification(Long adminMemberId, Integer generationNumber, SmsSendRequest smsSendRequest) { - - final AdminMember adminMember = adminMemberService.getByAdminMemberId(adminMemberId); - final List recipientApplicants = applicantService.getApplicants(smsSendRequest.getApplicantIds()); - - // 요청 정보 생성 -> Notification CREATED 상태 - final SmsSendRequestVo smsSendRequestVo - = SmsSendRequestVo.of(smsSendRequest.getName(), smsSendRequest.getContent()); - final Generation generation = generationService.getByNumberOrThrow(generationNumber); - final Notification notification - = notificationService.createSmsNotification(adminMember, generation, recipientApplicants, smsSendRequestVo); - // 문자 발송 비동기 이벤트 퍼블리싱 - final NotificationEvent notificationEvent - = NotificationEvent.of(notification.getNotificationId(), NotificationEventType.CREATED); - notificationEventPublisher.publishNotificationEvent(notificationEvent); - } - - public void updateSmsStatus(Long notificationId, SmsSendResultVo smsSendResultVo) { - notificationService.updateSmsStatus(notificationId, smsSendResultVo); - } - - public Page getNotifications( - Long adminMemberId, - Integer generationNumber, - String searchWord, - Pageable pageable) { - - return notificationService - .getNotifications(adminMemberId, searchWord, pageable) - .map(NotificationSimpleResponse::from); - } - - public NotificationDetailResponse getNotificationDetail(Long adminMemberId, Long notificationId) { - - final Notification notification = notificationService.getNotification(notificationId); - final Generation generation = notification.getGeneration(); - final List recipients = notification - .getSmsRequests() - .stream() - .map(it -> it.getRecipientApplicant()).collect(Collectors.toList()); - // 1기수 1지원 가정 - final Map applicationMap = applicationService.getApplications(generation, recipients); - - return NotificationDetailResponse.of(notification, applicationMap); - } - - - /** - * 지원자 1명에 대한 문자 발송 이력 조회 - * - * @param adminMemberId 어드민 멤버 식별자 - * @param applicantId 지원자 식별자 - * @return 지원자에게 발송한 문자 발송 이력 - */ - public List getSmsRequests(Long adminMemberId, Long applicantId) { - - Assert.notNull(adminMemberId, "'adminMemberId' must not be null"); - return notificationService.getSmsRequestsByApplicantId(applicantId); - } - - -} diff --git a/mashup-admin/src/main/java/kr/mashup/branding/facade/notification/SmsFacadeService.java b/mashup-admin/src/main/java/kr/mashup/branding/facade/notification/SmsFacadeService.java deleted file mode 100644 index ea6760eb6..000000000 --- a/mashup-admin/src/main/java/kr/mashup/branding/facade/notification/SmsFacadeService.java +++ /dev/null @@ -1,27 +0,0 @@ -package kr.mashup.branding.facade.notification; - -import kr.mashup.branding.domain.notification.Notification; -import kr.mashup.branding.domain.notification.exception.NotificationRequestInvalidException; -import kr.mashup.branding.domain.notification.sms.vo.SmsRequestVo; -import kr.mashup.branding.service.notification.NotificationService; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@Transactional -@RequiredArgsConstructor -public class SmsFacadeService { - private final NotificationService notificationService; - - public SmsRequestVo getSmsMetaData(Long notificationId){ - - final Notification notification = notificationService.getNotification(notificationId); - if(!notification.getSender().getPhoneNumberRegistered()){ - throw new NotificationRequestInvalidException( - "Sender's phoneNumber must be registered to NHN Cloud Notification Service"); - } - return SmsRequestVo.from(notification); - - } -} diff --git a/mashup-admin/src/main/java/kr/mashup/branding/ui/AdminControllerAdvice.java b/mashup-admin/src/main/java/kr/mashup/branding/ui/AdminControllerAdvice.java index e16ff2493..e7d37e7e2 100644 --- a/mashup-admin/src/main/java/kr/mashup/branding/ui/AdminControllerAdvice.java +++ b/mashup-admin/src/main/java/kr/mashup/branding/ui/AdminControllerAdvice.java @@ -1,8 +1,10 @@ package kr.mashup.branding.ui; -import java.security.Principal; - +import kr.mashup.branding.domain.ResultCode; +import kr.mashup.branding.domain.exception.*; +import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; +import org.springframework.security.access.AccessDeniedException; import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; import org.springframework.web.HttpMediaTypeException; import org.springframework.web.bind.MethodArgumentNotValidException; @@ -12,14 +14,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; -import kr.mashup.branding.domain.ResultCode; -import kr.mashup.branding.domain.exception.BadRequestException; -import kr.mashup.branding.domain.exception.ForbiddenException; -import kr.mashup.branding.domain.exception.InternalServerErrorException; -import kr.mashup.branding.domain.exception.NotFoundException; -import kr.mashup.branding.domain.exception.ServiceUnavailableException; -import kr.mashup.branding.domain.exception.UnauthorizedException; -import lombok.extern.slf4j.Slf4j; +import java.security.Principal; @Slf4j @RestControllerAdvice @@ -107,6 +102,13 @@ public ApiResponse handleIllegalArgumentException(Exception e) { return ApiResponse.failure(ResultCode.BAD_REQUEST, e.getMessage()); } + @ExceptionHandler(AccessDeniedException.class) + @ResponseStatus(HttpStatus.FORBIDDEN) + public ApiResponse handleAccessDeniedException(AccessDeniedException e) { + log.error("handleAccessDeniedException", e); + return ApiResponse.failure(ResultCode.FORBIDDEN); + } + @ExceptionHandler(Exception.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) public ApiResponse handleException(Exception e) { diff --git a/mashup-admin/src/main/java/kr/mashup/branding/ui/adminmember/AdminMemberController.java b/mashup-admin/src/main/java/kr/mashup/branding/ui/adminmember/AdminMemberController.java index 6aac1d220..6bbcc0f24 100644 --- a/mashup-admin/src/main/java/kr/mashup/branding/ui/adminmember/AdminMemberController.java +++ b/mashup-admin/src/main/java/kr/mashup/branding/ui/adminmember/AdminMemberController.java @@ -8,6 +8,7 @@ import kr.mashup.branding.ui.adminmember.vo.AdminMemberResponse; import kr.mashup.branding.ui.adminmember.vo.LoginRequest; import kr.mashup.branding.ui.adminmember.vo.LoginResponse; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import kr.mashup.branding.facade.adminmember.AdminMemberFacadeService; @@ -88,6 +89,7 @@ public ApiResponse> readAdminMembers() { /** 어드민 멤버 생성 */ @ApiOperation("어드민 멤버 생성") + @PreAuthorize("hasAnyAuthority('MASHUP_LEADER', 'MASHUP_SUBLEADER')") @PostMapping public ApiResponse createAdminMember(@RequestBody AdminMemberSignUpCommand signUpCommand) { AdminMemberVo data = adminMemberFacadeService.createAdminMember(signUpCommand); diff --git a/mashup-admin/src/main/java/kr/mashup/branding/ui/adminmember/vo/AdminMemberResponse.java b/mashup-admin/src/main/java/kr/mashup/branding/ui/adminmember/vo/AdminMemberResponse.java index 36f8e831a..2d96825d2 100644 --- a/mashup-admin/src/main/java/kr/mashup/branding/ui/adminmember/vo/AdminMemberResponse.java +++ b/mashup-admin/src/main/java/kr/mashup/branding/ui/adminmember/vo/AdminMemberResponse.java @@ -11,9 +11,8 @@ public class AdminMemberResponse { private Long adminMemberId; private String username; private Position position; - private String phoneNumber; public static AdminMemberResponse from(AdminMemberVo adminMemberVo){ - return AdminMemberResponse.of(adminMemberVo.getAdminMemberId(), adminMemberVo.getUsername(), adminMemberVo.getPosition(), adminMemberVo.getPhoneNumber()); + return AdminMemberResponse.of(adminMemberVo.getAdminMemberId(), adminMemberVo.getUsername(), adminMemberVo.getPosition()); } } diff --git a/mashup-admin/src/main/java/kr/mashup/branding/ui/application/vo/ApplicationDetailResponse.java b/mashup-admin/src/main/java/kr/mashup/branding/ui/application/vo/ApplicationDetailResponse.java index 0a0a5abbd..3e13a4664 100644 --- a/mashup-admin/src/main/java/kr/mashup/branding/ui/application/vo/ApplicationDetailResponse.java +++ b/mashup-admin/src/main/java/kr/mashup/branding/ui/application/vo/ApplicationDetailResponse.java @@ -1,10 +1,5 @@ package kr.mashup.branding.ui.application.vo; -import java.time.LocalDateTime; -import java.util.Comparator; -import java.util.List; -import java.util.stream.Collectors; - import kr.mashup.branding.domain.applicant.Applicant; import kr.mashup.branding.domain.application.Application; import kr.mashup.branding.domain.application.confirmation.ApplicantConfirmationStatus; @@ -12,16 +7,18 @@ import kr.mashup.branding.domain.application.form.ApplicationForm; import kr.mashup.branding.domain.application.form.Question; import kr.mashup.branding.domain.email.EmailRequest; -import kr.mashup.branding.domain.notification.sms.SmsRequest; import kr.mashup.branding.domain.team.Team; import kr.mashup.branding.ui.applicant.ApplicantResponse; import kr.mashup.branding.ui.application.form.vo.QuestionResponse; -import kr.mashup.branding.ui.emailnotification.vo.EmailRequestResponse; -import kr.mashup.branding.ui.notification.vo.SmsRequestDetailResponse; import kr.mashup.branding.ui.team.vo.TeamResponse; import lombok.AllArgsConstructor; import lombok.Data; +import java.time.LocalDateTime; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + @Data @AllArgsConstructor public class ApplicationDetailResponse { @@ -36,12 +33,10 @@ public class ApplicationDetailResponse { private LocalDateTime submittedAt; private LocalDateTime createdAt; private LocalDateTime updatedAt; - private List smsRequests; private List applicationEmailResponses; public static ApplicationDetailResponse of( Application application, - List smsRequests, List emailRequests){ final Confirmation confirmation = application.getConfirmation(); @@ -50,12 +45,6 @@ public static ApplicationDetailResponse of( final Team team = applicationForm.getTeam(); final List questions = applicationForm.getQuestions(); - final List smsRequestDetailResponses = smsRequests - .stream() - .sorted(Comparator.comparing(SmsRequest::getCreatedAt).reversed()) - .map(it -> SmsRequestDetailResponse.of(it, team)) - .collect(Collectors.toList()); - final List emailRequestResponses = emailRequests .stream() .sorted(Comparator.comparing(EmailRequest::getCreatedAt).reversed()) @@ -84,7 +73,6 @@ public static ApplicationDetailResponse of( application.getSubmittedAt(), // 제출 일시 application.getCreatedAt(), // 생성 일시 application.getUpdatedAt(), // 수정 일시 - smsRequestDetailResponses, // sms 발송 내역 emailRequestResponses // 이메일 발송 내역 ); } diff --git a/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/NotificationController.java b/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/NotificationController.java deleted file mode 100644 index 3aabd9ec5..000000000 --- a/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/NotificationController.java +++ /dev/null @@ -1,74 +0,0 @@ -package kr.mashup.branding.ui.notification; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import kr.mashup.branding.EmptyResponse; -import kr.mashup.branding.facade.notification.NotificationFacadeService; -import kr.mashup.branding.ui.ApiResponse; -import kr.mashup.branding.ui.notification.vo.NotificationDetailResponse; -import kr.mashup.branding.ui.notification.vo.NotificationSimpleResponse; -import kr.mashup.branding.ui.notification.vo.SmsSendRequest; -import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import springfox.documentation.annotations.ApiIgnore; - -import java.util.List; - -@Api(tags = "문자 발송 API") -@RequiredArgsConstructor -@RestController -@RequestMapping("/api/v1/notifications") -public class NotificationController { - - private final NotificationFacadeService notificationFacadeService; - - // 디자인 상 SMS 발송 -> 발송 내역으로 이동하시겠습니까? -> 발송 목록 조회 순. - // 굳이 응답 결과를 NotificationDetailResponse 로 조립해서 보낼 필요 없다. - @ApiOperation("SMS 발송") - @PostMapping("/sms/send") - public ApiResponse sendSms( - @ApiIgnore @ModelAttribute("adminMemberId") Long adminMemberId, - @RequestParam(defaultValue = "13", required = false) Integer generationNumber, - @RequestBody SmsSendRequest smsSendRequest - ) { - notificationFacadeService.createSmsNotification(adminMemberId, generationNumber, smsSendRequest); - - return ApiResponse.success(EmptyResponse.of()); - } - - - @ApiOperation("발송내역 목록조회") - @GetMapping - public ApiResponse> getNotifications( - @ApiIgnore @ModelAttribute("adminMemberId") Long adminMemberId, - @RequestParam(defaultValue = "13", required = false) Integer generationNumber, - @RequestParam(required = false) String searchWord, - Pageable pageable - ) { - final Page responses - = notificationFacadeService.getNotifications(adminMemberId,generationNumber, searchWord, pageable); - - return ApiResponse.success(responses); - } - //지원 이력이 없는 사람에게 문자 보낼 시 오류 발생 - @ApiOperation("발송내역 상세조회") - @GetMapping("/{notificationId}") - public ApiResponse getNotification( - @ApiIgnore @ModelAttribute("adminMemberId") Long adminMemberId, - @PathVariable Long notificationId - ) { - final NotificationDetailResponse response - = notificationFacadeService.getNotificationDetail(adminMemberId, notificationId); - - return ApiResponse.success(response); - } -} diff --git a/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/NotificationEventListener.java b/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/NotificationEventListener.java deleted file mode 100644 index ace0c6cfd..000000000 --- a/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/NotificationEventListener.java +++ /dev/null @@ -1,53 +0,0 @@ -package kr.mashup.branding.ui.notification; - -import kr.mashup.branding.config.async.ThreadPoolName; -import kr.mashup.branding.domain.notification.sms.vo.SmsRequestVo; -import kr.mashup.branding.domain.notification.sms.vo.SmsSendResultVo; -import kr.mashup.branding.facade.notification.NotificationFacadeService; -import kr.mashup.branding.facade.notification.SmsFacadeService; -import kr.mashup.branding.service.notification.NotificationEvent; -import kr.mashup.branding.service.notification.sms.SmsService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.transaction.event.TransactionPhase; -import org.springframework.transaction.event.TransactionalEventListener; - -@Slf4j -@Component -@RequiredArgsConstructor -public class NotificationEventListener { - - private final SmsFacadeService smsFacadeService; - private final NotificationFacadeService notificationFacadeService; - private final SmsService smsService; - - // 문자 발송 비동기 이벤트 처리 로직 - @Async(value = ThreadPoolName.EMAIL_SEND_THREAD_POOL) - @Transactional(propagation = Propagation.NEVER) - @TransactionalEventListener( - phase = TransactionPhase.AFTER_COMMIT, - condition = "#event.type eq T(kr.mashup.branding.service.notification.NotificationEventType).CREATED") - public void handleSendSms(NotificationEvent event){ - log.info("handle send sms notification event with notification id : {}", event.getNotificationId()); - final Long notificationId = event.getNotificationId(); - final SmsRequestVo smsRequestVo = smsFacadeService.getSmsMetaData(notificationId); - - SmsSendResultVo smsSendResultVo; - - try { - smsSendResultVo = smsService.send(smsRequestVo); - } catch (Exception e) { - log.error("Failed to send sms. notificationId: {}", notificationId, e); - smsSendResultVo = SmsSendResultVo.UNKNOWN; - } - - notificationFacadeService.updateSmsStatus(notificationId,smsSendResultVo); - } - - - -} diff --git a/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/SmsWhitelistController.java b/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/SmsWhitelistController.java deleted file mode 100644 index 74b9edd53..000000000 --- a/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/SmsWhitelistController.java +++ /dev/null @@ -1,47 +0,0 @@ -package kr.mashup.branding.ui.notification; - -import java.util.List; - -import org.springframework.context.annotation.Profile; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import kr.mashup.branding.service.notification.sms.SmsWhitelistService; -import kr.mashup.branding.ui.ApiResponse; -import lombok.RequiredArgsConstructor; - -@Profile("!production") -@RestController -@RequestMapping("/api/v1/notifications/sms/whitelist") -@RequiredArgsConstructor -public class SmsWhitelistController { - private final SmsWhitelistService smsWhitelistService; - - @GetMapping - public ApiResponse> getAll() { - return ApiResponse.success( - smsWhitelistService.getAll() - ); - } - - @PostMapping("/{phoneNumber}") - public ApiResponse add( - @PathVariable String phoneNumber - ) { - return ApiResponse.success( - smsWhitelistService.add(phoneNumber) - ); - } - - @DeleteMapping("/{phoneNumber}") - public ApiResponse remove( - @PathVariable String phoneNumber - ) { - smsWhitelistService.remove(phoneNumber); - return ApiResponse.success(); - } -} diff --git a/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/vo/NotificationDetailResponse.java b/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/vo/NotificationDetailResponse.java deleted file mode 100644 index 5a5f36ee4..000000000 --- a/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/vo/NotificationDetailResponse.java +++ /dev/null @@ -1,87 +0,0 @@ -package kr.mashup.branding.ui.notification.vo; - -import io.swagger.annotations.ApiModelProperty; -import kr.mashup.branding.domain.adminmember.entity.AdminMember; -import kr.mashup.branding.domain.adminmember.entity.Position; -import kr.mashup.branding.domain.applicant.Applicant; -import kr.mashup.branding.domain.application.Application; -import kr.mashup.branding.domain.notification.Notification; -import kr.mashup.branding.domain.notification.NotificationStatus; -import kr.mashup.branding.domain.notification.sms.SmsNotificationStatus; -import kr.mashup.branding.domain.notification.sms.SmsRequest; -import kr.mashup.branding.domain.team.Team; -import kr.mashup.branding.ui.team.vo.TeamResponse; -import lombok.AllArgsConstructor; -import lombok.Data; - -import java.time.LocalDateTime; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -@Data -@AllArgsConstructor -public class NotificationDetailResponse { - @ApiModelProperty(value = "발송 내역 식별자", example = "1") - private Long notificationId; - - @ApiModelProperty(value = "발송 내역 상태(생성됨, 알수없음, 진행중, 성공, 실패)") - private NotificationStatus status; - - @ApiModelProperty(value = "발송 메모", example = "스프링팀 서류 합격 문자 안내") - private String name; - - @ApiModelProperty(value = "발송 내용", example = "합격을 축하행~!") - private String content; - - @ApiModelProperty(value = "발송 번호", example = "01012341234") - private String senderPhoneNumber; - - @ApiModelProperty(value = "발송 시각") - private LocalDateTime sentAt; - - @ApiModelProperty(value = "발송자") - private Position sender; - - @ApiModelProperty(value = "발송 성공한 수신자 수", example = "209") - private Integer successCount; - - @ApiModelProperty(value = "발송 실패한 수신자 수", example = "11") - private Integer failureCount; - - @ApiModelProperty(value = "전체 수신자 수", example = "220") - private Integer totalCount; - - @ApiModelProperty(value = "발신 문자 목록") - private List smsRequests; - - public static NotificationDetailResponse of(final Notification notification, final Map applicationMap){ - Map statusCountMap = notification.getSmsRequests() - .stream() - .collect(Collectors.toMap( - SmsRequest::getStatus, - it -> 1, - Integer::sum - )); - AdminMember sender = notification.getSender(); - - return new NotificationDetailResponse( - notification.getNotificationId(), - notification.getStatus(), - notification.getName(), - notification.getContent(), - notification.getSenderPhoneNumber(), - notification.getSentAt(), - sender.getPosition(), - statusCountMap.getOrDefault(SmsNotificationStatus.SUCCESS, 0), - statusCountMap.getOrDefault(SmsNotificationStatus.FAILURE, 0), - statusCountMap.values().stream().mapToInt(it -> it).sum(), - notification.getSmsRequests() - .stream().map(it-> - SmsRequestSimpleResponse.of(it, TeamResponse.from(applicationMap.get(it.getRecipientApplicant()).getApplicationForm().getTeam()))) - .collect(Collectors.toList()) - - ); - } - -} diff --git a/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/vo/NotificationSimpleResponse.java b/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/vo/NotificationSimpleResponse.java deleted file mode 100644 index bac1f883b..000000000 --- a/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/vo/NotificationSimpleResponse.java +++ /dev/null @@ -1,66 +0,0 @@ -package kr.mashup.branding.ui.notification.vo; - -import java.time.LocalDateTime; -import java.util.Map; -import java.util.stream.Collectors; - -import io.swagger.annotations.ApiModelProperty; -import kr.mashup.branding.domain.adminmember.entity.Position; -import kr.mashup.branding.domain.notification.Notification; -import kr.mashup.branding.domain.notification.NotificationStatus; -import kr.mashup.branding.domain.notification.sms.SmsNotificationStatus; -import kr.mashup.branding.domain.notification.sms.SmsRequest; -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor -public class NotificationSimpleResponse { - @ApiModelProperty(value = "발송 내역 식별자", example = "1") - private Long notificationId; - - @ApiModelProperty(value = "발송 내역 상태(생성됨, 알수없음, 진행중, 성공, 실패)") - private NotificationStatus status; - - @ApiModelProperty(value = "발송 메모", example = "스프링팀 서류 합격 문자 안내") - private String name; - - @ApiModelProperty(value = "발송 번호", example = "01012341234") - private String senderPhoneNumber; - - @ApiModelProperty(value = "발송 시각") - private LocalDateTime sentAt; - - @ApiModelProperty(value = "발송자") - private Position sender; - - @ApiModelProperty(value = "발송 성공한 수신자 수", example = "209") - private Integer successCount; - - @ApiModelProperty(value = "발송 실패한 수신자 수", example = "11") - private Integer failureCount; - - @ApiModelProperty(value = "전체 수신자 수", example = "220") - private Integer totalCount; - - public static NotificationSimpleResponse from(Notification notification){ - Map statusCountMap = notification.getSmsRequests() - .stream() - .collect(Collectors.toMap( - SmsRequest::getStatus, - it -> 1, - Integer::sum - )); - return new NotificationSimpleResponse( - notification.getNotificationId(), - notification.getStatus(), - notification.getName(), - notification.getSenderPhoneNumber(), - notification.getSentAt(), - notification.getSender().getPosition(), - statusCountMap.getOrDefault(SmsNotificationStatus.SUCCESS, 0), - statusCountMap.getOrDefault(SmsNotificationStatus.FAILURE, 0), - statusCountMap.values().stream().mapToInt(it -> it).sum() - ); - } -} diff --git a/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/vo/SmsRequestDetailResponse.java b/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/vo/SmsRequestDetailResponse.java deleted file mode 100644 index 420e5c2a5..000000000 --- a/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/vo/SmsRequestDetailResponse.java +++ /dev/null @@ -1,53 +0,0 @@ -package kr.mashup.branding.ui.notification.vo; - -import io.swagger.annotations.ApiModelProperty; -import kr.mashup.branding.domain.adminmember.entity.Position; -import kr.mashup.branding.domain.notification.sms.SmsNotificationStatus; -import kr.mashup.branding.domain.notification.sms.SmsRequest; -import kr.mashup.branding.domain.team.Team; -import kr.mashup.branding.ui.team.vo.TeamResponse; -import lombok.AllArgsConstructor; -import lombok.Data; - -import java.time.LocalDateTime; - -@Data -@AllArgsConstructor -public class SmsRequestDetailResponse { - @ApiModelProperty(value = "발송 상세 정보 ID", example = "1") - private Long smsRequestId; - - @ApiModelProperty(value = "발송 메모", example = "스프링팀 서류 합격 문자 안내") - private String notificationName; - - @ApiModelProperty(value = "발송 번호") - private String senderPhoneNumber; - - @ApiModelProperty(value = "발송자") - private Position sender; - - @ApiModelProperty(value = "발송 내용", example = "합격을 축하행~!") - private String notificationContent; - - @ApiModelProperty(value = "발송 상태(성공, 실패)", example = "SUCCESS") - private SmsNotificationStatus status; - - @ApiModelProperty(value = "발송(생성) 날짜 및 시간") - private LocalDateTime createdAt; - - @ApiModelProperty(value = "수신자 지원 플랫폼") - private TeamResponse team; - - public static SmsRequestDetailResponse of(SmsRequest smsRequest, Team team){ - return new SmsRequestDetailResponse( - smsRequest.getSmsRequestId(), - smsRequest.getNotification().getName(), - smsRequest.getNotification().getSenderPhoneNumber(), - smsRequest.getNotification().getSender().getPosition(), - smsRequest.getNotification().getContent(), - smsRequest.getStatus(), - smsRequest.getCreatedAt(), - TeamResponse.from(team) - ); - } -} diff --git a/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/vo/SmsRequestSimpleResponse.java b/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/vo/SmsRequestSimpleResponse.java deleted file mode 100644 index ad763012a..000000000 --- a/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/vo/SmsRequestSimpleResponse.java +++ /dev/null @@ -1,37 +0,0 @@ -package kr.mashup.branding.ui.notification.vo; - -import io.swagger.annotations.ApiModelProperty; -import kr.mashup.branding.domain.notification.sms.SmsNotificationStatus; -import kr.mashup.branding.domain.notification.sms.SmsRequest; -import kr.mashup.branding.ui.team.vo.TeamResponse; -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor -public class SmsRequestSimpleResponse { - @ApiModelProperty(value = "발송 상세 정보 ID", example = "1") - private Long smsRequestId; - - @ApiModelProperty(value = "발송 상태(성공, 실패)", example = "SUCCESS") - private SmsNotificationStatus status; - - @ApiModelProperty(value = "수신자 이름", example = "홍길동") - private String recipientName; - - @ApiModelProperty(value = "수신자 전화번호", example = "01000000000") - private String recipientPhoneNumber; - - @ApiModelProperty(value = "수신자 지원 플랫폼") - private TeamResponse team; - - public static SmsRequestSimpleResponse of(SmsRequest smsRequest, TeamResponse teamResponse){ - return new SmsRequestSimpleResponse( - smsRequest.getSmsRequestId(), - smsRequest.getStatus(), - smsRequest.getRecipientApplicant().getName(), - smsRequest.getRecipientPhoneNumber(), - teamResponse); - } - -} diff --git a/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/vo/SmsSendRequest.java b/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/vo/SmsSendRequest.java deleted file mode 100644 index 283f68b42..000000000 --- a/mashup-admin/src/main/java/kr/mashup/branding/ui/notification/vo/SmsSendRequest.java +++ /dev/null @@ -1,22 +0,0 @@ -package kr.mashup.branding.ui.notification.vo; - -import java.util.List; - -import io.swagger.annotations.ApiModelProperty; -import kr.mashup.branding.domain.notification.sms.vo.SmsSendRequestVo; -import lombok.Getter; -import lombok.ToString; - -@Getter -@ToString -public class SmsSendRequest { - @ApiModelProperty(value = "발송 메모", example = "스프링팀 서류 합격 문자 안내") - private String name; - - @ApiModelProperty(value = "문자 내용", example = "합격을 축하행~!") - private String content; - - @ApiModelProperty(value = "문자 받을 지원자 ID 목록", example = "[1, 2, 3]") - private List applicantIds; - -} diff --git a/mashup-batch/src/main/java/kr/mashup/branding/job/signup/AdminMemberSignupJobConfig.java b/mashup-batch/src/main/java/kr/mashup/branding/job/signup/AdminMemberSignupJobConfig.java deleted file mode 100644 index e86d1bb7e..000000000 --- a/mashup-batch/src/main/java/kr/mashup/branding/job/signup/AdminMemberSignupJobConfig.java +++ /dev/null @@ -1,56 +0,0 @@ -package kr.mashup.branding.job.signup; - -import kr.mashup.branding.config.BatchConfig; -import kr.mashup.branding.service.adminmember.AdminMemberService; -import lombok.RequiredArgsConstructor; -import org.springframework.batch.core.Job; -import org.springframework.batch.core.Step; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.JobScope; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepScope; -import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.step.tasklet.Tasklet; -import org.springframework.batch.support.transaction.ResourcelessTransactionManager; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@ConditionalOnProperty( - value = BatchConfig.SPRING_BATCH_JOB_NAMES, - havingValue = AdminMemberSignupJobConfig.JOB_NAME -) -@Configuration -@RequiredArgsConstructor -public class AdminMemberSignupJobConfig { - static final String JOB_NAME = "admin-member-sign-up"; - private static final String STEP_NAME = JOB_NAME + "-step"; - - private final JobBuilderFactory jobBuilderFactory; - private final JobRepository jobRepository; - private final StepBuilderFactory stepBuilderFactory; - private final AdminMemberService adminMemberService; - - @Bean - public Job adminMemberSignUpJob() { - return jobBuilderFactory.get(JOB_NAME) - .repository(jobRepository) - .start(adminMemberSignUpStep()) - .build(); - } - - @Bean - @JobScope - public Step adminMemberSignUpStep() { - return stepBuilderFactory.get(STEP_NAME) - .tasklet(adminMemberSignUpTasklet()) - .transactionManager(new ResourcelessTransactionManager()) - .build(); - } - - @Bean - @StepScope - public Tasklet adminMemberSignUpTasklet() { - return new AdminMemberSignupTasklet(adminMemberService); - } -} diff --git a/mashup-batch/src/main/java/kr/mashup/branding/job/signup/AdminMemberSignupTasklet.java b/mashup-batch/src/main/java/kr/mashup/branding/job/signup/AdminMemberSignupTasklet.java deleted file mode 100644 index e8efea23e..000000000 --- a/mashup-batch/src/main/java/kr/mashup/branding/job/signup/AdminMemberSignupTasklet.java +++ /dev/null @@ -1,54 +0,0 @@ -package kr.mashup.branding.job.signup; - -import java.util.stream.Collectors; -import kr.mashup.branding.domain.adminmember.entity.AdminMember; -import kr.mashup.branding.domain.adminmember.entity.Position; -import kr.mashup.branding.domain.adminmember.vo.AdminMemberSignUpCommand; -import kr.mashup.branding.service.adminmember.AdminMemberService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.batch.core.StepContribution; -import org.springframework.batch.core.scope.context.ChunkContext; -import org.springframework.batch.core.step.tasklet.Tasklet; -import org.springframework.batch.repeat.RepeatStatus; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.util.Assert; - -@Slf4j -@RequiredArgsConstructor -public class AdminMemberSignupTasklet implements Tasklet { - private final AdminMemberService adminMemberService; - - @Value("#{jobParameters['username']}") - private String username; - @Value("#{jobParameters['password']}") - private String password; - @Value("#{jobParameters['phoneNumber']}") - private String phoneNumber; - @Value("#{jobParameters['position']}") - private String position; - - @Override - public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { - String formattedJobParameters = chunkContext.getStepContext().getJobParameters().entrySet().stream() - .map(it -> it.getKey() + ": " + it.getValue()) - .collect(Collectors.joining(", ")); - log.info("jobParameters: {}", formattedJobParameters); - - Assert.hasText(username, "'password' must not be null, empty or blank"); - Assert.hasText(password, "'password' must not be null, empty or blank"); - Assert.hasText(phoneNumber, "'phoneNumber' must not be null, empty or blank"); - Assert.hasText(position, "'position' must not be null, empty or blank"); - - AdminMemberSignUpCommand adminMemberSignUpCommand = AdminMemberSignUpCommand.of( - username, - password, - phoneNumber, - Position.valueOf(position) - ); - log.info("adminMemberVo: {}", adminMemberSignUpCommand); - AdminMember adminMember = adminMemberService.signUp(adminMemberSignUpCommand); - log.info("adminMember: {}", adminMember); - return RepeatStatus.FINISHED; - } -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/domain/adminmember/entity/AdminMember.java b/mashup-domain/src/main/java/kr/mashup/branding/domain/adminmember/entity/AdminMember.java index 38020ac0b..c0f807f72 100644 --- a/mashup-domain/src/main/java/kr/mashup/branding/domain/adminmember/entity/AdminMember.java +++ b/mashup-domain/src/main/java/kr/mashup/branding/domain/adminmember/entity/AdminMember.java @@ -1,25 +1,18 @@ package kr.mashup.branding.domain.adminmember.entity; -import java.time.LocalDateTime; - -import javax.persistence.Entity; -import javax.persistence.EntityListeners; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; - +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; import org.springframework.data.annotation.CreatedBy; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedBy; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; import org.springframework.security.crypto.password.PasswordEncoder; +import javax.persistence.*; +import java.time.LocalDateTime; + @Entity @Getter @ToString(of = {"adminMemberId", "username", "phoneNumber", "position", "createdAt", "updatedAt"}) @@ -34,10 +27,6 @@ public class AdminMember { private String password; - private String phoneNumber; - - private Boolean phoneNumberRegistered = false; - @Enumerated(EnumType.STRING) private Position position; @@ -56,13 +45,11 @@ public class AdminMember { public static AdminMember of( String username, String password, - String phoneNumber, Position position ) { AdminMember adminMember = new AdminMember(); adminMember.username = username; adminMember.password = password; - adminMember.phoneNumber = phoneNumber; adminMember.position = position; return adminMember; } diff --git a/mashup-domain/src/main/java/kr/mashup/branding/domain/adminmember/vo/AdminMemberSignUpCommand.java b/mashup-domain/src/main/java/kr/mashup/branding/domain/adminmember/vo/AdminMemberSignUpCommand.java index 4b1818724..aa664dad1 100644 --- a/mashup-domain/src/main/java/kr/mashup/branding/domain/adminmember/vo/AdminMemberSignUpCommand.java +++ b/mashup-domain/src/main/java/kr/mashup/branding/domain/adminmember/vo/AdminMemberSignUpCommand.java @@ -2,7 +2,6 @@ import kr.mashup.branding.domain.adminmember.entity.Position; import kr.mashup.branding.domain.adminmember.exception.AdminMemberSignUpRequestInvalidException; -import kr.mashup.branding.domain.adminmember.exception.AdminMemberUsernameDuplicatedException; import lombok.Value; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -12,7 +11,6 @@ public class AdminMemberSignUpCommand { String username; String password; - String phoneNumber; Position position; private void validate(AdminMemberSignUpCommand adminMemberSignUpCommand) { @@ -24,14 +22,5 @@ private void validate(AdminMemberSignUpCommand adminMemberSignUpCommand) { if (!StringUtils.hasText(adminMemberSignUpCommand.getPassword())) { throw new AdminMemberSignUpRequestInvalidException("'password' must not be null, empty or blank"); } - if (adminMemberSignUpCommand.getPhoneNumber() != null && adminMemberSignUpCommand.getPhoneNumber().length() > 13) { - throw new AdminMemberSignUpRequestInvalidException( - "'phoneNumber' length must be less than or equal to 13"); - } - if (adminMemberSignUpCommand.getPhoneNumber().replaceAll("-", "").length() != 11) { - throw new AdminMemberSignUpRequestInvalidException( - "'phoneNumber' format must include hyphen('-')."); - } - } } diff --git a/mashup-domain/src/main/java/kr/mashup/branding/domain/adminmember/vo/AdminMemberVo.java b/mashup-domain/src/main/java/kr/mashup/branding/domain/adminmember/vo/AdminMemberVo.java index a1b0875c1..aa64f8fa2 100644 --- a/mashup-domain/src/main/java/kr/mashup/branding/domain/adminmember/vo/AdminMemberVo.java +++ b/mashup-domain/src/main/java/kr/mashup/branding/domain/adminmember/vo/AdminMemberVo.java @@ -2,10 +2,7 @@ import kr.mashup.branding.domain.adminmember.entity.AdminMember; import kr.mashup.branding.domain.adminmember.entity.Position; -import lombok.EqualsAndHashCode; import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.ToString; import lombok.Value; import java.time.LocalDateTime; @@ -18,10 +15,6 @@ public class AdminMemberVo { String username; - String phoneNumber; - - Boolean phoneNumberRegistered = false; - Position position; String createdBy; @@ -36,7 +29,6 @@ public static AdminMemberVo from(AdminMember adminMember){ return AdminMemberVo.of( adminMember.getAdminMemberId(), adminMember.getUsername(), - adminMember.getPhoneNumber(), adminMember.getPosition(), adminMember.getCreatedBy(), adminMember.getCreatedAt(), diff --git a/mashup-domain/src/main/java/kr/mashup/branding/domain/email/EmailNotification.java b/mashup-domain/src/main/java/kr/mashup/branding/domain/email/EmailNotification.java index c33501e63..9377be54a 100644 --- a/mashup-domain/src/main/java/kr/mashup/branding/domain/email/EmailNotification.java +++ b/mashup-domain/src/main/java/kr/mashup/branding/domain/email/EmailNotification.java @@ -3,10 +3,8 @@ import kr.mashup.branding.config.EmailConfig; import kr.mashup.branding.domain.adminmember.entity.AdminMember; -import kr.mashup.branding.domain.applicant.Applicant; import kr.mashup.branding.domain.application.Application; import kr.mashup.branding.domain.generation.Generation; -import kr.mashup.branding.domain.notification.sms.SmsRequest; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -14,20 +12,8 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EntityListeners; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; +import javax.persistence.*; import java.time.LocalDateTime; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; diff --git a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/Notification.java b/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/Notification.java deleted file mode 100644 index e5397f463..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/Notification.java +++ /dev/null @@ -1,179 +0,0 @@ -package kr.mashup.branding.domain.notification; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EntityListeners; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; - -import kr.mashup.branding.domain.generation.Generation; -import kr.mashup.branding.domain.notification.exception.NotificationRequestInvalidException; -import org.springframework.data.annotation.CreatedBy; -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.annotation.LastModifiedBy; -import org.springframework.data.annotation.LastModifiedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import org.springframework.util.StringUtils; - -import kr.mashup.branding.domain.adminmember.entity.AdminMember; -import kr.mashup.branding.domain.notification.sms.SmsRequest; -import kr.mashup.branding.domain.notification.sms.vo.SmsSendRequestVo; -import lombok.AccessLevel; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.ToString; - -@Entity -@Getter -@ToString(of = {"notificationId", "senderValue", "sentAt", "name", "content", "status", "type", "messageId", "resultId", - "resultCode", "resultMessage", "createdAt", "updatedAt", "generation"}) -@EqualsAndHashCode(of = "notificationId") -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@EntityListeners(AuditingEntityListener.class) -public class Notification { - @Id - @GeneratedValue - private Long notificationId; - - /** - * 발송자 - */ - @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "admin_member_id") - private AdminMember sender; - - @OneToMany(mappedBy = "notification", cascade = CascadeType.ALL) - private final List smsRequests = new ArrayList<>(); - - @ManyToOne(fetch = FetchType.LAZY, optional = false) - private Generation generation; - - /** - * 발송자 번호 - */ - private String senderValue; - - /** - * 발송 시각 - */ - private LocalDateTime sentAt; - - /** - * 발송메모 - */ - @Column(unique = true) - private String name; - - /** - * 발송 내용 - */ - @Column(columnDefinition = "TEXT") - private String content; - - /** - * 발송 상태 - */ - @Enumerated(EnumType.STRING) - private NotificationStatus status; - - /** - * 발송 종류 (SMS, EMAIL, ...) - */ - @Enumerated(EnumType.STRING) - private NotificationType type; - - /** - * client 가 생성한 메시지 식별자 - */ - private String messageId; - - /** - * 외부 서비스에서 생성한 메시지 식별자 - */ - private String resultId; - - /** - * 결과 코드 - */ - private String resultCode; - - /** - * 결과 메시지 - */ - private String resultMessage; - - - - @CreatedBy - private String createdBy; - - @CreatedDate - private LocalDateTime createdAt; - - @LastModifiedBy - private String updatedBy; - - @LastModifiedDate - private LocalDateTime updatedAt; - - public static Notification sms( - AdminMember adminMember, - Generation generation, - SmsSendRequestVo smsSendRequestVo - ) { - if(!adminMember.getPhoneNumberRegistered()){ - throw new NotificationRequestInvalidException("Sender's phoneNumber must be registered to NHN Cloud Notification Service"); - } - Notification notification = new Notification(); - notification.sender = adminMember; - notification.generation = generation; - notification.senderValue = adminMember.getPhoneNumber(); - notification.sentAt = LocalDateTime.now(); - notification.messageId = UUID.randomUUID().toString(); - notification.name = smsSendRequestVo.getName(); - if (!StringUtils.hasText(notification.name)) { - throw new NotificationRequestInvalidException("'name' must not be null, empty or blank"); - } - notification.content = smsSendRequestVo.getContent(); - notification.status = NotificationStatus.CREATED; - notification.type = NotificationType.SMS; - return notification; - } - - public void setSmsRequests(List smsRequests) { - this.smsRequests.addAll(smsRequests); - } - - public String getSenderPhoneNumber() { - return senderValue; - } - - public void markToUnknown() { - status = NotificationStatus.UNKNOWN; - } - - public void markResult( - NotificationStatus status, - String resultId, - String resultCode, - String resultMessage - ) { - this.status = status; - this.resultId = resultId; - this.resultCode = resultCode; - this.resultMessage = resultMessage; - } -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/NotificationStatus.java b/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/NotificationStatus.java deleted file mode 100644 index 9c8d1c6a0..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/NotificationStatus.java +++ /dev/null @@ -1,13 +0,0 @@ -package kr.mashup.branding.domain.notification; - -public enum NotificationStatus { - CREATED("생성됨"), - UNKNOWN("확인 필요"), - IN_PROGRESS("전송 중"), - SUCCESS("성공"), - FAILURE("실패"), - ; - - NotificationStatus(String description) { - } -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/NotificationType.java b/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/NotificationType.java deleted file mode 100644 index efdc414c5..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/NotificationType.java +++ /dev/null @@ -1,10 +0,0 @@ -package kr.mashup.branding.domain.notification; - -public enum NotificationType { - SMS("문자"), - EMAIL("이메일"), - ; - - NotificationType(String description) { - } -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/exception/NotificationNotFoundException.java b/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/exception/NotificationNotFoundException.java deleted file mode 100644 index 33e17f201..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/exception/NotificationNotFoundException.java +++ /dev/null @@ -1,14 +0,0 @@ -package kr.mashup.branding.domain.notification.exception; - -import kr.mashup.branding.domain.ResultCode; -import kr.mashup.branding.domain.exception.NotFoundException; - -public class NotificationNotFoundException extends NotFoundException { - public NotificationNotFoundException() { - super(ResultCode.NOTIFICATION_NOT_FOUND); - } - - public NotificationNotFoundException(Long notificationId) { - super(ResultCode.NOTIFICATION_NOT_FOUND, "Notification not found. notificationId: " + notificationId); - } -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/exception/NotificationRequestInvalidException.java b/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/exception/NotificationRequestInvalidException.java deleted file mode 100644 index 41b8b3052..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/exception/NotificationRequestInvalidException.java +++ /dev/null @@ -1,10 +0,0 @@ -package kr.mashup.branding.domain.notification.exception; - -import kr.mashup.branding.domain.ResultCode; -import kr.mashup.branding.domain.exception.BadRequestException; - -public class NotificationRequestInvalidException extends BadRequestException { - public NotificationRequestInvalidException(String message) { - super(ResultCode.NOTIFICATION_REQUEST_INVALID, message); - } -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/SmsNotificationStatus.java b/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/SmsNotificationStatus.java deleted file mode 100644 index 56e8365fd..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/SmsNotificationStatus.java +++ /dev/null @@ -1,11 +0,0 @@ -package kr.mashup.branding.domain.notification.sms; - -public enum SmsNotificationStatus { - CREATED("생성"), - SUCCESS("성공"), - FAILURE("실패"), - ; - - SmsNotificationStatus(String description) { - } -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/SmsRequest.java b/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/SmsRequest.java deleted file mode 100644 index 0f942a3e7..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/SmsRequest.java +++ /dev/null @@ -1,112 +0,0 @@ -package kr.mashup.branding.domain.notification.sms; - -import java.time.LocalDateTime; -import java.util.UUID; - -import javax.persistence.Entity; -import javax.persistence.EntityListeners; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; - -import kr.mashup.branding.domain.notification.sms.vo.SmsSendResultRecipientVo; -import org.springframework.data.annotation.CreatedBy; -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.annotation.LastModifiedBy; -import org.springframework.data.annotation.LastModifiedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import kr.mashup.branding.domain.applicant.Applicant; -import kr.mashup.branding.domain.notification.Notification; -import lombok.AccessLevel; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.ToString; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -@Entity -@Getter -@ToString(of = {"smsRequestId", "status", "recipientPhoneNumber", "messageId", "resultId", "resultCode", - "resultMessage", "createdAt", "updatedAt"}) -@EqualsAndHashCode(of = "smsRequestId") -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@EntityListeners(AuditingEntityListener.class) -public class SmsRequest { - @Id - @GeneratedValue - private Long smsRequestId; - - @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "notification_id") - private Notification notification; - - @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "recipient_applicant_id") - private Applicant recipientApplicant; - - @Enumerated(EnumType.STRING) - private SmsNotificationStatus status = SmsNotificationStatus.CREATED; - - private String recipientPhoneNumber; - - /** - * client 에서 생성한 메시지 식별자 - */ - private String messageId; - - /** - * 외부 서비스에서 생성한 식별자 - */ - private String resultId; - - /** - * 결과 코드 - */ - private String resultCode; - - /** - * 결과 메시지 - */ - private String resultMessage; - - @CreatedBy - private String createdBy; - - @CreatedDate - private LocalDateTime createdAt; - - @LastModifiedBy - private String updatedBy; - - @LastModifiedDate - private LocalDateTime updatedAt; - - public static SmsRequest of( - Notification notification, - Applicant recipientApplicant - ) { - SmsRequest smsRequest = new SmsRequest(); - smsRequest.notification = notification; - smsRequest.messageId = UUID.randomUUID().toString(); - smsRequest.recipientApplicant = recipientApplicant; - smsRequest.recipientPhoneNumber = recipientApplicant.getPhoneNumber(); - return smsRequest; - } - - public void setResult(SmsSendResultRecipientVo smsSendResultRecipientVo) { - if (smsSendResultRecipientVo == null) { - log.error("'smsSendResultRecipientVo' must not be null"); - return; - } - this.status = smsSendResultRecipientVo.getStatus(); - this.resultId = smsSendResultRecipientVo.getRequestId(); - this.resultCode = smsSendResultRecipientVo.getResultCode(); - this.resultMessage = smsSendResultRecipientVo.getResultMessage(); - } -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/exception/SmsSendFailedException.java b/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/exception/SmsSendFailedException.java deleted file mode 100644 index 663af284b..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/exception/SmsSendFailedException.java +++ /dev/null @@ -1,10 +0,0 @@ -package kr.mashup.branding.domain.notification.sms.exception; - -import kr.mashup.branding.domain.ResultCode; -import kr.mashup.branding.domain.exception.ServiceUnavailableException; - -public class SmsSendFailedException extends ServiceUnavailableException { - public SmsSendFailedException() { - super(ResultCode.NOTIFICATION_FAILED_TO_SEND_SMS); - } -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/vo/SmsRecipientRequestVo.java b/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/vo/SmsRecipientRequestVo.java deleted file mode 100644 index 6afa3d385..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/vo/SmsRecipientRequestVo.java +++ /dev/null @@ -1,9 +0,0 @@ -package kr.mashup.branding.domain.notification.sms.vo; - -import lombok.Value; - -@Value(staticConstructor = "of") -public class SmsRecipientRequestVo { - String messageId; - String phoneNumber; -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/vo/SmsRecipientResultVo.java b/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/vo/SmsRecipientResultVo.java deleted file mode 100644 index a804fae39..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/vo/SmsRecipientResultVo.java +++ /dev/null @@ -1,24 +0,0 @@ -package kr.mashup.branding.domain.notification.sms.vo; - -import kr.mashup.branding.domain.notification.sms.SmsNotificationStatus; -import lombok.Value; - -@Value -public class SmsRecipientResultVo { - /** - * 메시지 식별자 - */ - String messageId; - /** - * 상태 - */ - SmsNotificationStatus status; - /** - * 에러 코드 - */ - String errorCode; - /** - * 에러 메시지 - */ - String errorMessage; -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/vo/SmsRequestVo.java b/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/vo/SmsRequestVo.java deleted file mode 100644 index 13f085740..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/vo/SmsRequestVo.java +++ /dev/null @@ -1,38 +0,0 @@ -package kr.mashup.branding.domain.notification.sms.vo; - -import java.util.List; -import java.util.stream.Collectors; - -import kr.mashup.branding.domain.adminmember.entity.AdminMember; -import kr.mashup.branding.domain.notification.Notification; -import kr.mashup.branding.domain.notification.exception.NotificationRequestInvalidException; -import lombok.Value; - -@Value(staticConstructor = "of") -public class SmsRequestVo { - String messageId; - String senderPhoneNumber; - String content; - List smsRecipientRequestVos; - - public static SmsRequestVo from(final Notification notification){ - - final AdminMember sender = notification.getSender(); - - final List SmsRecipientRequestVos = notification - .getSmsRequests() - .stream() - .map(it -> SmsRecipientRequestVo.of( - it.getMessageId(), - it.getRecipientPhoneNumber() - )) - .collect(Collectors.toList()); - - return SmsRequestVo.of( - notification.getMessageId(), - sender.getPhoneNumber(), - notification.getContent(), - SmsRecipientRequestVos - ); - } -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/vo/SmsSendRequestVo.java b/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/vo/SmsSendRequestVo.java deleted file mode 100644 index 8e6903665..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/vo/SmsSendRequestVo.java +++ /dev/null @@ -1,9 +0,0 @@ -package kr.mashup.branding.domain.notification.sms.vo; - -import lombok.Value; - -@Value(staticConstructor = "of") -public class SmsSendRequestVo { - String name; - String content; -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/vo/SmsSendResultRecipientVo.java b/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/vo/SmsSendResultRecipientVo.java deleted file mode 100644 index 4b4f76fe9..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/vo/SmsSendResultRecipientVo.java +++ /dev/null @@ -1,28 +0,0 @@ -package kr.mashup.branding.domain.notification.sms.vo; - -import kr.mashup.branding.domain.notification.sms.SmsNotificationStatus; -import lombok.Value; - -@Value(staticConstructor = "of") -public class SmsSendResultRecipientVo { - /** - * Toast SMS 에서 사용하는 요청 식별자. 발송 단건 조회시 사용 - */ - String requestId; - /** - * Toast 의 recipientGroupingKey. 수신자 기준으로 문자 발송 이력 조회시 사용 - */ - String messageId; - /** - * 발송 상태 - */ - SmsNotificationStatus status; - /** - * 결과 코드 - */ - String resultCode; - /** - * 결과 메시지 - */ - String resultMessage; -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/vo/SmsSendResultVo.java b/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/vo/SmsSendResultVo.java deleted file mode 100644 index e8602fce9..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/vo/SmsSendResultVo.java +++ /dev/null @@ -1,49 +0,0 @@ -package kr.mashup.branding.domain.notification.sms.vo; - -import java.util.Collections; -import java.util.List; - -import kr.mashup.branding.domain.notification.NotificationStatus; -import lombok.Value; - -@Value(staticConstructor = "of") -public class SmsSendResultVo { - - public static final SmsSendResultVo UNKNOWN; - - static { - UNKNOWN = new SmsSendResultVo( - null, - null, - NotificationStatus.UNKNOWN, - Collections.emptyList(), - null, - null - ); - } - - /** - * Toast SMS 에서 사용하는 요청 식별자. 발송 단건 조회시 사용 - */ - String resultId; - /** - * Toast 의 senderGroupingKey. 발송자 기준으로 문자 발송 목록 조회시 사용 - */ - String messageId; - /** - * 발송 상태 - */ - NotificationStatus status; - /** - * 수신자 별 결과 - */ - List recipientResultVos; - /** - * 결과 코드 - */ - String resultCode; - /** - * 결과 메시지 - */ - String resultMessage; -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/whitelist/SmsWhitelist.java b/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/whitelist/SmsWhitelist.java deleted file mode 100644 index 4c42d79ed..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/domain/notification/sms/whitelist/SmsWhitelist.java +++ /dev/null @@ -1,55 +0,0 @@ -package kr.mashup.branding.domain.notification.sms.whitelist; - -import java.time.LocalDateTime; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EntityListeners; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; - -import org.springframework.data.annotation.CreatedBy; -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.annotation.LastModifiedBy; -import org.springframework.data.annotation.LastModifiedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; - -/** - * 개발환경에서 실제 문자 발송을 제한하기위한 테이블 - * 아래 테이블에 등록된 번호만 실제 발송요청을 보내고, 등록되지 않은 번호는 발송요청을 보내지 않는다. - */ -@Entity -@Getter -@ToString(of = {"smsWhiteListId", "phoneNumber"}) -@EqualsAndHashCode(of = {"smsWhiteListId"}) -@EntityListeners(AuditingEntityListener.class) -public class SmsWhitelist { - @Id - @GeneratedValue - private Long smsWhiteListId; - - @Column(unique = true) - private String phoneNumber; - - @CreatedDate - private LocalDateTime createdAt; - - @CreatedBy - private String createdBy; - - @LastModifiedDate - private LocalDateTime updatedAt; - - @LastModifiedBy - private String updatedBy; - - public static SmsWhitelist of(String phoneNumber) { - SmsWhitelist smsWhitelist = new SmsWhitelist(); - smsWhitelist.phoneNumber = phoneNumber; - return smsWhitelist; - } -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/domain/popup/PopupType.java b/mashup-domain/src/main/java/kr/mashup/branding/domain/popup/PopupType.java index 19749f785..8fa6cbd36 100644 --- a/mashup-domain/src/main/java/kr/mashup/branding/domain/popup/PopupType.java +++ b/mashup-domain/src/main/java/kr/mashup/branding/domain/popup/PopupType.java @@ -1,19 +1,19 @@ package kr.mashup.branding.domain.popup; +import kr.mashup.branding.util.DateUtil; +import lombok.AllArgsConstructor; + import java.time.LocalDate; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; -import kr.mashup.branding.util.DateUtil; -import lombok.AllArgsConstructor; - @AllArgsConstructor public enum PopupType { DANGGN_REWARD(LocalDate.MIN, LocalDate.MAX), DANGGN(LocalDate.of(2023, 5, 18), LocalDate.of(2023, 6, 2)), // 당근 흔들기 릴리즈 팝업 타입 - DANGGN_UPDATE(LocalDate.of(2023, 6, 26), LocalDate.of(2023, 7, 26)), // 당근 흔들기 업데이트 팝업 타입 FIXME: 배포 일자에 맞춰서, 노출 일자 수정 필요 + DANGGN_UPDATE(LocalDate.of(2023, 6, 26), LocalDate.of(2023, 8, 26)), // 당근 흔들기 업데이트 팝업 타입 FIXME: 배포 일자에 맞춰서, 노출 일자 수정 필요 ; private final LocalDate startedDate; diff --git a/mashup-domain/src/main/java/kr/mashup/branding/infrastructure/sms/ToastSmsConfig.java b/mashup-domain/src/main/java/kr/mashup/branding/infrastructure/sms/ToastSmsConfig.java deleted file mode 100644 index 83380a407..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/infrastructure/sms/ToastSmsConfig.java +++ /dev/null @@ -1,47 +0,0 @@ -package kr.mashup.branding.infrastructure.sms; - -import org.springframework.beans.factory.ObjectProvider; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.http.MediaType; -import org.springframework.web.client.RestTemplate; - -import kr.mashup.branding.service.notification.sms.SmsService; -import kr.mashup.branding.service.notification.sms.SmsWhitelistService; -import kr.mashup.branding.util.RequestHeaderInterceptor; - -@Profile("sms") -@Configuration -public class ToastSmsConfig { - - @Value("${sms.toast.url}") - private String toastUrl; - - @Value("${sms.toast.app-key}") - private String appKey; - - @Value("${sms.toast.secret-key}") - private String secretKey; - - @Bean - public RestTemplate toastRestTemplate() { - return new RestTemplateBuilder() - .interceptors( - new RequestHeaderInterceptor("X-Secret-Key", secretKey), - new RequestHeaderInterceptor("Content-Type", MediaType.APPLICATION_JSON_VALUE)) - .build(); - } - - @Bean - public SmsService toastSmsService(ObjectProvider smsWhitelistService) { - return new ToastSmsService( - toastUrl, - appKey, - toastRestTemplate(), - smsWhitelistService - ); - } -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/infrastructure/sms/ToastSmsRecipient.java b/mashup-domain/src/main/java/kr/mashup/branding/infrastructure/sms/ToastSmsRecipient.java deleted file mode 100644 index 20516f683..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/infrastructure/sms/ToastSmsRecipient.java +++ /dev/null @@ -1,19 +0,0 @@ -package kr.mashup.branding.infrastructure.sms; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import lombok.Value; - -@Value(staticConstructor = "of") -public class ToastSmsRecipient { - /** - * 수신자 전화번호 - */ - @JsonProperty("recipientNo") - String recipientPhoneNumber; - /** - * 메시지 식별자 - */ - @JsonProperty("recipientGroupingKey") - String smsMessageId; -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/infrastructure/sms/ToastSmsRequest.java b/mashup-domain/src/main/java/kr/mashup/branding/infrastructure/sms/ToastSmsRequest.java deleted file mode 100644 index 8b4860fd8..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/infrastructure/sms/ToastSmsRequest.java +++ /dev/null @@ -1,35 +0,0 @@ -package kr.mashup.branding.infrastructure.sms; - -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import lombok.Value; - -@Value(staticConstructor = "of") -public class ToastSmsRequest { - /** - * 발신 제목 (LMS, MMS 에서만 사용) - */ - String title = "Mash-Up"; - /** - * 발신 내용 - */ - @JsonProperty("body") - String content; - /** - * 발신자 전화번호 - */ - @JsonProperty("sendNo") - String senderPhoneNumber; - /** - * 메시지 식별자 - */ - @JsonProperty("senderGroupingKey") - String notificationMessageId; - /** - * 수신자 정보 리스트 - */ - @JsonProperty("recipientList") - List toastSmsRecipients; -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/infrastructure/sms/ToastSmsResponse.java b/mashup-domain/src/main/java/kr/mashup/branding/infrastructure/sms/ToastSmsResponse.java deleted file mode 100644 index b0cc26cfc..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/infrastructure/sms/ToastSmsResponse.java +++ /dev/null @@ -1,52 +0,0 @@ -package kr.mashup.branding.infrastructure.sms; - -import java.util.List; - -import lombok.Data; - -@Data -public class ToastSmsResponse { - private ToastSmsResponseHeader header; - private ToastSmsResponseBody body; - - @Data - public static class ToastSmsResponseHeader { - private Boolean isSuccessful; - private Integer resultCode; - private String resultMessage; - } - - @Data - public static class ToastSmsResponseBody { - private ToastSmsResponseBodyData data; - } - - @Data - public static class ToastSmsResponseBodyData { - private String requestId; - /** - * 요청 상태 코드(1:요청 중, 2:요청 완료, 3:요청 실패) - */ - private Integer statusCode; - private String senderGroupingKey; - private List sendResultList; - } - - @Data - public static class ToastSendResult { - private String recipientNo; - private Integer resultCode; - private String resultMessage; - private Integer recipientSeq; - private String recipientGroupingKey; - } - - /** - * SMS의 성공 여부는 header.isSuccessful에 담겨옴 - * - * @return 요청 성공 여부 - */ - public boolean isSuccess() { - return this.header.isSuccessful; - } -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/infrastructure/sms/ToastSmsResponseStatus.java b/mashup-domain/src/main/java/kr/mashup/branding/infrastructure/sms/ToastSmsResponseStatus.java deleted file mode 100644 index 17263b900..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/infrastructure/sms/ToastSmsResponseStatus.java +++ /dev/null @@ -1,23 +0,0 @@ -package kr.mashup.branding.infrastructure.sms; - -public enum ToastSmsResponseStatus { - // 요청 상태 코드(1:요청 중, 2:요청 완료, 3:요청 실패) -> body.data.statusCode - IN_PROGRESS("발송 중", 1), - SUCCESS("발송 완료", 2), - FAILURE("발송 실패", 3), - ; - - private final int toastSmsStatusCode; - - ToastSmsResponseStatus(String description, int toastSmsStatusCode) { - this.toastSmsStatusCode = toastSmsStatusCode; - } - - public static boolean isInProgress(Integer toastSmsStatusCode) { - return toastSmsStatusCode != null && toastSmsStatusCode.equals(IN_PROGRESS.toastSmsStatusCode); - } - - public static boolean isSuccess(Integer toastSmsStatusCode) { - return toastSmsStatusCode != null && toastSmsStatusCode.equals(SUCCESS.toastSmsStatusCode); - } -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/infrastructure/sms/ToastSmsService.java b/mashup-domain/src/main/java/kr/mashup/branding/infrastructure/sms/ToastSmsService.java deleted file mode 100644 index c8087d855..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/infrastructure/sms/ToastSmsService.java +++ /dev/null @@ -1,194 +0,0 @@ -package kr.mashup.branding.infrastructure.sms; - -import java.nio.charset.Charset; -import java.util.Collections; -import java.util.Optional; -import java.util.stream.Collectors; - -import kr.mashup.branding.service.notification.sms.SmsWhitelistServiceImpl; -import org.springframework.beans.factory.ObjectProvider; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.ResponseEntity; -import org.springframework.util.Assert; -import org.springframework.web.client.RestClientException; -import org.springframework.web.client.RestTemplate; - -import kr.mashup.branding.domain.notification.NotificationStatus; -import kr.mashup.branding.domain.notification.sms.SmsNotificationStatus; -import kr.mashup.branding.domain.notification.sms.vo.SmsRequestVo; -import kr.mashup.branding.domain.notification.sms.exception.SmsSendFailedException; -import kr.mashup.branding.domain.notification.sms.vo.SmsSendResultRecipientVo; -import kr.mashup.branding.domain.notification.sms.vo.SmsSendResultVo; -import kr.mashup.branding.service.notification.sms.SmsService; -import kr.mashup.branding.service.notification.sms.SmsWhitelistService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -/** - * 지원하는 문자 길이는 아래와 같습니다. - * 최대 지원 글자 수는 저장 기준이며 문자 잘림을 방지하기 위해서 표준 규격으로 작성해주세요. - * 인코딩은 EUC-KR 기준으로 발송되며 지원하지 않는 이모티콘은 발송에 실패합니다. - * - * 분류 최대 지원 표준 규격 - * SMS 본문 255자 90바이트(한글 45자, 영문 90자) - * MMS 제목 120자 40바이트(한글 20자, 영문 40자) - * MMS 본문 4,000자 2,000바이트(한글 1,000자, 영문 2,000자) - * - * - * @see https://docs.toast.com/ko/Notification/SMS/ko/api-guide/ - */ -@Slf4j -@RequiredArgsConstructor // Configured by ToastSmsConfig -public class ToastSmsService implements SmsService { - private static final Charset CHARSET_EUC_KR = Charset.forName("euc-kr"); - private static final int SMS_MAX_LENGTH = 90; - - private final String toastUrl; - private final String appKey; - private final RestTemplate toastRestTemplate; - private final ObjectProvider smsWhitelistService; - - @Override - public SmsSendResultVo send(SmsRequestVo smsRequestVo) { - - final ToastSmsRequest toastSmsRequest = toToastSmsRequest(smsRequestVo); - final HttpEntity httpEntity - = new HttpEntity<>(toastSmsRequest, new HttpHeaders()); - - final ResponseEntity responseEntity; - try { - responseEntity = toastRestTemplate.exchange( - toastUrl + "/sms/v3.0/appKeys/" + appKey + "/sender/" + resolveRequestType(smsRequestVo.getContent()), - HttpMethod.POST, - httpEntity, - ToastSmsResponse.class - ); - } catch (RestClientException e) { - // request timeout 등 요청 만들다가 에러 - // read timeout 요청 보냈는데 답을 못받아서 에러 - // 응답 받았으나 status code 가 성공이 아님 - log.error("Failed while sending request to Toast SMS Api. toastSmsRequest: {}", toastSmsRequest, e); - throw new SmsSendFailedException(); - } - // 응답 잘 받았고, 내용이 성공 - // 응답 잘 받았고, 내용이 실패 - final ToastSmsResponse toastSmsResponse = responseEntity.getBody(); - if (toastSmsResponse == null || !toastSmsResponse.isSuccess()) { - log.error( - "Failed to send SMS. toastSmsResponse: " + toastSmsResponse + ", toastSmsRequest: " + toastSmsRequest); - } - return toSmsResultVo(toastSmsResponse); - } - - - - /** - * 글자수에 따라 SMS, MMS 를 구분한다. - * @return sms or mms - */ - private String resolveRequestType(String content) { - return content.getBytes(CHARSET_EUC_KR).length > SMS_MAX_LENGTH ? "mms" : "sms"; - } - - private ToastSmsRequest toToastSmsRequest(SmsRequestVo smsRequestVo) { - return ToastSmsRequest.of( - smsRequestVo.getContent(), - Optional.ofNullable(smsRequestVo.getSenderPhoneNumber()) - .map(it -> it.replaceAll("-", "")) - .orElse(null), - smsRequestVo.getMessageId(), - smsRequestVo.getSmsRecipientRequestVos() - .stream() - .map(it -> ToastSmsRecipient.of( - Optional.ofNullable(it.getPhoneNumber()) -// .filter(this::isInWhitelist) - .map(phoneNumber -> phoneNumber.replaceAll("-", "")) - .orElse(null), - it.getMessageId() - )) - .collect(Collectors.toList()) - ); - } - - /** - * 문자 발송을 시도해도 되는 전화번호인지 검사 - * @see SmsWhitelistServiceImpl - * @param phoneNumber 수신자 전화번호 - * @return 문자 발송을 시도해도되는지 여부 - */ - private boolean isInWhitelist(String phoneNumber) { - SmsWhitelistService service = smsWhitelistService.getIfAvailable(); - // 운영환경에서는 smsWhitelistService 가 존재하지 않고, 검사할 필요도 없다. - if (service == null) { - return true; - } - return service.contains(phoneNumber); - } - - private SmsSendResultVo toSmsResultVo(ToastSmsResponse toastSmsResponse) { - Assert.notNull(toastSmsResponse, "'toastSmsResponse' must not be null"); - if (toastSmsResponse.getBody() == null || toastSmsResponse.getBody().getData() == null) { - log.error("Failed to parse toastSmsResponse. toastSmsResponse: {}", toastSmsResponse); - return SmsSendResultVo.of( - null, - null, - NotificationStatus.FAILURE, - Collections.emptyList(), - String.valueOf(toastSmsResponse.getHeader().getResultCode()), - toastSmsResponse.getHeader().getResultMessage() - ); - } - return SmsSendResultVo.of( - toastSmsResponse.getBody().getData().getRequestId(), - toastSmsResponse.getBody().getData().getSenderGroupingKey(), - toNotificationStatus(toastSmsResponse), - toastSmsResponse.getBody().getData().getSendResultList() - .stream() - .map(this::toSmsSendResultRecipientVo) - .collect(Collectors.toList()), - String.valueOf(toastSmsResponse.getHeader().getResultCode()), - toastSmsResponse.getHeader().getResultMessage() - ); - } - - private NotificationStatus toNotificationStatus(ToastSmsResponse toastSmsResponse) { - final boolean isSuccess = toastSmsResponse.getHeader().getIsSuccessful(); - if (!isSuccess) { - return NotificationStatus.FAILURE; - } - final Integer toastSmsStatusCode = Optional.ofNullable(toastSmsResponse) - .map(ToastSmsResponse::getBody) - .map(ToastSmsResponse.ToastSmsResponseBody::getData) - .map(ToastSmsResponse.ToastSmsResponseBodyData::getStatusCode) - .orElse(null); - if (toastSmsStatusCode == null) { - return NotificationStatus.UNKNOWN; - } - switch (toastSmsStatusCode) { - case 1: - return NotificationStatus.IN_PROGRESS; - case 2: - return NotificationStatus.SUCCESS; - case 3: - return NotificationStatus.FAILURE; - default: - log.error("Unknown toastSmsStatusCode. toastSmsStatusCode: {}", toastSmsResponse); - return NotificationStatus.UNKNOWN; - } - } - - private SmsSendResultRecipientVo toSmsSendResultRecipientVo(ToastSmsResponse.ToastSendResult toastSendResult) { - Assert.notNull(toastSendResult, "'toastSendResult' must not be null"); - return SmsSendResultRecipientVo.of( - String.valueOf(toastSendResult.getRecipientSeq()), - toastSendResult.getRecipientGroupingKey(), - toastSendResult.getResultCode() != null && toastSendResult.getResultCode() == 0 - ? SmsNotificationStatus.SUCCESS - : SmsNotificationStatus.FAILURE, - String.valueOf(toastSendResult.getResultCode()), - toastSendResult.getResultMessage() - ); - } -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/repository/notification/NotificationRepository.java b/mashup-domain/src/main/java/kr/mashup/branding/repository/notification/NotificationRepository.java deleted file mode 100644 index f97f628c1..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/repository/notification/NotificationRepository.java +++ /dev/null @@ -1,16 +0,0 @@ -package kr.mashup.branding.repository.notification; - -import kr.mashup.branding.domain.notification.Notification; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface NotificationRepository extends JpaRepository, NotificationRepositoryCustom { - boolean existsByName(String name); - -} -/** - * Notification 연관관계 - * one to many : smsRequest - * many to one : adminMember - */ \ No newline at end of file diff --git a/mashup-domain/src/main/java/kr/mashup/branding/repository/notification/NotificationRepositoryCustom.java b/mashup-domain/src/main/java/kr/mashup/branding/repository/notification/NotificationRepositoryCustom.java deleted file mode 100644 index 72978073f..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/repository/notification/NotificationRepositoryCustom.java +++ /dev/null @@ -1,9 +0,0 @@ -package kr.mashup.branding.repository.notification; - -import kr.mashup.branding.domain.notification.Notification; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; - -public interface NotificationRepositoryCustom { - Page findWithSearchWord(String searchWord, Pageable pageable); -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/repository/notification/NotificationRepositoryCustomImpl.java b/mashup-domain/src/main/java/kr/mashup/branding/repository/notification/NotificationRepositoryCustomImpl.java deleted file mode 100644 index 0f03a7e6f..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/repository/notification/NotificationRepositoryCustomImpl.java +++ /dev/null @@ -1,30 +0,0 @@ -package kr.mashup.branding.repository.notification; - -import com.querydsl.core.QueryResults; -import com.querydsl.jpa.impl.JPAQueryFactory; -import kr.mashup.branding.domain.adminmember.entity.QAdminMember; -import kr.mashup.branding.domain.notification.Notification; -import kr.mashup.branding.util.QueryUtils; -import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; - -import static kr.mashup.branding.domain.adminmember.entity.QAdminMember.adminMember; -import static kr.mashup.branding.domain.notification.QNotification.notification; - -@RequiredArgsConstructor -public class NotificationRepositoryCustomImpl implements NotificationRepositoryCustom { - private final JPAQueryFactory queryFactory; - - @Override - public Page findWithSearchWord(String searchWord, Pageable pageable) { - QueryResults fetchResults = queryFactory - .selectFrom(notification) - .join(notification.sender, adminMember).fetchJoin() - .where(notification.name.contains(searchWord) // 발송 메모 - .or(adminMember.phoneNumber.contains(searchWord)) // 발송 번호 - .or(adminMember.position.stringValue().containsIgnoreCase(searchWord))) - .fetchResults(); - return QueryUtils.toPage(fetchResults, pageable); - } -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/repository/notification/sms/SmsRequestRepository.java b/mashup-domain/src/main/java/kr/mashup/branding/repository/notification/sms/SmsRequestRepository.java deleted file mode 100644 index 6511950e1..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/repository/notification/sms/SmsRequestRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package kr.mashup.branding.repository.notification.sms; - -import kr.mashup.branding.domain.notification.sms.SmsRequest; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface SmsRequestRepository extends JpaRepository, SmsRequestRepositoryCustom { - - -} -/** - * Sms Request 연관관계 - * many to one : notification, applicant - */ \ No newline at end of file diff --git a/mashup-domain/src/main/java/kr/mashup/branding/repository/notification/sms/SmsRequestRepositoryCustom.java b/mashup-domain/src/main/java/kr/mashup/branding/repository/notification/sms/SmsRequestRepositoryCustom.java deleted file mode 100644 index c4a04e13d..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/repository/notification/sms/SmsRequestRepositoryCustom.java +++ /dev/null @@ -1,9 +0,0 @@ -package kr.mashup.branding.repository.notification.sms; - -import kr.mashup.branding.domain.notification.sms.SmsRequest; - -import java.util.List; - -public interface SmsRequestRepositoryCustom { - List findByRecipient(Long applicantId); -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/repository/notification/sms/SmsRequestRepositoryCustomImpl.java b/mashup-domain/src/main/java/kr/mashup/branding/repository/notification/sms/SmsRequestRepositoryCustomImpl.java deleted file mode 100644 index fa9a9a1ec..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/repository/notification/sms/SmsRequestRepositoryCustomImpl.java +++ /dev/null @@ -1,25 +0,0 @@ -package kr.mashup.branding.repository.notification.sms; - -import com.querydsl.jpa.impl.JPAQueryFactory; -import kr.mashup.branding.domain.notification.sms.SmsRequest; -import lombok.RequiredArgsConstructor; - -import java.util.List; - -import static kr.mashup.branding.domain.notification.sms.QSmsRequest.smsRequest; - -@RequiredArgsConstructor -public class SmsRequestRepositoryCustomImpl implements SmsRequestRepositoryCustom{ - private final JPAQueryFactory queryFactory; - - - @Override - public List findByRecipient(Long applicantId) { - return queryFactory - .selectFrom(smsRequest) - .join(smsRequest.notification).fetchJoin() - .join(smsRequest.recipientApplicant).fetchJoin() - .where(smsRequest.recipientApplicant.applicantId.eq(applicantId)) - .fetch(); - } -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/repository/notification/sms/SmsWhitelistRepository.java b/mashup-domain/src/main/java/kr/mashup/branding/repository/notification/sms/SmsWhitelistRepository.java deleted file mode 100644 index 56297c7f0..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/repository/notification/sms/SmsWhitelistRepository.java +++ /dev/null @@ -1,15 +0,0 @@ -package kr.mashup.branding.repository.notification.sms; - -import java.util.Optional; - -import kr.mashup.branding.domain.notification.sms.whitelist.SmsWhitelist; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface SmsWhitelistRepository extends JpaRepository { - boolean existsByPhoneNumber(String phoneNumber); - - Optional findByPhoneNumber(String phoneNumber); -} -/** - * 연관관계 없음 - */ diff --git a/mashup-domain/src/main/java/kr/mashup/branding/service/adminmember/AdminMemberService.java b/mashup-domain/src/main/java/kr/mashup/branding/service/adminmember/AdminMemberService.java index 48410ab4b..202b41b29 100644 --- a/mashup-domain/src/main/java/kr/mashup/branding/service/adminmember/AdminMemberService.java +++ b/mashup-domain/src/main/java/kr/mashup/branding/service/adminmember/AdminMemberService.java @@ -17,7 +17,6 @@ import javax.transaction.Transactional; import java.util.List; -import java.util.Optional; @Validated @RequiredArgsConstructor @@ -36,9 +35,6 @@ public AdminMember signUp(final AdminMemberSignUpCommand command) { final AdminMember adminMember = AdminMember.of( command.getUsername(), passwordEncoder.encode(command.getPassword()), - Optional.ofNullable(command.getPhoneNumber()) - .map(String::trim) - .orElse(null), command.getPosition() ); diff --git a/mashup-domain/src/main/java/kr/mashup/branding/service/danggn/DanggnRankingRoundService.java b/mashup-domain/src/main/java/kr/mashup/branding/service/danggn/DanggnRankingRoundService.java index 5f4e28a97..9a00b3cb6 100644 --- a/mashup-domain/src/main/java/kr/mashup/branding/service/danggn/DanggnRankingRoundService.java +++ b/mashup-domain/src/main/java/kr/mashup/branding/service/danggn/DanggnRankingRoundService.java @@ -1,8 +1,10 @@ package kr.mashup.branding.service.danggn; +import kr.mashup.branding.domain.danggn.DanggnRankingReward; import kr.mashup.branding.domain.danggn.DanggnRankingRound; import kr.mashup.branding.domain.danggn.Exception.DanggnRankingRoundNotFoundException; import kr.mashup.branding.domain.generation.Generation; +import kr.mashup.branding.repository.danggn.DanggnRankingRewardRepository; import kr.mashup.branding.repository.danggn.DanggnRankingRoundRepository; import kr.mashup.branding.util.DateUtil; import lombok.RequiredArgsConstructor; @@ -19,6 +21,7 @@ public class DanggnRankingRoundService { private final DanggnRankingRoundRepository danggnRankingRoundRepository; + private final DanggnRankingRewardRepository danggnRankingRewardRepository; public DanggnRankingRound findCurrentByGeneration(Integer generationNumber) { return danggnRankingRoundRepository.retrieveCurrentByGenerationNum(generationNumber) @@ -53,4 +56,22 @@ public List getAllSorted() { public void save(DanggnRankingRound danggnRankingRound) { danggnRankingRoundRepository.save(danggnRankingRound); } + + public Boolean isLatestFirstPlaceMember(Integer generationNumber, Long memberId) { + Optional current = danggnRankingRoundRepository.retrieveCurrentByGenerationNum(generationNumber); + if (current.isEmpty()) { + return false; + } + + Optional previous = danggnRankingRoundRepository.findByNumberAndGenerationId(current.get().getNumber() - 1, current.get().getGenerationId()); + if (previous.isEmpty()) { + return false; + } + + Long firstPlaceRecordMemberId = danggnRankingRewardRepository.findByDanggnRankingRoundId(previous.get().getId()) + .map(DanggnRankingReward::getFirstPlaceRecordMemberId) + .orElse(null); + + return memberId == firstPlaceRecordMemberId; + } } diff --git a/mashup-domain/src/main/java/kr/mashup/branding/service/notification/NotificationEvent.java b/mashup-domain/src/main/java/kr/mashup/branding/service/notification/NotificationEvent.java deleted file mode 100644 index 493663e1b..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/service/notification/NotificationEvent.java +++ /dev/null @@ -1,9 +0,0 @@ -package kr.mashup.branding.service.notification; - -import lombok.Value; - -@Value(staticConstructor = "of") -public class NotificationEvent { - Long notificationId; - NotificationEventType type; -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/service/notification/NotificationEventPublisher.java b/mashup-domain/src/main/java/kr/mashup/branding/service/notification/NotificationEventPublisher.java deleted file mode 100644 index 40df877e6..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/service/notification/NotificationEventPublisher.java +++ /dev/null @@ -1,17 +0,0 @@ -package kr.mashup.branding.service.notification; - -import lombok.RequiredArgsConstructor; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.stereotype.Component; - -@Component -@RequiredArgsConstructor -public class NotificationEventPublisher { - - private final ApplicationEventPublisher eventPublisher; - - // listener: NotificationEventListener - public void publishNotificationEvent(NotificationEvent notificationEvent){ - eventPublisher.publishEvent(notificationEvent); - } -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/service/notification/NotificationEventType.java b/mashup-domain/src/main/java/kr/mashup/branding/service/notification/NotificationEventType.java deleted file mode 100644 index af864adbe..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/service/notification/NotificationEventType.java +++ /dev/null @@ -1,5 +0,0 @@ -package kr.mashup.branding.service.notification; - -public enum NotificationEventType { - CREATED, -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/service/notification/NotificationService.java b/mashup-domain/src/main/java/kr/mashup/branding/service/notification/NotificationService.java deleted file mode 100644 index 85395cb12..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/service/notification/NotificationService.java +++ /dev/null @@ -1,175 +0,0 @@ -package kr.mashup.branding.service.notification; - -import kr.mashup.branding.domain.adminmember.entity.AdminMember; -import kr.mashup.branding.domain.applicant.Applicant; -import kr.mashup.branding.domain.generation.Generation; -import kr.mashup.branding.domain.notification.Notification; -import kr.mashup.branding.domain.notification.exception.NotificationNotFoundException; -import kr.mashup.branding.domain.notification.exception.NotificationRequestInvalidException; -import kr.mashup.branding.domain.notification.sms.SmsRequest; -import kr.mashup.branding.domain.notification.sms.vo.SmsSendRequestVo; -import kr.mashup.branding.domain.notification.sms.vo.SmsSendResultRecipientVo; -import kr.mashup.branding.domain.notification.sms.vo.SmsSendResultVo; -import kr.mashup.branding.repository.notification.NotificationRepository; -import kr.mashup.branding.repository.notification.sms.SmsRequestRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; -import org.springframework.lang.Nullable; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -@Service -@Transactional(readOnly = true) -@RequiredArgsConstructor -public class NotificationService { - private final NotificationRepository notificationRepository; - private final SmsRequestRepository smsRequestRepository; - - @Transactional - public Notification createSmsNotification( - final AdminMember adminMember, - final Generation generation, - final List recipientApplicants, - final SmsSendRequestVo smsSendRequestVo) { - - Assert.notNull(smsSendRequestVo, "'smsSendVo' must not be null"); - validateSmsRequest(adminMember, recipientApplicants, smsSendRequestVo); - - final Notification notification - = notificationRepository.save(Notification.sms(adminMember, generation, smsSendRequestVo)); - - final List smsRequests - = recipientApplicants - .stream() - .map(it -> SmsRequest.of(notification, it)) - .collect(Collectors.toList()); - - notification.setSmsRequests(smsRequests); // cascade all - - return notification; - } - - @Transactional - public Notification updateSmsStatus( - final Long notificationId, - final SmsSendResultVo smsSendResultVo) { - - Assert.notNull(notificationId, "'notificationId' must not be null"); - Assert.notNull(smsSendResultVo, "'smsSendResultVo' must not be null"); - - final Notification notification - = notificationRepository - .findById(notificationId) - .orElseThrow(() -> new NotificationNotFoundException(notificationId)); - - if (smsSendResultVo == SmsSendResultVo.UNKNOWN) { - // API 결과 못받은 경우 - notification.markToUnknown(); - } - // API 결과 받은 경우 - notification.markResult( - smsSendResultVo.getStatus(), - smsSendResultVo.getResultId(), - smsSendResultVo.getResultCode(), - smsSendResultVo.getResultMessage() - ); - final Map resultRecipientVoMap - = smsSendResultVo.getRecipientResultVos() - .stream() - .collect(Collectors.toMap(SmsSendResultRecipientVo::getMessageId, it -> it)); - - final List smsRequests = notification.getSmsRequests(); - - smsRequests.forEach(it -> it.setResult(resultRecipientVoMap.get(it.getMessageId()))); - - return notification; - } - - public Page getNotifications( - final Long adminMemberId, - @Nullable final String searchWord, - Pageable pageable) { - - Assert.notNull(pageable, "'pageable' must not be null"); - - pageable = PageRequest.of( - pageable.getPageNumber(), - pageable.getPageSize(), - pageable.getSortOr(Sort.by(Sort.Order.desc("sentAt"))) - ); - - return notificationRepository.findWithSearchWord(searchWord, pageable); - } - - - public Notification getNotification(final Long notificationId) { - Assert.notNull(notificationId, "'notificationId' must not be null"); - return notificationRepository.findById(notificationId) - .orElseThrow(NotificationNotFoundException::new); - } - - public List getSmsRequestsByApplicantId(final Long applicantId) { - Assert.notNull(applicantId, "'applicantId' must not be null"); - return smsRequestRepository.findByRecipient(applicantId); - } - - /** - * ========= Private Methods =============== - */ - private void validateSmsRequest( - final AdminMember adminMember, - final List recipientApplicants, - SmsSendRequestVo smsSendRequestVo) { - - validatedNotDuplicatedNotificationName(smsSendRequestVo); - - validateNotEmptyContents(smsSendRequestVo); - - validateNotEmptyRecipient(recipientApplicants); - - validateAdminPhoneNumberRegisteredToExternalService(adminMember); - - validateNotEmptyAdminPhoneNumber(adminMember); - } - - private void validateNotEmptyAdminPhoneNumber(final AdminMember adminMember) { - if (!StringUtils.hasText(adminMember.getPhoneNumber())) { - throw new NotificationRequestInvalidException("Sender's phoneNumber must not be null, empty or blank"); - } - } - - private void validateAdminPhoneNumberRegisteredToExternalService(final AdminMember adminMember) { - if (adminMember.getPhoneNumberRegistered() != Boolean.TRUE) { - throw new NotificationRequestInvalidException( - "Sender's phoneNumber must be registered to NHN Cloud Notification Service"); - } - } - - private void validateNotEmptyRecipient(final List recipientApplicants) { - if (recipientApplicants.isEmpty()) { - throw new NotificationRequestInvalidException("'recipientApplicantIds' must not be empty or null"); - } - } - - private void validateNotEmptyContents(final SmsSendRequestVo smsSendRequestVo) { - if (!StringUtils.hasText(smsSendRequestVo.getContent())) { - throw new NotificationRequestInvalidException("'content' must not be null, empty or blank"); - } - } - - private void validatedNotDuplicatedNotificationName(final SmsSendRequestVo smsSendRequestVo) { - if (notificationRepository.existsByName(smsSendRequestVo.getName())) { - throw new NotificationRequestInvalidException( - "Notification name duplicated. name: " + smsSendRequestVo.getName()); - } - } -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/service/notification/sms/SmsService.java b/mashup-domain/src/main/java/kr/mashup/branding/service/notification/sms/SmsService.java deleted file mode 100644 index 483ef5bc2..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/service/notification/sms/SmsService.java +++ /dev/null @@ -1,9 +0,0 @@ -package kr.mashup.branding.service.notification.sms; - -import kr.mashup.branding.domain.notification.sms.vo.SmsRequestVo; -import kr.mashup.branding.domain.notification.sms.vo.SmsSendResultVo; - -// 외부서비스 호출하는 거라서 인터페이스 유지 필요 -public interface SmsService { - SmsSendResultVo send(SmsRequestVo smsRequestVo); -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/service/notification/sms/SmsWhitelistService.java b/mashup-domain/src/main/java/kr/mashup/branding/service/notification/sms/SmsWhitelistService.java deleted file mode 100644 index 69b592df2..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/service/notification/sms/SmsWhitelistService.java +++ /dev/null @@ -1,13 +0,0 @@ -package kr.mashup.branding.service.notification.sms; - -import java.util.List; - -public interface SmsWhitelistService { - boolean contains(String phoneNumber); - - String add(String phoneNumber); - - void remove(String phoneNumber); - - List getAll(); -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/service/notification/sms/SmsWhitelistServiceImpl.java b/mashup-domain/src/main/java/kr/mashup/branding/service/notification/sms/SmsWhitelistServiceImpl.java deleted file mode 100644 index b202c78b6..000000000 --- a/mashup-domain/src/main/java/kr/mashup/branding/service/notification/sms/SmsWhitelistServiceImpl.java +++ /dev/null @@ -1,60 +0,0 @@ -package kr.mashup.branding.service.notification.sms; - -import java.util.List; -import java.util.stream.Collectors; - -import kr.mashup.branding.domain.notification.sms.whitelist.SmsWhitelist; -import kr.mashup.branding.repository.notification.sms.SmsWhitelistRepository; -import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import lombok.RequiredArgsConstructor; - -/** - * 개발환경에서 실수로 SMS 발송하는걸 방지하기 위해서 whitelist 를 관리한다. - * 개발환경인 경우 whitelist 에 등록된 번호만 실제 문자 발송요청을 보낸다. - * 운영환경인 경우 whitelist 를 사용하지 않는다. - */ -@Profile("!production") -@Transactional(readOnly = true) -@Service -@RequiredArgsConstructor -public class SmsWhitelistServiceImpl implements SmsWhitelistService { - private final SmsWhitelistRepository smsWhitelistRepository; - - /** - * 전화번호가 whitelist 에 등록되었는지 검사 - * @param phoneNumber 전화번호 - * @return 주어진 전화번호가 whitelist 에 존재하는지 여부 - */ - @Override - public boolean contains(String phoneNumber) { - return smsWhitelistRepository.existsByPhoneNumber(phoneNumber); - } - - @Override - @Transactional - public String add(String phoneNumber) { - if (smsWhitelistRepository.existsByPhoneNumber(phoneNumber)) { - return phoneNumber; - } - return smsWhitelistRepository.save(SmsWhitelist.of(phoneNumber)) - .getPhoneNumber(); - } - - @Override - @Transactional - public void remove(String phoneNumber) { - smsWhitelistRepository.findByPhoneNumber(phoneNumber) - .ifPresent(smsWhitelistRepository::delete); - } - - @Override - public List getAll() { - return smsWhitelistRepository.findAll() - .stream() - .map(SmsWhitelist::getPhoneNumber) - .collect(Collectors.toList()); - } -} diff --git a/mashup-domain/src/main/java/kr/mashup/branding/service/popup/MemberPopupService.java b/mashup-domain/src/main/java/kr/mashup/branding/service/popup/MemberPopupService.java index d91e653f6..41ecf8140 100644 --- a/mashup-domain/src/main/java/kr/mashup/branding/service/popup/MemberPopupService.java +++ b/mashup-domain/src/main/java/kr/mashup/branding/service/popup/MemberPopupService.java @@ -1,16 +1,15 @@ package kr.mashup.branding.service.popup; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.Optional; - -import org.springframework.stereotype.Service; - import kr.mashup.branding.domain.member.Member; import kr.mashup.branding.domain.popup.MemberPopup; import kr.mashup.branding.domain.popup.PopupType; import kr.mashup.branding.repository.memberpopup.MemberPopupRepository; import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.Optional; @Service @RequiredArgsConstructor diff --git a/mashup-member/src/main/java/kr/mashup/branding/facade/popup/MemberPopupFacadeService.java b/mashup-member/src/main/java/kr/mashup/branding/facade/popup/MemberPopupFacadeService.java index a8b5b349c..93b8fcc3f 100644 --- a/mashup-member/src/main/java/kr/mashup/branding/facade/popup/MemberPopupFacadeService.java +++ b/mashup-member/src/main/java/kr/mashup/branding/facade/popup/MemberPopupFacadeService.java @@ -1,21 +1,20 @@ package kr.mashup.branding.facade.popup; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; - -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - import kr.mashup.branding.domain.member.MemberGeneration; import kr.mashup.branding.domain.member.exception.InactiveGenerationException; import kr.mashup.branding.domain.popup.MemberPopup; import kr.mashup.branding.domain.popup.PopupType; +import kr.mashup.branding.service.danggn.DanggnRankingRoundService; import kr.mashup.branding.service.member.MemberService; import kr.mashup.branding.service.popup.MemberPopupService; -import kr.mashup.branding.service.storage.StorageService; import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; @Service @RequiredArgsConstructor @@ -24,7 +23,7 @@ public class MemberPopupFacadeService { private final MemberPopupService memberPopupService; private final MemberService memberService; - private final StorageService storageService; + private final DanggnRankingRoundService danggnRankingRoundService; public List getEnabledPopupTypes( Long memberGenerationId @@ -44,6 +43,11 @@ public List getEnabledPopupTypes( .filter(popupType -> memberPopupService.isEnabledMemberPopup(memberGeneration.getMember(), popupType)) .forEach(enabledMemberPopupTypes::add); + // 당근 1등 리워드 팝업의 경우, 최근 1등인 경우에만 노출 + if (!danggnRankingRoundService.isLatestFirstPlaceMember(memberGeneration.getGeneration().getNumber(), memberGeneration.getMember().getId())) { + enabledMemberPopupTypes.remove(PopupType.DANGGN_REWARD); + } + return enabledMemberPopupTypes; }