Skip to content

Commit

Permalink
[BE-50] Mongo Atlas -> local Mongo Migration Setting #155
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackBean99 authored Feb 12, 2024
1 parent 553ae09 commit 3a63819
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 46 deletions.
Binary file modified server/.gradle/7.6.1/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified server/.gradle/7.6.1/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified server/.gradle/7.6.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified server/.gradle/7.6.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified server/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified server/.gradle/file-system.probe
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,27 +1,81 @@
package com.econovation.recruit.api.applicant.aggregate;

import com.econovation.recruitcommon.exception.RecruitCodeException;
import com.econovation.recruitdomain.common.aop.domainEvent.Events;
import com.econovation.recruitdomain.domains.applicant.domain.MongoAnswer;
import com.econovation.recruitdomain.domains.applicant.domain.MongoAnswerAdaptor;
import com.econovation.recruitdomain.domains.applicant.event.aggregateevent.AnswerCreatedEvent;
import com.econovation.recruitdomain.domains.applicant.event.domainevent.ApplicantRegisterEvent;
import com.econovation.recruitdomain.domains.applicant.exception.ApplicantDuplicateSubmitException;
import com.econovation.recruitdomain.domains.applicant.exception.ApplicantWrongPositionException;
import io.vavr.collection.Seq;
import io.vavr.control.Validation;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.axonframework.eventhandling.EventHandler;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
@RequiredArgsConstructor
public class AnswerCreatedEventListener {
private final MongoAnswerAdaptor answerAdaptor;

@Value("${econovation.year}")
private Integer year;

@EventHandler
@Transactional
public void handle(AnswerCreatedEvent event) {
Map<String, Object> qna = event.getQna();
MongoAnswer answer =
MongoAnswer.builder()
.id(event.getId())
.year(event.getYear())
.qna(event.getQna())
.build();
// 학번으로 중복 체크
validateRegisterApplicant(qna);

answerAdaptor.save(answer);

String name = qna.get("name").toString().replace("\"", "");
;
String hopeField = qna.get("field").toString().replace("\"", "");
;
String email = qna.get("email").toString().replace("\"", "");
;

// email 전송 event처리
ApplicantRegisterEvent applicantRegisterEvent =
ApplicantRegisterEvent.of(answer.getId(), name, hopeField, email);
Events.raise(applicantRegisterEvent);
}

private Validation<Seq<RecruitCodeException>, Map<String, Object>> validateRegisterApplicant(
Map<String, Object> qna) {
return Validation.combine(validateDuplicateSudentId(qna), validateIsRightPosition(qna))
.ap((a, b) -> qna);
}

private Validation<RecruitCodeException, Object> validateIsRightPosition(
Map<String, Object> qna) {
String field = qna.get("field").toString().replace("\"", "");
;
if (field.equals("기획자") || field.equals("개발자") || field.equals("디자이너")) {
return Validation.valid(qna);
}
throw ApplicantWrongPositionException.EXCEPTION;
}

private Validation<RecruitCodeException, Map<String, Object>> validateDuplicateSudentId(
Map<String, Object> qna) {
String studentId = qna.get("classOf").toString().replace("\"", "");
;
if (answerAdaptor.existsByAnswer(studentId, year)) {
throw ApplicantDuplicateSubmitException.EXCEPTION;
}
return Validation.valid(qna);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.econovation.recruit.api.applicant.handler;

import com.econovation.recruit.api.user.helper.NcpMailHelper;
import com.econovation.recruitdomain.domains.applicant.event.domainevent.ApplicantRegisterEvent;
import com.econovation.recruitinfrastructure.apache.CommonsEmailSender;
import lombok.RequiredArgsConstructor;
Expand All @@ -16,7 +15,6 @@
@RequiredArgsConstructor
@Slf4j
public class ApplicantRegisterEventConfirmEmailHandler {
private final NcpMailHelper ncpMailHelper;
private final CommonsEmailSender commonsEmailSender;

@Async
Expand All @@ -25,9 +23,9 @@ public class ApplicantRegisterEventConfirmEmailHandler {
phase = TransactionPhase.AFTER_COMMIT)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void handle(ApplicantRegisterEvent applicantRegistEvent) {
log.info("%s님의 지원서가 접수되었습니다.", applicantRegistEvent.getUserName());
String email = applicantRegistEvent.getEmail().replace("\"", "");
commonsEmailSender.send(email, applicantRegistEvent.getApplicantId());
log.info(applicantRegistEvent.getUserName() + "님의 지원서가 접수되었습니다.");
commonsEmailSender.send(
applicantRegistEvent.getEmail(), applicantRegistEvent.getApplicantId());
}

private String generateConfirmRegisterEmailBody(String userName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package com.econovation.recruit.api.applicant.service;

import com.econovation.recruit.api.applicant.usecase.ApplicantCommandUseCase;
import com.econovation.recruitcommon.exception.RecruitCodeException;
import com.econovation.recruitdomain.common.aop.domainEvent.Events;
import com.econovation.recruitdomain.domains.applicant.domain.MongoAnswer;
import com.econovation.recruitdomain.domains.applicant.domain.MongoAnswerAdaptor;
import com.econovation.recruitdomain.domains.applicant.event.domainevent.ApplicantRegisterEvent;
import com.econovation.recruitdomain.domains.applicant.exception.ApplicantDuplicateSubmitException;
import com.econovation.recruitdomain.domains.applicant.exception.ApplicantWrongPositionException;
import io.vavr.collection.Seq;
import io.vavr.control.Validation;
import java.util.Map;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
Expand All @@ -25,11 +21,12 @@ public class AnswerCommandService implements ApplicantCommandUseCase {
private Integer year;

@Override
@Transactional
public UUID execute(Map<String, Object> qna) {
UUID id = UUID.randomUUID();
MongoAnswer answer = MongoAnswer.builder().id(id.toString()).qna(qna).year(year).build();
// 학번으로 중복 체크
validateRegisterApplicant(qna);
// 학번으로 중복 체크
// validateRegisterApplicant(qna);
answerAdaptor.save(answer);

String name = qna.get("name").toString();
Expand All @@ -41,28 +38,4 @@ public UUID execute(Map<String, Object> qna) {
Events.raise(applicantRegisterEvent);
return id;
}

private Validation<Seq<RecruitCodeException>, Map<String, Object>> validateRegisterApplicant(
Map<String, Object> qna) {
return Validation.combine(validateDuplicateSudentId(qna), validateIsRightPosition(qna))
.ap((a, b) -> qna);
}

private Validation<RecruitCodeException, Object> validateIsRightPosition(
Map<String, Object> qna) {
String field = qna.get("field").toString();
if (field.equals("기획자") || field.equals("개발자") || field.equals("디자이너")) {
return Validation.valid(qna);
}
throw ApplicantWrongPositionException.EXCEPTION;
}

private Validation<RecruitCodeException, Map<String, Object>> validateDuplicateSudentId(
Map<String, Object> qna) {
String studentId = qna.get("classOf").toString();
if (answerAdaptor.existsByAnswer(studentId, year)) {
throw ApplicantDuplicateSubmitException.EXCEPTION;
}
return Validation.valid(qna);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@Component
@RequiredArgsConstructor
@Slf4j
public class ApplicantRegisterEventHandler {
public class ApplicantSlackSendAndCardRegisterEventHandler {
private final SlackMessageProvider slackMessageProvider;
private final SlackProperties slackProperties;
private final CardAdaptor cardAdaptor;
Expand All @@ -45,7 +45,10 @@ public void handle(ApplicantRegisterEvent applicantRegistEvent) {

private String generateApplicantRegisterMessage(ApplicantRegisterEvent applicantRegistEvent) {
return String.format(
":clapping: 지원자가 등록되었습니다.:clapping:\n"
":drum_with_drumsticks:두둥-탁 -!\n"
+ ":space_invader::black_small_square::space_invader::black_small_square::space_invader::black_small_square::space_invader::black_small_square::space_invader::black_small_square:\n"
+ ":sparkles::eyes:새로운 지원자 등장:eyes::sparkles:\n"
+ ":black_small_square::space_invader::black_small_square::space_invader::black_small_square::space_invader::black_small_square::space_invader::black_small_square::space_invader:\n"
+ ":chikorita: 지원자 이름: %s\n"
+ ":chikorita:희망 분야: %s",
applicantRegistEvent.getUserName(), applicantRegistEvent.getHopeField());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.datasource.init.ScriptUtils;
import org.springframework.security.crypto.password.PasswordEncoder;

// @Component
@RequiredArgsConstructor
@Slf4j
// @ConditionalOnProperty(name = "data.init.disabled", havingValue = "false", matchIfMissing = true)
@ConditionalOnProperty(name = "data.init.disabled", havingValue = "false", matchIfMissing = true)
public class DataInit {
private final DataSource dataSource;
private final InterviewerRecordPort interviewerRecordPort;
Expand Down
5 changes: 5 additions & 0 deletions server/Recruit-Api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ throttle:
auth:
blacklist:
prefix: ${JWT_BLACKLIST_PREFIX:BlackList_AccessToken_}
notification:
email:
enabled: ${NOTIFICATION_EMAIL_ENABLED:true}
slack:
enabled: ${NOTIFICATION_SLACK_ENABLED:true}
login:
page:
url: ${LOGIN_PAGE_URL:http://localhost:8080/login}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.apache.commons.mail.SimpleEmail;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class CommonsEmailSender {
private final CommonsEmailProperties commonsEmailProperties;

@Value("${econovation.year}")
private Integer year;

public void send(String toEmail, String name, String contents) {
SimpleEmail email = new SimpleEmail();
email.setCharset("euc-kr");
Expand All @@ -29,7 +33,7 @@ public void send(String toEmail, String name, String contents) {
email.setContent(contents, "text/html; charset=euc-kr");
email.send();
} catch (EmailException e) {
throw new RuntimeException(e);
throw new IllegalArgumentException(e);
}
}

Expand All @@ -51,13 +55,15 @@ public void send(String toEmail, String applicantId) {
email.setHtmlMsg(generateHtml(applicantId));
email.send();
} catch (EmailException e) {
throw new RuntimeException(e);
throw new IllegalArgumentException(e);
}
}

private String generateHtml(String applicantId) {
String html =
"<!DOCTYPE html><html lang=\"ko\"><head> <meta charset=\"utf-8\"> <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"> <title>Econovation Recruit</title> <meta name=\"description\" content=\"Recruit site for econovation\"> <style>.hover-a{text-decoration: none;} .hover-a:hover{text-decoration: underline;}</style></head><body style=\"width:fit-content; height: 100vh; max-width: 1920px; margin: auto; display: block; text-align: center;\"> <section style=\"padding-top: 100px;\"><img alt=\"econo-3d-logo\" width=\"114\" height=\"143\" style=\"color:transparent; margin:auto;\" src=\"https://recruit.econovation.kr/images/econo-3d-logo.png\"> <h1 style=\"font-weight: 800; font-size:40px;\">신입모집 지원 완료!</h1> <div style=\"font-size: 18px;\"> <div style=\"margin: 8px;\">에코노베이션 26기 지원서가 정상적으로 업로드 되었습니다</div> <div style=\"margin: 8px;\">서류 합격 결과는 9월 19일에 개인 메일으로 공지 될 예정입니다.</div> <div style=\"margin: 8px;\"><a class=\"hover-a\" style=\"color: #2160FF; font-weight: 700;\" href=\"https://recruit.econovation.kr/applicant/pdf-viewer?id=%APPLICANT_ID%\">여기</a>에서 지원서를 확인하실 수 있습니다.</div> <div style=\"margin: 8px;\">지원해주셔서 감사합니다.</div> </div> </section></body></html>";
"<!DOCTYPE html><html lang=\"ko\"><head> <meta charset=\"utf-8\"> <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"> <title>Econovation Recruit</title> <meta name=\"description\" content=\"Recruit site for econovation\"> <style>.hover-a{text-decoration: none;} .hover-a:hover{text-decoration: underline;}</style></head><body style=\"width:fit-content; height: 100vh; max-width: 1920px; margin: auto; display: block; text-align: center;\"> <section style=\"padding-top: 100px;\"><img alt=\"econo-3d-logo\" width=\"114\" height=\"143\" style=\"color:transparent; margin:auto;\" src=\"https://recruit.econovation.kr/images/econo-3d-logo.png\"> <h1 style=\"font-weight: 800; font-size:40px;\">신입모집 지원 완료!</h1> <div style=\"font-size: 18px;\"> <div style=\"margin: 8px;\">에코노베이션 "
+ year
+ "기 지원서가 정상적으로 업로드 되었습니다</div> <div style=\"margin: 8px;\">서류 합격 결과는 9월 19일에 개인 메일으로 공지 될 예정입니다.</div> <div style=\"margin: 8px;\"><a class=\"hover-a\" style=\"color: #2160FF; font-weight: 700;\" href=\"https://recruit.econovation.kr/applicant/pdf-viewer?id=%APPLICANT_ID%\">여기</a>에서 지원서를 확인하실 수 있습니다.</div> <div style=\"margin: 8px;\">지원해주셔서 감사합니다.</div> </div> </section></body></html>";
return html.replace("%APPLICANT_ID%", applicantId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ncp:
access-key: ${NCP_ACCESS_KEY}
secret-key: ${NCP_SECRET_KEY}
sender-address: ${NCP_SENDER_ADDRESS:}
send-url: ${NCP_MAIL_URL:https://mail.apigw.gov-ntruss.com}
send-url: ${NCP_MAIL_URL:https://mail.apigw.gov-ntruss. com}
commons:
email:
host: ${COMMONS_EMAIL_HOST:smtp.naver.com}
Expand Down
11 changes: 8 additions & 3 deletions server/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
version: "3.7"
services:
redis:
image: "redis:alpine"
image: redis:alpine
hostname: redis
container_name: redis
network_mode: "host"

axon-server:
image: axoniq/axonserver:4.6.11
container_name: axon-server
restart: unless-stopped
network_mode: "host"
ports:
- "8024:8024"
- "8124:8124"

backend:
image: blackbean99/econo-recruit:latest
restart: unless-stopped
Expand All @@ -20,5 +25,5 @@ services:
environment:
- TZ=Asia/Seoul
depends_on:
- axon-server
- redis
- redis
- axon-server

0 comments on commit 3a63819

Please sign in to comment.