From 6b29533d2c6c7104e2d49b6e0ced14ef762d9b84 Mon Sep 17 00:00:00 2001 From: nahyeon99 Date: Mon, 6 May 2024 04:59:12 +0900 Subject: [PATCH 01/12] =?UTF-8?q?style:=20email=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=BD=94=EB=93=9C=20=EC=8A=A4=ED=83=80=EC=9D=BC=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../email/application/EmailService.java | 2 +- .../application/port/out/LoadEmailPort.java | 5 +++-- .../idorm/idormServer/email/entity/Email.java | 21 ++++++++++--------- .../idormServer/email/entity/EmailStatus.java | 19 ++++++++++------- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/main/java/idorm/idormServer/email/application/EmailService.java b/src/main/java/idorm/idormServer/email/application/EmailService.java index fc40e4a8..b2faeecc 100644 --- a/src/main/java/idorm/idormServer/email/application/EmailService.java +++ b/src/main/java/idorm/idormServer/email/application/EmailService.java @@ -21,8 +21,8 @@ public class EmailService implements EmailUseCase { private final SaveEmailPort saveEmailPort; private final LoadEmailPort loadEmailPort; - private final GenerateVerificationCodePort verificationCodePort; private final SendEmailPort sendEmailPort; + private final GenerateVerificationCodePort verificationCodePort; @Override @Transactional diff --git a/src/main/java/idorm/idormServer/email/application/port/out/LoadEmailPort.java b/src/main/java/idorm/idormServer/email/application/port/out/LoadEmailPort.java index 5cadf18d..6f5a1510 100644 --- a/src/main/java/idorm/idormServer/email/application/port/out/LoadEmailPort.java +++ b/src/main/java/idorm/idormServer/email/application/port/out/LoadEmailPort.java @@ -5,7 +5,8 @@ import idorm.idormServer.email.entity.Email; public interface LoadEmailPort { - Optional findByEmailWithOptional(String email); - Email findByEmail(String email); + Optional findByEmailWithOptional(String email); + + Email findByEmail(String email); } diff --git a/src/main/java/idorm/idormServer/email/entity/Email.java b/src/main/java/idorm/idormServer/email/entity/Email.java index 1daaba0b..5ce845ca 100644 --- a/src/main/java/idorm/idormServer/email/entity/Email.java +++ b/src/main/java/idorm/idormServer/email/entity/Email.java @@ -31,8 +31,9 @@ public class Email { public static final int MAX_EMAIL_LENGTH = 20; - private static final String EMAIL_REGEX = "^([\\w-]+(?:\\.[\\w-]+)*)+@(inu.ac.kr)$"; public static final int CODE_LENGTH = 7; + + private static final String EMAIL_REGEX = "^([\\w-]+(?:\\.[\\w-]+)*)+@(inu.ac.kr)$"; private static final String CODE_REGEX = "^\\d{3}-\\d{3}$"; private static final long VALID_VERIFY_MINUTE = 5L; @@ -63,25 +64,25 @@ public Email(final String email, final String code) { validateConstructor(email, code); this.email = email; this.code = code; - emailStatus = EmailStatus.SEND; - registered = false; + this.emailStatus = EmailStatus.SEND; + this.registered = false; this.issuedAt = LocalDateTime.now(); } - private static void validateConstructor(final String email, final String code) { + private void validateConstructor(final String email, final String code) { Validator.validateNotBlank(email); Validator.validateNotBlank(code); Validator.validateFormat(email, EMAIL_REGEX, EmailResponseCode.INVALID_EMAIL_CHARACTER); } - public void updateVerificationCode(String code) { + public void updateVerificationCode(final String code) { validateNotSignUp(); this.code = code; this.issuedAt = LocalDateTime.now(); this.emailStatus = EmailStatus.SEND; } - public void updateReVerificationCode(String code) { + public void updateReVerificationCode(final String code) { validateSignUpEmail(); this.code = code; this.issuedAt = LocalDateTime.now(); @@ -105,7 +106,7 @@ public void reVerify(final String code) { } public void register() { - if (VERIFIED.isNot(emailStatus)) { + if (emailStatus.isNotVerified()) { throw new UnAuthorizedEmailException(); } this.registered = true; @@ -113,7 +114,7 @@ public void register() { public void validateReVerified() { validateSignUpEmail(); - if (RE_VERIFIED.isNot(emailStatus)) { + if (emailStatus.isNotReverified()) { throw new UnAuthorizedEmailException(); } validateValidTime(); @@ -129,13 +130,13 @@ private void validateValidTime() { } private void validateNotSignUp() { - if (isRegistered()) { + if (registered) { throw new DuplicatedEmailException(); } } private void validateSignUpEmail() { - if (!isRegistered()) { + if (!registered) { throw new NotFoundMemberException(); } } diff --git a/src/main/java/idorm/idormServer/email/entity/EmailStatus.java b/src/main/java/idorm/idormServer/email/entity/EmailStatus.java index 0097f703..2fd3a2b1 100644 --- a/src/main/java/idorm/idormServer/email/entity/EmailStatus.java +++ b/src/main/java/idorm/idormServer/email/entity/EmailStatus.java @@ -1,12 +1,17 @@ package idorm.idormServer.email.entity; public enum EmailStatus { - SEND, - VERIFIED, - RE_SEND, - RE_VERIFIED; + SEND, + VERIFIED, + RE_SEND, + RE_VERIFIED, + DELETED; - public boolean isNot(EmailStatus emailStatus) { - return !this.equals(emailStatus); - } + public boolean isNotVerified() { + return !this.equals(VERIFIED); + } + + public boolean isNotReverified() { + return !this.equals(RE_VERIFIED); + } } From c352da01974766421bd8dfd7aebfc73d17b91c82 Mon Sep 17 00:00:00 2001 From: nahyeon99 Date: Mon, 6 May 2024 05:00:09 +0900 Subject: [PATCH 02/12] =?UTF-8?q?feat:=20matchingInfo=20=ED=83=88=ED=87=B4?= =?UTF-8?q?=20=EC=8B=9C=20=ED=95=98=EB=93=9C=20=EB=94=9C=EB=A6=AC=ED=8A=B8?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/DeleteMatchingInfoAdapter.java | 18 ++++++++++++++++++ .../persistence/MatchingInfoRepository.java | 4 ++++ .../port/out/DeleteMatchingInfoPort.java | 6 ++++++ 3 files changed, 28 insertions(+) create mode 100644 src/main/java/idorm/idormServer/matchingInfo/adapter/out/persistence/DeleteMatchingInfoAdapter.java create mode 100644 src/main/java/idorm/idormServer/matchingInfo/application/port/out/DeleteMatchingInfoPort.java diff --git a/src/main/java/idorm/idormServer/matchingInfo/adapter/out/persistence/DeleteMatchingInfoAdapter.java b/src/main/java/idorm/idormServer/matchingInfo/adapter/out/persistence/DeleteMatchingInfoAdapter.java new file mode 100644 index 00000000..2a6594d0 --- /dev/null +++ b/src/main/java/idorm/idormServer/matchingInfo/adapter/out/persistence/DeleteMatchingInfoAdapter.java @@ -0,0 +1,18 @@ +package idorm.idormServer.matchingInfo.adapter.out.persistence; + +import org.springframework.stereotype.Component; + +import idorm.idormServer.matchingInfo.application.port.out.DeleteMatchingInfoPort; +import lombok.RequiredArgsConstructor; + +@Component +@RequiredArgsConstructor +public class DeleteMatchingInfoAdapter implements DeleteMatchingInfoPort { + + private final MatchingInfoRepository matchingInfoRepository; + + @Override + public void delete(Long matchingInfoId) { + matchingInfoRepository.deleteById(matchingInfoId); + } +} diff --git a/src/main/java/idorm/idormServer/matchingInfo/adapter/out/persistence/MatchingInfoRepository.java b/src/main/java/idorm/idormServer/matchingInfo/adapter/out/persistence/MatchingInfoRepository.java index 6613930d..9f5b1b74 100644 --- a/src/main/java/idorm/idormServer/matchingInfo/adapter/out/persistence/MatchingInfoRepository.java +++ b/src/main/java/idorm/idormServer/matchingInfo/adapter/out/persistence/MatchingInfoRepository.java @@ -3,6 +3,7 @@ import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Repository; import idorm.idormServer.matchingInfo.entity.MatchingInfo; @@ -13,4 +14,7 @@ public interface MatchingInfoRepository extends JpaRepository findByMemberId(Long memberId); boolean existsByMemberId(Long memberId); + + @Modifying + void deleteById(Long matchingInfoId); } \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/matchingInfo/application/port/out/DeleteMatchingInfoPort.java b/src/main/java/idorm/idormServer/matchingInfo/application/port/out/DeleteMatchingInfoPort.java new file mode 100644 index 00000000..819990cf --- /dev/null +++ b/src/main/java/idorm/idormServer/matchingInfo/application/port/out/DeleteMatchingInfoPort.java @@ -0,0 +1,6 @@ +package idorm.idormServer.matchingInfo.application.port.out; + +public interface DeleteMatchingInfoPort { + + void delete(Long matchingInfoId); +} \ No newline at end of file From 583694c99187855ba51fe033517486e1c9779fdc Mon Sep 17 00:00:00 2001 From: nahyeon99 Date: Mon, 6 May 2024 05:02:09 +0900 Subject: [PATCH 03/12] =?UTF-8?q?feat:=20matchingMate=20=ED=83=88=ED=87=B4?= =?UTF-8?q?=20=EC=8B=9C=20=ED=95=98=EB=93=9C=20=EB=94=9C=EB=A6=AC=ED=8A=B8?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeleteMatchingMateAdapter.java | 20 +++++++++++++++++++ .../persistence/MatchingMateRepository.java | 7 +++++++ .../port/out/DeleteMatchingMatePort.java | 8 ++++++++ .../matchingMate/entity/MatchingMate.java | 16 --------------- 4 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 src/main/java/idorm/idormServer/matchingMate/adapter/out/persistence/DeleteMatchingMateAdapter.java create mode 100644 src/main/java/idorm/idormServer/matchingMate/application/port/out/DeleteMatchingMatePort.java diff --git a/src/main/java/idorm/idormServer/matchingMate/adapter/out/persistence/DeleteMatchingMateAdapter.java b/src/main/java/idorm/idormServer/matchingMate/adapter/out/persistence/DeleteMatchingMateAdapter.java new file mode 100644 index 00000000..f13561dd --- /dev/null +++ b/src/main/java/idorm/idormServer/matchingMate/adapter/out/persistence/DeleteMatchingMateAdapter.java @@ -0,0 +1,20 @@ +package idorm.idormServer.matchingMate.adapter.out.persistence; + +import org.springframework.stereotype.Component; + +import idorm.idormServer.matchingMate.application.port.out.DeleteMatchingMatePort; +import idorm.idormServer.member.entity.Member; +import lombok.RequiredArgsConstructor; + +@Component +@RequiredArgsConstructor +public class DeleteMatchingMateAdapter implements DeleteMatchingMatePort { + + private final MatchingMateRepository matchingMateRepository; + + @Override + public void deleteByMemberWithdrawn(Member deletedMember) { + matchingMateRepository.deleteAllByMatchingInfoForTargetId(deletedMember.getMatchingInfo().getId()); + matchingMateRepository.deleteAllByOwnerId(deletedMember.getId()); + } +} \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/matchingMate/adapter/out/persistence/MatchingMateRepository.java b/src/main/java/idorm/idormServer/matchingMate/adapter/out/persistence/MatchingMateRepository.java index a98eece0..ca7799ce 100644 --- a/src/main/java/idorm/idormServer/matchingMate/adapter/out/persistence/MatchingMateRepository.java +++ b/src/main/java/idorm/idormServer/matchingMate/adapter/out/persistence/MatchingMateRepository.java @@ -1,10 +1,17 @@ package idorm.idormServer.matchingMate.adapter.out.persistence; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Repository; import idorm.idormServer.matchingMate.entity.MatchingMate; @Repository public interface MatchingMateRepository extends JpaRepository { + + @Modifying + void deleteAllByMatchingInfoForTargetId(Long matchingInfoId); + + @Modifying + void deleteAllByOwnerId(Long memberId); } diff --git a/src/main/java/idorm/idormServer/matchingMate/application/port/out/DeleteMatchingMatePort.java b/src/main/java/idorm/idormServer/matchingMate/application/port/out/DeleteMatchingMatePort.java new file mode 100644 index 00000000..6b85d583 --- /dev/null +++ b/src/main/java/idorm/idormServer/matchingMate/application/port/out/DeleteMatchingMatePort.java @@ -0,0 +1,8 @@ +package idorm.idormServer.matchingMate.application.port.out; + +import idorm.idormServer.member.entity.Member; + +public interface DeleteMatchingMatePort { + + void deleteByMemberWithdrawn(Member member); +} \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/matchingMate/entity/MatchingMate.java b/src/main/java/idorm/idormServer/matchingMate/entity/MatchingMate.java index 1b93c3ab..16d62e0a 100644 --- a/src/main/java/idorm/idormServer/matchingMate/entity/MatchingMate.java +++ b/src/main/java/idorm/idormServer/matchingMate/entity/MatchingMate.java @@ -66,22 +66,6 @@ private void validateConstructor(final Member member, final MatchingInfo matchin } - public boolean isPublic() { - return matchingInfoForTarget.getIsPublic(); - } - - public boolean isFavorite() { - return preferenceType.equals(MatePreferenceType.FAVORITE); - } - - public boolean isNonFavorite() { - return preferenceType.equals(MatePreferenceType.NONFAVORITE); - } - - public boolean isNonFavorite(final MatchingInfo matchingInfo) { - return this.matchingInfoForTarget.equals(matchingInfo) && isNonFavorite(); - } - @Override public boolean equals(Object object) { if (this == object) From c97368ab3c8dc0d024f3523adbbce047d9612cd9 Mon Sep 17 00:00:00 2001 From: nahyeon99 Date: Mon, 6 May 2024 05:04:55 +0900 Subject: [PATCH 04/12] =?UTF-8?q?style:=20calendar=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=BD=94=EB=93=9C=20=EC=A0=95=EB=A6=AC=20=EB=B0=8F?= =?UTF-8?q?=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/DeleteTeamCalendarAdapter.java | 4 ++-- .../TeamCalendarCustomRepositoryImpl.java | 17 ++++++++--------- .../persistence/TeamCustomRepositoryImpl.java | 2 +- .../application/TeamCalendarService.java | 15 +++++++-------- .../application/port/in/dto/TeamResponse.java | 4 +--- .../idorm/idormServer/calendar/entity/Team.java | 16 +++++++--------- .../calendar/entity/TeamCalendar.java | 6 ------ .../idormServer/calendar/entity/TeamStatus.java | 11 ++++++----- 8 files changed, 32 insertions(+), 43 deletions(-) diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamCalendarAdapter.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamCalendarAdapter.java index 3b30ff99..e2d8e60e 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamCalendarAdapter.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamCalendarAdapter.java @@ -1,12 +1,12 @@ package idorm.idormServer.calendar.adapter.out.persistence; +import org.springframework.stereotype.Component; + import idorm.idormServer.calendar.application.port.out.DeleteTeamCalendarPort; import idorm.idormServer.calendar.entity.TeamCalendar; import lombok.AccessLevel; import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; - @Component @RequiredArgsConstructor(access = AccessLevel.PROTECTED) public class DeleteTeamCalendarAdapter implements DeleteTeamCalendarPort { diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCalendarCustomRepositoryImpl.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCalendarCustomRepositoryImpl.java index 403f084d..2a3cd6cd 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCalendarCustomRepositoryImpl.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCalendarCustomRepositoryImpl.java @@ -1,9 +1,13 @@ package idorm.idormServer.calendar.adapter.out.persistence; -import static idorm.idormServer.calendar.entity.QParticipant.participant; -import static idorm.idormServer.calendar.entity.QTeam.team; -import static idorm.idormServer.calendar.entity.QTeamCalendar.teamCalendar; -import static idorm.idormServer.notification.entity.QFcmToken.fcmToken; +import static idorm.idormServer.calendar.entity.QParticipant.*; +import static idorm.idormServer.calendar.entity.QTeam.*; +import static idorm.idormServer.calendar.entity.QTeamCalendar.*; +import static idorm.idormServer.notification.entity.QFcmToken.*; + +import java.time.LocalDate; +import java.time.YearMonth; +import java.util.List; import com.querydsl.core.Tuple; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -12,11 +16,6 @@ import idorm.idormServer.calendar.entity.TeamCalendar; import idorm.idormServer.notification.adapter.out.api.NotificationRequest; import idorm.idormServer.notification.entity.FcmChannel; - -import java.time.LocalDate; -import java.time.YearMonth; -import java.util.List; - import lombok.RequiredArgsConstructor; @RequiredArgsConstructor diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCustomRepositoryImpl.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCustomRepositoryImpl.java index 81419d11..a0cc9c0e 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCustomRepositoryImpl.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCustomRepositoryImpl.java @@ -11,7 +11,7 @@ @RequiredArgsConstructor public class TeamCustomRepositoryImpl implements TeamCustomRepository { - JPAQueryFactory queryFactory; + private final JPAQueryFactory queryFactory; @Override public Team findByMemberId(final Long memberId) { diff --git a/src/main/java/idorm/idormServer/calendar/application/TeamCalendarService.java b/src/main/java/idorm/idormServer/calendar/application/TeamCalendarService.java index 5a194e8a..57ab3ef3 100644 --- a/src/main/java/idorm/idormServer/calendar/application/TeamCalendarService.java +++ b/src/main/java/idorm/idormServer/calendar/application/TeamCalendarService.java @@ -1,5 +1,12 @@ package idorm.idormServer.calendar.application; +import java.util.Comparator; +import java.util.List; +import java.util.stream.IntStream; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + import idorm.idormServer.auth.application.port.in.dto.AuthResponse; import idorm.idormServer.calendar.application.port.in.TeamCalendarUseCase; import idorm.idormServer.calendar.application.port.in.dto.FindOfficialCalendarsRequest; @@ -16,16 +23,8 @@ import idorm.idormServer.calendar.entity.TeamCalendar; import idorm.idormServer.member.application.port.out.LoadMemberPort; import idorm.idormServer.member.entity.Member; - -import java.util.Comparator; -import java.util.List; -import java.util.stream.IntStream; - import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - @Service @Transactional(readOnly = true) @RequiredArgsConstructor diff --git a/src/main/java/idorm/idormServer/calendar/application/port/in/dto/TeamResponse.java b/src/main/java/idorm/idormServer/calendar/application/port/in/dto/TeamResponse.java index 7a4ded4a..413737a7 100644 --- a/src/main/java/idorm/idormServer/calendar/application/port/in/dto/TeamResponse.java +++ b/src/main/java/idorm/idormServer/calendar/application/port/in/dto/TeamResponse.java @@ -3,17 +3,15 @@ import java.util.List; import idorm.idormServer.calendar.entity.Team; -import idorm.idormServer.calendar.entity.TeamStatus; public record TeamResponse( Long teamId, boolean isNeedToConfirmDeleted, List members ) { - public static TeamResponse of(final Team team, final List responses) { return new TeamResponse(team.getId(), - TeamStatus.isAlone(team.getTeamStatus()), + team.getTeamStatus().isAlone(), responses); } } \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/calendar/entity/Team.java b/src/main/java/idorm/idormServer/calendar/entity/Team.java index ebe2ba64..e5f43204 100644 --- a/src/main/java/idorm/idormServer/calendar/entity/Team.java +++ b/src/main/java/idorm/idormServer/calendar/entity/Team.java @@ -1,12 +1,5 @@ package idorm.idormServer.calendar.entity; -import idorm.idormServer.calendar.adapter.out.exception.CannotExplodeTeamException; -import idorm.idormServer.calendar.adapter.out.exception.CannotRegisterTeamStatusFullException; -import idorm.idormServer.calendar.adapter.out.exception.NotFoundTeamMemberException; -import idorm.idormServer.common.entity.BaseTimeEntity; -import idorm.idormServer.calendar.adapter.out.exception.DuplicatedMemberException; -import idorm.idormServer.member.entity.Member; - import java.util.ArrayList; import java.util.List; @@ -20,6 +13,12 @@ import javax.persistence.Id; import javax.persistence.OneToMany; +import idorm.idormServer.calendar.adapter.out.exception.CannotExplodeTeamException; +import idorm.idormServer.calendar.adapter.out.exception.CannotRegisterTeamStatusFullException; +import idorm.idormServer.calendar.adapter.out.exception.DuplicatedMemberException; +import idorm.idormServer.calendar.adapter.out.exception.NotFoundTeamMemberException; +import idorm.idormServer.common.entity.BaseTimeEntity; +import idorm.idormServer.member.entity.Member; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -72,9 +71,8 @@ public void deleteMember(Member member) { } public void delete(Member member) { - if (TeamStatus.isNotAlone(this.teamStatus)) { + if (teamStatus.isNotAlone()) throw new CannotExplodeTeamException(); - } member.removeTeam(); } diff --git a/src/main/java/idorm/idormServer/calendar/entity/TeamCalendar.java b/src/main/java/idorm/idormServer/calendar/entity/TeamCalendar.java index d64f95fd..aadbdb41 100644 --- a/src/main/java/idorm/idormServer/calendar/entity/TeamCalendar.java +++ b/src/main/java/idorm/idormServer/calendar/entity/TeamCalendar.java @@ -107,12 +107,6 @@ public List getParticipants() { return participants.getParticipants(); } - public List getParticipantMemberIds() { - return participants.getParticipants().stream() - .map(Participant::getMemberId) - .toList(); - } - private void validateAuthorization(final Team team) { if (!this.team.equals(team)) { throw new AccessDeniedTeamCalendarException(); diff --git a/src/main/java/idorm/idormServer/calendar/entity/TeamStatus.java b/src/main/java/idorm/idormServer/calendar/entity/TeamStatus.java index ca84cf76..561d2698 100644 --- a/src/main/java/idorm/idormServer/calendar/entity/TeamStatus.java +++ b/src/main/java/idorm/idormServer/calendar/entity/TeamStatus.java @@ -2,13 +2,14 @@ public enum TeamStatus { ACTIVE, - ALONE; + ALONE, + DELETED; - public static boolean isNotAlone(TeamStatus teamStatus) { - return !teamStatus.equals(ALONE); + public boolean isNotAlone() { + return !this.equals(ALONE); } - public static boolean isAlone(TeamStatus teamStatus) { - return teamStatus.equals(ALONE); + public boolean isAlone() { + return this.equals(ALONE); } } \ No newline at end of file From 5e5e0a6a24beecaae55f91a4e226665fb2ce98c1 Mon Sep 17 00:00:00 2001 From: nahyeon99 Date: Mon, 6 May 2024 05:05:36 +0900 Subject: [PATCH 05/12] =?UTF-8?q?feature:=20sleepoverCalendar=20=ED=83=88?= =?UTF-8?q?=ED=87=B4=20=EC=9A=A9=EB=8F=84=20=ED=95=98=EB=93=9C=20=EB=94=9C?= =?UTF-8?q?=EB=A6=AC=ED=8A=B8=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../out/persistence/DeleteSleepoverCalendarAdapter.java | 5 +++++ .../adapter/out/persistence/SleepoverCalendarRepository.java | 4 ++++ .../application/port/out/DeleteSleepoverCalendarPort.java | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteSleepoverCalendarAdapter.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteSleepoverCalendarAdapter.java index a249164b..f67373d5 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteSleepoverCalendarAdapter.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteSleepoverCalendarAdapter.java @@ -17,4 +17,9 @@ public class DeleteSleepoverCalendarAdapter implements DeleteSleepoverCalendarPo public void delete(SleepoverCalendar sleepoverCalendar) { sleepoverCalendarRepository.delete(sleepoverCalendar); } + + @Override + public void deleteByMemberId(Long memberId) { + sleepoverCalendarRepository.deleteByMemberId(memberId); + } } \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/SleepoverCalendarRepository.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/SleepoverCalendarRepository.java index 7fc8c7fa..2f8c97ec 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/SleepoverCalendarRepository.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/SleepoverCalendarRepository.java @@ -5,6 +5,7 @@ import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Repository; @Repository @@ -12,4 +13,7 @@ public interface SleepoverCalendarRepository extends JpaRepository, SleepoverCalendarCustomRepository { List findByMemberId(Long memberId); + + @Modifying + void deleteByMemberId(Long memberId); } \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/calendar/application/port/out/DeleteSleepoverCalendarPort.java b/src/main/java/idorm/idormServer/calendar/application/port/out/DeleteSleepoverCalendarPort.java index 90b098be..065496f8 100644 --- a/src/main/java/idorm/idormServer/calendar/application/port/out/DeleteSleepoverCalendarPort.java +++ b/src/main/java/idorm/idormServer/calendar/application/port/out/DeleteSleepoverCalendarPort.java @@ -5,4 +5,6 @@ public interface DeleteSleepoverCalendarPort { void delete(SleepoverCalendar sleepoverCalendar); + + void deleteByMemberId(Long memberId); } \ No newline at end of file From c315923d56271710e016f7befbafb4d732f8275a Mon Sep 17 00:00:00 2001 From: nahyeon99 Date: Mon, 6 May 2024 05:08:37 +0900 Subject: [PATCH 06/12] =?UTF-8?q?feature:=20member=20=ED=83=88=ED=87=B4=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=9D=BC=EB=B6=80=20=EA=B5=AC=ED=98=84(?= =?UTF-8?q?=ED=8C=80=20=EB=82=B4=20=ED=8C=80=EC=9B=90=20=EC=A0=9C=EA=B1=B0?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=20=EA=B5=AC=ED=98=84=20=ED=95=84=EC=9A=94?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../out/persistence/LoadMemberAdapter.java | 84 ++++++++--------- .../out/persistence/WithdrawAdapter.java | 89 +++++++++++++++++++ .../persistence/WithdrawMemberAdaptor.java | 20 ----- .../member/application/MemberService.java | 22 ++--- .../application/port/out/LoadMemberPort.java | 1 + .../port/out/WithdrawMemberPort.java | 8 -- .../application/port/out/WithdrawPort.java | 9 ++ .../idormServer/member/entity/Member.java | 36 ++------ .../idormServer/member/entity/Nickname.java | 4 + .../idormServer/member/entity/Password.java | 4 + 10 files changed, 162 insertions(+), 115 deletions(-) create mode 100644 src/main/java/idorm/idormServer/member/adapter/out/persistence/WithdrawAdapter.java delete mode 100644 src/main/java/idorm/idormServer/member/adapter/out/persistence/WithdrawMemberAdaptor.java delete mode 100644 src/main/java/idorm/idormServer/member/application/port/out/WithdrawMemberPort.java create mode 100644 src/main/java/idorm/idormServer/member/application/port/out/WithdrawPort.java diff --git a/src/main/java/idorm/idormServer/member/adapter/out/persistence/LoadMemberAdapter.java b/src/main/java/idorm/idormServer/member/adapter/out/persistence/LoadMemberAdapter.java index 6ab3c326..c2c5b567 100644 --- a/src/main/java/idorm/idormServer/member/adapter/out/persistence/LoadMemberAdapter.java +++ b/src/main/java/idorm/idormServer/member/adapter/out/persistence/LoadMemberAdapter.java @@ -1,5 +1,7 @@ package idorm.idormServer.member.adapter.out.persistence; +import org.springframework.stereotype.Component; + import idorm.idormServer.auth.adapter.out.exception.LoginFailedException; import idorm.idormServer.email.adapter.out.exception.DuplicatedEmailException; import idorm.idormServer.member.adapter.out.exception.DuplicatedNicknameException; @@ -8,50 +10,50 @@ import idorm.idormServer.member.entity.Member; import idorm.idormServer.member.entity.MemberStatus; import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; @Component @RequiredArgsConstructor public class LoadMemberAdapter implements LoadMemberPort { - private final MemberRepository memberRepository; - - @Override - public Member loadMember(final Long memberId) { - return memberRepository.findByIdAndMemberStatus(memberId, MemberStatus.ACTIVE) - .orElseThrow(NotFoundMemberException::new); - } - - @Override - public Member loadMember(final String email, final String password) { - return memberRepository.findByEmailAndPasswordValueAndMemberStatus(email, password, MemberStatus.ACTIVE) - .orElseThrow(LoginFailedException::new); - } - - @Override - public Member loadMember(final String email) { - return memberRepository.findByEmailAndMemberStatus(email, MemberStatus.ACTIVE) - .orElseThrow(NotFoundMemberException::new); - } - - @Override - public Member loadMemberWithOptional(final Long memberId) { - return memberRepository.findByIdAndMemberStatus(memberId, MemberStatus.ACTIVE).orElse(null); - } - - @Override - public void validateUniqueNickname(final String nickname) { - boolean exists = memberRepository.existsByNicknameValueAndMemberStatus(nickname, MemberStatus.ACTIVE); - if (exists) { - throw new DuplicatedNicknameException(); - } - } - - @Override - public void validateUniqueEmail(final String email) { - boolean exists = memberRepository.existsByEmailAndMemberStatus(email, MemberStatus.ACTIVE); - if (exists) { - throw new DuplicatedEmailException(); - } - } + private final MemberRepository memberRepository; + + @Override + public Member loadMember(final Long memberId) { + return memberRepository.findByIdAndMemberStatus(memberId, MemberStatus.ACTIVE) + .orElseThrow(NotFoundMemberException::new); + } + + @Override + public Member loadMember(final String email, final String password) { + return memberRepository.findByEmailAndPasswordValueAndMemberStatus(email, password, MemberStatus.ACTIVE) + .orElseThrow(LoginFailedException::new); + } + + @Override + public Member loadMember(final String email) { + return memberRepository.findByEmailAndMemberStatus(email, MemberStatus.ACTIVE) + .orElseThrow(NotFoundMemberException::new); + } + + @Override + public Member loadMemberWithOptional(final Long memberId) { + return memberRepository.findByIdAndMemberStatus(memberId, MemberStatus.ACTIVE) + .orElse(null); + } + + @Override + public void validateUniqueNickname(final String nickname) { + boolean exists = memberRepository.existsByNicknameValueAndMemberStatus(nickname, MemberStatus.ACTIVE); + if (exists) { + throw new DuplicatedNicknameException(); + } + } + + @Override + public void validateUniqueEmail(final String email) { + boolean exists = memberRepository.existsByEmailAndMemberStatus(email, MemberStatus.ACTIVE); + if (exists) { + throw new DuplicatedEmailException(); + } + } } \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/member/adapter/out/persistence/WithdrawAdapter.java b/src/main/java/idorm/idormServer/member/adapter/out/persistence/WithdrawAdapter.java new file mode 100644 index 00000000..ac25d725 --- /dev/null +++ b/src/main/java/idorm/idormServer/member/adapter/out/persistence/WithdrawAdapter.java @@ -0,0 +1,89 @@ +package idorm.idormServer.member.adapter.out.persistence; + +import java.util.Objects; + +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; + +import idorm.idormServer.auth.application.port.out.DeleteRefreshTokenPort; +import idorm.idormServer.calendar.application.port.out.DeleteSleepoverCalendarPort; +import idorm.idormServer.calendar.entity.Team; +import idorm.idormServer.email.application.port.out.DeleteEmailPort; +import idorm.idormServer.email.entity.Email; +import idorm.idormServer.matchingInfo.application.port.out.DeleteMatchingInfoPort; +import idorm.idormServer.matchingMate.application.port.out.DeleteMatchingMatePort; +import idorm.idormServer.member.application.port.out.WithdrawPort; +import idorm.idormServer.member.entity.Member; +import idorm.idormServer.notification.application.port.out.DeleteFcmTokenPort; +import idorm.idormServer.photo.application.port.out.DeleteFilePort; +import lombok.RequiredArgsConstructor; + +@Component +@RequiredArgsConstructor +public class WithdrawAdapter implements WithdrawPort { + + private final DeleteEmailPort deleteEmailPort; + private final DeleteFilePort deleteFilePort; + private final DeleteRefreshTokenPort deleteRefreshTokenPort; + private final DeleteFcmTokenPort deleteFcmTokenPort; + private final DeleteMatchingMatePort deleteMatchingMatePort; + private final DeleteMatchingInfoPort deleteMatchingInfoPort; + private final DeleteSleepoverCalendarPort deleteSleepoverCalendarPort; + + @Override + public void withdraw(Member member, Email email) { + deleteRefreshTokenPort.deleteAll(member.getId()); + deleteEmailPort.delete(email); + deleteFcmTokenPort.deleteAll(member.getId()); + deleteMatchingMatePort.deleteByMemberWithdrawn(member); + deleteMatchingInfoPort.delete(member.getMatchingInfo().getId()); + + if (StringUtils.hasLength(member.getProfilePhotoUrl())) { + deleteFilePort.deleteMemberPhotoFile(member.getProfilePhotoUrl()); + } + + /** + * TODO: Team 내 Member 제거 시나리오 + * + * 1. 팀이 존재하지 않는 경우 + * : 바로 반환 + * + * 2. 팀이 존재하는 경우 + * a) 탈퇴 회원이 마지막 회원인 경우 (Team.team_status == ALONE) + * 0. [a, b, c 공통] SleepoverCalendar : 모든 외박캘린더 삭제 + * 1. TeamCalendar : 모든 TeamCalendar 삭제 + * - Participant : 각 TeamCalendar를 가진 모든 Participant 삭제 + * 2. Team : TeamStatus == DELETED 변경 + * + * b) 탈퇴 회원 삭제 시 한명만 팀에 남는 경우 + * 0. [a, b, c 공통] SleepoverCalendar : 모든 외박캘린더 삭제 + * 1. [b, c 공통] Participant : 탈퇴 회원을 가진 모든 Participant 삭제 + * 2. [b, c 공통] TeamCalendar : Participant가 하나도 없는 경우 삭제 + * 3. Team : TeamStatus == ALONE 변경 + * + * c) 탈퇴 회원 삭제 후 두 명 이상 팀에 있는 경우 + * 0. [a, b, c 공통] SleepoverCalendar : 모든 외박캘린더 삭제 + * 1. [b, c 공통] Participant : 탈퇴 회원을 가진 Participant 삭제 + * 2. [b, c 공통] TeamCalendar : Participant가 하나도 없는 경우 삭제 + * 3. Team : TeamStatus == ACTIVE 유지 + */ + if (Objects.isNull(member.getTeam())) { + // no-op + } else { + deleteSleepoverCalendarPort.deleteByMemberId(member.getId()); + + if (member.getTeam().getTeamStatus().isAlone()) { + explodeTeam(member.getTeam()); + } + + // TODO -CASE 1: 탈퇴 회원 삭제 시 한 명만 남는 경우 + // TODO -CASE 2: 탈퇴 회원 삭제 시 두 명 이상 남는 경우 + } + + member.withdraw(); + } + + private void explodeTeam(Team team) { + // TODO: + } +} diff --git a/src/main/java/idorm/idormServer/member/adapter/out/persistence/WithdrawMemberAdaptor.java b/src/main/java/idorm/idormServer/member/adapter/out/persistence/WithdrawMemberAdaptor.java deleted file mode 100644 index 6af681f2..00000000 --- a/src/main/java/idorm/idormServer/member/adapter/out/persistence/WithdrawMemberAdaptor.java +++ /dev/null @@ -1,20 +0,0 @@ -package idorm.idormServer.member.adapter.out.persistence; - -import org.springframework.stereotype.Component; - -import idorm.idormServer.member.application.port.out.WithdrawMemberPort; -import idorm.idormServer.member.entity.Member; -import lombok.RequiredArgsConstructor; - -@Component -@RequiredArgsConstructor -public class WithdrawMemberAdaptor implements WithdrawMemberPort { - - private final MemberRepository memberRepository; - - @Override - public void withdraw(final Member member) { - memberRepository.delete(member); - member.withdraw(); - } -} diff --git a/src/main/java/idorm/idormServer/member/application/MemberService.java b/src/main/java/idorm/idormServer/member/application/MemberService.java index 287ba01c..955a3747 100644 --- a/src/main/java/idorm/idormServer/member/application/MemberService.java +++ b/src/main/java/idorm/idormServer/member/application/MemberService.java @@ -1,12 +1,12 @@ package idorm.idormServer.member.application; +import static idorm.idormServer.member.application.port.in.dto.MemberInfoResponse.*; + import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import idorm.idormServer.auth.application.port.in.dto.AuthResponse; -import idorm.idormServer.auth.application.port.out.DeleteRefreshTokenPort; import idorm.idormServer.auth.application.port.out.EncryptPort; -import idorm.idormServer.email.application.port.out.DeleteEmailPort; import idorm.idormServer.email.application.port.out.LoadEmailPort; import idorm.idormServer.email.entity.Email; import idorm.idormServer.member.application.port.in.MemberUseCase; @@ -16,7 +16,7 @@ import idorm.idormServer.member.application.port.in.dto.SignupRequest; import idorm.idormServer.member.application.port.out.LoadMemberPort; import idorm.idormServer.member.application.port.out.SaveMemberPort; -import idorm.idormServer.member.application.port.out.WithdrawMemberPort; +import idorm.idormServer.member.application.port.out.WithdrawPort; import idorm.idormServer.member.entity.Member; import lombok.RequiredArgsConstructor; @@ -27,18 +27,15 @@ public class MemberService implements MemberUseCase { private final EncryptPort encryptPort; private final LoadEmailPort loadEmailPort; - private final DeleteEmailPort deleteEmailPort; private final SaveMemberPort saveMemberPort; private final LoadMemberPort loadMemberPort; - private final WithdrawMemberPort withdrawMemberPort; - - private final DeleteRefreshTokenPort deleteRefreshTokenPort; + private final WithdrawPort withdrawPort; @Override @Transactional public void signUp(final SignupRequest request) { - Email email = loadEmailPort.findByEmail(request.email()); + final Email email = loadEmailPort.findByEmail(request.email()); loadMemberPort.validateUniqueEmail(request.email()); loadMemberPort.validateUniqueNickname(request.nickname()); @@ -51,7 +48,7 @@ public void signUp(final SignupRequest request) { @Override public MemberInfoResponse getInfo(final AuthResponse auth) { Member member = loadMemberPort.loadMember(auth.getId()); - return MemberInfoResponse.of(member); + return of(member); } @Override @@ -77,13 +74,8 @@ public void editPassword(final PasswordUpdateRequest request) { @Transactional public void withdraw(final AuthResponse authResponse) { Member deleteMember = loadMemberPort.loadMember(authResponse.getId()); - deleteRefreshTokenPort.deleteAll(authResponse.getId()); - Email deleteEmail = loadEmailPort.findByEmail(deleteMember.getEmail()); - deleteEmailPort.delete(deleteEmail); - - // TODO : 타 도메인 삭제 처리 - withdrawMemberPort.withdraw(deleteMember); + withdrawPort.withdraw(deleteMember, deleteEmail); } } \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/member/application/port/out/LoadMemberPort.java b/src/main/java/idorm/idormServer/member/application/port/out/LoadMemberPort.java index 4b79f38c..e9fc064c 100644 --- a/src/main/java/idorm/idormServer/member/application/port/out/LoadMemberPort.java +++ b/src/main/java/idorm/idormServer/member/application/port/out/LoadMemberPort.java @@ -9,6 +9,7 @@ public interface LoadMemberPort { Member loadMember(String email, String password); Member loadMember(String email); + Member loadMemberWithOptional(Long memberId); void validateUniqueNickname(String nickname); diff --git a/src/main/java/idorm/idormServer/member/application/port/out/WithdrawMemberPort.java b/src/main/java/idorm/idormServer/member/application/port/out/WithdrawMemberPort.java deleted file mode 100644 index 3b86acd9..00000000 --- a/src/main/java/idorm/idormServer/member/application/port/out/WithdrawMemberPort.java +++ /dev/null @@ -1,8 +0,0 @@ -package idorm.idormServer.member.application.port.out; - -import idorm.idormServer.member.entity.Member; - -public interface WithdrawMemberPort { - - void withdraw(Member member); -} \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/member/application/port/out/WithdrawPort.java b/src/main/java/idorm/idormServer/member/application/port/out/WithdrawPort.java new file mode 100644 index 00000000..1a5c4ce6 --- /dev/null +++ b/src/main/java/idorm/idormServer/member/application/port/out/WithdrawPort.java @@ -0,0 +1,9 @@ +package idorm.idormServer.member.application.port.out; + +import idorm.idormServer.email.entity.Email; +import idorm.idormServer.member.entity.Member; + +public interface WithdrawPort { + + void withdraw(Member member, Email email); +} \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/member/entity/Member.java b/src/main/java/idorm/idormServer/member/entity/Member.java index 3a60ac21..1ad99409 100644 --- a/src/main/java/idorm/idormServer/member/entity/Member.java +++ b/src/main/java/idorm/idormServer/member/entity/Member.java @@ -6,7 +6,6 @@ import java.util.List; import java.util.Objects; import java.util.Optional; -import java.util.stream.Collectors; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -141,37 +140,12 @@ public void deleteMemberPhoto() { public void withdraw() { memberStatus = MemberStatus.DELETED; - email = null; - nickname = null; - password = null; + nickname.delete(); + password.delete(); + email = ""; profilePhotoUrl = null; - roleType = null; - matchingMates = null; - team = null; - posts = null; - comments = null; - } - - public List getFavoriteMates() { - List results = this.matchingMates.stream() - .filter(MatchingMate::isPublic) - .filter(MatchingMate::isFavorite) - .collect(Collectors.toUnmodifiableList()); - return results; - } - - public List getNonFavoriteMates() { - List results = this.matchingMates.stream() - .filter(MatchingMate::isPublic) - .filter(MatchingMate::isNonFavorite) - .collect(Collectors.toUnmodifiableList()); - return results; - } - - public boolean isNotNonFavoriteMate(final MatchingInfo matchingInfo) { - boolean result = matchingMates.stream() - .anyMatch(mate -> mate.isNonFavorite(matchingInfo)); - return !result; + this.matchingInfo = null; + this.team = null; } public void addReport(final Report report) { diff --git a/src/main/java/idorm/idormServer/member/entity/Nickname.java b/src/main/java/idorm/idormServer/member/entity/Nickname.java index 7d13e7d9..a41a5b03 100644 --- a/src/main/java/idorm/idormServer/member/entity/Nickname.java +++ b/src/main/java/idorm/idormServer/member/entity/Nickname.java @@ -50,6 +50,10 @@ void update(final String newNickname) { this.value = newNickname; } + void delete() { + this.value = ""; + } + private void validateValidUpdate() { final LocalDateTime now = LocalDateTime.now(); if (now.isBefore(this.updatedAt.plusDays(VALID_UPDATE_DAY))) { diff --git a/src/main/java/idorm/idormServer/member/entity/Password.java b/src/main/java/idorm/idormServer/member/entity/Password.java index 75eaa83b..4e65b74c 100644 --- a/src/main/java/idorm/idormServer/member/entity/Password.java +++ b/src/main/java/idorm/idormServer/member/entity/Password.java @@ -34,6 +34,10 @@ void update(final EncryptPort encryptPort, final String newPassword) { this.value = encryptPort.encrypt(newPassword); } + void delete() { + this.value = ""; + } + private static void validateConstructor(final String value) { Validator.validateNotBlank(value); Validator.validateFormat(value, PASSWORD_REGEX, MemberResponseCode.INVALID_PASSWORD_CHARACTER); From 4af4b54786efd180af978b833f320994bf6312c9 Mon Sep 17 00:00:00 2001 From: nahyeon99 Date: Mon, 6 May 2024 05:14:12 +0900 Subject: [PATCH 07/12] =?UTF-8?q?fix:=20refresh=20=EC=8B=9C=20=EB=A7=8C?= =?UTF-8?q?=EB=A3=8C=EB=90=9C=20access=20token=EC=9D=84=20=EB=B0=9B?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EA=B5=AC=ED=98=84=20=ED=95=84=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/adapter/in/web/AuthController.java | 17 ++++++++++++++--- .../out/persistence/RefreshTokenRepository.java | 2 ++ .../idormServer/common/config/WebMvcConfig.java | 2 +- .../common/config/WebMvcLocalConfig.java | 2 +- .../idormServer/common/util/Validator.java | 6 ++++-- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/main/java/idorm/idormServer/auth/adapter/in/web/AuthController.java b/src/main/java/idorm/idormServer/auth/adapter/in/web/AuthController.java index e97794e9..1d4d8a50 100644 --- a/src/main/java/idorm/idormServer/auth/adapter/in/web/AuthController.java +++ b/src/main/java/idorm/idormServer/auth/adapter/in/web/AuthController.java @@ -69,8 +69,15 @@ public ResponseEntity> login( .body(SuccessResponse.from(AuthResponseCode.MEMBER_LOGIN)); } - @Operation(summary = "Access Token 재발급", security = {@SecurityRequirement(name = AUTHORIZATION), - @SecurityRequirement(name = "Refresh-Token")}) + @Auth + @Operation(summary = "Access Token 재발급", + description = "해당 API 사용법\n" + + "1. 원래 보내려던 요청을 보내기 전, access token의 payload를 통해 만료 기한을 얻습니다.\n" + + "2. 만료 기한이 지난 토큰이라면, 해당 API 요청을 보낸 후에 새로운 access token을 발급받습니다.\n" + + "3. 그 후에 원래 하려던 요청을 보내주세요.\n" + + "-> 목적 : 네트워크 요청 줄이기", + security = {@SecurityRequirement(name = AUTHORIZATION), + @SecurityRequirement(name = "Refresh-Token")}) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "MEMBER_REFRESH"), @ApiResponse(responseCode = "401", description = "UNAUTHORIZED_ACCESS_TOKEN / UNAUTHORIZED_REFRESH_TOKEN"), @@ -84,8 +91,11 @@ public ResponseEntity> refresh( @AuthInfo AuthResponse auth ) { validateExistHeader(servletRequest); + String accessToken = AuthorizationExtractor.extractAccessToken(servletRequest); String refreshToken = AuthorizationExtractor.extractRefreshToken(servletRequest); + // TODO: 만료된 access token도 받도록 처리해야 한다.(BUG) + refreshTokenUseCase.matches(refreshToken, auth.getId()); String reissueAccessToken = jwtTokenUseCase.createAccessToken(auth); @@ -114,9 +124,10 @@ public ResponseEntity> logout( } private void validateExistHeader(HttpServletRequest request) { + String accessTokenHeader = request.getHeader(AUTHORIZATION); String refreshTokenHeader = request.getHeader("Refresh-Token"); - if (Objects.isNull(refreshTokenHeader)) { + if (Objects.isNull(accessTokenHeader) || Objects.isNull(refreshTokenHeader)) { throw new UnAuthorizedRefreshTokenException(); } } diff --git a/src/main/java/idorm/idormServer/auth/adapter/out/persistence/RefreshTokenRepository.java b/src/main/java/idorm/idormServer/auth/adapter/out/persistence/RefreshTokenRepository.java index 8b5feee0..be9ae703 100644 --- a/src/main/java/idorm/idormServer/auth/adapter/out/persistence/RefreshTokenRepository.java +++ b/src/main/java/idorm/idormServer/auth/adapter/out/persistence/RefreshTokenRepository.java @@ -3,6 +3,7 @@ import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Repository; import idorm.idormServer.auth.entity.RefreshToken; @@ -12,5 +13,6 @@ public interface RefreshTokenRepository extends JpaRepository findByMemberId(Long memberId); + @Modifying void deleteAllByMemberId(Long memberId); } diff --git a/src/main/java/idorm/idormServer/common/config/WebMvcConfig.java b/src/main/java/idorm/idormServer/common/config/WebMvcConfig.java index e5ead9c6..55695f4b 100644 --- a/src/main/java/idorm/idormServer/common/config/WebMvcConfig.java +++ b/src/main/java/idorm/idormServer/common/config/WebMvcConfig.java @@ -27,7 +27,7 @@ public void addInterceptors(InterceptorRegistry registry) { .addPathPatterns("/**") .excludePathPatterns("/swagger-ui/**", "/swagger-resources/**", "/v3/api-docs/**") .excludePathPatterns("/api/v1/email/**") - .excludePathPatterns("/api/v1/signup", "/api/v1/signin", "/api/v1/refresh") + .excludePathPatterns("/api/v1/signup", "/api/v1/signin") .excludePathPatterns("/api/v1/members/me/password") .excludePathPatterns("/test/**"); } diff --git a/src/main/java/idorm/idormServer/common/config/WebMvcLocalConfig.java b/src/main/java/idorm/idormServer/common/config/WebMvcLocalConfig.java index 8b7e2d16..14e0cec2 100644 --- a/src/main/java/idorm/idormServer/common/config/WebMvcLocalConfig.java +++ b/src/main/java/idorm/idormServer/common/config/WebMvcLocalConfig.java @@ -30,7 +30,7 @@ public void addInterceptors(InterceptorRegistry registry) { .addPathPatterns("/**") .excludePathPatterns("/swagger-ui/**", "/swagger-resources/**", "/v3/api-docs/**") .excludePathPatterns("/api/v1/email/**") - .excludePathPatterns("/api/v1/signup", "/api/v1/signin", "/api/v1/refresh") + .excludePathPatterns("/api/v1/signup", "/api/v1/signin") .excludePathPatterns("/api/v1/members/me/password") .excludePathPatterns("/test/**"); diff --git a/src/main/java/idorm/idormServer/common/util/Validator.java b/src/main/java/idorm/idormServer/common/util/Validator.java index 9332aab8..46103339 100644 --- a/src/main/java/idorm/idormServer/common/util/Validator.java +++ b/src/main/java/idorm/idormServer/common/util/Validator.java @@ -4,6 +4,8 @@ import java.util.Objects; import java.util.regex.Pattern; +import org.springframework.util.StringUtils; + import idorm.idormServer.common.exception.BaseException; import idorm.idormServer.common.exception.BaseResponseCode; import idorm.idormServer.common.exception.FieldRequiredException; @@ -14,7 +16,7 @@ public final class Validator { public static void validateNotBlank(String value) { - if (value == null || value.isBlank()) { + if (!StringUtils.hasLength(value)) { throw new FieldRequiredException(); } } @@ -24,7 +26,7 @@ public static void validateNotBlank(List values) { } public static void validateNotNull(Object object) { - if (object == null) { + if (Objects.isNull(object)) { throw new FieldRequiredException(); } } From 1ee3df50063c46156a6ef26a21bd240e9a396460 Mon Sep 17 00:00:00 2001 From: shyeon4643 Date: Mon, 6 May 2024 22:16:36 +0900 Subject: [PATCH 08/12] =?UTF-8?q?[Feature]=20=EB=A9=A4=EB=B2=84=EA=B0=80?= =?UTF-8?q?=20=ED=8C=80=EC=97=90=EC=84=9C=20=EC=A0=9C=EA=B1=B0=EB=90=A0=20?= =?UTF-8?q?=EB=95=8C=20=EA=B4=80=EB=A0=A8=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/in/web/TeamController.java | 2 +- .../persistence/DeleteTeamMemberAdapter.java | 43 +++++++++++++++++++ .../out/persistence/LoadTeamAdapter.java | 11 +++-- .../persistence/LoadTeamCalendarAdapter.java | 15 +++---- .../TeamCalendarCustomRepositoryImpl.java | 4 +- .../application/TeamCalendarService.java | 4 +- .../calendar/application/TeamService.java | 26 ++++++----- .../application/port/in/TeamUseCase.java | 2 +- .../port/out/DeleteTeamMemberPort.java | 5 +++ .../idormServer/calendar/entity/Team.java | 2 + 10 files changed, 80 insertions(+), 34 deletions(-) create mode 100644 src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamMemberAdapter.java create mode 100644 src/main/java/idorm/idormServer/calendar/application/port/out/DeleteTeamMemberPort.java diff --git a/src/main/java/idorm/idormServer/calendar/adapter/in/web/TeamController.java b/src/main/java/idorm/idormServer/calendar/adapter/in/web/TeamController.java index c8dbb021..7ed4d333 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/in/web/TeamController.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/in/web/TeamController.java @@ -90,7 +90,7 @@ public ResponseEntity> deleteTeamMember( @Positive(message = "삭제할 회원 식별자는 양수만 가능합니다.") Long memberId ) { - teamUseCase.deleteMember(authResponse, memberId); + teamUseCase.deleteMember(memberId); return ResponseEntity.ok().body(SuccessResponse.from(TEAM_MEMBER_DELETED)); } diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamMemberAdapter.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamMemberAdapter.java new file mode 100644 index 00000000..620d256f --- /dev/null +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamMemberAdapter.java @@ -0,0 +1,43 @@ +package idorm.idormServer.calendar.adapter.out.persistence; + +import java.util.List; + +import org.springframework.stereotype.Component; + +import idorm.idormServer.calendar.application.port.out.DeleteSleepoverCalendarPort; +import idorm.idormServer.calendar.application.port.out.DeleteTeamMemberPort; +import idorm.idormServer.calendar.application.port.out.DeleteTeamPort; +import idorm.idormServer.calendar.application.port.out.LoadTeamCalendarPort; +import idorm.idormServer.calendar.application.port.out.LoadTeamPort; +import idorm.idormServer.calendar.entity.Team; +import idorm.idormServer.calendar.entity.TeamCalendar; +import idorm.idormServer.member.application.port.out.LoadMemberPort; +import idorm.idormServer.member.entity.Member; +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; + +@Component +@RequiredArgsConstructor(access = AccessLevel.PROTECTED) +public class DeleteTeamMemberAdapter implements DeleteTeamMemberPort { + + private final LoadMemberPort loadMemberPort; + private final LoadTeamPort loadTeamPort; + private final LoadTeamCalendarPort loadTeamCalendarPort; + private final DeleteSleepoverCalendarPort deleteSleepoverCalendarPort; + private final DeleteTeamPort deleteTeamPort; + + @Override + public void deleteTeamMember(Long memberId) { + final Member member = loadMemberPort.loadMember(memberId); + final Team team = loadTeamPort.findByMemberId(member.getId()); + final List teamCalendars = loadTeamCalendarPort.findByMemberId(member.getId()); + + deleteSleepoverCalendarPort.deleteByMemberId(memberId); + teamCalendars + .forEach(teamCalendar -> teamCalendar.deletePariticipant(member.getId())); + team.deleteMember(member); + if (team.getMembers().isEmpty()) { + deleteTeamPort.delete(team); + } + } +} diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/LoadTeamAdapter.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/LoadTeamAdapter.java index fc434645..fc712145 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/LoadTeamAdapter.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/LoadTeamAdapter.java @@ -1,15 +1,14 @@ package idorm.idormServer.calendar.adapter.out.persistence; +import java.util.Optional; + +import org.springframework.stereotype.Component; + import idorm.idormServer.calendar.adapter.out.exception.NotFoundTeamException; import idorm.idormServer.calendar.application.port.out.LoadTeamPort; import idorm.idormServer.calendar.entity.Team; - -import java.util.Optional; - import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; - @Component @RequiredArgsConstructor public class LoadTeamAdapter implements LoadTeamPort { @@ -24,7 +23,7 @@ public Optional findByMemberIdWithOptional(Long memberId) { @Override public Team findByMemberId(Long memberId) { - Team response = findByMemberId(memberId); + Team response = teamRepository.findByMemberId(memberId); if (response == null) { throw new NotFoundTeamException(); } diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/LoadTeamCalendarAdapter.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/LoadTeamCalendarAdapter.java index 97e53d69..5b1e9d16 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/LoadTeamCalendarAdapter.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/LoadTeamCalendarAdapter.java @@ -1,20 +1,19 @@ package idorm.idormServer.calendar.adapter.out.persistence; +import java.time.YearMonth; +import java.util.Collections; +import java.util.List; + +import org.springframework.stereotype.Component; + import idorm.idormServer.calendar.adapter.out.exception.NotFoundTeamCalendarException; import idorm.idormServer.calendar.application.port.out.LoadTeamCalendarPort; import idorm.idormServer.calendar.entity.Team; import idorm.idormServer.calendar.entity.TeamCalendar; import idorm.idormServer.notification.adapter.out.api.NotificationRequest; - -import java.time.YearMonth; -import java.util.Collections; -import java.util.List; - import lombok.AccessLevel; import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; - @Component @RequiredArgsConstructor(access = AccessLevel.PROTECTED) public class LoadTeamCalendarAdapter implements LoadTeamCalendarPort { @@ -39,7 +38,7 @@ public TeamCalendar findByIdAndMemberId(Long teamCalendarId, Long memberId) { @Override public List findByMemberId(Long memberId) { - List responses = findByMemberId(memberId); + List responses = teamCalendarRepository.findByMemberId(memberId); return responses != null ? responses : Collections.emptyList(); } diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCalendarCustomRepositoryImpl.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCalendarCustomRepositoryImpl.java index 2a3cd6cd..31d99dea 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCalendarCustomRepositoryImpl.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCalendarCustomRepositoryImpl.java @@ -39,8 +39,8 @@ public List findByMemberId(Long memberId) { return queryFactory .select(teamCalendar) .from(teamCalendar) - .join(teamCalendar.team, team) - .where(teamCalendar.participants.participants.any().memberId.eq(memberId)) + .join(teamCalendar.participants.participants, participant) + .where(participant.memberId.eq(memberId)) .fetch(); } diff --git a/src/main/java/idorm/idormServer/calendar/application/TeamCalendarService.java b/src/main/java/idorm/idormServer/calendar/application/TeamCalendarService.java index 57ab3ef3..10d8b789 100644 --- a/src/main/java/idorm/idormServer/calendar/application/TeamCalendarService.java +++ b/src/main/java/idorm/idormServer/calendar/application/TeamCalendarService.java @@ -52,9 +52,9 @@ public TeamCalendarResponse save(final AuthResponse authResponse, final SaveTeam @Transactional @Override public TeamCalendarResponse update(final AuthResponse authResponse, final UpdateTeamCalendarRequest request) { - final TeamCalendar teamCalendar = loadTeamCalendarPort.findByIdAndMemberId(request.teamCalendarId(), - authResponse.getId()); final Team team = loadTeamPort.findByMemberId(authResponse.getId()); + final TeamCalendar teamCalendar = loadTeamCalendarPort.findByIdAndTeamId(request.teamCalendarId(), + team.getId()); teamCalendar.update(team, request.title(), request.content(), request.getPeriod(), request.startTime(), request.endTime(), request.targets()); diff --git a/src/main/java/idorm/idormServer/calendar/application/TeamService.java b/src/main/java/idorm/idormServer/calendar/application/TeamService.java index 0ebef5af..e78cf8f1 100644 --- a/src/main/java/idorm/idormServer/calendar/application/TeamService.java +++ b/src/main/java/idorm/idormServer/calendar/application/TeamService.java @@ -1,9 +1,18 @@ package idorm.idormServer.calendar.application; +import java.util.Comparator; +import java.util.List; +import java.util.Optional; +import java.util.stream.IntStream; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + import idorm.idormServer.auth.application.port.in.dto.AuthResponse; import idorm.idormServer.calendar.application.port.in.TeamUseCase; import idorm.idormServer.calendar.application.port.in.dto.TeamParticipantResponse; import idorm.idormServer.calendar.application.port.in.dto.TeamResponse; +import idorm.idormServer.calendar.application.port.out.DeleteTeamMemberPort; import idorm.idormServer.calendar.application.port.out.DeleteTeamPort; import idorm.idormServer.calendar.application.port.out.LoadSleepoverCalendarPort; import idorm.idormServer.calendar.application.port.out.LoadTeamPort; @@ -12,17 +21,8 @@ import idorm.idormServer.calendar.entity.Team; import idorm.idormServer.member.application.port.out.LoadMemberPort; import idorm.idormServer.member.entity.Member; - -import java.util.Comparator; -import java.util.List; -import java.util.Optional; -import java.util.stream.IntStream; - import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - @Service @Transactional(readOnly = true) @RequiredArgsConstructor @@ -36,6 +36,7 @@ public class TeamService implements TeamUseCase { private final LoadSleepoverCalendarPort loadSleepoverCalendarPort; private final DeleteTeamPort deleteTeamPort; + private final DeleteTeamMemberPort deleteTeamMemberPort; @Override @Transactional @@ -60,12 +61,9 @@ public void addTeamMember(final AuthResponse authResponse, final Long registerMe @Override @Transactional - public void deleteMember(final AuthResponse authResponse, final Long targetId) { - final Member loginMember = loadMemberPort.loadMember(authResponse.getId()); - final Member deleteMember = loadMemberPort.loadMember(targetId); - final Team team = loadTeamPort.findByMemberId(loginMember.getId()); + public void deleteMember(final Long targetId) { - team.deleteMember(deleteMember); + deleteTeamMemberPort.deleteTeamMember(targetId); } @Override diff --git a/src/main/java/idorm/idormServer/calendar/application/port/in/TeamUseCase.java b/src/main/java/idorm/idormServer/calendar/application/port/in/TeamUseCase.java index f8e7a4b2..1bdd2b4f 100644 --- a/src/main/java/idorm/idormServer/calendar/application/port/in/TeamUseCase.java +++ b/src/main/java/idorm/idormServer/calendar/application/port/in/TeamUseCase.java @@ -7,7 +7,7 @@ public interface TeamUseCase { void addTeamMember(AuthResponse authResponse, Long registerMemberId); - void deleteMember(AuthResponse authResponse, Long memberId); + void deleteMember(Long memberId); void explodeTeam(AuthResponse authResponse); diff --git a/src/main/java/idorm/idormServer/calendar/application/port/out/DeleteTeamMemberPort.java b/src/main/java/idorm/idormServer/calendar/application/port/out/DeleteTeamMemberPort.java new file mode 100644 index 00000000..df109c86 --- /dev/null +++ b/src/main/java/idorm/idormServer/calendar/application/port/out/DeleteTeamMemberPort.java @@ -0,0 +1,5 @@ +package idorm.idormServer.calendar.application.port.out; + +public interface DeleteTeamMemberPort { + void deleteTeamMember(final Long memberId); +} diff --git a/src/main/java/idorm/idormServer/calendar/entity/Team.java b/src/main/java/idorm/idormServer/calendar/entity/Team.java index e5f43204..6df0915a 100644 --- a/src/main/java/idorm/idormServer/calendar/entity/Team.java +++ b/src/main/java/idorm/idormServer/calendar/entity/Team.java @@ -65,6 +65,7 @@ public void deleteMember(Member member) { throw new NotFoundTeamMemberException(); } member.removeTeam(); + this.members.remove(member); if (this.members.size() == 1) { this.teamStatus = TeamStatus.ALONE; } @@ -74,6 +75,7 @@ public void delete(Member member) { if (teamStatus.isNotAlone()) throw new CannotExplodeTeamException(); member.removeTeam(); + this.members.remove(member); } private void validateParticipationInTeam(Member member) { From 7bfcdb5d5a36f76c7b2be5794e792227bb0ac7e6 Mon Sep 17 00:00:00 2001 From: shyeon4643 Date: Tue, 7 May 2024 11:22:55 +0900 Subject: [PATCH 09/12] =?UTF-8?q?refactor=20:=20=EB=A9=A4=EB=B2=84?= =?UTF-8?q?=EA=B0=80=20=ED=8C=80=EC=97=90=EC=84=9C=20=EC=A0=9C=EA=B1=B0?= =?UTF-8?q?=EB=90=A0=20=EC=8B=9C=20=EA=B4=80=EB=A0=A8=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EB=B2=8C=ED=81=AC=EC=97=B0=EC=82=B0=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../out/persistence/DeleteTeamAdapter.java | 6 +++--- .../persistence/DeleteTeamMemberAdapter.java | 16 ++++++++------ .../SleepoverCalendarCustomRepository.java | 10 +++++---- ...SleepoverCalendarCustomRepositoryImpl.java | 21 ++++++++++++------- .../SleepoverCalendarRepository.java | 6 ++---- .../persistence/TeamCalendarRepository.java | 7 ++----- .../out/persistence/TeamCustomRepository.java | 6 ++++-- .../persistence/TeamCustomRepositoryImpl.java | 12 +++++++++-- .../out/persistence/TeamRepository.java | 4 ++-- 9 files changed, 53 insertions(+), 35 deletions(-) diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamAdapter.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamAdapter.java index 1b471904..4c786790 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamAdapter.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamAdapter.java @@ -1,11 +1,11 @@ package idorm.idormServer.calendar.adapter.out.persistence; +import org.springframework.stereotype.Component; + import idorm.idormServer.calendar.application.port.out.DeleteTeamPort; import idorm.idormServer.calendar.entity.Team; import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; - @Component @RequiredArgsConstructor public class DeleteTeamAdapter implements DeleteTeamPort { @@ -14,6 +14,6 @@ public class DeleteTeamAdapter implements DeleteTeamPort { @Override public void delete(Team team) { - teamRepository.delete(team); + teamRepository.delete(team.getId()); } } \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamMemberAdapter.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamMemberAdapter.java index 620d256f..a2a1917f 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamMemberAdapter.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamMemberAdapter.java @@ -20,11 +20,14 @@ @RequiredArgsConstructor(access = AccessLevel.PROTECTED) public class DeleteTeamMemberAdapter implements DeleteTeamMemberPort { - private final LoadMemberPort loadMemberPort; private final LoadTeamPort loadTeamPort; + private final DeleteTeamPort deleteTeamPort; + + private final LoadMemberPort loadMemberPort; + private final LoadTeamCalendarPort loadTeamCalendarPort; + private final DeleteSleepoverCalendarPort deleteSleepoverCalendarPort; - private final DeleteTeamPort deleteTeamPort; @Override public void deleteTeamMember(Long memberId) { @@ -32,12 +35,13 @@ public void deleteTeamMember(Long memberId) { final Team team = loadTeamPort.findByMemberId(member.getId()); final List teamCalendars = loadTeamCalendarPort.findByMemberId(member.getId()); - deleteSleepoverCalendarPort.deleteByMemberId(memberId); - teamCalendars - .forEach(teamCalendar -> teamCalendar.deletePariticipant(member.getId())); team.deleteMember(member); if (team.getMembers().isEmpty()) { deleteTeamPort.delete(team); + } else { + deleteSleepoverCalendarPort.deleteByMemberId(memberId); + teamCalendars + .forEach(teamCalendar -> teamCalendar.deletePariticipant(member.getId())); } } -} +} \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/SleepoverCalendarCustomRepository.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/SleepoverCalendarCustomRepository.java index 51ac67bc..98202622 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/SleepoverCalendarCustomRepository.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/SleepoverCalendarCustomRepository.java @@ -1,14 +1,14 @@ package idorm.idormServer.calendar.adapter.out.persistence; -import idorm.idormServer.calendar.entity.Period; -import idorm.idormServer.calendar.entity.SleepoverCalendar; -import idorm.idormServer.calendar.entity.Team; - import java.time.YearMonth; import java.util.List; import org.springframework.stereotype.Repository; +import idorm.idormServer.calendar.entity.Period; +import idorm.idormServer.calendar.entity.SleepoverCalendar; +import idorm.idormServer.calendar.entity.Team; + @Repository public interface SleepoverCalendarCustomRepository { @@ -21,4 +21,6 @@ public interface SleepoverCalendarCustomRepository { Long hasOverlappingDatesWithSleepoverId(Long memberId, Period period, Long sleepoverCalendarId); Long hasOverlappingDatesWithoutSleepoverId(Long memberId, Period period); + + void deleteByMemberId(Long memberId); } \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/SleepoverCalendarCustomRepositoryImpl.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/SleepoverCalendarCustomRepositoryImpl.java index b43dc24d..79902d28 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/SleepoverCalendarCustomRepositoryImpl.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/SleepoverCalendarCustomRepositoryImpl.java @@ -1,18 +1,17 @@ package idorm.idormServer.calendar.adapter.out.persistence; -import static idorm.idormServer.calendar.entity.QSleepoverCalendar.sleepoverCalendar; -import static idorm.idormServer.calendar.entity.QTeam.team; +import static idorm.idormServer.calendar.entity.QSleepoverCalendar.*; +import static idorm.idormServer.calendar.entity.QTeam.*; + +import java.time.LocalDate; +import java.time.YearMonth; +import java.util.List; import com.querydsl.jpa.impl.JPAQueryFactory; import idorm.idormServer.calendar.entity.Period; import idorm.idormServer.calendar.entity.SleepoverCalendar; import idorm.idormServer.calendar.entity.Team; - -import java.time.LocalDate; -import java.time.YearMonth; -import java.util.List; - import lombok.RequiredArgsConstructor; @RequiredArgsConstructor @@ -75,4 +74,12 @@ public Long hasOverlappingDatesWithoutSleepoverId(Long memberId, Period period) .and(sleepoverCalendar.memberId.eq(memberId))) .fetchCount(); } + + @Override + public void deleteByMemberId(Long memberId) { + queryFactory + .delete(sleepoverCalendar) + .where(sleepoverCalendar.memberId.eq(memberId)) + .execute(); + } } \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/SleepoverCalendarRepository.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/SleepoverCalendarRepository.java index 2f8c97ec..d19177af 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/SleepoverCalendarRepository.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/SleepoverCalendarRepository.java @@ -1,19 +1,17 @@ package idorm.idormServer.calendar.adapter.out.persistence; -import idorm.idormServer.calendar.entity.SleepoverCalendar; - import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Repository; +import idorm.idormServer.calendar.entity.SleepoverCalendar; + @Repository public interface SleepoverCalendarRepository extends JpaRepository, SleepoverCalendarCustomRepository { List findByMemberId(Long memberId); - @Modifying void deleteByMemberId(Long memberId); } \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCalendarRepository.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCalendarRepository.java index 70667e70..ebc5cc5a 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCalendarRepository.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCalendarRepository.java @@ -1,17 +1,14 @@ package idorm.idormServer.calendar.adapter.out.persistence; -import idorm.idormServer.calendar.entity.TeamCalendar; - -import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import idorm.idormServer.calendar.entity.TeamCalendar; + @Repository public interface TeamCalendarRepository extends JpaRepository, TeamCalendarCustomRepository { Optional findByIdAndTeamId(Long teamCalendarId, Long teamId); - - List findByTeamId(Long teamId); } \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCustomRepository.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCustomRepository.java index 50a72d76..5f8d22e6 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCustomRepository.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCustomRepository.java @@ -1,11 +1,13 @@ package idorm.idormServer.calendar.adapter.out.persistence; -import idorm.idormServer.calendar.entity.Team; - import org.springframework.stereotype.Repository; +import idorm.idormServer.calendar.entity.Team; + @Repository public interface TeamCustomRepository { Team findByMemberId(Long memberId); + + void delete(Long teamId); } \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCustomRepositoryImpl.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCustomRepositoryImpl.java index a0cc9c0e..ef141dfe 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCustomRepositoryImpl.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCustomRepositoryImpl.java @@ -1,7 +1,7 @@ package idorm.idormServer.calendar.adapter.out.persistence; -import static idorm.idormServer.calendar.entity.QTeam.team; -import static idorm.idormServer.member.entity.QMember.member; +import static idorm.idormServer.calendar.entity.QTeam.*; +import static idorm.idormServer.member.entity.QMember.*; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -22,4 +22,12 @@ public Team findByMemberId(final Long memberId) { .where(member.id.eq(memberId)) .fetchOne(); } + + @Override + public void delete(Long teamId) { + queryFactory + .delete(team) + .where(team.id.eq(teamId)) + .execute(); + } } \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamRepository.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamRepository.java index 7afcac45..15844011 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamRepository.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamRepository.java @@ -1,10 +1,10 @@ package idorm.idormServer.calendar.adapter.out.persistence; -import idorm.idormServer.calendar.entity.Team; - import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import idorm.idormServer.calendar.entity.Team; + @Repository public interface TeamRepository extends JpaRepository, TeamCustomRepository { From b7e9089d23fa0f188d6fddefbb23e8daf8c66571 Mon Sep 17 00:00:00 2001 From: shyeon4643 Date: Tue, 7 May 2024 11:41:33 +0900 Subject: [PATCH 10/12] =?UTF-8?q?fix=20:=20=ED=8C=80=EC=9B=90=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EC=8B=9C=20=ED=9A=8C=EC=9B=90=20=EC=83=81=ED=83=9C=20?= =?UTF-8?q?=ED=95=84=ED=84=B0=EB=A7=81=20=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../idorm/idormServer/calendar/application/TeamService.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/idorm/idormServer/calendar/application/TeamService.java b/src/main/java/idorm/idormServer/calendar/application/TeamService.java index e78cf8f1..16bf902a 100644 --- a/src/main/java/idorm/idormServer/calendar/application/TeamService.java +++ b/src/main/java/idorm/idormServer/calendar/application/TeamService.java @@ -1,5 +1,7 @@ package idorm.idormServer.calendar.application; +import static idorm.idormServer.member.entity.MemberStatus.*; + import java.util.Comparator; import java.util.List; import java.util.Optional; @@ -21,6 +23,7 @@ import idorm.idormServer.calendar.entity.Team; import idorm.idormServer.member.application.port.out.LoadMemberPort; import idorm.idormServer.member.entity.Member; +import idorm.idormServer.member.entity.MemberStatus; import lombok.RequiredArgsConstructor; @Service @@ -72,7 +75,7 @@ public TeamResponse findTeam(final AuthResponse authResponse) { final List sleepoverCalendars = loadSleepoverCalendarPort.findByToday(team); List members = team.getMembers().stream() - .filter(member -> member.getMemberStatus().equals("ACTIVE")) + .filter(member -> member.getMemberStatus().equals(ACTIVE)) .sorted(Comparator.comparing(Member::getId)) .toList(); From 16b185d1bb860f23be601ad8664df21bea1809c7 Mon Sep 17 00:00:00 2001 From: shyeon4643 Date: Sun, 12 May 2024 16:30:17 +0900 Subject: [PATCH 11/12] =?UTF-8?q?refactor=20:=20=EB=A9=A4=EB=B2=84=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EB=A5=BC=20=EC=84=9C=EB=B9=84=EC=8A=A4?= =?UTF-8?q?=EB=8B=A8=EC=9C=BC=EB=A1=9C=20=EC=9D=B4=EB=8F=99=ED=95=98?= =?UTF-8?q?=EA=B3=A0,=20=ED=8C=80=20=EC=BA=98=EB=A6=B0=EB=8D=94=EC=9D=98?= =?UTF-8?q?=20participant=EA=B0=80=20=EB=B9=84=EC=96=B4=EC=9E=88=EC=9D=84?= =?UTF-8?q?=20=EA=B2=BD=EC=9A=B0=20=ED=8C=80=20=EC=BA=98=EB=A6=B0=EB=8D=94?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../out/persistence/DeleteTeamMemberAdapter.java | 16 +++++++++------- .../calendar/application/TeamService.java | 6 +++--- .../port/out/DeleteTeamMemberPort.java | 4 +++- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamMemberAdapter.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamMemberAdapter.java index a2a1917f..9308b6e2 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamMemberAdapter.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamMemberAdapter.java @@ -5,13 +5,13 @@ import org.springframework.stereotype.Component; import idorm.idormServer.calendar.application.port.out.DeleteSleepoverCalendarPort; +import idorm.idormServer.calendar.application.port.out.DeleteTeamCalendarPort; import idorm.idormServer.calendar.application.port.out.DeleteTeamMemberPort; import idorm.idormServer.calendar.application.port.out.DeleteTeamPort; import idorm.idormServer.calendar.application.port.out.LoadTeamCalendarPort; import idorm.idormServer.calendar.application.port.out.LoadTeamPort; import idorm.idormServer.calendar.entity.Team; import idorm.idormServer.calendar.entity.TeamCalendar; -import idorm.idormServer.member.application.port.out.LoadMemberPort; import idorm.idormServer.member.entity.Member; import lombok.AccessLevel; import lombok.RequiredArgsConstructor; @@ -23,15 +23,13 @@ public class DeleteTeamMemberAdapter implements DeleteTeamMemberPort { private final LoadTeamPort loadTeamPort; private final DeleteTeamPort deleteTeamPort; - private final LoadMemberPort loadMemberPort; - private final LoadTeamCalendarPort loadTeamCalendarPort; + private final DeleteTeamCalendarPort deleteTeamCalendarPort; private final DeleteSleepoverCalendarPort deleteSleepoverCalendarPort; @Override - public void deleteTeamMember(Long memberId) { - final Member member = loadMemberPort.loadMember(memberId); + public void deleteTeamMember(Member member) { final Team team = loadTeamPort.findByMemberId(member.getId()); final List teamCalendars = loadTeamCalendarPort.findByMemberId(member.getId()); @@ -39,9 +37,13 @@ public void deleteTeamMember(Long memberId) { if (team.getMembers().isEmpty()) { deleteTeamPort.delete(team); } else { - deleteSleepoverCalendarPort.deleteByMemberId(memberId); + deleteSleepoverCalendarPort.deleteByMemberId(member.getId()); teamCalendars - .forEach(teamCalendar -> teamCalendar.deletePariticipant(member.getId())); + .forEach(teamCalendar -> { + teamCalendar.deletePariticipant(member.getId()); + if (teamCalendar.getParticipants().isEmpty()) + deleteTeamCalendarPort.delete(teamCalendar); + }); } } } \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/calendar/application/TeamService.java b/src/main/java/idorm/idormServer/calendar/application/TeamService.java index 16bf902a..776dbcd1 100644 --- a/src/main/java/idorm/idormServer/calendar/application/TeamService.java +++ b/src/main/java/idorm/idormServer/calendar/application/TeamService.java @@ -23,7 +23,6 @@ import idorm.idormServer.calendar.entity.Team; import idorm.idormServer.member.application.port.out.LoadMemberPort; import idorm.idormServer.member.entity.Member; -import idorm.idormServer.member.entity.MemberStatus; import lombok.RequiredArgsConstructor; @Service @@ -64,9 +63,10 @@ public void addTeamMember(final AuthResponse authResponse, final Long registerMe @Override @Transactional - public void deleteMember(final Long targetId) { + public void deleteMember(final Long memberId) { + final Member member = loadMemberPort.loadMember(memberId); - deleteTeamMemberPort.deleteTeamMember(targetId); + deleteTeamMemberPort.deleteTeamMember(member); } @Override diff --git a/src/main/java/idorm/idormServer/calendar/application/port/out/DeleteTeamMemberPort.java b/src/main/java/idorm/idormServer/calendar/application/port/out/DeleteTeamMemberPort.java index df109c86..23e9a651 100644 --- a/src/main/java/idorm/idormServer/calendar/application/port/out/DeleteTeamMemberPort.java +++ b/src/main/java/idorm/idormServer/calendar/application/port/out/DeleteTeamMemberPort.java @@ -1,5 +1,7 @@ package idorm.idormServer.calendar.application.port.out; +import idorm.idormServer.member.entity.Member; + public interface DeleteTeamMemberPort { - void deleteTeamMember(final Long memberId); + void deleteTeamMember(final Member member); } From ccf2eda513b592a624d19f9e41350e786fb636da Mon Sep 17 00:00:00 2001 From: shyeon4643 Date: Sun, 12 May 2024 23:08:34 +0900 Subject: [PATCH 12/12] =?UTF-8?q?refactor=20:=20=ED=8C=80=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EC=8B=9C=20=EC=99=B8=EB=B0=95=EC=BA=98=EB=A6=B0?= =?UTF-8?q?=EB=8D=94=20=EC=82=AD=EC=A0=9C=20=ED=9B=84=20=ED=8C=80=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/out/persistence/DeleteTeamAdapter.java | 2 +- .../adapter/out/persistence/DeleteTeamMemberAdapter.java | 1 + .../adapter/out/persistence/TeamCustomRepository.java | 2 -- .../adapter/out/persistence/TeamCustomRepositoryImpl.java | 8 -------- .../calendar/adapter/out/persistence/TeamRepository.java | 2 +- 5 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamAdapter.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamAdapter.java index 4c786790..f36c2070 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamAdapter.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamAdapter.java @@ -14,6 +14,6 @@ public class DeleteTeamAdapter implements DeleteTeamPort { @Override public void delete(Team team) { - teamRepository.delete(team.getId()); + teamRepository.deleteById(team.getId()); } } \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamMemberAdapter.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamMemberAdapter.java index 9308b6e2..326beec3 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamMemberAdapter.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/DeleteTeamMemberAdapter.java @@ -35,6 +35,7 @@ public void deleteTeamMember(Member member) { team.deleteMember(member); if (team.getMembers().isEmpty()) { + deleteSleepoverCalendarPort.deleteByMemberId(member.getId()); deleteTeamPort.delete(team); } else { deleteSleepoverCalendarPort.deleteByMemberId(member.getId()); diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCustomRepository.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCustomRepository.java index 5f8d22e6..7c2a28a2 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCustomRepository.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCustomRepository.java @@ -8,6 +8,4 @@ public interface TeamCustomRepository { Team findByMemberId(Long memberId); - - void delete(Long teamId); } \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCustomRepositoryImpl.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCustomRepositoryImpl.java index ef141dfe..a4e81fd1 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCustomRepositoryImpl.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamCustomRepositoryImpl.java @@ -22,12 +22,4 @@ public Team findByMemberId(final Long memberId) { .where(member.id.eq(memberId)) .fetchOne(); } - - @Override - public void delete(Long teamId) { - queryFactory - .delete(team) - .where(team.id.eq(teamId)) - .execute(); - } } \ No newline at end of file diff --git a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamRepository.java b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamRepository.java index 15844011..d3209e1a 100644 --- a/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamRepository.java +++ b/src/main/java/idorm/idormServer/calendar/adapter/out/persistence/TeamRepository.java @@ -7,5 +7,5 @@ @Repository public interface TeamRepository extends JpaRepository, TeamCustomRepository { - + void deleteById(Long teamId); } \ No newline at end of file