Skip to content

Commit

Permalink
Merge pull request #62 from dnd-side-project/feat/#59
Browse files Browse the repository at this point in the history
Style: 코드 리펙토링
  • Loading branch information
haeyonghahn authored Mar 18, 2024
2 parents 030dcbc + 63cceac commit 0818409
Show file tree
Hide file tree
Showing 36 changed files with 111 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public interface FileStoreUseCase {

String putFile(String key, File file);
void deleteFile(String key);
String putFile(String key, File file);

void deleteFile(String key);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.dnd.gooding.filestore.infra;

import com.dnd.gooding.filestore.application.in.FileStoreUseCase;
import java.io.File;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.dnd.gooding.filestore.application.in.FileStoreUseCase;

import software.amazon.awssdk.core.ResponseInputStream;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.services.s3.S3Client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public interface EmailSender {

void sendLoginSuccess(String toMail);
void sendLoginSuccess(String toMail);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.dnd.gooding.mail.exception;

public class EmailSendException extends RuntimeException {
public EmailSendException(Exception e) {
super(e);
}
public EmailSendException(Exception e) {
super(e);
}
}
Original file line number Diff line number Diff line change
@@ -1,55 +1,52 @@
package com.dnd.gooding.mail.infra;

import com.dnd.gooding.mail.application.adapter.EmailSender;
import com.dnd.gooding.mail.exception.EmailSendException;
import javax.mail.internet.MimeMessage;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring5.SpringTemplateEngine;

import com.dnd.gooding.mail.application.adapter.EmailSender;
import com.dnd.gooding.mail.exception.EmailSendException;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class DefaultEmailEventAdapter implements EmailSender {

private final JavaMailSender mailSender;
private final SpringTemplateEngine springTemplateEngine;
@Value("${spring.mail.username}")
private String fromMail;

public DefaultEmailEventAdapter(JavaMailSender mailSender,
SpringTemplateEngine springTemplateEngine) {
this.mailSender = mailSender;
this.springTemplateEngine = springTemplateEngine;
}

@Override
public void sendLoginSuccess(String toMail) {
Context context = new Context();
String text = springTemplateEngine.process(EmailMetaData.LOGIN_SUCCESS_TEMPLATE, context);
sendMail(EmailMetaData.LOGIN_SUCCESS_TITLE, toMail, text);
}

private void sendMail(String subject, String toEmail, String text) {
try {
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true);

helper.setSubject(subject);
helper.setTo(toEmail);
helper.setText(text);
helper.setFrom(fromMail, "gooding");

mailSender.send(message);
} catch (Exception e) {
throw new EmailSendException(e);
}

}
private final JavaMailSender mailSender;
private final SpringTemplateEngine springTemplateEngine;

@Value("${spring.mail.username}")
private String fromMail;

public DefaultEmailEventAdapter(
JavaMailSender mailSender, SpringTemplateEngine springTemplateEngine) {
this.mailSender = mailSender;
this.springTemplateEngine = springTemplateEngine;
}

@Override
public void sendLoginSuccess(String toMail) {
Context context = new Context();
String text = springTemplateEngine.process(EmailMetaData.LOGIN_SUCCESS_TEMPLATE, context);
sendMail(EmailMetaData.LOGIN_SUCCESS_TITLE, toMail, text);
}

private void sendMail(String subject, String toEmail, String text) {
try {
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true);

helper.setSubject(subject);
helper.setTo(toEmail);
helper.setText(text);
helper.setFrom(fromMail, "gooding");

mailSender.send(message);
} catch (Exception e) {
throw new EmailSendException(e);
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/dnd/gooding/mail/infra/EmailMetaData.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.dnd.gooding.mail.infra;

public class EmailMetaData {
static String LOGIN_SUCCESS_TEMPLATE = "login-sucess";
static String LOGIN_SUCCESS_TITLE = "gooding 서비스에 가입해주셔서 감사합니다.";
static String LOGIN_SUCCESS_TEMPLATE = "login-sucess";
static String LOGIN_SUCCESS_TITLE = "gooding 서비스에 가입해주셔서 감사합니다.";
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

public interface CreateOAuthUseCase {

Token create(String code);
Token create(String code);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public interface OAuthMemberPort {

void create(String id, String oAuthId);
void create(String id, String oAuthId);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.dnd.gooding.oauth.command.domain.repository;

import java.util.Optional;
import org.springframework.data.repository.Repository;

import com.dnd.gooding.oauth.command.domain.OAuth;
import com.dnd.gooding.oauth.command.domain.OAuthId;
import java.util.Optional;
import org.springframework.data.repository.Repository;

public interface OAuthRepository extends Repository<OAuth, OAuthId> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import com.dnd.gooding.oauth.command.application.out.OAuthTokenPort;
import com.dnd.gooding.oauth.command.domain.OAuth;
import com.dnd.gooding.oauth.command.domain.OAuthId;
import com.dnd.gooding.oauth.command.domain.repository.OAuthRepository;
import com.dnd.gooding.oauth.command.domain.dto.OAuthMember;

import com.dnd.gooding.oauth.command.domain.repository.OAuthRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -24,10 +23,11 @@ public class CreateOAuthService implements CreateOAuthUseCase {

private final OAuthTokenPort oAuthTokenPort;

public CreateOAuthService(OAuthRepository oAuthRepository,
ExternalLoginPort externalLoginPort,
OAuthMemberPort oAuthMemberPort,
OAuthTokenPort oAuthTokenPort) {
public CreateOAuthService(
OAuthRepository oAuthRepository,
ExternalLoginPort externalLoginPort,
OAuthMemberPort oAuthMemberPort,
OAuthTokenPort oAuthTokenPort) {
this.oAuthRepository = oAuthRepository;
this.externalLoginPort = externalLoginPort;
this.oAuthMemberPort = oAuthMemberPort;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.dnd.gooding.oauth.infra;

import com.dnd.gooding.oauth.exception.ConnectionException;
import com.dnd.gooding.oauth.command.domain.dto.GoogleMember;
import com.dnd.gooding.oauth.command.domain.dto.OAuthMember;
import com.dnd.gooding.oauth.exception.ConnectionException;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.dnd.gooding.oauth.infra;

import com.dnd.gooding.oauth.exception.ConnectionException;
import com.dnd.gooding.oauth.command.application.out.ExternalLoginPort;
import com.dnd.gooding.oauth.command.domain.dto.KakaoInfo;
import com.dnd.gooding.oauth.command.domain.dto.KakaoMember;
import com.dnd.gooding.oauth.command.domain.dto.KakaoResponse;
import com.dnd.gooding.oauth.command.domain.dto.OAuthMember;
import com.dnd.gooding.oauth.exception.ConnectionException;
import java.util.Objects;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.dnd.gooding.common.model.Token;
import com.dnd.gooding.oauth.command.application.in.CreateOAuthUseCase;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.dnd.gooding.record.command.application.in;

import java.io.IOException;

import com.dnd.gooding.record.ui.dto.request.RecordRequest;
import java.io.IOException;

public interface CreateRecordUseCase {

void create(RecordRequest recordRequest) throws IOException;
void create(RecordRequest recordRequest) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public interface DeleteRecordUseCase {

void delete(String recordNo);
void delete(String recordNo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

public interface RecordMemberPort {

Recorder createRecorder(MemberId recorderMemberId);
Recorder createRecorder(MemberId recorderMemberId);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.dnd.gooding.record.command.domain.repository;

import com.dnd.gooding.record.command.domain.Record;
import com.dnd.gooding.record.command.domain.RecordNo;
import java.security.SecureRandom;
import java.util.Date;
import java.util.Optional;
import org.springframework.data.repository.Repository;

import com.dnd.gooding.record.command.domain.Record;
import com.dnd.gooding.record.command.domain.RecordNo;

public interface RecordRepository extends Repository<Record, RecordNo> {

Optional<Record> findById(RecordNo recordNo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public class RecordService implements CreateRecordUseCase {
private final RecordFilePort recordFilePort;

public RecordService(
RecordRepository recordRepository, RecordMemberPort recordMemberPort, RecordFilePort recordFilePort) {
RecordRepository recordRepository,
RecordMemberPort recordMemberPort,
RecordFilePort recordFilePort) {
this.recordRepository = recordRepository;
this.recordMemberPort = recordMemberPort;
this.recordFilePort = recordFilePort;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.dnd.gooding.record.query.application;

import com.dnd.gooding.record.exception.NoRecordException;
import com.dnd.gooding.record.command.domain.RecordNo;
import com.dnd.gooding.record.exception.NoRecordException;
import com.dnd.gooding.record.query.dao.ImageDataDao;
import com.dnd.gooding.record.query.dao.RecordDataDao;
import com.dnd.gooding.record.query.dto.ImageData;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/dnd/gooding/record/ui/RecordController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.dnd.gooding.record.command.application.in.CreateRecordUseCase;
import com.dnd.gooding.record.command.application.in.DeleteRecordUseCase;
import com.dnd.gooding.record.ui.dto.request.RecordRequest;
import com.dnd.gooding.record.command.domain.service.RecordService;
import com.dnd.gooding.token.command.domain.dto.JwtAuthentication;
import com.dnd.gooding.user.command.domain.MemberId;
import java.io.IOException;
Expand All @@ -21,8 +20,8 @@ public class RecordController {
private final CreateRecordUseCase createRecordUseCase;
private final DeleteRecordUseCase deleteRecordUseCase;

public RecordController(CreateRecordUseCase createRecordUseCase,
DeleteRecordUseCase deleteRecordUseCase) {
public RecordController(
CreateRecordUseCase createRecordUseCase, DeleteRecordUseCase deleteRecordUseCase) {
this.createRecordUseCase = createRecordUseCase;
this.deleteRecordUseCase = deleteRecordUseCase;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
package com.dnd.gooding.springconfig.log;

import java.util.Map;

import org.slf4j.MDC;
import org.springframework.core.task.TaskDecorator;

public class MDCCopyTaskDecorator implements TaskDecorator {

@Override
public Runnable decorate(Runnable runnable) {
Map<String, String> contextMap = MDC.getCopyOfContextMap();
return () -> {
try {
if (contextMap != null) {
MDC.setContextMap(contextMap);
}
runnable.run();
} finally {
MDC.clear();
}
};
}
@Override
public Runnable decorate(Runnable runnable) {
Map<String, String> contextMap = MDC.getCopyOfContextMap();
return () -> {
try {
if (contextMap != null) {
MDC.setContextMap(contextMap);
}
runnable.run();
} finally {
MDC.clear();
}
};
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.dnd.gooding.springconfig.security;

import com.dnd.gooding.token.command.domain.service.TokenService;
import com.dnd.gooding.token.command.domain.dto.JwtAuthenticationToken;
import com.dnd.gooding.token.command.domain.service.TokenService;
import com.dnd.gooding.util.ExtractUtil;
import java.io.IOException;
import javax.servlet.FilterChain;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.dnd.gooding.springconfig.web;

import com.dnd.gooding.springconfig.log.MDCLoggingInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.dnd.gooding.springconfig.log.MDCLoggingInterceptor;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public interface CreateTokenUseCase {

String getAccessTokensByRefreshToken(String refreshToken);
Token createTokens(String id);
String getAccessTokensByRefreshToken(String refreshToken);

Token createTokens(String id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public interface LogoutTokenUseCase {

void deleteRefreshToken(String refreshToken);
void deleteRefreshToken(String refreshToken);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.dnd.gooding.token.command.domain.repository;

import org.springframework.data.repository.CrudRepository;

import com.dnd.gooding.token.command.domain.RefreshToken;
import org.springframework.data.repository.CrudRepository;

public interface RefreshTokenRepository extends CrudRepository<RefreshToken, String> {}
Loading

0 comments on commit 0818409

Please sign in to comment.