Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] 회원 탈퇴 구현 #74

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,15 @@ public ResponseEntity<SuccessResponse<Object>> 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 = "<b>해당 API 사용법</b>\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"),
Expand All @@ -84,8 +91,11 @@ public ResponseEntity<SuccessResponse<Object>> 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);

Expand Down Expand Up @@ -114,9 +124,10 @@ public ResponseEntity<SuccessResponse<Object>> 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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,5 +13,6 @@ public interface RefreshTokenRepository extends JpaRepository<RefreshToken, Long

Optional<RefreshToken> findByMemberId(Long memberId);

@Modifying
void deleteAllByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public ResponseEntity<SuccessResponse<Object>> deleteTeamMember(
@Positive(message = "삭제할 회원 식별자는 양수만 가능합니다.")
Long memberId
) {
teamUseCase.deleteMember(authResponse, memberId);
teamUseCase.deleteMember(memberId);
return ResponseEntity.ok().body(SuccessResponse.from(TEAM_MEMBER_DELETED));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -14,6 +14,6 @@ public class DeleteTeamAdapter implements DeleteTeamPort {

@Override
public void delete(Team team) {
teamRepository.delete(team);
teamRepository.delete(team.getId());
}
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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.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.entity.Member;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;

@Component
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
public class DeleteTeamMemberAdapter implements DeleteTeamMemberPort {

private final LoadTeamPort loadTeamPort;
private final DeleteTeamPort deleteTeamPort;

private final LoadTeamCalendarPort loadTeamCalendarPort;
private final DeleteTeamCalendarPort deleteTeamCalendarPort;

private final DeleteSleepoverCalendarPort deleteSleepoverCalendarPort;

@Override
public void deleteTeamMember(Member member) {
final Team team = loadTeamPort.findByMemberId(member.getId());
final List<TeamCalendar> teamCalendars = loadTeamCalendarPort.findByMemberId(member.getId());

team.deleteMember(member);
if (team.getMembers().isEmpty()) {
deleteTeamPort.delete(team);
} else {
deleteSleepoverCalendarPort.deleteByMemberId(member.getId());
teamCalendars
.forEach(teamCalendar -> {
teamCalendar.deletePariticipant(member.getId());
if (teamCalendar.getParticipants().isEmpty())
deleteTeamCalendarPort.delete(teamCalendar);
});
}
}
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -24,7 +23,7 @@ public Optional<Team> findByMemberIdWithOptional(Long memberId) {

@Override
public Team findByMemberId(Long memberId) {
Team response = findByMemberId(memberId);
Team response = teamRepository.findByMemberId(memberId);
if (response == null) {
throw new NotFoundTeamException();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -39,7 +38,7 @@ public TeamCalendar findByIdAndMemberId(Long teamCalendarId, Long memberId) {

@Override
public List<TeamCalendar> findByMemberId(Long memberId) {
List<TeamCalendar> responses = findByMemberId(memberId);
List<TeamCalendar> responses = teamCalendarRepository.findByMemberId(memberId);
return responses != null ? responses : Collections.emptyList();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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);
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +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.stereotype.Repository;

import idorm.idormServer.calendar.entity.SleepoverCalendar;

@Repository
public interface SleepoverCalendarRepository
extends JpaRepository<SleepoverCalendar, Long>, SleepoverCalendarCustomRepository {

List<SleepoverCalendar> findByMemberId(Long memberId);

void deleteByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -40,8 +39,8 @@ public List<TeamCalendar> 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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<TeamCalendar, Long>, TeamCalendarCustomRepository {

Optional<TeamCalendar> findByIdAndTeamId(Long teamCalendarId, Long teamId);

List<TeamCalendar> findByTeamId(Long teamId);
}
Original file line number Diff line number Diff line change
@@ -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);
}
Loading