Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

️♻️ refactor: 이메일 & 포트원 모듈 분리 #254

Merged
merged 6 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions .github/workflows/ci_gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
echo "spring:" > application.yml
echo " profiles:" >> application.yml
echo " group:" >> application.yml
echo " "local": "db, s3, secret"" >> application.yml
echo " "prod": "db, s3, redis"" >> application.yml
echo " "local": "db, s3, email, portone, secret"" >> application.yml
echo " "prod": "db, s3, redis, email, portone"" >> application.yml
echo " default: prod" >> application.yml

echo " servlet:" >> application.yml
Expand All @@ -49,13 +49,8 @@ jobs:
spring.jwt.secret: ${{ secrets.JWT_SECRET }}
spring.jwt.token.access-expiration-time: ${{ secrets.JWT_ACCESS_EXPIRATION_TIME }}
spring.jwt.token.refresh-expiration-time: ${{ secrets.JWT_REFRESH_EXPIRATION_TIME }}
mail.smtp.port: ${{ secrets.EMAIL_PORT }}
AdminMail.id: ${{ secrets.EMAIL_ID }}
AdminMail.password: ${{ secrets.EMAIL_PASSWORD }}
firebase.fcmUrl: ${{ secrets.FIREBASE_URL}}
firebase.firebaseConfigPath: ${{ secrets.FIREBASE_PATH}}
PORT_ONE_KEY: ${{ secrets.PORT_ONE_KEY}}
PORT_ONE_SECRET: ${{ secrets.PORT_ONE_SECRET}}

- name: 4) Set application-db.yml
uses: microsoft/variable-substitution@v1
Expand Down Expand Up @@ -84,6 +79,23 @@ jobs:
spring.data.redis.host: ${{ secrets.REDIS_HOST }}
spring.data.redis.port: ${{ secrets.REDIS_PORT }}

- name: 7) Set application-email.yml
uses: microsoft/variable-substitution@v1
with:
files: ./core/core-infra-email/src/main/resources/application-email.yml
env:
mail.smtp.port: ${{ secrets.EMAIL_PORT }}
AdminMail.id: ${{ secrets.EMAIL_ID }}
AdminMail.password: ${{ secrets.EMAIL_PASSWORD }}

- name: 8) Set application-portone.yml
uses: microsoft/variable-substitution@v1
with:
files: ./core/core-infra-portone/src/main/resources/application-portone.yml
env:
PORT_ONE_KEY: ${{ secrets.PORT_ONE_KEY}}
PORT_ONE_SECRET: ${{ secrets.PORT_ONE_SECRET}}

- name: Grant execute permission for gradlew and build
run: |
chmod +x ./gradlew
Expand Down
15 changes: 5 additions & 10 deletions api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ dependencies {
implementation project(':core:core-infra-db');
implementation project(':core:core-infra-s3');
implementation project(':core:core-infra-redis');
implementation project(':core:core-infra-email');
implementation project(':core:core-infra-portone');

// Core
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
Expand All @@ -15,9 +17,9 @@ dependencies {
implementation 'org.slf4j:slf4j-api:2.0.7'

// Lombok
implementation 'org.projectlombok:lombok:1.18.22'
annotationProcessor('org.projectlombok:lombok')
testAnnotationProcessor('org.projectlombok:lombok')
// implementation 'org.projectlombok:lombok:1.18.22'
// annotationProcessor('org.projectlombok:lombok')
// testAnnotationProcessor('org.projectlombok:lombok')

// Jwt
implementation 'io.jsonwebtoken:jjwt-api:0.12.3'
Expand All @@ -31,16 +33,9 @@ dependencies {
// Validation
implementation 'org.springframework.boot:spring-boot-starter-validation'

// email
implementation 'org.springframework.boot:spring-boot-starter-mail'

// FCM
implementation 'com.google.firebase:firebase-admin:9.1.1'
implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.2.2'

// Iamport
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'com.github.iamport:iamport-rest-client-java:0.2.23'
}
bootJar { enabled = true }
jar { enabled = false }
14 changes: 0 additions & 14 deletions api/out/production/resources/application-local.yml

This file was deleted.

37 changes: 0 additions & 37 deletions api/out/production/resources/application-prod.yml

This file was deleted.

14 changes: 0 additions & 14 deletions api/out/production/resources/application.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import static com.sponus.sponusbe.domain.organization.exception.OrganizationErrorCode.*;

import java.util.List;
import java.util.Random;

import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -15,6 +13,7 @@
import com.sponus.coredomain.domain.notification.repository.NotificationRepository;
import com.sponus.coredomain.domain.organization.Organization;
import com.sponus.coredomain.domain.organization.repository.OrganizationRepository;
import com.sponus.coreinfraemail.EmailUtil;
import com.sponus.coreinfras3.S3Util;
import com.sponus.sponusbe.domain.notification.exception.NotificationErrorCode;
import com.sponus.sponusbe.domain.notification.exception.NotificationException;
Expand All @@ -24,8 +23,6 @@
import com.sponus.sponusbe.domain.organization.dto.OrganizationUpdateRequest;
import com.sponus.sponusbe.domain.organization.exception.OrganizationException;

import jakarta.mail.internet.InternetAddress;
import jakarta.mail.internet.MimeMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -38,8 +35,8 @@ public class OrganizationService {
private final OrganizationRepository organizationRepository;
private final NotificationRepository notificationRepository;
private final PasswordEncoder passwordEncoder;
private final JavaMailSender emailSender;
private final S3Util s3Util;
private final EmailUtil emailUtil;

public OrganizationJoinResponse join(OrganizationJoinRequest request) {
final Organization organization = organizationRepository.save(
Expand Down Expand Up @@ -72,57 +69,7 @@ public void deactivateOrganization(Long organizationId) {
}

public String sendEmail(String to) throws Exception {
String code = createEmailCode();
MimeMessage message = createEmail(to, code);
emailSender.send(message);
return code;
}

private MimeMessage createEmail(String to, String code) throws Exception {
log.info("보내는 대상 : " + to);
log.info("인증 코드 : " + code);
MimeMessage message = emailSender.createMimeMessage();
message.addRecipients(MimeMessage.RecipientType.TO, to); // 보내는 대상
message.setSubject("Spon-us 인증 코드 발급입니다."); // 제목

String msgg = "";
msgg += "<div style='margin:20px;'>";
msgg += "<h1> Spon-us 인증 코드입니다. </h1>"; // 동적으로 메시지 내용 변경
msgg += "<br>";
msgg += "<div align='center' style='border:1px solid black; font-family:verdana';>";
msgg += "<h3 style='color:blue;'> 인증 코드 </h3>";
msgg += "<div style='font-size:130%'>";
msgg += "인증 코드 : <strong>";
msgg += code + "</strong><div><br/> ";
msgg += "</div>";
message.setText(msgg, "utf-8", "html"); // 내용
message.setFrom(new InternetAddress("Spon-us_team", "Spon-us")); // 보내는 사람

return message;
}

public static String createEmailCode() {
StringBuilder code = new StringBuilder();
Random rnd = new Random();

for (int i = 0; i < 6; i++) { // 인증 코드 6자리
int index = rnd.nextInt(3); // 0~2 까지 랜덤
switch (index) {
case 0:
code.append((char)((rnd.nextInt(26)) + 97));
// a~z (ex. 1+97=98 => (char)98 = 'b')
break;
case 1:
code.append((char)((rnd.nextInt(26)) + 65));
// A~Z
break;
default:
code.append((rnd.nextInt(10)));
// 0~9
break;
}
}
return code.toString();
return emailUtil.sendEmail(to);
}

public List<OrganizationSummaryResponse> searchOrganization(String keyword) {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public enum ProposeErrorCode implements BaseErrorCode {
INVALID_PROPOSED_ORGANIZATION(HttpStatus.BAD_REQUEST, "PROP4003", "제안을 받은 단체만 접근이 가능합니다."),
PROPOSE_STATUS_NOT_PENDING(HttpStatus.BAD_REQUEST, "PROP4004", "수락 대기 중인 제안만 수정이 가능합니다."),
INVALID_PROPOSE_STATUS(HttpStatus.BAD_REQUEST, "PROP4005", "유효하지 않은 제안 상태입니다."),
PROPOSE_ALREADY_PAID(HttpStatus.BAD_REQUEST, "PROP4006", "이미 결제된 제안입니다."),
PROPOSE_NOT_FOUND(HttpStatus.NOT_FOUND, "PROP4040", "해당 제안이 존재하지 않습니다."),
PAYMENT_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "PROP5001", "결제 중 에러가 발생했습니다.");
PROPOSE_NOT_FOUND(HttpStatus.NOT_FOUND, "PROP4040", "해당 제안이 존재하지 않습니다.");

private final HttpStatus httpStatus;
private final String code;
Expand Down
18 changes: 0 additions & 18 deletions api/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,7 @@ spring:
access-expiration-time: ${JWT_ACCESS_EXPIRATION_TIME}
refresh-expiration-time: ${JWT_REFRESH_EXPIRATION_TIME}

mail:
smtp:
port: ${EMAIL_PORT}
auth: true
starttls:
required: true
enable: true
socketFactory:
class: javax.net.ssl.SSLSocketFactory
fallback: false

AdminMail:
id: ${EMAIL_ID}
password: ${EMAIL_PASSWORD}

firebase:
fcmUrl: ${FIREBASE_URL}
firebaseConfigPath: ${FIREBASE_PATH}
scope: https://www.googleapis.com/auth/cloud-platform

PORT_ONE_KEY: ${PORT_ONE_KEY}
PORT_ONE_SECRET: ${PORT_ONE_SECRET}
4 changes: 2 additions & 2 deletions api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ server:
spring:
profiles:
group:
"local": "db, s3, secret"
"prod": "db, s3, redis"
"local": "db, s3, email, portone, secret"
"prod": "db, s3, redis, email, portone"
default: local

servlet:
Expand Down
Loading
Loading