Skip to content

Commit

Permalink
Merge pull request #44 from Modagbul/feat/마이페이지
Browse files Browse the repository at this point in the history
Feat/마이페이지
  • Loading branch information
seungueonn authored Oct 23, 2023
2 parents 9b4fe17 + b7e520c commit 23c133d
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 16 deletions.
15 changes: 15 additions & 0 deletions src/docs/asciidoc/Overview.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@

|===

=== MyPage ErrorCode
|===
| ErrorCode | Scope | Description
| `MP0001`
| 알람을 수정할 때
| 알람 입력값이 유효하지 않음

| `MP0002`
| 회원 탈퇴할 때
| 탈퇴되지 않은 소모임이 있음
|===

=== Board ErrorCode
|===
| ErrorCode | Scope | Description
Expand All @@ -117,6 +129,7 @@
| 작성자가 아님 (권한 없음)
|===

=== BoardComment ErrorCode
|===
| ErrorCode | Scope | Description
| `BC0001`
Expand All @@ -128,6 +141,8 @@
| 작성자가 아님 (권한 없음)
|===



=== Mission ErrorCode
|===
| ErrorCode | Scope | Description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class SignOutUserCase {
private final MemberGetService memberGetService;

public void signOut(String socialId){
//TODO: teamMember가 isDeleted가 아닌게 한개라도 있으면 error 반환
tokenUtil.expireRefreshToken(socialId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,34 @@
import com.moing.backend.domain.member.domain.service.MemberGetService;
import com.moing.backend.domain.mypage.application.dto.request.WithdrawRequest;
import com.moing.backend.domain.mypage.domain.service.FeedbackSaveService;
import com.moing.backend.domain.mypage.exception.ExistingTeamException;
import com.moing.backend.domain.teamMember.domain.service.TeamMemberGetService;
import com.moing.backend.global.config.security.jwt.TokenUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class WithdrawUserCase {

private final MemberGetService memberGetService;
private final FeedbackSaveService feedbackSaveService;
private final TokenUtil tokenUtil;
private final MemberDeleteService memberDeleteService;
private final TeamMemberGetService teamMemberGetService;

public void withdraw(String socialId, WithdrawRequest withdrawRequest) {
//1. 멤버 삭제
Member member = memberGetService.getMemberBySocialId(socialId);
checkMemberIsNotPartOfAnyTeam(member);
memberDeleteService.deleteMember(member);
//TODO: 애플과 카카오 회원탈퇴
//2. 피드백 저장
feedbackSaveService.saveFeedback(member, withdrawRequest);
//3. 리프레시 토큰 만료
tokenUtil.expireRefreshToken(socialId);
}

private void checkMemberIsNotPartOfAnyTeam(Member member) {
if (!teamMemberGetService.getNotDeletedTeamMember(member.getMemberId()).isEmpty()) {
throw new ExistingTeamException();
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.moing.backend.domain.mypage.exception;

import com.moing.backend.global.exception.ApplicationException;
import com.moing.backend.global.response.ErrorCode;
import org.springframework.http.HttpStatus;

public class ExistingTeamException extends ApplicationException {
public ExistingTeamException() {
super(ErrorCode.EXISTING_TEAM_ERROR,
HttpStatus.NOT_FOUND);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.moing.backend.domain.teamMember.domain.repository;

import com.moing.backend.domain.member.domain.entity.Member;
import com.moing.backend.domain.team.application.dto.response.TeamMemberInfo;
import com.moing.backend.domain.teamMember.domain.entity.TeamMember;

import java.util.List;
import java.util.Optional;
Expand All @@ -10,4 +12,5 @@ public interface TeamMemberCustomRepository {
Optional<List<String>> findFcmTokensByTeamIdAndMemberId(Long teamId, Long memberId);
Optional<List<String>> findFcmTokensByTeamId(Long teamId);
List<TeamMemberInfo> findTeamMemberInfoByTeamId(Long teamId);
List<TeamMember> findTeamMemberByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.moing.backend.domain.team.application.dto.response.TeamMemberInfo;
import com.moing.backend.domain.team.domain.constant.ApprovalStatus;
import com.moing.backend.domain.team.domain.entity.QTeam;
import com.moing.backend.domain.teamMember.domain.entity.TeamMember;
import com.querydsl.jpa.impl.JPAQueryFactory;

import javax.persistence.EntityManager;
Expand Down Expand Up @@ -69,4 +70,12 @@ public List<TeamMemberInfo> findTeamMemberInfoByTeamId(Long teamId){
.groupBy(teamMember.member.memberId)
.fetch();
}

@Override
public List<TeamMember> findTeamMemberByMemberId(Long memberId) {
return queryFactory.selectFrom(teamMember)
.where(teamMember.member.memberId.eq(memberId)
.and(teamMember.isDeleted.eq(false)))
.fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ public Optional<List<String>> getFcmTokens(Long teamId) {
public List<TeamMemberInfo> getTeamMemberInfo(Long teamId){
return teamMemberRepository.findTeamMemberInfoByTeamId(teamId);
}

public List<TeamMember> getNotDeletedTeamMember(Long memberId){
return teamMemberRepository.findTeamMemberByMemberId(memberId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,30 @@
@Transactional
public class TeamMemberSaveService {
private final TeamMemberRepository teamMemberRepository;
public void addTeamMember(Team team, Member member){
public void addTeamMember(Team team, Member member) {
Optional<TeamMember> teamMember = teamMemberRepository.findTeamMemberByTeamAndMember(team, member);

if (teamMember.isPresent()) {
if (teamMember.get().isDeleted()) {
throw new AlreadyWithdrawTeamException();
} else {
throw new AlreadyJoinTeamException();
}
handleExistingMember(teamMember.get());
} else {
addNewTeamMember(team, member);
}
}

private void handleExistingMember(TeamMember teamMember) {
if (teamMember.isDeleted()) {
throw new AlreadyWithdrawTeamException();
} else {
TeamMember newMember = new TeamMember();
newMember.updateMember(member);
newMember.updateTeam(team);
team.addTeamMember();
this.teamMemberRepository.save(newMember);
throw new AlreadyJoinTeamException();
}
}

private void addNewTeamMember(Team team, Member member) {
TeamMember newMember = new TeamMember();
newMember.updateMember(member);
newMember.updateTeam(team);
team.addTeamMember();
this.teamMemberRepository.save(newMember);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public enum ErrorCode {

//마이페이지 관련 에러 코드
INVALID_ALARM_ERROR("MP0001","유효하지 않는 알람 입력값입니다"),
EXISTING_TEAM_ERROR("MP0002","탈퇴되지 않은 소모임이 있습니다."),

//게시글 관련 에러 코드
NOT_FOUND_BY_BOARD_ID_ERROR("B0001","해당 boardId인 게시글이 존재하지 않습니다."),
Expand Down

0 comments on commit 23c133d

Please sign in to comment.