From 8355608fa75a8aba206840d1c65489c634ee9edc Mon Sep 17 00:00:00 2001 From: 0702Yoon Date: Fri, 16 Aug 2024 14:38:02 +0900 Subject: [PATCH 01/14] =?UTF-8?q?refactor=20:=20JsonValue=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/entity/enums/AffiliationCode.java | 3 ++- .../bigbrotherbe/domain/member/entity/enums/CouncilType.java | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/AffiliationCode.java b/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/AffiliationCode.java index f7ea7ce..2202526 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/AffiliationCode.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/AffiliationCode.java @@ -107,7 +107,8 @@ private static int getMaxValForCollege(AffiliationCode college) { } @JsonValue - public String getAffiliationCode() { + public String serializationValue() { return this.name; } + // Lombok getter vs Json 방식 논점 } diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/CouncilType.java b/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/CouncilType.java index 1467429..d4b1089 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/CouncilType.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/CouncilType.java @@ -13,7 +13,7 @@ public enum CouncilType { } @JsonValue - public String getCouncilType() { + public String serializationValue() { return this.councilType; } @@ -25,5 +25,4 @@ public static CouncilType fromcouncilType(String councilType) { } throw new IllegalArgumentException("없는 CouncilType입니다." + councilType); } - } From 6d25e6f6208f58416d5973e021137e31f2734fdb Mon Sep 17 00:00:00 2001 From: 0702Yoon Date: Fri, 16 Aug 2024 14:40:51 +0900 Subject: [PATCH 02/14] =?UTF-8?q?refactor=20:=20memberservice=EC=97=90?= =?UTF-8?q?=EC=84=9C=20emailservice=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/bigbrotherbe/global/email/entity/Email.java | 9 +++++++++ .../global/email/{ => entity}/EmailRequest.java | 2 +- .../email/{ => entity}/EmailVerificationResult.java | 3 +-- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/example/bigbrotherbe/global/email/entity/Email.java rename src/main/java/com/example/bigbrotherbe/global/email/{ => entity}/EmailRequest.java (61%) rename src/main/java/com/example/bigbrotherbe/global/email/{ => entity}/EmailVerificationResult.java (82%) diff --git a/src/main/java/com/example/bigbrotherbe/global/email/entity/Email.java b/src/main/java/com/example/bigbrotherbe/global/email/entity/Email.java new file mode 100644 index 0000000..22c8e46 --- /dev/null +++ b/src/main/java/com/example/bigbrotherbe/global/email/entity/Email.java @@ -0,0 +1,9 @@ +package com.example.bigbrotherbe.global.email.entity; + + +import lombok.Builder; + +@Builder +public record Email(String title, String authCode, String toEmailAddress) { + +} diff --git a/src/main/java/com/example/bigbrotherbe/global/email/EmailRequest.java b/src/main/java/com/example/bigbrotherbe/global/email/entity/EmailRequest.java similarity index 61% rename from src/main/java/com/example/bigbrotherbe/global/email/EmailRequest.java rename to src/main/java/com/example/bigbrotherbe/global/email/entity/EmailRequest.java index 6c6ed3e..7c481fc 100644 --- a/src/main/java/com/example/bigbrotherbe/global/email/EmailRequest.java +++ b/src/main/java/com/example/bigbrotherbe/global/email/entity/EmailRequest.java @@ -1,4 +1,4 @@ -package com.example.bigbrotherbe.global.email; +package com.example.bigbrotherbe.global.email.entity; import lombok.Getter; diff --git a/src/main/java/com/example/bigbrotherbe/global/email/EmailVerificationResult.java b/src/main/java/com/example/bigbrotherbe/global/email/entity/EmailVerificationResult.java similarity index 82% rename from src/main/java/com/example/bigbrotherbe/global/email/EmailVerificationResult.java rename to src/main/java/com/example/bigbrotherbe/global/email/entity/EmailVerificationResult.java index 49c3908..1d3d9e7 100644 --- a/src/main/java/com/example/bigbrotherbe/global/email/EmailVerificationResult.java +++ b/src/main/java/com/example/bigbrotherbe/global/email/entity/EmailVerificationResult.java @@ -1,11 +1,10 @@ -package com.example.bigbrotherbe.global.email; +package com.example.bigbrotherbe.global.email.entity; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.RequiredArgsConstructor; @Getter @Builder From 9be5e8e5a51cd74b4e5ab85c08af29f70ccb0d85 Mon Sep 17 00:00:00 2001 From: 0702Yoon Date: Fri, 16 Aug 2024 14:41:27 +0900 Subject: [PATCH 03/14] =?UTF-8?q?refactor=20:=20emailservice=EC=95=88?= =?UTF-8?q?=EC=97=90=EC=84=9C=20Checker,=20maker=EB=A1=9C=20=EC=97=AD?= =?UTF-8?q?=ED=95=A0=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/email/component/MailChecker.java | 21 ++++++ .../global/email/component/MailMaker.java | 44 +++++++++++++ .../email/{ => component}/MailService.java | 66 +++++++------------ 3 files changed, 88 insertions(+), 43 deletions(-) create mode 100644 src/main/java/com/example/bigbrotherbe/global/email/component/MailChecker.java create mode 100644 src/main/java/com/example/bigbrotherbe/global/email/component/MailMaker.java rename src/main/java/com/example/bigbrotherbe/global/email/{ => component}/MailService.java (56%) diff --git a/src/main/java/com/example/bigbrotherbe/global/email/component/MailChecker.java b/src/main/java/com/example/bigbrotherbe/global/email/component/MailChecker.java new file mode 100644 index 0000000..90a5c53 --- /dev/null +++ b/src/main/java/com/example/bigbrotherbe/global/email/component/MailChecker.java @@ -0,0 +1,21 @@ +package com.example.bigbrotherbe.global.email.component; + + +import com.example.bigbrotherbe.domain.member.component.MemberLoader; +import com.example.bigbrotherbe.global.email.entity.EmailVerificationResult; +import com.example.bigbrotherbe.global.exception.BusinessException; +import com.example.bigbrotherbe.global.exception.enums.ErrorCode; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class MailChecker { + private final MemberLoader memberLoader; + public EmailVerificationResult checkDuplicateEmail(String email) { + if (memberLoader.findByMemberEmailForCheck(email).isPresent()) { + throw new BusinessException(ErrorCode.EXIST_EMAIL); + } + return EmailVerificationResult.builder().authResult(false).build(); + } +} diff --git a/src/main/java/com/example/bigbrotherbe/global/email/component/MailMaker.java b/src/main/java/com/example/bigbrotherbe/global/email/component/MailMaker.java new file mode 100644 index 0000000..ead842f --- /dev/null +++ b/src/main/java/com/example/bigbrotherbe/global/email/component/MailMaker.java @@ -0,0 +1,44 @@ +package com.example.bigbrotherbe.global.email.component; + +import com.example.bigbrotherbe.global.email.entity.Email; +import com.example.bigbrotherbe.global.exception.BusinessException; +import com.example.bigbrotherbe.global.exception.enums.ErrorCode; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.util.Random; +import org.springframework.mail.SimpleMailMessage; +import org.springframework.stereotype.Component; + +@Component +public class MailMaker { + private static final String EMAIL_TITLE = "명지대 big brother 이메일 인증 번호"; + public Email makeMail(String toEmail) { + return Email + .builder() + .title(EMAIL_TITLE) + .authCode(createCode()) + .toEmailAddress(toEmail) + .build(); + } + + private String createCode() { + int lenth = 6; + try { + Random random = SecureRandom.getInstanceStrong(); + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < lenth; i++) { + builder.append(random.nextInt(10)); + } + return builder.toString(); + } catch (NoSuchAlgorithmException e) { + throw new BusinessException(ErrorCode.NO_SUCH_ALGORITHM); + } + } + public SimpleMailMessage createEmailForm(Email email) { + SimpleMailMessage message = new SimpleMailMessage(); + message.setTo(email.toEmailAddress()); + message.setSubject(email.title()); + message.setText(email.authCode()); + return message; + } +} diff --git a/src/main/java/com/example/bigbrotherbe/global/email/MailService.java b/src/main/java/com/example/bigbrotherbe/global/email/component/MailService.java similarity index 56% rename from src/main/java/com/example/bigbrotherbe/global/email/MailService.java rename to src/main/java/com/example/bigbrotherbe/global/email/component/MailService.java index 0710555..d6d019b 100644 --- a/src/main/java/com/example/bigbrotherbe/global/email/MailService.java +++ b/src/main/java/com/example/bigbrotherbe/global/email/component/MailService.java @@ -1,13 +1,12 @@ -package com.example.bigbrotherbe.global.email; +package com.example.bigbrotherbe.global.email.component; import com.example.bigbrotherbe.domain.member.entity.EMailVerification; import com.example.bigbrotherbe.domain.member.repository.MailRepository; +import com.example.bigbrotherbe.global.email.entity.Email; +import com.example.bigbrotherbe.global.email.entity.EmailVerificationResult; import com.example.bigbrotherbe.global.exception.BusinessException; import com.example.bigbrotherbe.global.exception.enums.ErrorCode; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; import java.time.Duration; -import java.util.Random; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.mail.SimpleMailMessage; @@ -23,39 +22,29 @@ public class MailService { private final JavaMailSender javaMailSender; private final MailRepository mailRepository; - + private final MailChecker mailChecker; + private final MailMaker mailMaker; // @Value("${spring.mail.auth-code-expiration-millis}") private final long authCodeExpirationMillis = 1800000; + + @Transactional public void sendCodeToEmail(String toEmail) { - checkPresentEmail(toEmail); - String title = "명지대 big brother 이메일 인증 번호"; - String authCode = createCode(); - sendEmail(toEmail, title, authCode); - // 이메일 인증 요청 시 인증 번호 Redis에 저장 ( key = "AuthCode " + Email / value = AuthCode ) - saveEmailAuthCode(toEmail, authCode, Duration.ofMillis(this.authCodeExpirationMillis)); + deleteByEmailAddress(toEmail); + Email email = mailMaker.makeMail(toEmail); + SimpleMailMessage emailForm = mailMaker.createEmailForm(email); + sendEmail(emailForm); + saveEmailAuthCode(toEmail, email.authCode(), Duration.ofMillis(this.authCodeExpirationMillis)); } - private void sendEmail(String toEmail, String title, String text) { - SimpleMailMessage emailForm = createEmailForm(toEmail, title, text); + private void sendEmail(SimpleMailMessage emailForm) { try { javaMailSender.send(emailForm); } catch (RuntimeException e) { - log.debug("MailService.sendEmail exception occur toEmail: {}, " + - "title: {}, text: {}", toEmail, title, text); throw new BusinessException(ErrorCode.UNABLE_TO_SEND_EMAIL); } } - private SimpleMailMessage createEmailForm(String toEmail, - String title, - String text) { - SimpleMailMessage message = new SimpleMailMessage(); - message.setTo(toEmail); - message.setSubject(title); - message.setText(text); - return message; - } @Transactional protected void saveEmailAuthCode(String emailAddress, String authCode, Duration duration) { mailRepository.save( @@ -65,7 +54,8 @@ protected void saveEmailAuthCode(String emailAddress, String authCode, Duration scheduleDeletion(emailAddress,duration); } - private void scheduleDeletion(String emailAddress, Duration duration) { + @Transactional + public void scheduleDeletion(String emailAddress, Duration duration) { new Thread(() -> { try { Thread.sleep(duration.toMillis()); @@ -75,7 +65,7 @@ private void scheduleDeletion(String emailAddress, Duration duration) { } }).start(); } - + @Transactional(readOnly = true) public String getAuthCode(String emailAddress) { EMailVerification emailVerification = mailRepository.findByEmailAddress(emailAddress).orElseThrow ( ()-> new IllegalArgumentException("이메일 인증 시간이 만료되었습니다.")); @@ -83,33 +73,23 @@ public String getAuthCode(String emailAddress) { } @Transactional - protected void checkPresentEmail(String toEmail) { + protected void deleteByEmailAddress(String toEmail) { mailRepository.findByEmailAddress(toEmail) .ifPresent(mail -> mailRepository.deleteByEmailAddress(toEmail)); } - private String createCode() { - int lenth = 6; - try { - Random random = SecureRandom.getInstanceStrong(); - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < lenth; i++) { - builder.append(random.nextInt(10)); - } - return builder.toString(); - } catch (NoSuchAlgorithmException e) { - log.debug("MemberService.createCode() exception occur"); - throw new BusinessException(ErrorCode.NO_SUCH_ALGORITHM); - } - } + public EmailVerificationResult verifiedCode(String email, String authCode) { - String redisAuthCode = getAuthCode(email); - boolean authResult = redisAuthCode.equals(authCode); + String saveAuthCode = getAuthCode(email); + boolean authResult = authCode.equals(saveAuthCode); if (!authResult) { throw new BusinessException(ErrorCode.MISMATCH_VERIFIED_CODE); } return EmailVerificationResult.of(true); } + public EmailVerificationResult verificationDuplicateEmail(String email) { + return mailChecker.checkDuplicateEmail(email); + } } From 880ed9ffc899717afadc344f366300cb522db973 Mon Sep 17 00:00:00 2001 From: 0702Yoon Date: Fri, 16 Aug 2024 14:42:02 +0900 Subject: [PATCH 04/14] =?UTF-8?q?refactor=20:=20member=20service=EC=97=90?= =?UTF-8?q?=EC=84=9C=20affiliationSerivce=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/AffiliationManger.java | 2 +- .../service/AffiliationService.java | 15 ++++++++ .../service/AffiliationServiceImpl.java | 37 +++++++++++++++++++ .../role => dto}/AffiliationListDto.java | 6 +-- 4 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationService.java create mode 100644 src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationServiceImpl.java rename src/main/java/com/example/bigbrotherbe/domain/member/{entity/role => dto}/AffiliationListDto.java (81%) diff --git a/src/main/java/com/example/bigbrotherbe/domain/affiliation/component/AffiliationManger.java b/src/main/java/com/example/bigbrotherbe/domain/affiliation/component/AffiliationManger.java index b4f6c98..0b78783 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/affiliation/component/AffiliationManger.java +++ b/src/main/java/com/example/bigbrotherbe/domain/affiliation/component/AffiliationManger.java @@ -26,7 +26,7 @@ public Affiliation findAffiliationByName(String name) { public AffiliationMember createAfiiliationMember(Member savedMember, String affiliationName, Role role) { Affiliation affiliation = findAffiliationByName(affiliationName); - AffiliationMember affiliationMember= AffiliationMember.builder() + AffiliationMember affiliationMember = AffiliationMember.builder() .member(savedMember) .affiliation(affiliation) .role(role.getRole()) diff --git a/src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationService.java b/src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationService.java new file mode 100644 index 0000000..40165b2 --- /dev/null +++ b/src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationService.java @@ -0,0 +1,15 @@ +package com.example.bigbrotherbe.domain.affiliation.service; + +import com.example.bigbrotherbe.domain.member.dto.response.AffiliationResponse; +import java.util.List; +import org.springframework.stereotype.Service; + +public interface AffiliationService { + boolean checkExistAffiliationById(Long affiliationId); + + List getColleges(); + + List getDepartments(String councilName); + + +} diff --git a/src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationServiceImpl.java new file mode 100644 index 0000000..ec81949 --- /dev/null +++ b/src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationServiceImpl.java @@ -0,0 +1,37 @@ +package com.example.bigbrotherbe.domain.affiliation.service; + +import com.example.bigbrotherbe.domain.affiliation.component.AffiliationManger; +import com.example.bigbrotherbe.domain.member.dto.response.AffiliationResponse; +import com.example.bigbrotherbe.domain.member.entity.enums.AffiliationCode; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Transactional(readOnly = true) +@Service +public class AffiliationServiceImpl implements AffiliationService{ + private final AffiliationManger affiliationManger; + @Override + public boolean checkExistAffiliationById(Long affiliationId) { + return affiliationManger.existsById(affiliationId); + } + + + @Override + public List getColleges() { + return Arrays.stream(AffiliationCode.values()) + .filter(code -> code.getCouncilType().equals("단과대")) + .map(code -> AffiliationResponse.fromAffiliationResponse(code.getVal(), code.getName())) + .collect(Collectors.toList()); + } + + @Override + public List getDepartments(String councilName) { + return AffiliationCode.getDepartmentsByCollegeName(councilName); + } + +} diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/entity/role/AffiliationListDto.java b/src/main/java/com/example/bigbrotherbe/domain/member/dto/AffiliationListDto.java similarity index 81% rename from src/main/java/com/example/bigbrotherbe/domain/member/entity/role/AffiliationListDto.java rename to src/main/java/com/example/bigbrotherbe/domain/member/dto/AffiliationListDto.java index 2d6f7a3..9c816b4 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/entity/role/AffiliationListDto.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/dto/AffiliationListDto.java @@ -1,9 +1,10 @@ -package com.example.bigbrotherbe.domain.member.entity.role; +package com.example.bigbrotherbe.domain.member.dto; import com.example.bigbrotherbe.domain.member.entity.enums.AffiliationCode; import com.example.bigbrotherbe.domain.member.entity.enums.CouncilType; import com.example.bigbrotherbe.domain.member.entity.enums.Role; +import com.example.bigbrotherbe.domain.member.entity.role.AffiliationType; import java.util.ArrayList; import java.util.List; @@ -18,8 +19,7 @@ public class AffiliationListDto { private final List affiliationTypeList = new ArrayList<>(); private final String memberName; - - public void addAffiliation(String councilType,String affiliation, String role) { + public void addAffiliation(String councilType, String affiliation, String role) { try { affiliationTypeList.add(AffiliationType .builder() From d41dbc5dc19b686f21dcfcbd09f6ed725b2da46c Mon Sep 17 00:00:00 2001 From: 0702Yoon Date: Fri, 16 Aug 2024 14:42:43 +0900 Subject: [PATCH 05/14] =?UTF-8?q?refactor=20:=20memberservice=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=EC=A0=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/service/EventServiceImpl.java | 10 +-- .../domain/faq/service/FAQServiceImpl.java | 8 +- .../meetings/service/MeetingsServiceImpl.java | 14 +-- .../member/component/MemberChecker.java | 2 + .../domain/member/component/MemberLoader.java | 22 ----- .../member/component/MemberManager.java | 82 ++++++++--------- .../domain/member/component/MemberSaver.java | 17 ++++ .../member/controller/MemberController.java | 8 +- .../controller/MemberControllerImpl.java | 26 +++--- .../domain/member/dto/request/SignUpDto.java | 8 +- .../dto/response/MemberInfoResponse.java | 2 +- .../domain/member/service/MemberService.java | 23 +---- .../member/service/MemberServiceImpl.java | 90 +------------------ .../notice/service/NoticeServiceImpl.java | 8 +- .../domain/rule/service/RuleServiceImpl.java | 8 +- .../service/TransactionsServiceImpl.java | 8 +- .../global/jwt/{ => component}/AuthUtil.java | 3 +- .../global/security/SecurityConfig.java | 3 +- 18 files changed, 112 insertions(+), 230 deletions(-) create mode 100644 src/main/java/com/example/bigbrotherbe/domain/member/component/MemberSaver.java rename src/main/java/com/example/bigbrotherbe/global/jwt/{ => component}/AuthUtil.java (97%) diff --git a/src/main/java/com/example/bigbrotherbe/domain/event/service/EventServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/event/service/EventServiceImpl.java index 1dcdf87..be8c91b 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/event/service/EventServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/event/service/EventServiceImpl.java @@ -1,12 +1,12 @@ package com.example.bigbrotherbe.domain.event.service; +import com.example.bigbrotherbe.domain.affiliation.service.AffiliationService; import com.example.bigbrotherbe.domain.event.dto.request.EventRegisterRequest; import com.example.bigbrotherbe.domain.event.dto.request.EventUpdateRequest; import com.example.bigbrotherbe.domain.event.dto.response.EventResponse; import com.example.bigbrotherbe.domain.event.entity.Event; import com.example.bigbrotherbe.domain.event.repository.EventRepository; import com.example.bigbrotherbe.domain.member.entity.Member; -import com.example.bigbrotherbe.domain.member.service.MemberService; import com.example.bigbrotherbe.global.exception.BusinessException; import com.example.bigbrotherbe.global.file.dto.FileDeleteDTO; import com.example.bigbrotherbe.global.file.dto.FileSaveDTO; @@ -14,7 +14,7 @@ import com.example.bigbrotherbe.global.file.entity.File; import com.example.bigbrotherbe.global.file.enums.FileType; import com.example.bigbrotherbe.global.file.service.FileService; -import com.example.bigbrotherbe.global.jwt.AuthUtil; +import com.example.bigbrotherbe.global.jwt.component.AuthUtil; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -31,16 +31,14 @@ public class EventServiceImpl implements EventService { private final EventRepository eventRepository; - - private final MemberService memberService; + private final AffiliationService affiliationService; private final FileService fileService; - private final AuthUtil authUtil; @Override @Transactional(rollbackFor = Exception.class) public void registerEvent(EventRegisterRequest eventRegisterRequest, List multipartFiles) { - if (!memberService.checkExistAffiliationById(eventRegisterRequest.getAffiliationId())) { + if (!affiliationService.checkExistAffiliationById(eventRegisterRequest.getAffiliationId())) { throw new BusinessException(NO_EXIST_AFFILIATION); } diff --git a/src/main/java/com/example/bigbrotherbe/domain/faq/service/FAQServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/faq/service/FAQServiceImpl.java index b9c8803..229c2e0 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/faq/service/FAQServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/faq/service/FAQServiceImpl.java @@ -1,12 +1,12 @@ package com.example.bigbrotherbe.domain.faq.service; +import com.example.bigbrotherbe.domain.affiliation.service.AffiliationService; import com.example.bigbrotherbe.domain.faq.dto.request.FAQModifyRequest; import com.example.bigbrotherbe.domain.faq.dto.request.FAQRegisterRequest; import com.example.bigbrotherbe.domain.faq.dto.response.FAQResponse; import com.example.bigbrotherbe.domain.faq.entity.FAQ; import com.example.bigbrotherbe.domain.faq.repository.FAQRepository; import com.example.bigbrotherbe.domain.member.entity.Member; -import com.example.bigbrotherbe.domain.member.service.MemberService; import com.example.bigbrotherbe.global.exception.BusinessException; import com.example.bigbrotherbe.global.exception.enums.ErrorCode; import com.example.bigbrotherbe.global.file.dto.FileSaveDTO; @@ -14,7 +14,7 @@ import com.example.bigbrotherbe.global.file.entity.File; import com.example.bigbrotherbe.global.file.enums.FileType; import com.example.bigbrotherbe.global.file.service.FileService; -import com.example.bigbrotherbe.global.jwt.AuthUtil; +import com.example.bigbrotherbe.global.jwt.component.AuthUtil; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -32,14 +32,14 @@ public class FAQServiceImpl implements FAQService { private final FAQRepository faqRepository; private final FileService fileService; - private final MemberService memberService; + private final AffiliationService affiliationService; private final AuthUtil authUtil; @Override @Transactional(rollbackFor = Exception.class) // 트랜잭션 시작 및 커밋 -> 모든 예외상황 발생시 롤백 public void register(FAQRegisterRequest faqRegisterRequest, List multipartFiles) { - if (!memberService.checkExistAffiliationById(faqRegisterRequest.getAffiliationId())) { + if (!affiliationService.checkExistAffiliationById(faqRegisterRequest.getAffiliationId())) { throw new BusinessException(NO_EXIST_AFFILIATION); } diff --git a/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsServiceImpl.java index 0bda18f..fdc0d87 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsServiceImpl.java @@ -1,12 +1,12 @@ package com.example.bigbrotherbe.domain.meetings.service; +import com.example.bigbrotherbe.domain.affiliation.service.AffiliationService; import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsRegisterRequest; import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsUpdateRequest; import com.example.bigbrotherbe.domain.meetings.dto.response.MeetingsResponse; import com.example.bigbrotherbe.domain.meetings.entity.Meetings; import com.example.bigbrotherbe.domain.meetings.repository.MeetingsRepository; import com.example.bigbrotherbe.domain.member.entity.Member; -import com.example.bigbrotherbe.domain.member.service.MemberService; import com.example.bigbrotherbe.global.exception.BusinessException; import com.example.bigbrotherbe.global.file.dto.FileDeleteDTO; import com.example.bigbrotherbe.global.file.dto.FileSaveDTO; @@ -14,8 +14,7 @@ import com.example.bigbrotherbe.global.file.entity.File; import com.example.bigbrotherbe.global.file.enums.FileType; import com.example.bigbrotherbe.global.file.service.FileService; -import com.example.bigbrotherbe.global.jwt.AuthUtil; -import io.lettuce.core.ScriptOutputType; +import com.example.bigbrotherbe.global.jwt.component.AuthUtil; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -24,8 +23,6 @@ import org.springframework.web.multipart.MultipartFile; import java.util.List; -import java.util.Optional; -import java.util.OptionalLong; import static com.example.bigbrotherbe.global.exception.enums.ErrorCode.*; @@ -34,20 +31,17 @@ public class MeetingsServiceImpl implements MeetingsService { private final MeetingsRepository meetingsRepository; - private final FileService fileService; - private final MemberService memberService; - + private final AffiliationService affiliationService; private final AuthUtil authUtil; @Override @Transactional(rollbackFor = Exception.class) public void registerMeetings(MeetingsRegisterRequest meetingsRegisterRequest, List multipartFiles) { - if (!memberService.checkExistAffiliationById(meetingsRegisterRequest.getAffiliationId())) { + if (!affiliationService.checkExistAffiliationById(meetingsRegisterRequest.getAffiliationId())) { throw new BusinessException(NO_EXIST_AFFILIATION); } - if (authUtil.checkCouncilRole(meetingsRegisterRequest.getAffiliationId())) { throw new BusinessException(NOT_COUNCIL_MEMBER); } diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberChecker.java b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberChecker.java index 99b34f6..54b518f 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberChecker.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberChecker.java @@ -7,9 +7,11 @@ import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor +@Transactional(readOnly = true) public class MemberChecker { private final MemberRepository memberRepository; diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberLoader.java b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberLoader.java index bfbac99..e4c633b 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberLoader.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberLoader.java @@ -16,25 +16,6 @@ public class MemberLoader { private final MemberRepository memberRepository; - public Member saveMember(Member member) { - return memberRepository.save(member); - } - - public Member getMember(Long id) { - return memberRepository.findById(id).orElseThrow( - () -> new BusinessException(ErrorCode.FAIL_LOAD_MEMBER) - ); - } - - public Member findByUserName(String username) { - return memberRepository.findByUsername(username) - .orElseThrow(() -> new IllegalArgumentException("잘못된 사용자 이름입니다.")); - } - - public Member findByMemberId(String memberId) { - return memberRepository.findById(Long.valueOf(memberId)).orElseThrow(() -> new IllegalArgumentException("잘못된 사용자 아이디입니다.")); - } - public Member findByMemberEmail(String memberEmail) { return memberRepository.findByEmail(memberEmail).orElseThrow(() -> new BusinessException(ErrorCode.NO_EXIST_EMAIL)); @@ -47,7 +28,4 @@ public List getAllMember() { return memberRepository.findAll(); } - public Member signUp(SignUpDto signUpDto, String encodePassword) { - return saveMember(signUpDto.toEntity(signUpDto,encodePassword)); - } } diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberManager.java b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberManager.java index dc5fe72..f11ffae 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberManager.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberManager.java @@ -7,21 +7,20 @@ import com.example.bigbrotherbe.domain.member.entity.Member; import com.example.bigbrotherbe.domain.member.entity.enums.Role; import com.example.bigbrotherbe.domain.member.entity.role.Affiliation; -import com.example.bigbrotherbe.domain.member.entity.role.AffiliationListDto; +import com.example.bigbrotherbe.domain.member.dto.AffiliationListDto; import com.example.bigbrotherbe.domain.member.entity.role.AffiliationMember; -import com.example.bigbrotherbe.global.email.EmailVerificationResult; -import com.example.bigbrotherbe.global.exception.BusinessException; -import com.example.bigbrotherbe.global.exception.enums.ErrorCode; -import com.example.bigbrotherbe.global.jwt.AuthUtil; -import com.example.bigbrotherbe.global.jwt.JwtToken; -import java.util.ArrayList; +import com.example.bigbrotherbe.global.jwt.component.AuthUtil; +import com.example.bigbrotherbe.global.jwt.entity.JwtToken; import java.util.List; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; @Component @RequiredArgsConstructor +@Transactional(readOnly = true) public class MemberManager { private final AuthUtil authUtil; @@ -29,14 +28,19 @@ public class MemberManager { private final MemberLoader memberLoader; private final MemberChecker memberChecker; private final MemberDeleter memberDeleter; + private final MemberSaver memberSaver; private final AffiliationManger affiliationManger; + + @Transactional(rollbackFor = Exception.class) public MemberResponse userSignup(SignUpDto signUpDto) { memberChecker.checkExistUserEmail(signUpDto.getEmail()); - - Member savedMember = memberLoader.signUp(signUpDto,passwordEncoder.encode(signUpDto.getPassword())); + String encodePassword = passwordEncoder.encode(signUpDto.getPassword()); + Member member = signUpDto.toEntity(encodePassword); + Member savedMember = memberSaver.saveMember(member); AffiliationMember collegeMember = affiliationManger.createAfiiliationMember(savedMember,signUpDto.getCollege(), Role.ROLE_USER); AffiliationMember affiliationMember = affiliationManger.createAfiiliationMember(savedMember,signUpDto.getAffiliation(),Role.ROLE_USER); + return MemberResponse.form( savedMember.getId(), savedMember.getUsername(), @@ -47,6 +51,7 @@ public MemberResponse userSignup(SignUpDto signUpDto) { ); } + @Transactional public JwtToken signIn(String email, String password) { memberLoader.findByMemberEmail(email); return authUtil.createAuthenticationToken(email,password); @@ -62,27 +67,33 @@ public Member getLoginMember() { return authUtil.getLoginMember(); } - - public EmailVerificationResult checkDuplicateEmail(String email) { - if (memberLoader.findByMemberEmailForCheck(email).isPresent()) { - throw new BusinessException(ErrorCode.EXIST_EMAIL); - } - return EmailVerificationResult.builder().authResult(false).build(); - } - + @Transactional public void changePassword(String email, String password) { Member member = memberLoader.findByMemberEmail(email); member.changePassword(passwordEncoder.encode(password)); } - + @Transactional public void deleteSelf() { Member member = authUtil.getLoginMember(); memberDeleter.deleteMember(member); } + @Transactional public MemberInfoResponse changeMemberInfo(String username) { Member member = authUtil.getLoginMember(); member.changeName(username); + return toMemberInfoResponse(member); + } + + public List inquireAllMemberInfo() { + return memberLoader.getAllMember().stream() + .filter(this::isUserRoleOnly) // 조건에 맞는 멤버만 필터링 + .map(this::toMemberInfoResponse) // Member를 MemberInfoResponse로 변환 + .collect(Collectors.toList()); + } + + public MemberInfoResponse findUserByEmail(String email) { + Member member = memberLoader.findByMemberEmail(email); return MemberInfoResponse .builder() .email(member.getEmail()) @@ -93,27 +104,8 @@ public MemberInfoResponse changeMemberInfo(String username) { .build(); } - public List inquireAllMemberInfo() { - List memberInfoResponseList = new ArrayList<>(); - for(Member member: memberLoader.getAllMember()){ - if(distinguishUser(member.getAffiliations())){ - memberInfoResponseList.add(MemberInfoResponse - .builder() - .email(member.getEmail()) - .memberName(member.getUsername()) - .createAt(member.getCreateAt()) - .updateAt(member.getUpdateAt()) - .affiliationListDto(getMemberAffiliationRoleList()) - .build()); - } - } - return memberInfoResponseList; - } - - public MemberInfoResponse findUserByEmail(String email) { - Member member = memberLoader.findByMemberEmail(email); - return MemberInfoResponse - .builder() + public MemberInfoResponse toMemberInfoResponse(Member member) { + return MemberInfoResponse.builder() .email(member.getEmail()) .memberName(member.getUsername()) .createAt(member.getCreateAt()) @@ -131,12 +123,10 @@ private AffiliationListDto affiliationListToEntity(String userName, List affiliations) { - for(AffiliationMember affiliationMember : affiliations){ - if(!"ROLE_USER".equals(affiliationMember.getRole())){ - return false; - } - } - return true; + + private boolean isUserRoleOnly(Member member) { + return member.getAffiliations().stream() + .allMatch(affiliationMember -> "ROLE_USER".equals(affiliationMember.getRole())); } + } diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberSaver.java b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberSaver.java new file mode 100644 index 0000000..b97a8a9 --- /dev/null +++ b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberSaver.java @@ -0,0 +1,17 @@ +package com.example.bigbrotherbe.domain.member.component; + + +import com.example.bigbrotherbe.domain.member.entity.Member; +import com.example.bigbrotherbe.domain.member.repository.MemberRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class MemberSaver { + private final MemberRepository memberRepository; + public Member saveMember(Member member) { + return memberRepository.save(member); + } +} diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/controller/MemberController.java b/src/main/java/com/example/bigbrotherbe/domain/member/controller/MemberController.java index 54eb583..acb74bd 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/controller/MemberController.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/controller/MemberController.java @@ -7,10 +7,10 @@ import com.example.bigbrotherbe.domain.member.dto.response.AffiliationResponse; import com.example.bigbrotherbe.domain.member.dto.response.MemberInfoResponse; import com.example.bigbrotherbe.domain.member.dto.response.MemberResponse; -import com.example.bigbrotherbe.domain.member.entity.role.AffiliationListDto; -import com.example.bigbrotherbe.global.email.EmailRequest; -import com.example.bigbrotherbe.global.email.EmailVerificationResult; -import com.example.bigbrotherbe.global.jwt.JwtToken; +import com.example.bigbrotherbe.domain.member.dto.AffiliationListDto; +import com.example.bigbrotherbe.global.email.entity.EmailRequest; +import com.example.bigbrotherbe.global.email.entity.EmailVerificationResult; +import com.example.bigbrotherbe.global.jwt.entity.JwtToken; import com.example.bigbrotherbe.global.jwt.entity.TokenDto; import com.example.bigbrotherbe.global.security.SecurityConfig; import io.swagger.v3.oas.annotations.Operation; diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/controller/MemberControllerImpl.java b/src/main/java/com/example/bigbrotherbe/domain/member/controller/MemberControllerImpl.java index 58cc80c..dacb118 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/controller/MemberControllerImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/controller/MemberControllerImpl.java @@ -1,5 +1,6 @@ package com.example.bigbrotherbe.domain.member.controller; +import com.example.bigbrotherbe.domain.affiliation.service.AffiliationService; import com.example.bigbrotherbe.domain.member.dto.request.ChangePasswordRequest; import com.example.bigbrotherbe.domain.member.dto.request.MemberInfoChangeRequest; import com.example.bigbrotherbe.domain.member.dto.request.MemberRequest; @@ -7,13 +8,15 @@ import com.example.bigbrotherbe.domain.member.dto.response.AffiliationResponse; import com.example.bigbrotherbe.domain.member.dto.response.MemberInfoResponse; import com.example.bigbrotherbe.domain.member.dto.response.MemberResponse; -import com.example.bigbrotherbe.domain.member.entity.role.AffiliationListDto; -import com.example.bigbrotherbe.global.email.EmailRequest; -import com.example.bigbrotherbe.global.email.EmailVerificationResult; +import com.example.bigbrotherbe.domain.member.dto.AffiliationListDto; +import com.example.bigbrotherbe.global.email.entity.EmailRequest; +import com.example.bigbrotherbe.global.email.entity.EmailVerificationResult; +import com.example.bigbrotherbe.global.email.component.MailService; import com.example.bigbrotherbe.global.exception.response.ApiResponse; -import com.example.bigbrotherbe.global.jwt.JwtToken; +import com.example.bigbrotherbe.global.jwt.entity.JwtToken; import com.example.bigbrotherbe.domain.member.service.MemberService; +import com.example.bigbrotherbe.global.jwt.component.JwtTokenProvider; import com.example.bigbrotherbe.global.jwt.entity.TokenDto; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -30,6 +33,9 @@ public class MemberControllerImpl implements MemberController { private final MemberService memberService; + private final AffiliationService affiliationService; + private final MailService mailService; + private final JwtTokenProvider jwtTokenProvider; public ResponseEntity> signUp(SignUpDto signUpDto) { return ResponseEntity.ok(ApiResponse.success(SUCCESS, memberService.userSignUp(signUpDto))); @@ -53,17 +59,17 @@ public ResponseEntity> inquireMemberInfo() { } public ResponseEntity> verificateEmail(String email) { - return ResponseEntity.ok(ApiResponse.success(SUCCESS, memberService.verificationDuplicateEmail(email))); + return ResponseEntity.ok(ApiResponse.success(SUCCESS, mailService.verificationDuplicateEmail(email))); } public ResponseEntity> sendMessage(EmailRequest emailRequest) { - memberService.sendCodeToEmail(emailRequest.getEmail()); + mailService.sendCodeToEmail(emailRequest.getEmail()); return ResponseEntity.ok(ApiResponse.success(SUCCESS, EmailVerificationResult.builder().authResult(true).build())); } public ResponseEntity> verificationEmail(String email, String code) { - return ResponseEntity.ok(ApiResponse.success(SUCCESS, memberService.verifiedCode(email, code))); + return ResponseEntity.ok(ApiResponse.success(SUCCESS, mailService.verifiedCode(email, code))); } @@ -73,17 +79,17 @@ public ResponseEntity> changePassword(ChangePasswordRequest ch } public ResponseEntity>> getCollegesList() { - List collegesList = memberService.getColleges(); + List collegesList = affiliationService.getColleges(); return ResponseEntity.ok(ApiResponse.success(SUCCESS, collegesList)); } public ResponseEntity>> getDepartmentList(String councilName) { - List departmentsList = memberService.getDepartments(councilName); + List departmentsList = affiliationService.getDepartments(councilName); return ResponseEntity.ok(ApiResponse.success(SUCCESS, departmentsList)); } public ResponseEntity> refreshToken(String refreshToken) { - return ResponseEntity.ok(ApiResponse.success(SUCCESS, memberService.refreshToken(refreshToken))); + return ResponseEntity.ok(ApiResponse.success(SUCCESS, jwtTokenProvider.refreshAccessToken(refreshToken))); } @Override diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/dto/request/SignUpDto.java b/src/main/java/com/example/bigbrotherbe/domain/member/dto/request/SignUpDto.java index f331974..4eff80d 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/dto/request/SignUpDto.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/dto/request/SignUpDto.java @@ -52,14 +52,14 @@ public class SignUpDto { @Schema(description = "학과, 전공", example = "응용소프트웨어전공") private String affiliation; - public Member toEntity(SignUpDto signUpDto, String encodePassword) { - if(!isVaildEmail(signUpDto.getEmail())){ + public Member toEntity(String encodePassword) { + if(!isVaildEmail(email)){ throw new BusinessException(ErrorCode.INVALID_EMAIL_FORMAT); } return Member.builder() - .username(signUpDto.getUsername()) + .username(username) .password(encodePassword) - .email(signUpDto.getEmail()) + .email(email) .is_active("true") .createAt(LocalDateTime.now()) .updateAt(LocalDateTime.now()) diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/dto/response/MemberInfoResponse.java b/src/main/java/com/example/bigbrotherbe/domain/member/dto/response/MemberInfoResponse.java index 18fa833..9b916dd 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/dto/response/MemberInfoResponse.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/dto/response/MemberInfoResponse.java @@ -1,6 +1,6 @@ package com.example.bigbrotherbe.domain.member.dto.response; -import com.example.bigbrotherbe.domain.member.entity.role.AffiliationListDto; +import com.example.bigbrotherbe.domain.member.dto.AffiliationListDto; import java.time.LocalDateTime; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/service/MemberService.java b/src/main/java/com/example/bigbrotherbe/domain/member/service/MemberService.java index cc3d1b5..218d2bc 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/service/MemberService.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/service/MemberService.java @@ -1,14 +1,11 @@ package com.example.bigbrotherbe.domain.member.service; import com.example.bigbrotherbe.domain.member.dto.request.SignUpDto; -import com.example.bigbrotherbe.domain.member.dto.response.AffiliationResponse; import com.example.bigbrotherbe.domain.member.dto.response.MemberInfoResponse; import com.example.bigbrotherbe.domain.member.dto.response.MemberResponse; -import com.example.bigbrotherbe.domain.member.entity.role.AffiliationListDto; -import com.example.bigbrotherbe.global.email.EmailVerificationResult; -import com.example.bigbrotherbe.global.jwt.JwtToken; +import com.example.bigbrotherbe.domain.member.dto.AffiliationListDto; +import com.example.bigbrotherbe.global.jwt.entity.JwtToken; -import com.example.bigbrotherbe.global.jwt.entity.TokenDto; import java.util.List; public interface MemberService { @@ -18,26 +15,10 @@ public interface MemberService { MemberInfoResponse inquireMemberInfo(); - void sendCodeToEmail(String email); - - EmailVerificationResult verifiedCode(String email, String authCode); - - EmailVerificationResult verificationDuplicateEmail(String email); - - boolean checkExistAffiliationById(Long affiliationId); - void changePassword(String email,String password); - void makeAffiliation(); - AffiliationListDto getMemberAffiliationRoleList(); - List getColleges(); - - List getDepartments(String councilName); - - TokenDto refreshToken(String refreshToken); - void deleteSelf(); MemberInfoResponse changeMemberInfo(String userName); diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/service/MemberServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/member/service/MemberServiceImpl.java index 67c03b5..9b7820c 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/service/MemberServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/service/MemberServiceImpl.java @@ -1,62 +1,34 @@ package com.example.bigbrotherbe.domain.member.service; -import com.example.bigbrotherbe.domain.affiliation.component.AffiliationManger; import com.example.bigbrotherbe.domain.member.component.MemberManager; import com.example.bigbrotherbe.domain.member.dto.request.SignUpDto; -import com.example.bigbrotherbe.domain.member.dto.response.AffiliationResponse; import com.example.bigbrotherbe.domain.member.dto.response.MemberInfoResponse; import com.example.bigbrotherbe.domain.member.dto.response.MemberResponse; -import com.example.bigbrotherbe.domain.member.entity.enums.AffiliationCode; -import com.example.bigbrotherbe.domain.member.entity.role.Affiliation; -import com.example.bigbrotherbe.domain.member.entity.role.AffiliationListDto; -import com.example.bigbrotherbe.domain.member.entity.role.AffiliationMember; -import com.example.bigbrotherbe.domain.member.component.MemberChecker; -import com.example.bigbrotherbe.domain.member.component.MemberDeleter; -import com.example.bigbrotherbe.domain.member.component.MemberLoader; -import com.example.bigbrotherbe.global.email.EmailVerificationResult; -import com.example.bigbrotherbe.global.email.MailService; -import com.example.bigbrotherbe.global.exception.BusinessException; -import com.example.bigbrotherbe.global.exception.enums.ErrorCode; -import com.example.bigbrotherbe.global.jwt.AuthUtil; -import com.example.bigbrotherbe.global.jwt.JwtToken; +import com.example.bigbrotherbe.domain.member.dto.AffiliationListDto; +import com.example.bigbrotherbe.global.jwt.entity.JwtToken; import com.example.bigbrotherbe.domain.member.entity.Member; -import com.example.bigbrotherbe.global.jwt.JwtTokenProvider; -import com.example.bigbrotherbe.global.jwt.entity.TokenDto; - -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; @Service @RequiredArgsConstructor -@Transactional(readOnly = true) @Slf4j public class MemberServiceImpl implements MemberService { - private final MailService mailService; private final MemberManager memberManager; - private final AffiliationManger affiliationManger; - private final JwtTokenProvider jwtTokenProvider; - @Transactional(rollbackFor = Exception.class) @Override public MemberResponse userSignUp(SignUpDto signUpDto) { return memberManager.userSignup(signUpDto); } - @Transactional @Override public JwtToken userSignIN(String email, String password) { return memberManager.signIn(email, password); @@ -66,76 +38,20 @@ public JwtToken userSignIN(String email, String password) { @Override public MemberInfoResponse inquireMemberInfo() { Member member = memberManager.getLoginMember(); - return MemberInfoResponse - .builder() - .email(member.getEmail()) - .memberName(member.getUsername()) - .createAt(member.getCreateAt()) - .updateAt(member.getUpdateAt()) - .affiliationListDto(getMemberAffiliationRoleList()) - .build(); - } - - - // 인증코드 요청 및 일시 저장 - @Override - @Transactional - public void sendCodeToEmail(String toEmail) { - mailService.sendCodeToEmail(toEmail); + return memberManager.toMemberInfoResponse(member); } - public EmailVerificationResult verifiedCode(String email, String authCode) { - return mailService.verifiedCode(email,authCode); - } - - // 이메일 중복 체크 - @Override - public EmailVerificationResult verificationDuplicateEmail(String email) { - return memberManager.checkDuplicateEmail(email); - } /* 거의 모든 도메인 validation으로 사용 */ - @Override - @Transactional(readOnly = true) - public boolean checkExistAffiliationById(Long affiliationId) { - return affiliationManger.existsById(affiliationId); - } @Override - @Transactional public void changePassword(String email, String password) { memberManager.changePassword(email,password); } @Override - @Transactional - public void makeAffiliation() { -// affiliationRepository.save(Affiliation.builder().affiliation_id(1L).name("총학").build()); - } - - @Override - public List getColleges() { - return Arrays.stream(AffiliationCode.values()) - .filter(code -> code.getCouncilType().equals("단과대")) - .map(code -> AffiliationResponse.fromAffiliationResponse(code.getVal(), code.getName())) - .collect(Collectors.toList()); - } - - @Override - public List getDepartments(String councilName) { - return AffiliationCode.getDepartmentsByCollegeName(councilName); - } - - - @Override - public TokenDto refreshToken(String refreshToken) { - return jwtTokenProvider.refreshToken(refreshToken); - } - - @Override - @Transactional() public void deleteSelf() { memberManager.deleteSelf(); } diff --git a/src/main/java/com/example/bigbrotherbe/domain/notice/service/NoticeServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/notice/service/NoticeServiceImpl.java index b1376d5..317d881 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/notice/service/NoticeServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/notice/service/NoticeServiceImpl.java @@ -1,9 +1,9 @@ package com.example.bigbrotherbe.domain.notice.service; +import com.example.bigbrotherbe.domain.affiliation.service.AffiliationService; import com.example.bigbrotherbe.domain.member.entity.Member; import com.example.bigbrotherbe.domain.notice.dto.response.NoticeResponse; import com.example.bigbrotherbe.domain.notice.entity.Notice; -import com.example.bigbrotherbe.domain.member.service.MemberService; import com.example.bigbrotherbe.domain.notice.dto.request.NoticeModifyRequest; import com.example.bigbrotherbe.domain.notice.dto.request.NoticeRegisterRequest; import com.example.bigbrotherbe.domain.notice.repository.NoticeRepository; @@ -15,7 +15,7 @@ import com.example.bigbrotherbe.global.file.entity.File; import com.example.bigbrotherbe.global.file.enums.FileType; import com.example.bigbrotherbe.global.file.service.FileService; -import com.example.bigbrotherbe.global.jwt.AuthUtil; +import com.example.bigbrotherbe.global.jwt.component.AuthUtil; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -34,14 +34,14 @@ public class NoticeServiceImpl implements NoticeService { private final NoticeRepository noticeRepository; private final FileService fileService; - private final MemberService memberService; + private final AffiliationService affiliationService; private final AuthUtil authUtil; @Override @Transactional(rollbackFor = Exception.class) // 트랜잭션 시작 및 커밋 -> 모든 예외상황 발생시 롤백 public void register(NoticeRegisterRequest noticeRegisterRequest, List multipartFiles) { - if (!memberService.checkExistAffiliationById(noticeRegisterRequest.getAffiliationId())) { + if (!affiliationService.checkExistAffiliationById(noticeRegisterRequest.getAffiliationId())) { throw new BusinessException(NO_EXIST_AFFILIATION); } diff --git a/src/main/java/com/example/bigbrotherbe/domain/rule/service/RuleServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/rule/service/RuleServiceImpl.java index 9e45f3a..3a76b67 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/rule/service/RuleServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/rule/service/RuleServiceImpl.java @@ -1,7 +1,7 @@ package com.example.bigbrotherbe.domain.rule.service; +import com.example.bigbrotherbe.domain.affiliation.service.AffiliationService; import com.example.bigbrotherbe.domain.member.entity.Member; -import com.example.bigbrotherbe.domain.member.service.MemberService; import com.example.bigbrotherbe.domain.rule.dto.request.RuleRegisterRequest; import com.example.bigbrotherbe.domain.rule.dto.request.RuleUpdateRequest; import com.example.bigbrotherbe.domain.rule.dto.response.RuleResponse; @@ -14,7 +14,7 @@ import com.example.bigbrotherbe.global.file.entity.File; import com.example.bigbrotherbe.global.file.enums.FileType; import com.example.bigbrotherbe.global.file.service.FileService; -import com.example.bigbrotherbe.global.jwt.AuthUtil; +import com.example.bigbrotherbe.global.jwt.component.AuthUtil; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -33,14 +33,14 @@ public class RuleServiceImpl implements RuleService { private final RuleRepository ruleRepository; private final FileService fileService; - private final MemberService memberService; + private final AffiliationService affiliationService; private final AuthUtil authUtil; @Override @Transactional(rollbackFor = Exception.class) public void registerRule(RuleRegisterRequest ruleRegisterRequest, List multipartFiles) { - if (!memberService.checkExistAffiliationById(ruleRegisterRequest.getAffiliationId())) { + if (!affiliationService.checkExistAffiliationById(ruleRegisterRequest.getAffiliationId())) { throw new BusinessException(NO_EXIST_AFFILIATION); } diff --git a/src/main/java/com/example/bigbrotherbe/domain/transactions/service/TransactionsServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/transactions/service/TransactionsServiceImpl.java index 0b4df00..7c66a29 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/transactions/service/TransactionsServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/transactions/service/TransactionsServiceImpl.java @@ -1,7 +1,7 @@ package com.example.bigbrotherbe.domain.transactions.service; +import com.example.bigbrotherbe.domain.affiliation.service.AffiliationService; import com.example.bigbrotherbe.domain.member.entity.Member; -import com.example.bigbrotherbe.domain.member.service.MemberService; import com.example.bigbrotherbe.domain.transactions.dto.request.TransactionsUpdateRequest; import com.example.bigbrotherbe.domain.transactions.dto.response.TransactionsResponse; import com.example.bigbrotherbe.domain.transactions.entity.Transactions; @@ -11,7 +11,7 @@ import com.example.bigbrotherbe.global.file.entity.File; import com.example.bigbrotherbe.global.file.enums.FileType; import com.example.bigbrotherbe.global.file.service.FileService; -import com.example.bigbrotherbe.global.jwt.AuthUtil; +import com.example.bigbrotherbe.global.jwt.component.AuthUtil; import com.example.bigbrotherbe.global.ocr.dto.OcrDTO; import com.example.bigbrotherbe.global.ocr.service.OcrService; import lombok.RequiredArgsConstructor; @@ -35,7 +35,7 @@ public class TransactionsServiceImpl implements TransactionsService { private final TransactionsRepository transactionsRepository; - private final MemberService memberService; + private final AffiliationService affiliationService; private final OcrService ocrService; private final FileService fileService; @@ -44,7 +44,7 @@ public class TransactionsServiceImpl implements TransactionsService { @Override @Transactional(rollbackFor = Exception.class) public void register(MultipartFile multipartFile, Long affiliationId) { - if (!memberService.checkExistAffiliationById(affiliationId)) { + if (!affiliationService.checkExistAffiliationById(affiliationId)) { throw new BusinessException(NO_EXIST_AFFILIATION); } diff --git a/src/main/java/com/example/bigbrotherbe/global/jwt/AuthUtil.java b/src/main/java/com/example/bigbrotherbe/global/jwt/component/AuthUtil.java similarity index 97% rename from src/main/java/com/example/bigbrotherbe/global/jwt/AuthUtil.java rename to src/main/java/com/example/bigbrotherbe/global/jwt/component/AuthUtil.java index 5f4b01a..3c6b82f 100644 --- a/src/main/java/com/example/bigbrotherbe/global/jwt/AuthUtil.java +++ b/src/main/java/com/example/bigbrotherbe/global/jwt/component/AuthUtil.java @@ -1,10 +1,11 @@ -package com.example.bigbrotherbe.global.jwt; +package com.example.bigbrotherbe.global.jwt.component; import com.example.bigbrotherbe.domain.member.entity.Member; import com.example.bigbrotherbe.domain.member.entity.role.AffiliationMember; import com.example.bigbrotherbe.domain.member.repository.AffiliationMemberRepository; import com.example.bigbrotherbe.domain.member.repository.AffiliationRepository; import com.example.bigbrotherbe.domain.member.repository.MemberRepository; +import com.example.bigbrotherbe.global.jwt.entity.JwtToken; import java.util.List; import com.example.bigbrotherbe.global.exception.BusinessException; diff --git a/src/main/java/com/example/bigbrotherbe/global/security/SecurityConfig.java b/src/main/java/com/example/bigbrotherbe/global/security/SecurityConfig.java index 29c1cb9..0b5c246 100644 --- a/src/main/java/com/example/bigbrotherbe/global/security/SecurityConfig.java +++ b/src/main/java/com/example/bigbrotherbe/global/security/SecurityConfig.java @@ -1,12 +1,11 @@ package com.example.bigbrotherbe.global.security; import com.example.bigbrotherbe.global.jwt.JwtAuthenticationFilter; -import com.example.bigbrotherbe.global.jwt.JwtTokenProvider; +import com.example.bigbrotherbe.global.jwt.component.JwtTokenProvider; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpMethod; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer; From 88e33cdbb99134b45ef1e24f8f79b8ffdb2642fb Mon Sep 17 00:00:00 2001 From: 0702Yoon Date: Fri, 16 Aug 2024 14:42:54 +0900 Subject: [PATCH 06/14] =?UTF-8?q?refactor=20:=20memberservice=EC=97=90?= =?UTF-8?q?=EC=84=9C=20jwt=20=ED=86=A0=ED=81=B0=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bigbrotherbe/global/jwt/JwtAuthenticationFilter.java | 1 + .../global/jwt/{ => component}/JwtTokenProvider.java | 7 ++++--- .../bigbrotherbe/global/jwt/{ => entity}/JwtToken.java | 2 +- .../bigbrotherbe/global/jwt/{ => entity}/RefreshToken.java | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) rename src/main/java/com/example/bigbrotherbe/global/jwt/{ => component}/JwtTokenProvider.java (97%) rename src/main/java/com/example/bigbrotherbe/global/jwt/{ => entity}/JwtToken.java (81%) rename src/main/java/com/example/bigbrotherbe/global/jwt/{ => entity}/RefreshToken.java (94%) diff --git a/src/main/java/com/example/bigbrotherbe/global/jwt/JwtAuthenticationFilter.java b/src/main/java/com/example/bigbrotherbe/global/jwt/JwtAuthenticationFilter.java index 59839a1..a44eba2 100644 --- a/src/main/java/com/example/bigbrotherbe/global/jwt/JwtAuthenticationFilter.java +++ b/src/main/java/com/example/bigbrotherbe/global/jwt/JwtAuthenticationFilter.java @@ -1,6 +1,7 @@ package com.example.bigbrotherbe.global.jwt; import com.example.bigbrotherbe.global.exception.BusinessException; import com.example.bigbrotherbe.global.exception.response.ApiResponse; +import com.example.bigbrotherbe.global.jwt.component.JwtTokenProvider; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; diff --git a/src/main/java/com/example/bigbrotherbe/global/jwt/JwtTokenProvider.java b/src/main/java/com/example/bigbrotherbe/global/jwt/component/JwtTokenProvider.java similarity index 97% rename from src/main/java/com/example/bigbrotherbe/global/jwt/JwtTokenProvider.java rename to src/main/java/com/example/bigbrotherbe/global/jwt/component/JwtTokenProvider.java index af2cd94..5ff0365 100644 --- a/src/main/java/com/example/bigbrotherbe/global/jwt/JwtTokenProvider.java +++ b/src/main/java/com/example/bigbrotherbe/global/jwt/component/JwtTokenProvider.java @@ -1,10 +1,11 @@ -package com.example.bigbrotherbe.global.jwt; +package com.example.bigbrotherbe.global.jwt.component; import static com.example.bigbrotherbe.global.jwt.entity.TokenDto.ACCESS_TOKEN; import static com.example.bigbrotherbe.global.jwt.entity.TokenDto.REFRESH_TOKEN; import com.example.bigbrotherbe.global.exception.BusinessException; import com.example.bigbrotherbe.global.exception.enums.ErrorCode; +import com.example.bigbrotherbe.global.jwt.entity.JwtToken; import com.example.bigbrotherbe.global.jwt.entity.TokenDto; import io.jsonwebtoken.Claims; import io.jsonwebtoken.ExpiredJwtException; @@ -35,7 +36,7 @@ @Component public class JwtTokenProvider { private final Key key; - private static final long ACCESS_TIME = 10 * 60 * 1000L; // 1초 + private static final long ACCESS_TIME = 10 * 60 * 1000L; // 10분 private static final long REFRESH_TIME = 30 * 60 * 1000L; //30분 public JwtTokenProvider(@Value("${jwt.secret}") String secretKey){ byte[] keyBytes = Decoders.BASE64.decode(secretKey); @@ -171,7 +172,7 @@ private Claims getAllClaimsFromToken(String token) { .getBody(); } - public TokenDto refreshToken(String refreshToken) { + public TokenDto refreshAccessToken(String refreshToken) { String resolveToken = resolveToken(refreshToken); diff --git a/src/main/java/com/example/bigbrotherbe/global/jwt/JwtToken.java b/src/main/java/com/example/bigbrotherbe/global/jwt/entity/JwtToken.java similarity index 81% rename from src/main/java/com/example/bigbrotherbe/global/jwt/JwtToken.java rename to src/main/java/com/example/bigbrotherbe/global/jwt/entity/JwtToken.java index 90e98a1..5d9e7bb 100644 --- a/src/main/java/com/example/bigbrotherbe/global/jwt/JwtToken.java +++ b/src/main/java/com/example/bigbrotherbe/global/jwt/entity/JwtToken.java @@ -1,4 +1,4 @@ -package com.example.bigbrotherbe.global.jwt; +package com.example.bigbrotherbe.global.jwt.entity; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/com/example/bigbrotherbe/global/jwt/RefreshToken.java b/src/main/java/com/example/bigbrotherbe/global/jwt/entity/RefreshToken.java similarity index 94% rename from src/main/java/com/example/bigbrotherbe/global/jwt/RefreshToken.java rename to src/main/java/com/example/bigbrotherbe/global/jwt/entity/RefreshToken.java index 0bfc952..7bd7811 100644 --- a/src/main/java/com/example/bigbrotherbe/global/jwt/RefreshToken.java +++ b/src/main/java/com/example/bigbrotherbe/global/jwt/entity/RefreshToken.java @@ -1,4 +1,4 @@ -package com.example.bigbrotherbe.global.jwt; +package com.example.bigbrotherbe.global.jwt.entity; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; From 6ae2691b4e91671cad96248998cf061b3560cd53 Mon Sep 17 00:00:00 2001 From: 0702Yoon Date: Fri, 16 Aug 2024 14:47:18 +0900 Subject: [PATCH 07/14] =?UTF-8?q?refactor=20:=20Unused=20import=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0=20=EB=B0=8F=20=EC=95=88=EC=93=B0=EB=8A=94=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../affiliation/service/AffiliationService.java | 1 - .../domain/member/component/MemberChecker.java | 7 ------- .../domain/member/component/MemberLoader.java | 1 - .../domain/member/component/MemberSaver.java | 1 - .../member/dto/response/MemberInfoResponse.java | 13 ------------- .../domain/member/entity/enums/CouncilType.java | 2 -- .../global/jwt/component/JwtTokenProvider.java | 12 ------------ 7 files changed, 37 deletions(-) diff --git a/src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationService.java b/src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationService.java index 40165b2..e2573e2 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationService.java +++ b/src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationService.java @@ -2,7 +2,6 @@ import com.example.bigbrotherbe.domain.member.dto.response.AffiliationResponse; import java.util.List; -import org.springframework.stereotype.Service; public interface AffiliationService { boolean checkExistAffiliationById(Long affiliationId); diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberChecker.java b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberChecker.java index 54b518f..fd86deb 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberChecker.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberChecker.java @@ -22,11 +22,4 @@ public void checkExistUserEmail(String email) { } } - public void checkDuplicatedEmail(String email) { - Optional member = memberRepository.findByEmail(email); - if (member.isPresent()) { - throw new BusinessException(ErrorCode.EXIST_EMAIL); - } - } - } diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberLoader.java b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberLoader.java index e4c633b..78988bd 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberLoader.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberLoader.java @@ -1,6 +1,5 @@ package com.example.bigbrotherbe.domain.member.component; -import com.example.bigbrotherbe.domain.member.dto.request.SignUpDto; import com.example.bigbrotherbe.domain.member.entity.Member; import com.example.bigbrotherbe.domain.member.repository.MemberRepository; import com.example.bigbrotherbe.global.exception.BusinessException; diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberSaver.java b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberSaver.java index b97a8a9..1432ee2 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberSaver.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberSaver.java @@ -5,7 +5,6 @@ import com.example.bigbrotherbe.domain.member.repository.MemberRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/dto/response/MemberInfoResponse.java b/src/main/java/com/example/bigbrotherbe/domain/member/dto/response/MemberInfoResponse.java index 9b916dd..982b511 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/dto/response/MemberInfoResponse.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/dto/response/MemberInfoResponse.java @@ -15,19 +15,6 @@ public class MemberInfoResponse { private final LocalDateTime createAt; private final LocalDateTime updateAt; private final AffiliationListDto affiliationListDto; - - public static MemberInfoResponse form(Long id, String username, String email, LocalDateTime createAt, LocalDateTime updateAt, - AffiliationListDto affiliationListDto) { - return MemberInfoResponse - .builder() - .memberName(username) - .email(email) - .createAt(createAt) - .updateAt(updateAt) - .affiliationListDto(affiliationListDto) - .build(); - } - } diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/CouncilType.java b/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/CouncilType.java index d4b1089..3f22bac 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/CouncilType.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/CouncilType.java @@ -1,8 +1,6 @@ package com.example.bigbrotherbe.domain.member.entity.enums; import com.fasterxml.jackson.annotation.JsonValue; -import lombok.Getter; - public enum CouncilType { GENERAL_STUDENTS_ASSOCIATION("총학"), COLLEGE("단과대"), diff --git a/src/main/java/com/example/bigbrotherbe/global/jwt/component/JwtTokenProvider.java b/src/main/java/com/example/bigbrotherbe/global/jwt/component/JwtTokenProvider.java index 5ff0365..8c398aa 100644 --- a/src/main/java/com/example/bigbrotherbe/global/jwt/component/JwtTokenProvider.java +++ b/src/main/java/com/example/bigbrotherbe/global/jwt/component/JwtTokenProvider.java @@ -136,18 +136,6 @@ private Claims parseClaims(String accessToken){ return e.getClaims(); } } - public String getMemberEmailFromToken(String token) { - try { - Jws claims = Jwts.parserBuilder() - .setSigningKey(key) - .build().parseClaimsJws(token); - return claims.getBody().getSubject(); - } catch (Exception e) { - log.error("Failed to extract username from token", e); - return null; - } - } - public String createTokenByRefreshToken(String refreshToken) { Claims claims = getAllClaimsFromToken(refreshToken); Date now = new Date(); From c1d9388e26380414861ca1ef919d3ad798f76232 Mon Sep 17 00:00:00 2001 From: 0702Yoon Date: Fri, 16 Aug 2024 14:38:02 +0900 Subject: [PATCH 08/14] =?UTF-8?q?refactor=20:=20JsonValue=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/entity/enums/AffiliationCode.java | 3 ++- .../bigbrotherbe/domain/member/entity/enums/CouncilType.java | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/AffiliationCode.java b/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/AffiliationCode.java index f7ea7ce..2202526 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/AffiliationCode.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/AffiliationCode.java @@ -107,7 +107,8 @@ private static int getMaxValForCollege(AffiliationCode college) { } @JsonValue - public String getAffiliationCode() { + public String serializationValue() { return this.name; } + // Lombok getter vs Json 방식 논점 } diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/CouncilType.java b/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/CouncilType.java index 1467429..d4b1089 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/CouncilType.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/CouncilType.java @@ -13,7 +13,7 @@ public enum CouncilType { } @JsonValue - public String getCouncilType() { + public String serializationValue() { return this.councilType; } @@ -25,5 +25,4 @@ public static CouncilType fromcouncilType(String councilType) { } throw new IllegalArgumentException("없는 CouncilType입니다." + councilType); } - } From 1233c7fb1cd99a904b2be6441b75002992eab76b Mon Sep 17 00:00:00 2001 From: 0702Yoon Date: Fri, 16 Aug 2024 14:40:51 +0900 Subject: [PATCH 09/14] =?UTF-8?q?refactor=20:=20memberservice=EC=97=90?= =?UTF-8?q?=EC=84=9C=20emailservice=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/bigbrotherbe/global/email/entity/Email.java | 9 +++++++++ .../global/email/{ => entity}/EmailRequest.java | 2 +- .../email/{ => entity}/EmailVerificationResult.java | 3 +-- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/example/bigbrotherbe/global/email/entity/Email.java rename src/main/java/com/example/bigbrotherbe/global/email/{ => entity}/EmailRequest.java (61%) rename src/main/java/com/example/bigbrotherbe/global/email/{ => entity}/EmailVerificationResult.java (82%) diff --git a/src/main/java/com/example/bigbrotherbe/global/email/entity/Email.java b/src/main/java/com/example/bigbrotherbe/global/email/entity/Email.java new file mode 100644 index 0000000..22c8e46 --- /dev/null +++ b/src/main/java/com/example/bigbrotherbe/global/email/entity/Email.java @@ -0,0 +1,9 @@ +package com.example.bigbrotherbe.global.email.entity; + + +import lombok.Builder; + +@Builder +public record Email(String title, String authCode, String toEmailAddress) { + +} diff --git a/src/main/java/com/example/bigbrotherbe/global/email/EmailRequest.java b/src/main/java/com/example/bigbrotherbe/global/email/entity/EmailRequest.java similarity index 61% rename from src/main/java/com/example/bigbrotherbe/global/email/EmailRequest.java rename to src/main/java/com/example/bigbrotherbe/global/email/entity/EmailRequest.java index 6c6ed3e..7c481fc 100644 --- a/src/main/java/com/example/bigbrotherbe/global/email/EmailRequest.java +++ b/src/main/java/com/example/bigbrotherbe/global/email/entity/EmailRequest.java @@ -1,4 +1,4 @@ -package com.example.bigbrotherbe.global.email; +package com.example.bigbrotherbe.global.email.entity; import lombok.Getter; diff --git a/src/main/java/com/example/bigbrotherbe/global/email/EmailVerificationResult.java b/src/main/java/com/example/bigbrotherbe/global/email/entity/EmailVerificationResult.java similarity index 82% rename from src/main/java/com/example/bigbrotherbe/global/email/EmailVerificationResult.java rename to src/main/java/com/example/bigbrotherbe/global/email/entity/EmailVerificationResult.java index 49c3908..1d3d9e7 100644 --- a/src/main/java/com/example/bigbrotherbe/global/email/EmailVerificationResult.java +++ b/src/main/java/com/example/bigbrotherbe/global/email/entity/EmailVerificationResult.java @@ -1,11 +1,10 @@ -package com.example.bigbrotherbe.global.email; +package com.example.bigbrotherbe.global.email.entity; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.RequiredArgsConstructor; @Getter @Builder From 2975cacce6f1032076920d60d188efd43c05ed74 Mon Sep 17 00:00:00 2001 From: 0702Yoon Date: Fri, 16 Aug 2024 14:41:27 +0900 Subject: [PATCH 10/14] =?UTF-8?q?refactor=20:=20emailservice=EC=95=88?= =?UTF-8?q?=EC=97=90=EC=84=9C=20Checker,=20maker=EB=A1=9C=20=EC=97=AD?= =?UTF-8?q?=ED=95=A0=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/email/component/MailChecker.java | 21 ++++++ .../global/email/component/MailMaker.java | 44 +++++++++++++ .../email/{ => component}/MailService.java | 66 +++++++------------ 3 files changed, 88 insertions(+), 43 deletions(-) create mode 100644 src/main/java/com/example/bigbrotherbe/global/email/component/MailChecker.java create mode 100644 src/main/java/com/example/bigbrotherbe/global/email/component/MailMaker.java rename src/main/java/com/example/bigbrotherbe/global/email/{ => component}/MailService.java (56%) diff --git a/src/main/java/com/example/bigbrotherbe/global/email/component/MailChecker.java b/src/main/java/com/example/bigbrotherbe/global/email/component/MailChecker.java new file mode 100644 index 0000000..90a5c53 --- /dev/null +++ b/src/main/java/com/example/bigbrotherbe/global/email/component/MailChecker.java @@ -0,0 +1,21 @@ +package com.example.bigbrotherbe.global.email.component; + + +import com.example.bigbrotherbe.domain.member.component.MemberLoader; +import com.example.bigbrotherbe.global.email.entity.EmailVerificationResult; +import com.example.bigbrotherbe.global.exception.BusinessException; +import com.example.bigbrotherbe.global.exception.enums.ErrorCode; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class MailChecker { + private final MemberLoader memberLoader; + public EmailVerificationResult checkDuplicateEmail(String email) { + if (memberLoader.findByMemberEmailForCheck(email).isPresent()) { + throw new BusinessException(ErrorCode.EXIST_EMAIL); + } + return EmailVerificationResult.builder().authResult(false).build(); + } +} diff --git a/src/main/java/com/example/bigbrotherbe/global/email/component/MailMaker.java b/src/main/java/com/example/bigbrotherbe/global/email/component/MailMaker.java new file mode 100644 index 0000000..ead842f --- /dev/null +++ b/src/main/java/com/example/bigbrotherbe/global/email/component/MailMaker.java @@ -0,0 +1,44 @@ +package com.example.bigbrotherbe.global.email.component; + +import com.example.bigbrotherbe.global.email.entity.Email; +import com.example.bigbrotherbe.global.exception.BusinessException; +import com.example.bigbrotherbe.global.exception.enums.ErrorCode; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.util.Random; +import org.springframework.mail.SimpleMailMessage; +import org.springframework.stereotype.Component; + +@Component +public class MailMaker { + private static final String EMAIL_TITLE = "명지대 big brother 이메일 인증 번호"; + public Email makeMail(String toEmail) { + return Email + .builder() + .title(EMAIL_TITLE) + .authCode(createCode()) + .toEmailAddress(toEmail) + .build(); + } + + private String createCode() { + int lenth = 6; + try { + Random random = SecureRandom.getInstanceStrong(); + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < lenth; i++) { + builder.append(random.nextInt(10)); + } + return builder.toString(); + } catch (NoSuchAlgorithmException e) { + throw new BusinessException(ErrorCode.NO_SUCH_ALGORITHM); + } + } + public SimpleMailMessage createEmailForm(Email email) { + SimpleMailMessage message = new SimpleMailMessage(); + message.setTo(email.toEmailAddress()); + message.setSubject(email.title()); + message.setText(email.authCode()); + return message; + } +} diff --git a/src/main/java/com/example/bigbrotherbe/global/email/MailService.java b/src/main/java/com/example/bigbrotherbe/global/email/component/MailService.java similarity index 56% rename from src/main/java/com/example/bigbrotherbe/global/email/MailService.java rename to src/main/java/com/example/bigbrotherbe/global/email/component/MailService.java index 0710555..d6d019b 100644 --- a/src/main/java/com/example/bigbrotherbe/global/email/MailService.java +++ b/src/main/java/com/example/bigbrotherbe/global/email/component/MailService.java @@ -1,13 +1,12 @@ -package com.example.bigbrotherbe.global.email; +package com.example.bigbrotherbe.global.email.component; import com.example.bigbrotherbe.domain.member.entity.EMailVerification; import com.example.bigbrotherbe.domain.member.repository.MailRepository; +import com.example.bigbrotherbe.global.email.entity.Email; +import com.example.bigbrotherbe.global.email.entity.EmailVerificationResult; import com.example.bigbrotherbe.global.exception.BusinessException; import com.example.bigbrotherbe.global.exception.enums.ErrorCode; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; import java.time.Duration; -import java.util.Random; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.mail.SimpleMailMessage; @@ -23,39 +22,29 @@ public class MailService { private final JavaMailSender javaMailSender; private final MailRepository mailRepository; - + private final MailChecker mailChecker; + private final MailMaker mailMaker; // @Value("${spring.mail.auth-code-expiration-millis}") private final long authCodeExpirationMillis = 1800000; + + @Transactional public void sendCodeToEmail(String toEmail) { - checkPresentEmail(toEmail); - String title = "명지대 big brother 이메일 인증 번호"; - String authCode = createCode(); - sendEmail(toEmail, title, authCode); - // 이메일 인증 요청 시 인증 번호 Redis에 저장 ( key = "AuthCode " + Email / value = AuthCode ) - saveEmailAuthCode(toEmail, authCode, Duration.ofMillis(this.authCodeExpirationMillis)); + deleteByEmailAddress(toEmail); + Email email = mailMaker.makeMail(toEmail); + SimpleMailMessage emailForm = mailMaker.createEmailForm(email); + sendEmail(emailForm); + saveEmailAuthCode(toEmail, email.authCode(), Duration.ofMillis(this.authCodeExpirationMillis)); } - private void sendEmail(String toEmail, String title, String text) { - SimpleMailMessage emailForm = createEmailForm(toEmail, title, text); + private void sendEmail(SimpleMailMessage emailForm) { try { javaMailSender.send(emailForm); } catch (RuntimeException e) { - log.debug("MailService.sendEmail exception occur toEmail: {}, " + - "title: {}, text: {}", toEmail, title, text); throw new BusinessException(ErrorCode.UNABLE_TO_SEND_EMAIL); } } - private SimpleMailMessage createEmailForm(String toEmail, - String title, - String text) { - SimpleMailMessage message = new SimpleMailMessage(); - message.setTo(toEmail); - message.setSubject(title); - message.setText(text); - return message; - } @Transactional protected void saveEmailAuthCode(String emailAddress, String authCode, Duration duration) { mailRepository.save( @@ -65,7 +54,8 @@ protected void saveEmailAuthCode(String emailAddress, String authCode, Duration scheduleDeletion(emailAddress,duration); } - private void scheduleDeletion(String emailAddress, Duration duration) { + @Transactional + public void scheduleDeletion(String emailAddress, Duration duration) { new Thread(() -> { try { Thread.sleep(duration.toMillis()); @@ -75,7 +65,7 @@ private void scheduleDeletion(String emailAddress, Duration duration) { } }).start(); } - + @Transactional(readOnly = true) public String getAuthCode(String emailAddress) { EMailVerification emailVerification = mailRepository.findByEmailAddress(emailAddress).orElseThrow ( ()-> new IllegalArgumentException("이메일 인증 시간이 만료되었습니다.")); @@ -83,33 +73,23 @@ public String getAuthCode(String emailAddress) { } @Transactional - protected void checkPresentEmail(String toEmail) { + protected void deleteByEmailAddress(String toEmail) { mailRepository.findByEmailAddress(toEmail) .ifPresent(mail -> mailRepository.deleteByEmailAddress(toEmail)); } - private String createCode() { - int lenth = 6; - try { - Random random = SecureRandom.getInstanceStrong(); - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < lenth; i++) { - builder.append(random.nextInt(10)); - } - return builder.toString(); - } catch (NoSuchAlgorithmException e) { - log.debug("MemberService.createCode() exception occur"); - throw new BusinessException(ErrorCode.NO_SUCH_ALGORITHM); - } - } + public EmailVerificationResult verifiedCode(String email, String authCode) { - String redisAuthCode = getAuthCode(email); - boolean authResult = redisAuthCode.equals(authCode); + String saveAuthCode = getAuthCode(email); + boolean authResult = authCode.equals(saveAuthCode); if (!authResult) { throw new BusinessException(ErrorCode.MISMATCH_VERIFIED_CODE); } return EmailVerificationResult.of(true); } + public EmailVerificationResult verificationDuplicateEmail(String email) { + return mailChecker.checkDuplicateEmail(email); + } } From 869d40b9bd99ff9e88d777317c5df22f91c04d0d Mon Sep 17 00:00:00 2001 From: 0702Yoon Date: Fri, 16 Aug 2024 14:42:02 +0900 Subject: [PATCH 11/14] =?UTF-8?q?refactor=20:=20member=20service=EC=97=90?= =?UTF-8?q?=EC=84=9C=20affiliationSerivce=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/AffiliationManger.java | 2 +- .../service/AffiliationService.java | 15 ++++++++ .../service/AffiliationServiceImpl.java | 37 +++++++++++++++++++ .../role => dto}/AffiliationListDto.java | 6 +-- 4 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationService.java create mode 100644 src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationServiceImpl.java rename src/main/java/com/example/bigbrotherbe/domain/member/{entity/role => dto}/AffiliationListDto.java (81%) diff --git a/src/main/java/com/example/bigbrotherbe/domain/affiliation/component/AffiliationManger.java b/src/main/java/com/example/bigbrotherbe/domain/affiliation/component/AffiliationManger.java index b4f6c98..0b78783 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/affiliation/component/AffiliationManger.java +++ b/src/main/java/com/example/bigbrotherbe/domain/affiliation/component/AffiliationManger.java @@ -26,7 +26,7 @@ public Affiliation findAffiliationByName(String name) { public AffiliationMember createAfiiliationMember(Member savedMember, String affiliationName, Role role) { Affiliation affiliation = findAffiliationByName(affiliationName); - AffiliationMember affiliationMember= AffiliationMember.builder() + AffiliationMember affiliationMember = AffiliationMember.builder() .member(savedMember) .affiliation(affiliation) .role(role.getRole()) diff --git a/src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationService.java b/src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationService.java new file mode 100644 index 0000000..40165b2 --- /dev/null +++ b/src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationService.java @@ -0,0 +1,15 @@ +package com.example.bigbrotherbe.domain.affiliation.service; + +import com.example.bigbrotherbe.domain.member.dto.response.AffiliationResponse; +import java.util.List; +import org.springframework.stereotype.Service; + +public interface AffiliationService { + boolean checkExistAffiliationById(Long affiliationId); + + List getColleges(); + + List getDepartments(String councilName); + + +} diff --git a/src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationServiceImpl.java new file mode 100644 index 0000000..ec81949 --- /dev/null +++ b/src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationServiceImpl.java @@ -0,0 +1,37 @@ +package com.example.bigbrotherbe.domain.affiliation.service; + +import com.example.bigbrotherbe.domain.affiliation.component.AffiliationManger; +import com.example.bigbrotherbe.domain.member.dto.response.AffiliationResponse; +import com.example.bigbrotherbe.domain.member.entity.enums.AffiliationCode; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Transactional(readOnly = true) +@Service +public class AffiliationServiceImpl implements AffiliationService{ + private final AffiliationManger affiliationManger; + @Override + public boolean checkExistAffiliationById(Long affiliationId) { + return affiliationManger.existsById(affiliationId); + } + + + @Override + public List getColleges() { + return Arrays.stream(AffiliationCode.values()) + .filter(code -> code.getCouncilType().equals("단과대")) + .map(code -> AffiliationResponse.fromAffiliationResponse(code.getVal(), code.getName())) + .collect(Collectors.toList()); + } + + @Override + public List getDepartments(String councilName) { + return AffiliationCode.getDepartmentsByCollegeName(councilName); + } + +} diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/entity/role/AffiliationListDto.java b/src/main/java/com/example/bigbrotherbe/domain/member/dto/AffiliationListDto.java similarity index 81% rename from src/main/java/com/example/bigbrotherbe/domain/member/entity/role/AffiliationListDto.java rename to src/main/java/com/example/bigbrotherbe/domain/member/dto/AffiliationListDto.java index 2d6f7a3..9c816b4 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/entity/role/AffiliationListDto.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/dto/AffiliationListDto.java @@ -1,9 +1,10 @@ -package com.example.bigbrotherbe.domain.member.entity.role; +package com.example.bigbrotherbe.domain.member.dto; import com.example.bigbrotherbe.domain.member.entity.enums.AffiliationCode; import com.example.bigbrotherbe.domain.member.entity.enums.CouncilType; import com.example.bigbrotherbe.domain.member.entity.enums.Role; +import com.example.bigbrotherbe.domain.member.entity.role.AffiliationType; import java.util.ArrayList; import java.util.List; @@ -18,8 +19,7 @@ public class AffiliationListDto { private final List affiliationTypeList = new ArrayList<>(); private final String memberName; - - public void addAffiliation(String councilType,String affiliation, String role) { + public void addAffiliation(String councilType, String affiliation, String role) { try { affiliationTypeList.add(AffiliationType .builder() From e6d303f09364498a1ea41ab13151aab6205834a8 Mon Sep 17 00:00:00 2001 From: 0702Yoon Date: Fri, 16 Aug 2024 14:42:43 +0900 Subject: [PATCH 12/14] =?UTF-8?q?refactor=20:=20memberservice=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=EC=A0=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/service/EventServiceImpl.java | 10 +-- .../domain/faq/service/FAQServiceImpl.java | 8 +- .../meetings/service/MeetingsServiceImpl.java | 14 +-- .../member/component/MemberChecker.java | 2 + .../domain/member/component/MemberLoader.java | 22 ----- .../member/component/MemberManager.java | 82 ++++++++--------- .../domain/member/component/MemberSaver.java | 17 ++++ .../member/controller/MemberController.java | 8 +- .../controller/MemberControllerImpl.java | 26 +++--- .../domain/member/dto/request/SignUpDto.java | 8 +- .../dto/response/MemberInfoResponse.java | 2 +- .../domain/member/service/MemberService.java | 23 +---- .../member/service/MemberServiceImpl.java | 90 +------------------ .../notice/service/NoticeServiceImpl.java | 8 +- .../domain/rule/service/RuleServiceImpl.java | 8 +- .../service/TransactionsServiceImpl.java | 8 +- .../global/jwt/{ => component}/AuthUtil.java | 3 +- .../global/security/SecurityConfig.java | 3 +- 18 files changed, 112 insertions(+), 230 deletions(-) create mode 100644 src/main/java/com/example/bigbrotherbe/domain/member/component/MemberSaver.java rename src/main/java/com/example/bigbrotherbe/global/jwt/{ => component}/AuthUtil.java (97%) diff --git a/src/main/java/com/example/bigbrotherbe/domain/event/service/EventServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/event/service/EventServiceImpl.java index 1dcdf87..be8c91b 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/event/service/EventServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/event/service/EventServiceImpl.java @@ -1,12 +1,12 @@ package com.example.bigbrotherbe.domain.event.service; +import com.example.bigbrotherbe.domain.affiliation.service.AffiliationService; import com.example.bigbrotherbe.domain.event.dto.request.EventRegisterRequest; import com.example.bigbrotherbe.domain.event.dto.request.EventUpdateRequest; import com.example.bigbrotherbe.domain.event.dto.response.EventResponse; import com.example.bigbrotherbe.domain.event.entity.Event; import com.example.bigbrotherbe.domain.event.repository.EventRepository; import com.example.bigbrotherbe.domain.member.entity.Member; -import com.example.bigbrotherbe.domain.member.service.MemberService; import com.example.bigbrotherbe.global.exception.BusinessException; import com.example.bigbrotherbe.global.file.dto.FileDeleteDTO; import com.example.bigbrotherbe.global.file.dto.FileSaveDTO; @@ -14,7 +14,7 @@ import com.example.bigbrotherbe.global.file.entity.File; import com.example.bigbrotherbe.global.file.enums.FileType; import com.example.bigbrotherbe.global.file.service.FileService; -import com.example.bigbrotherbe.global.jwt.AuthUtil; +import com.example.bigbrotherbe.global.jwt.component.AuthUtil; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -31,16 +31,14 @@ public class EventServiceImpl implements EventService { private final EventRepository eventRepository; - - private final MemberService memberService; + private final AffiliationService affiliationService; private final FileService fileService; - private final AuthUtil authUtil; @Override @Transactional(rollbackFor = Exception.class) public void registerEvent(EventRegisterRequest eventRegisterRequest, List multipartFiles) { - if (!memberService.checkExistAffiliationById(eventRegisterRequest.getAffiliationId())) { + if (!affiliationService.checkExistAffiliationById(eventRegisterRequest.getAffiliationId())) { throw new BusinessException(NO_EXIST_AFFILIATION); } diff --git a/src/main/java/com/example/bigbrotherbe/domain/faq/service/FAQServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/faq/service/FAQServiceImpl.java index b9c8803..229c2e0 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/faq/service/FAQServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/faq/service/FAQServiceImpl.java @@ -1,12 +1,12 @@ package com.example.bigbrotherbe.domain.faq.service; +import com.example.bigbrotherbe.domain.affiliation.service.AffiliationService; import com.example.bigbrotherbe.domain.faq.dto.request.FAQModifyRequest; import com.example.bigbrotherbe.domain.faq.dto.request.FAQRegisterRequest; import com.example.bigbrotherbe.domain.faq.dto.response.FAQResponse; import com.example.bigbrotherbe.domain.faq.entity.FAQ; import com.example.bigbrotherbe.domain.faq.repository.FAQRepository; import com.example.bigbrotherbe.domain.member.entity.Member; -import com.example.bigbrotherbe.domain.member.service.MemberService; import com.example.bigbrotherbe.global.exception.BusinessException; import com.example.bigbrotherbe.global.exception.enums.ErrorCode; import com.example.bigbrotherbe.global.file.dto.FileSaveDTO; @@ -14,7 +14,7 @@ import com.example.bigbrotherbe.global.file.entity.File; import com.example.bigbrotherbe.global.file.enums.FileType; import com.example.bigbrotherbe.global.file.service.FileService; -import com.example.bigbrotherbe.global.jwt.AuthUtil; +import com.example.bigbrotherbe.global.jwt.component.AuthUtil; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -32,14 +32,14 @@ public class FAQServiceImpl implements FAQService { private final FAQRepository faqRepository; private final FileService fileService; - private final MemberService memberService; + private final AffiliationService affiliationService; private final AuthUtil authUtil; @Override @Transactional(rollbackFor = Exception.class) // 트랜잭션 시작 및 커밋 -> 모든 예외상황 발생시 롤백 public void register(FAQRegisterRequest faqRegisterRequest, List multipartFiles) { - if (!memberService.checkExistAffiliationById(faqRegisterRequest.getAffiliationId())) { + if (!affiliationService.checkExistAffiliationById(faqRegisterRequest.getAffiliationId())) { throw new BusinessException(NO_EXIST_AFFILIATION); } diff --git a/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsServiceImpl.java index 0bda18f..fdc0d87 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsServiceImpl.java @@ -1,12 +1,12 @@ package com.example.bigbrotherbe.domain.meetings.service; +import com.example.bigbrotherbe.domain.affiliation.service.AffiliationService; import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsRegisterRequest; import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsUpdateRequest; import com.example.bigbrotherbe.domain.meetings.dto.response.MeetingsResponse; import com.example.bigbrotherbe.domain.meetings.entity.Meetings; import com.example.bigbrotherbe.domain.meetings.repository.MeetingsRepository; import com.example.bigbrotherbe.domain.member.entity.Member; -import com.example.bigbrotherbe.domain.member.service.MemberService; import com.example.bigbrotherbe.global.exception.BusinessException; import com.example.bigbrotherbe.global.file.dto.FileDeleteDTO; import com.example.bigbrotherbe.global.file.dto.FileSaveDTO; @@ -14,8 +14,7 @@ import com.example.bigbrotherbe.global.file.entity.File; import com.example.bigbrotherbe.global.file.enums.FileType; import com.example.bigbrotherbe.global.file.service.FileService; -import com.example.bigbrotherbe.global.jwt.AuthUtil; -import io.lettuce.core.ScriptOutputType; +import com.example.bigbrotherbe.global.jwt.component.AuthUtil; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -24,8 +23,6 @@ import org.springframework.web.multipart.MultipartFile; import java.util.List; -import java.util.Optional; -import java.util.OptionalLong; import static com.example.bigbrotherbe.global.exception.enums.ErrorCode.*; @@ -34,20 +31,17 @@ public class MeetingsServiceImpl implements MeetingsService { private final MeetingsRepository meetingsRepository; - private final FileService fileService; - private final MemberService memberService; - + private final AffiliationService affiliationService; private final AuthUtil authUtil; @Override @Transactional(rollbackFor = Exception.class) public void registerMeetings(MeetingsRegisterRequest meetingsRegisterRequest, List multipartFiles) { - if (!memberService.checkExistAffiliationById(meetingsRegisterRequest.getAffiliationId())) { + if (!affiliationService.checkExistAffiliationById(meetingsRegisterRequest.getAffiliationId())) { throw new BusinessException(NO_EXIST_AFFILIATION); } - if (authUtil.checkCouncilRole(meetingsRegisterRequest.getAffiliationId())) { throw new BusinessException(NOT_COUNCIL_MEMBER); } diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberChecker.java b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberChecker.java index 99b34f6..54b518f 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberChecker.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberChecker.java @@ -7,9 +7,11 @@ import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor +@Transactional(readOnly = true) public class MemberChecker { private final MemberRepository memberRepository; diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberLoader.java b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberLoader.java index bfbac99..e4c633b 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberLoader.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberLoader.java @@ -16,25 +16,6 @@ public class MemberLoader { private final MemberRepository memberRepository; - public Member saveMember(Member member) { - return memberRepository.save(member); - } - - public Member getMember(Long id) { - return memberRepository.findById(id).orElseThrow( - () -> new BusinessException(ErrorCode.FAIL_LOAD_MEMBER) - ); - } - - public Member findByUserName(String username) { - return memberRepository.findByUsername(username) - .orElseThrow(() -> new IllegalArgumentException("잘못된 사용자 이름입니다.")); - } - - public Member findByMemberId(String memberId) { - return memberRepository.findById(Long.valueOf(memberId)).orElseThrow(() -> new IllegalArgumentException("잘못된 사용자 아이디입니다.")); - } - public Member findByMemberEmail(String memberEmail) { return memberRepository.findByEmail(memberEmail).orElseThrow(() -> new BusinessException(ErrorCode.NO_EXIST_EMAIL)); @@ -47,7 +28,4 @@ public List getAllMember() { return memberRepository.findAll(); } - public Member signUp(SignUpDto signUpDto, String encodePassword) { - return saveMember(signUpDto.toEntity(signUpDto,encodePassword)); - } } diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberManager.java b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberManager.java index dc5fe72..f11ffae 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberManager.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberManager.java @@ -7,21 +7,20 @@ import com.example.bigbrotherbe.domain.member.entity.Member; import com.example.bigbrotherbe.domain.member.entity.enums.Role; import com.example.bigbrotherbe.domain.member.entity.role.Affiliation; -import com.example.bigbrotherbe.domain.member.entity.role.AffiliationListDto; +import com.example.bigbrotherbe.domain.member.dto.AffiliationListDto; import com.example.bigbrotherbe.domain.member.entity.role.AffiliationMember; -import com.example.bigbrotherbe.global.email.EmailVerificationResult; -import com.example.bigbrotherbe.global.exception.BusinessException; -import com.example.bigbrotherbe.global.exception.enums.ErrorCode; -import com.example.bigbrotherbe.global.jwt.AuthUtil; -import com.example.bigbrotherbe.global.jwt.JwtToken; -import java.util.ArrayList; +import com.example.bigbrotherbe.global.jwt.component.AuthUtil; +import com.example.bigbrotherbe.global.jwt.entity.JwtToken; import java.util.List; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; @Component @RequiredArgsConstructor +@Transactional(readOnly = true) public class MemberManager { private final AuthUtil authUtil; @@ -29,14 +28,19 @@ public class MemberManager { private final MemberLoader memberLoader; private final MemberChecker memberChecker; private final MemberDeleter memberDeleter; + private final MemberSaver memberSaver; private final AffiliationManger affiliationManger; + + @Transactional(rollbackFor = Exception.class) public MemberResponse userSignup(SignUpDto signUpDto) { memberChecker.checkExistUserEmail(signUpDto.getEmail()); - - Member savedMember = memberLoader.signUp(signUpDto,passwordEncoder.encode(signUpDto.getPassword())); + String encodePassword = passwordEncoder.encode(signUpDto.getPassword()); + Member member = signUpDto.toEntity(encodePassword); + Member savedMember = memberSaver.saveMember(member); AffiliationMember collegeMember = affiliationManger.createAfiiliationMember(savedMember,signUpDto.getCollege(), Role.ROLE_USER); AffiliationMember affiliationMember = affiliationManger.createAfiiliationMember(savedMember,signUpDto.getAffiliation(),Role.ROLE_USER); + return MemberResponse.form( savedMember.getId(), savedMember.getUsername(), @@ -47,6 +51,7 @@ public MemberResponse userSignup(SignUpDto signUpDto) { ); } + @Transactional public JwtToken signIn(String email, String password) { memberLoader.findByMemberEmail(email); return authUtil.createAuthenticationToken(email,password); @@ -62,27 +67,33 @@ public Member getLoginMember() { return authUtil.getLoginMember(); } - - public EmailVerificationResult checkDuplicateEmail(String email) { - if (memberLoader.findByMemberEmailForCheck(email).isPresent()) { - throw new BusinessException(ErrorCode.EXIST_EMAIL); - } - return EmailVerificationResult.builder().authResult(false).build(); - } - + @Transactional public void changePassword(String email, String password) { Member member = memberLoader.findByMemberEmail(email); member.changePassword(passwordEncoder.encode(password)); } - + @Transactional public void deleteSelf() { Member member = authUtil.getLoginMember(); memberDeleter.deleteMember(member); } + @Transactional public MemberInfoResponse changeMemberInfo(String username) { Member member = authUtil.getLoginMember(); member.changeName(username); + return toMemberInfoResponse(member); + } + + public List inquireAllMemberInfo() { + return memberLoader.getAllMember().stream() + .filter(this::isUserRoleOnly) // 조건에 맞는 멤버만 필터링 + .map(this::toMemberInfoResponse) // Member를 MemberInfoResponse로 변환 + .collect(Collectors.toList()); + } + + public MemberInfoResponse findUserByEmail(String email) { + Member member = memberLoader.findByMemberEmail(email); return MemberInfoResponse .builder() .email(member.getEmail()) @@ -93,27 +104,8 @@ public MemberInfoResponse changeMemberInfo(String username) { .build(); } - public List inquireAllMemberInfo() { - List memberInfoResponseList = new ArrayList<>(); - for(Member member: memberLoader.getAllMember()){ - if(distinguishUser(member.getAffiliations())){ - memberInfoResponseList.add(MemberInfoResponse - .builder() - .email(member.getEmail()) - .memberName(member.getUsername()) - .createAt(member.getCreateAt()) - .updateAt(member.getUpdateAt()) - .affiliationListDto(getMemberAffiliationRoleList()) - .build()); - } - } - return memberInfoResponseList; - } - - public MemberInfoResponse findUserByEmail(String email) { - Member member = memberLoader.findByMemberEmail(email); - return MemberInfoResponse - .builder() + public MemberInfoResponse toMemberInfoResponse(Member member) { + return MemberInfoResponse.builder() .email(member.getEmail()) .memberName(member.getUsername()) .createAt(member.getCreateAt()) @@ -131,12 +123,10 @@ private AffiliationListDto affiliationListToEntity(String userName, List affiliations) { - for(AffiliationMember affiliationMember : affiliations){ - if(!"ROLE_USER".equals(affiliationMember.getRole())){ - return false; - } - } - return true; + + private boolean isUserRoleOnly(Member member) { + return member.getAffiliations().stream() + .allMatch(affiliationMember -> "ROLE_USER".equals(affiliationMember.getRole())); } + } diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberSaver.java b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberSaver.java new file mode 100644 index 0000000..b97a8a9 --- /dev/null +++ b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberSaver.java @@ -0,0 +1,17 @@ +package com.example.bigbrotherbe.domain.member.component; + + +import com.example.bigbrotherbe.domain.member.entity.Member; +import com.example.bigbrotherbe.domain.member.repository.MemberRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class MemberSaver { + private final MemberRepository memberRepository; + public Member saveMember(Member member) { + return memberRepository.save(member); + } +} diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/controller/MemberController.java b/src/main/java/com/example/bigbrotherbe/domain/member/controller/MemberController.java index 54eb583..acb74bd 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/controller/MemberController.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/controller/MemberController.java @@ -7,10 +7,10 @@ import com.example.bigbrotherbe.domain.member.dto.response.AffiliationResponse; import com.example.bigbrotherbe.domain.member.dto.response.MemberInfoResponse; import com.example.bigbrotherbe.domain.member.dto.response.MemberResponse; -import com.example.bigbrotherbe.domain.member.entity.role.AffiliationListDto; -import com.example.bigbrotherbe.global.email.EmailRequest; -import com.example.bigbrotherbe.global.email.EmailVerificationResult; -import com.example.bigbrotherbe.global.jwt.JwtToken; +import com.example.bigbrotherbe.domain.member.dto.AffiliationListDto; +import com.example.bigbrotherbe.global.email.entity.EmailRequest; +import com.example.bigbrotherbe.global.email.entity.EmailVerificationResult; +import com.example.bigbrotherbe.global.jwt.entity.JwtToken; import com.example.bigbrotherbe.global.jwt.entity.TokenDto; import com.example.bigbrotherbe.global.security.SecurityConfig; import io.swagger.v3.oas.annotations.Operation; diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/controller/MemberControllerImpl.java b/src/main/java/com/example/bigbrotherbe/domain/member/controller/MemberControllerImpl.java index 58cc80c..dacb118 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/controller/MemberControllerImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/controller/MemberControllerImpl.java @@ -1,5 +1,6 @@ package com.example.bigbrotherbe.domain.member.controller; +import com.example.bigbrotherbe.domain.affiliation.service.AffiliationService; import com.example.bigbrotherbe.domain.member.dto.request.ChangePasswordRequest; import com.example.bigbrotherbe.domain.member.dto.request.MemberInfoChangeRequest; import com.example.bigbrotherbe.domain.member.dto.request.MemberRequest; @@ -7,13 +8,15 @@ import com.example.bigbrotherbe.domain.member.dto.response.AffiliationResponse; import com.example.bigbrotherbe.domain.member.dto.response.MemberInfoResponse; import com.example.bigbrotherbe.domain.member.dto.response.MemberResponse; -import com.example.bigbrotherbe.domain.member.entity.role.AffiliationListDto; -import com.example.bigbrotherbe.global.email.EmailRequest; -import com.example.bigbrotherbe.global.email.EmailVerificationResult; +import com.example.bigbrotherbe.domain.member.dto.AffiliationListDto; +import com.example.bigbrotherbe.global.email.entity.EmailRequest; +import com.example.bigbrotherbe.global.email.entity.EmailVerificationResult; +import com.example.bigbrotherbe.global.email.component.MailService; import com.example.bigbrotherbe.global.exception.response.ApiResponse; -import com.example.bigbrotherbe.global.jwt.JwtToken; +import com.example.bigbrotherbe.global.jwt.entity.JwtToken; import com.example.bigbrotherbe.domain.member.service.MemberService; +import com.example.bigbrotherbe.global.jwt.component.JwtTokenProvider; import com.example.bigbrotherbe.global.jwt.entity.TokenDto; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -30,6 +33,9 @@ public class MemberControllerImpl implements MemberController { private final MemberService memberService; + private final AffiliationService affiliationService; + private final MailService mailService; + private final JwtTokenProvider jwtTokenProvider; public ResponseEntity> signUp(SignUpDto signUpDto) { return ResponseEntity.ok(ApiResponse.success(SUCCESS, memberService.userSignUp(signUpDto))); @@ -53,17 +59,17 @@ public ResponseEntity> inquireMemberInfo() { } public ResponseEntity> verificateEmail(String email) { - return ResponseEntity.ok(ApiResponse.success(SUCCESS, memberService.verificationDuplicateEmail(email))); + return ResponseEntity.ok(ApiResponse.success(SUCCESS, mailService.verificationDuplicateEmail(email))); } public ResponseEntity> sendMessage(EmailRequest emailRequest) { - memberService.sendCodeToEmail(emailRequest.getEmail()); + mailService.sendCodeToEmail(emailRequest.getEmail()); return ResponseEntity.ok(ApiResponse.success(SUCCESS, EmailVerificationResult.builder().authResult(true).build())); } public ResponseEntity> verificationEmail(String email, String code) { - return ResponseEntity.ok(ApiResponse.success(SUCCESS, memberService.verifiedCode(email, code))); + return ResponseEntity.ok(ApiResponse.success(SUCCESS, mailService.verifiedCode(email, code))); } @@ -73,17 +79,17 @@ public ResponseEntity> changePassword(ChangePasswordRequest ch } public ResponseEntity>> getCollegesList() { - List collegesList = memberService.getColleges(); + List collegesList = affiliationService.getColleges(); return ResponseEntity.ok(ApiResponse.success(SUCCESS, collegesList)); } public ResponseEntity>> getDepartmentList(String councilName) { - List departmentsList = memberService.getDepartments(councilName); + List departmentsList = affiliationService.getDepartments(councilName); return ResponseEntity.ok(ApiResponse.success(SUCCESS, departmentsList)); } public ResponseEntity> refreshToken(String refreshToken) { - return ResponseEntity.ok(ApiResponse.success(SUCCESS, memberService.refreshToken(refreshToken))); + return ResponseEntity.ok(ApiResponse.success(SUCCESS, jwtTokenProvider.refreshAccessToken(refreshToken))); } @Override diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/dto/request/SignUpDto.java b/src/main/java/com/example/bigbrotherbe/domain/member/dto/request/SignUpDto.java index f331974..4eff80d 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/dto/request/SignUpDto.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/dto/request/SignUpDto.java @@ -52,14 +52,14 @@ public class SignUpDto { @Schema(description = "학과, 전공", example = "응용소프트웨어전공") private String affiliation; - public Member toEntity(SignUpDto signUpDto, String encodePassword) { - if(!isVaildEmail(signUpDto.getEmail())){ + public Member toEntity(String encodePassword) { + if(!isVaildEmail(email)){ throw new BusinessException(ErrorCode.INVALID_EMAIL_FORMAT); } return Member.builder() - .username(signUpDto.getUsername()) + .username(username) .password(encodePassword) - .email(signUpDto.getEmail()) + .email(email) .is_active("true") .createAt(LocalDateTime.now()) .updateAt(LocalDateTime.now()) diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/dto/response/MemberInfoResponse.java b/src/main/java/com/example/bigbrotherbe/domain/member/dto/response/MemberInfoResponse.java index 18fa833..9b916dd 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/dto/response/MemberInfoResponse.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/dto/response/MemberInfoResponse.java @@ -1,6 +1,6 @@ package com.example.bigbrotherbe.domain.member.dto.response; -import com.example.bigbrotherbe.domain.member.entity.role.AffiliationListDto; +import com.example.bigbrotherbe.domain.member.dto.AffiliationListDto; import java.time.LocalDateTime; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/service/MemberService.java b/src/main/java/com/example/bigbrotherbe/domain/member/service/MemberService.java index cc3d1b5..218d2bc 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/service/MemberService.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/service/MemberService.java @@ -1,14 +1,11 @@ package com.example.bigbrotherbe.domain.member.service; import com.example.bigbrotherbe.domain.member.dto.request.SignUpDto; -import com.example.bigbrotherbe.domain.member.dto.response.AffiliationResponse; import com.example.bigbrotherbe.domain.member.dto.response.MemberInfoResponse; import com.example.bigbrotherbe.domain.member.dto.response.MemberResponse; -import com.example.bigbrotherbe.domain.member.entity.role.AffiliationListDto; -import com.example.bigbrotherbe.global.email.EmailVerificationResult; -import com.example.bigbrotherbe.global.jwt.JwtToken; +import com.example.bigbrotherbe.domain.member.dto.AffiliationListDto; +import com.example.bigbrotherbe.global.jwt.entity.JwtToken; -import com.example.bigbrotherbe.global.jwt.entity.TokenDto; import java.util.List; public interface MemberService { @@ -18,26 +15,10 @@ public interface MemberService { MemberInfoResponse inquireMemberInfo(); - void sendCodeToEmail(String email); - - EmailVerificationResult verifiedCode(String email, String authCode); - - EmailVerificationResult verificationDuplicateEmail(String email); - - boolean checkExistAffiliationById(Long affiliationId); - void changePassword(String email,String password); - void makeAffiliation(); - AffiliationListDto getMemberAffiliationRoleList(); - List getColleges(); - - List getDepartments(String councilName); - - TokenDto refreshToken(String refreshToken); - void deleteSelf(); MemberInfoResponse changeMemberInfo(String userName); diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/service/MemberServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/member/service/MemberServiceImpl.java index 67c03b5..9b7820c 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/service/MemberServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/service/MemberServiceImpl.java @@ -1,62 +1,34 @@ package com.example.bigbrotherbe.domain.member.service; -import com.example.bigbrotherbe.domain.affiliation.component.AffiliationManger; import com.example.bigbrotherbe.domain.member.component.MemberManager; import com.example.bigbrotherbe.domain.member.dto.request.SignUpDto; -import com.example.bigbrotherbe.domain.member.dto.response.AffiliationResponse; import com.example.bigbrotherbe.domain.member.dto.response.MemberInfoResponse; import com.example.bigbrotherbe.domain.member.dto.response.MemberResponse; -import com.example.bigbrotherbe.domain.member.entity.enums.AffiliationCode; -import com.example.bigbrotherbe.domain.member.entity.role.Affiliation; -import com.example.bigbrotherbe.domain.member.entity.role.AffiliationListDto; -import com.example.bigbrotherbe.domain.member.entity.role.AffiliationMember; -import com.example.bigbrotherbe.domain.member.component.MemberChecker; -import com.example.bigbrotherbe.domain.member.component.MemberDeleter; -import com.example.bigbrotherbe.domain.member.component.MemberLoader; -import com.example.bigbrotherbe.global.email.EmailVerificationResult; -import com.example.bigbrotherbe.global.email.MailService; -import com.example.bigbrotherbe.global.exception.BusinessException; -import com.example.bigbrotherbe.global.exception.enums.ErrorCode; -import com.example.bigbrotherbe.global.jwt.AuthUtil; -import com.example.bigbrotherbe.global.jwt.JwtToken; +import com.example.bigbrotherbe.domain.member.dto.AffiliationListDto; +import com.example.bigbrotherbe.global.jwt.entity.JwtToken; import com.example.bigbrotherbe.domain.member.entity.Member; -import com.example.bigbrotherbe.global.jwt.JwtTokenProvider; -import com.example.bigbrotherbe.global.jwt.entity.TokenDto; - -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; @Service @RequiredArgsConstructor -@Transactional(readOnly = true) @Slf4j public class MemberServiceImpl implements MemberService { - private final MailService mailService; private final MemberManager memberManager; - private final AffiliationManger affiliationManger; - private final JwtTokenProvider jwtTokenProvider; - @Transactional(rollbackFor = Exception.class) @Override public MemberResponse userSignUp(SignUpDto signUpDto) { return memberManager.userSignup(signUpDto); } - @Transactional @Override public JwtToken userSignIN(String email, String password) { return memberManager.signIn(email, password); @@ -66,76 +38,20 @@ public JwtToken userSignIN(String email, String password) { @Override public MemberInfoResponse inquireMemberInfo() { Member member = memberManager.getLoginMember(); - return MemberInfoResponse - .builder() - .email(member.getEmail()) - .memberName(member.getUsername()) - .createAt(member.getCreateAt()) - .updateAt(member.getUpdateAt()) - .affiliationListDto(getMemberAffiliationRoleList()) - .build(); - } - - - // 인증코드 요청 및 일시 저장 - @Override - @Transactional - public void sendCodeToEmail(String toEmail) { - mailService.sendCodeToEmail(toEmail); + return memberManager.toMemberInfoResponse(member); } - public EmailVerificationResult verifiedCode(String email, String authCode) { - return mailService.verifiedCode(email,authCode); - } - - // 이메일 중복 체크 - @Override - public EmailVerificationResult verificationDuplicateEmail(String email) { - return memberManager.checkDuplicateEmail(email); - } /* 거의 모든 도메인 validation으로 사용 */ - @Override - @Transactional(readOnly = true) - public boolean checkExistAffiliationById(Long affiliationId) { - return affiliationManger.existsById(affiliationId); - } @Override - @Transactional public void changePassword(String email, String password) { memberManager.changePassword(email,password); } @Override - @Transactional - public void makeAffiliation() { -// affiliationRepository.save(Affiliation.builder().affiliation_id(1L).name("총학").build()); - } - - @Override - public List getColleges() { - return Arrays.stream(AffiliationCode.values()) - .filter(code -> code.getCouncilType().equals("단과대")) - .map(code -> AffiliationResponse.fromAffiliationResponse(code.getVal(), code.getName())) - .collect(Collectors.toList()); - } - - @Override - public List getDepartments(String councilName) { - return AffiliationCode.getDepartmentsByCollegeName(councilName); - } - - - @Override - public TokenDto refreshToken(String refreshToken) { - return jwtTokenProvider.refreshToken(refreshToken); - } - - @Override - @Transactional() public void deleteSelf() { memberManager.deleteSelf(); } diff --git a/src/main/java/com/example/bigbrotherbe/domain/notice/service/NoticeServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/notice/service/NoticeServiceImpl.java index b1376d5..317d881 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/notice/service/NoticeServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/notice/service/NoticeServiceImpl.java @@ -1,9 +1,9 @@ package com.example.bigbrotherbe.domain.notice.service; +import com.example.bigbrotherbe.domain.affiliation.service.AffiliationService; import com.example.bigbrotherbe.domain.member.entity.Member; import com.example.bigbrotherbe.domain.notice.dto.response.NoticeResponse; import com.example.bigbrotherbe.domain.notice.entity.Notice; -import com.example.bigbrotherbe.domain.member.service.MemberService; import com.example.bigbrotherbe.domain.notice.dto.request.NoticeModifyRequest; import com.example.bigbrotherbe.domain.notice.dto.request.NoticeRegisterRequest; import com.example.bigbrotherbe.domain.notice.repository.NoticeRepository; @@ -15,7 +15,7 @@ import com.example.bigbrotherbe.global.file.entity.File; import com.example.bigbrotherbe.global.file.enums.FileType; import com.example.bigbrotherbe.global.file.service.FileService; -import com.example.bigbrotherbe.global.jwt.AuthUtil; +import com.example.bigbrotherbe.global.jwt.component.AuthUtil; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -34,14 +34,14 @@ public class NoticeServiceImpl implements NoticeService { private final NoticeRepository noticeRepository; private final FileService fileService; - private final MemberService memberService; + private final AffiliationService affiliationService; private final AuthUtil authUtil; @Override @Transactional(rollbackFor = Exception.class) // 트랜잭션 시작 및 커밋 -> 모든 예외상황 발생시 롤백 public void register(NoticeRegisterRequest noticeRegisterRequest, List multipartFiles) { - if (!memberService.checkExistAffiliationById(noticeRegisterRequest.getAffiliationId())) { + if (!affiliationService.checkExistAffiliationById(noticeRegisterRequest.getAffiliationId())) { throw new BusinessException(NO_EXIST_AFFILIATION); } diff --git a/src/main/java/com/example/bigbrotherbe/domain/rule/service/RuleServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/rule/service/RuleServiceImpl.java index 9e45f3a..3a76b67 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/rule/service/RuleServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/rule/service/RuleServiceImpl.java @@ -1,7 +1,7 @@ package com.example.bigbrotherbe.domain.rule.service; +import com.example.bigbrotherbe.domain.affiliation.service.AffiliationService; import com.example.bigbrotherbe.domain.member.entity.Member; -import com.example.bigbrotherbe.domain.member.service.MemberService; import com.example.bigbrotherbe.domain.rule.dto.request.RuleRegisterRequest; import com.example.bigbrotherbe.domain.rule.dto.request.RuleUpdateRequest; import com.example.bigbrotherbe.domain.rule.dto.response.RuleResponse; @@ -14,7 +14,7 @@ import com.example.bigbrotherbe.global.file.entity.File; import com.example.bigbrotherbe.global.file.enums.FileType; import com.example.bigbrotherbe.global.file.service.FileService; -import com.example.bigbrotherbe.global.jwt.AuthUtil; +import com.example.bigbrotherbe.global.jwt.component.AuthUtil; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -33,14 +33,14 @@ public class RuleServiceImpl implements RuleService { private final RuleRepository ruleRepository; private final FileService fileService; - private final MemberService memberService; + private final AffiliationService affiliationService; private final AuthUtil authUtil; @Override @Transactional(rollbackFor = Exception.class) public void registerRule(RuleRegisterRequest ruleRegisterRequest, List multipartFiles) { - if (!memberService.checkExistAffiliationById(ruleRegisterRequest.getAffiliationId())) { + if (!affiliationService.checkExistAffiliationById(ruleRegisterRequest.getAffiliationId())) { throw new BusinessException(NO_EXIST_AFFILIATION); } diff --git a/src/main/java/com/example/bigbrotherbe/domain/transactions/service/TransactionsServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/transactions/service/TransactionsServiceImpl.java index 0b4df00..7c66a29 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/transactions/service/TransactionsServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/transactions/service/TransactionsServiceImpl.java @@ -1,7 +1,7 @@ package com.example.bigbrotherbe.domain.transactions.service; +import com.example.bigbrotherbe.domain.affiliation.service.AffiliationService; import com.example.bigbrotherbe.domain.member.entity.Member; -import com.example.bigbrotherbe.domain.member.service.MemberService; import com.example.bigbrotherbe.domain.transactions.dto.request.TransactionsUpdateRequest; import com.example.bigbrotherbe.domain.transactions.dto.response.TransactionsResponse; import com.example.bigbrotherbe.domain.transactions.entity.Transactions; @@ -11,7 +11,7 @@ import com.example.bigbrotherbe.global.file.entity.File; import com.example.bigbrotherbe.global.file.enums.FileType; import com.example.bigbrotherbe.global.file.service.FileService; -import com.example.bigbrotherbe.global.jwt.AuthUtil; +import com.example.bigbrotherbe.global.jwt.component.AuthUtil; import com.example.bigbrotherbe.global.ocr.dto.OcrDTO; import com.example.bigbrotherbe.global.ocr.service.OcrService; import lombok.RequiredArgsConstructor; @@ -35,7 +35,7 @@ public class TransactionsServiceImpl implements TransactionsService { private final TransactionsRepository transactionsRepository; - private final MemberService memberService; + private final AffiliationService affiliationService; private final OcrService ocrService; private final FileService fileService; @@ -44,7 +44,7 @@ public class TransactionsServiceImpl implements TransactionsService { @Override @Transactional(rollbackFor = Exception.class) public void register(MultipartFile multipartFile, Long affiliationId) { - if (!memberService.checkExistAffiliationById(affiliationId)) { + if (!affiliationService.checkExistAffiliationById(affiliationId)) { throw new BusinessException(NO_EXIST_AFFILIATION); } diff --git a/src/main/java/com/example/bigbrotherbe/global/jwt/AuthUtil.java b/src/main/java/com/example/bigbrotherbe/global/jwt/component/AuthUtil.java similarity index 97% rename from src/main/java/com/example/bigbrotherbe/global/jwt/AuthUtil.java rename to src/main/java/com/example/bigbrotherbe/global/jwt/component/AuthUtil.java index 5f4b01a..3c6b82f 100644 --- a/src/main/java/com/example/bigbrotherbe/global/jwt/AuthUtil.java +++ b/src/main/java/com/example/bigbrotherbe/global/jwt/component/AuthUtil.java @@ -1,10 +1,11 @@ -package com.example.bigbrotherbe.global.jwt; +package com.example.bigbrotherbe.global.jwt.component; import com.example.bigbrotherbe.domain.member.entity.Member; import com.example.bigbrotherbe.domain.member.entity.role.AffiliationMember; import com.example.bigbrotherbe.domain.member.repository.AffiliationMemberRepository; import com.example.bigbrotherbe.domain.member.repository.AffiliationRepository; import com.example.bigbrotherbe.domain.member.repository.MemberRepository; +import com.example.bigbrotherbe.global.jwt.entity.JwtToken; import java.util.List; import com.example.bigbrotherbe.global.exception.BusinessException; diff --git a/src/main/java/com/example/bigbrotherbe/global/security/SecurityConfig.java b/src/main/java/com/example/bigbrotherbe/global/security/SecurityConfig.java index 29c1cb9..0b5c246 100644 --- a/src/main/java/com/example/bigbrotherbe/global/security/SecurityConfig.java +++ b/src/main/java/com/example/bigbrotherbe/global/security/SecurityConfig.java @@ -1,12 +1,11 @@ package com.example.bigbrotherbe.global.security; import com.example.bigbrotherbe.global.jwt.JwtAuthenticationFilter; -import com.example.bigbrotherbe.global.jwt.JwtTokenProvider; +import com.example.bigbrotherbe.global.jwt.component.JwtTokenProvider; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpMethod; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer; From f66a40ef09fdebb430e5b03c350460269806ecf7 Mon Sep 17 00:00:00 2001 From: 0702Yoon Date: Fri, 16 Aug 2024 14:42:54 +0900 Subject: [PATCH 13/14] =?UTF-8?q?refactor=20:=20memberservice=EC=97=90?= =?UTF-8?q?=EC=84=9C=20jwt=20=ED=86=A0=ED=81=B0=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bigbrotherbe/global/jwt/JwtAuthenticationFilter.java | 1 + .../global/jwt/{ => component}/JwtTokenProvider.java | 7 ++++--- .../bigbrotherbe/global/jwt/{ => entity}/JwtToken.java | 2 +- .../bigbrotherbe/global/jwt/{ => entity}/RefreshToken.java | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) rename src/main/java/com/example/bigbrotherbe/global/jwt/{ => component}/JwtTokenProvider.java (97%) rename src/main/java/com/example/bigbrotherbe/global/jwt/{ => entity}/JwtToken.java (81%) rename src/main/java/com/example/bigbrotherbe/global/jwt/{ => entity}/RefreshToken.java (94%) diff --git a/src/main/java/com/example/bigbrotherbe/global/jwt/JwtAuthenticationFilter.java b/src/main/java/com/example/bigbrotherbe/global/jwt/JwtAuthenticationFilter.java index 59839a1..a44eba2 100644 --- a/src/main/java/com/example/bigbrotherbe/global/jwt/JwtAuthenticationFilter.java +++ b/src/main/java/com/example/bigbrotherbe/global/jwt/JwtAuthenticationFilter.java @@ -1,6 +1,7 @@ package com.example.bigbrotherbe.global.jwt; import com.example.bigbrotherbe.global.exception.BusinessException; import com.example.bigbrotherbe.global.exception.response.ApiResponse; +import com.example.bigbrotherbe.global.jwt.component.JwtTokenProvider; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; diff --git a/src/main/java/com/example/bigbrotherbe/global/jwt/JwtTokenProvider.java b/src/main/java/com/example/bigbrotherbe/global/jwt/component/JwtTokenProvider.java similarity index 97% rename from src/main/java/com/example/bigbrotherbe/global/jwt/JwtTokenProvider.java rename to src/main/java/com/example/bigbrotherbe/global/jwt/component/JwtTokenProvider.java index af2cd94..5ff0365 100644 --- a/src/main/java/com/example/bigbrotherbe/global/jwt/JwtTokenProvider.java +++ b/src/main/java/com/example/bigbrotherbe/global/jwt/component/JwtTokenProvider.java @@ -1,10 +1,11 @@ -package com.example.bigbrotherbe.global.jwt; +package com.example.bigbrotherbe.global.jwt.component; import static com.example.bigbrotherbe.global.jwt.entity.TokenDto.ACCESS_TOKEN; import static com.example.bigbrotherbe.global.jwt.entity.TokenDto.REFRESH_TOKEN; import com.example.bigbrotherbe.global.exception.BusinessException; import com.example.bigbrotherbe.global.exception.enums.ErrorCode; +import com.example.bigbrotherbe.global.jwt.entity.JwtToken; import com.example.bigbrotherbe.global.jwt.entity.TokenDto; import io.jsonwebtoken.Claims; import io.jsonwebtoken.ExpiredJwtException; @@ -35,7 +36,7 @@ @Component public class JwtTokenProvider { private final Key key; - private static final long ACCESS_TIME = 10 * 60 * 1000L; // 1초 + private static final long ACCESS_TIME = 10 * 60 * 1000L; // 10분 private static final long REFRESH_TIME = 30 * 60 * 1000L; //30분 public JwtTokenProvider(@Value("${jwt.secret}") String secretKey){ byte[] keyBytes = Decoders.BASE64.decode(secretKey); @@ -171,7 +172,7 @@ private Claims getAllClaimsFromToken(String token) { .getBody(); } - public TokenDto refreshToken(String refreshToken) { + public TokenDto refreshAccessToken(String refreshToken) { String resolveToken = resolveToken(refreshToken); diff --git a/src/main/java/com/example/bigbrotherbe/global/jwt/JwtToken.java b/src/main/java/com/example/bigbrotherbe/global/jwt/entity/JwtToken.java similarity index 81% rename from src/main/java/com/example/bigbrotherbe/global/jwt/JwtToken.java rename to src/main/java/com/example/bigbrotherbe/global/jwt/entity/JwtToken.java index 90e98a1..5d9e7bb 100644 --- a/src/main/java/com/example/bigbrotherbe/global/jwt/JwtToken.java +++ b/src/main/java/com/example/bigbrotherbe/global/jwt/entity/JwtToken.java @@ -1,4 +1,4 @@ -package com.example.bigbrotherbe.global.jwt; +package com.example.bigbrotherbe.global.jwt.entity; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/com/example/bigbrotherbe/global/jwt/RefreshToken.java b/src/main/java/com/example/bigbrotherbe/global/jwt/entity/RefreshToken.java similarity index 94% rename from src/main/java/com/example/bigbrotherbe/global/jwt/RefreshToken.java rename to src/main/java/com/example/bigbrotherbe/global/jwt/entity/RefreshToken.java index 0bfc952..7bd7811 100644 --- a/src/main/java/com/example/bigbrotherbe/global/jwt/RefreshToken.java +++ b/src/main/java/com/example/bigbrotherbe/global/jwt/entity/RefreshToken.java @@ -1,4 +1,4 @@ -package com.example.bigbrotherbe.global.jwt; +package com.example.bigbrotherbe.global.jwt.entity; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; From 5e07b517200a72906d734326a0a74baf5e1a9212 Mon Sep 17 00:00:00 2001 From: 0702Yoon Date: Fri, 16 Aug 2024 14:47:18 +0900 Subject: [PATCH 14/14] =?UTF-8?q?refactor=20:=20Unused=20import=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0=20=EB=B0=8F=20=EC=95=88=EC=93=B0=EB=8A=94=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../affiliation/service/AffiliationService.java | 1 - .../domain/member/component/MemberChecker.java | 7 ------- .../domain/member/component/MemberLoader.java | 1 - .../domain/member/component/MemberSaver.java | 1 - .../member/dto/response/MemberInfoResponse.java | 13 ------------- .../domain/member/entity/enums/CouncilType.java | 2 -- .../global/jwt/component/JwtTokenProvider.java | 12 ------------ 7 files changed, 37 deletions(-) diff --git a/src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationService.java b/src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationService.java index 40165b2..e2573e2 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationService.java +++ b/src/main/java/com/example/bigbrotherbe/domain/affiliation/service/AffiliationService.java @@ -2,7 +2,6 @@ import com.example.bigbrotherbe.domain.member.dto.response.AffiliationResponse; import java.util.List; -import org.springframework.stereotype.Service; public interface AffiliationService { boolean checkExistAffiliationById(Long affiliationId); diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberChecker.java b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberChecker.java index 54b518f..fd86deb 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberChecker.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberChecker.java @@ -22,11 +22,4 @@ public void checkExistUserEmail(String email) { } } - public void checkDuplicatedEmail(String email) { - Optional member = memberRepository.findByEmail(email); - if (member.isPresent()) { - throw new BusinessException(ErrorCode.EXIST_EMAIL); - } - } - } diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberLoader.java b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberLoader.java index e4c633b..78988bd 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberLoader.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberLoader.java @@ -1,6 +1,5 @@ package com.example.bigbrotherbe.domain.member.component; -import com.example.bigbrotherbe.domain.member.dto.request.SignUpDto; import com.example.bigbrotherbe.domain.member.entity.Member; import com.example.bigbrotherbe.domain.member.repository.MemberRepository; import com.example.bigbrotherbe.global.exception.BusinessException; diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberSaver.java b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberSaver.java index b97a8a9..1432ee2 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberSaver.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/component/MemberSaver.java @@ -5,7 +5,6 @@ import com.example.bigbrotherbe.domain.member.repository.MemberRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/dto/response/MemberInfoResponse.java b/src/main/java/com/example/bigbrotherbe/domain/member/dto/response/MemberInfoResponse.java index 9b916dd..982b511 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/dto/response/MemberInfoResponse.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/dto/response/MemberInfoResponse.java @@ -15,19 +15,6 @@ public class MemberInfoResponse { private final LocalDateTime createAt; private final LocalDateTime updateAt; private final AffiliationListDto affiliationListDto; - - public static MemberInfoResponse form(Long id, String username, String email, LocalDateTime createAt, LocalDateTime updateAt, - AffiliationListDto affiliationListDto) { - return MemberInfoResponse - .builder() - .memberName(username) - .email(email) - .createAt(createAt) - .updateAt(updateAt) - .affiliationListDto(affiliationListDto) - .build(); - } - } diff --git a/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/CouncilType.java b/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/CouncilType.java index d4b1089..3f22bac 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/CouncilType.java +++ b/src/main/java/com/example/bigbrotherbe/domain/member/entity/enums/CouncilType.java @@ -1,8 +1,6 @@ package com.example.bigbrotherbe.domain.member.entity.enums; import com.fasterxml.jackson.annotation.JsonValue; -import lombok.Getter; - public enum CouncilType { GENERAL_STUDENTS_ASSOCIATION("총학"), COLLEGE("단과대"), diff --git a/src/main/java/com/example/bigbrotherbe/global/jwt/component/JwtTokenProvider.java b/src/main/java/com/example/bigbrotherbe/global/jwt/component/JwtTokenProvider.java index 5ff0365..8c398aa 100644 --- a/src/main/java/com/example/bigbrotherbe/global/jwt/component/JwtTokenProvider.java +++ b/src/main/java/com/example/bigbrotherbe/global/jwt/component/JwtTokenProvider.java @@ -136,18 +136,6 @@ private Claims parseClaims(String accessToken){ return e.getClaims(); } } - public String getMemberEmailFromToken(String token) { - try { - Jws claims = Jwts.parserBuilder() - .setSigningKey(key) - .build().parseClaimsJws(token); - return claims.getBody().getSubject(); - } catch (Exception e) { - log.error("Failed to extract username from token", e); - return null; - } - } - public String createTokenByRefreshToken(String refreshToken) { Claims claims = getAllClaimsFromToken(refreshToken); Date now = new Date();