Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.concurrent.CompletableFuture;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.retry.annotation.Recover;
Expand All @@ -15,6 +16,7 @@
import com.gamzabat.algohub.enums.EmailType;
import com.gamzabat.algohub.exception.MessagingRuntimeException;

import jakarta.annotation.PostConstruct;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeMessage;
import lombok.RequiredArgsConstructor;
Expand All @@ -24,9 +26,13 @@
@RequiredArgsConstructor
@Slf4j
public class EmailService {

@Value("${spring.profiles.active:dev}")
private String activeProfile;

private static final String FROM_ADDRESS = "noreply@algohub.kr";
private static final String EMAIL_VERIFICATION_CLIENT_ENDPOINT = "https://algohub.kr/signup";
private static final String RESET_PASSWORD_CLIENT_ENDPOINT = "https://algohub.kr/reset-password";
private String EMAIL_VERIFICATION_CLIENT_ENDPOINT;
private String RESET_PASSWORD_CLIENT_ENDPOINT;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이제 상수가 아니니까 선언을 제거하고, 함수 내부에서 변수로 선언해주세요. 네이밍 케이스도 카멜케이스로 수정 부탁드리구요

private final JavaMailSender mailSender;
private final TemplateEngine templateEngine;

Expand All @@ -51,7 +57,6 @@ private void sendMail(String recipient, EmailType type, String content) {
try {
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");

helper.setTo(recipient);
helper.setFrom(FROM_ADDRESS);
helper.setSubject(getEmailSubject(type));
Expand Down Expand Up @@ -102,4 +107,20 @@ private String getEmailSubject(EmailType type) {
default -> throw new IllegalArgumentException("LOGIC ERROR : Unreachable code block");
};
}

@PostConstruct
private void init() {
this.EMAIL_VERIFICATION_CLIENT_ENDPOINT = createClientEndpoint("signup");
this.RESET_PASSWORD_CLIENT_ENDPOINT = createClientEndpoint("reset-password");
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그냥 요거 없애고 createClientEndpoint 내부에서 하게 해주세요

private String createClientEndpoint(String apiType) {
System.out.println(activeProfile);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건뭐죠.. 로거도 아니고..


if ("prod".equals(activeProfile)) {
return ("https://algohub.kr/" + apiType);
} else {
return ("https://rc.algohub.kr/" + apiType);
}
}
}
5 changes: 0 additions & 5 deletions src/main/resources/application.yml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???????????????

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ spring:
rc:
- dev
- common

---
spring:
config:
Expand All @@ -23,19 +22,16 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
username: ${mysql_username}
password: ${mysql_password}

jpa:
database: mysql
database-platform: org.hibernate.dialect.MySQLDialect
open-in-view: false
hibernate:
ddl-auto: update

servlet:
multipart:
max-file-size: 5MB
max-request-size: 6MB

data:
redis:
host: localhost
Expand Down Expand Up @@ -64,7 +60,6 @@ cloud:
credentials:
access-key: ${aws_access_key}
secret-key: ${aws_secret_key}

logging:
config: classpath:logback-spring.xml
server:
Expand Down