From 1ee3df50063c46156a6ef26a21bd240e9a396460 Mon Sep 17 00:00:00 2001 From: shyeon4643 Date: Mon, 6 May 2024 22:16:36 +0900 Subject: [PATCH] =?UTF-8?q?[Feature]=20=EB=A9=A4=EB=B2=84=EA=B0=80=20?= =?UTF-8?q?=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) {