-
Notifications
You must be signed in to change notification settings - Fork 0
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 : 스터디룸 탈퇴 API 구현 #27
The head ref may contain hidden characters: "LINKODE-14-BE-API-\uC2A4\uD130\uB514\uB8F8-\uD0C8\uD1F4"
Changes from all commits
ad2c26c
650fabd
b41c1ad
71c1183
48cf08b
62d077c
167b076
702083d
18ea823
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.linkode.api_server.common.exception; | ||
|
||
import com.linkode.api_server.common.response.status.ResponseStatus; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class LeaveStudyroomExeption extends RuntimeException{ | ||
|
||
private final ResponseStatus exceptionStatus; | ||
|
||
public LeaveStudyroomExeption(ResponseStatus exceptionStatus) { | ||
super(exceptionStatus.getMessage()); | ||
this.exceptionStatus = exceptionStatus; | ||
} | ||
|
||
public LeaveStudyroomExeption(ResponseStatus exceptionStatus, String message) { | ||
super(message); | ||
this.exceptionStatus = exceptionStatus; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.linkode.api_server.dto.studyroom; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
@Getter @Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class MemberStudyroomListResponse { | ||
|
||
private List<MemberStudyroomListResponse.Studyroom> studyroomList; | ||
|
||
@Getter @Setter | ||
@AllArgsConstructor | ||
public static class Studyroom{ | ||
Long studyroomId; | ||
String studyroomProfile; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
package com.linkode.api_server.service; | ||
|
||
import com.linkode.api_server.common.exception.LeaveStudyroomExeption; | ||
import com.linkode.api_server.common.exception.MemberStudyroomException; | ||
import com.linkode.api_server.common.response.BaseResponse; | ||
import com.linkode.api_server.common.response.status.BaseExceptionResponseStatus; | ||
import com.linkode.api_server.domain.Studyroom; | ||
import com.linkode.api_server.domain.base.BaseStatus; | ||
import com.linkode.api_server.domain.memberstudyroom.MemberRole; | ||
import com.linkode.api_server.domain.memberstudyroom.MemberStudyroom; | ||
import com.linkode.api_server.dto.studyroom.DetailStudyroomResponse; | ||
import com.linkode.api_server.dto.studyroom.MemberStudyroomListResponse; | ||
import com.linkode.api_server.repository.MemberstudyroomRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
@@ -18,8 +22,7 @@ | |
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import static com.linkode.api_server.common.response.status.BaseExceptionResponseStatus.NOT_FOUND_CREW; | ||
import static com.linkode.api_server.common.response.status.BaseExceptionResponseStatus.NOT_FOUND_MEMBER_STUDYROOM; | ||
import static com.linkode.api_server.common.response.status.BaseExceptionResponseStatus.*; | ||
|
||
@Slf4j | ||
@Service | ||
|
@@ -88,4 +91,55 @@ public DetailStudyroomResponse getStudyroomDetail(long studyroomId, long memberI | |
return response; | ||
} | ||
|
||
/** | ||
* 스터디룸 탈퇴 | ||
* | ||
* memberStudyroom에 대한 유효성 검증을 한후 적절하지 못한 맴버 스터디룸이면 예외를 던집니다. | ||
* 방장이면 탈퇴할 수 없도록 조건문을 통해 방장인지 파악한 뒤 예외를 강제로 던집니다! | ||
* | ||
* */ | ||
@Transactional | ||
public BaseExceptionResponseStatus leaveStudyroom(long studyroomId, long memberId){ | ||
jsilver01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
try { | ||
MemberStudyroom memberStudyroom = memberstudyroomRepository | ||
.findByMember_MemberIdAndStudyroom_StudyroomIdAndStatus(memberId,studyroomId,BaseStatus.ACTIVE) | ||
.orElseThrow(()-> new MemberStudyroomException(NOT_FOUND_MEMBER_STUDYROOM)); | ||
if(memberStudyroom.getRole()==MemberRole.CAPTAIN) throw new | ||
LeaveStudyroomExeption(CANNOT_LEAVE_STUDYROOM); | ||
memberStudyroom.updateMemberStudyroomStatus(BaseStatus.DELETE); | ||
memberstudyroomRepository.save(memberStudyroom); | ||
return BaseExceptionResponseStatus.SUCCESS; | ||
} | ||
catch (LeaveStudyroomExeption e) { | ||
log.error("MemberStudyroomException! -> ", e); | ||
return CANNOT_LEAVE_STUDYROOM; | ||
} | ||
catch (MemberStudyroomException e) { | ||
log.error("MemberStudyroomException! -> ", e); | ||
return NOT_FOUND_MEMBER_STUDYROOM; | ||
} | ||
catch (Exception e){ | ||
return FAILURE; | ||
} | ||
} | ||
|
||
/** | ||
* 유저의 스터디룸 리스트 조회 | ||
* | ||
* 스트림 문법으로 매핑 | ||
* */ | ||
public MemberStudyroomListResponse getMemberStudyroomList(long memberId){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분에서 셀렉트문이 하나 더 날라갈 것 같은데 방장이라면 기존 스터디룸과 달라질 부분이 없으니 CAPTAIN 이라면 그냥 null 로 반환하는 것은 어떨까요??? 근데 또 생각해보면 그 사이에 다른 스터디룸에서 업데이트 된 것을 여기서 채워넣을 수 있어서 좋은 방법인 것 같기두 합니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 엇 저도 그 부분에대해 고민하였었는데 |
||
|
||
List<MemberStudyroomListResponse.Studyroom> studyroomList = | ||
memberstudyroomRepository.findByMemberIdAndStatus(memberId,BaseStatus.ACTIVE) | ||
.orElseThrow(()->new MemberStudyroomException(NOT_FOUND_MEMBER_STUDYROOM)) | ||
.stream() | ||
.map(ms -> new MemberStudyroomListResponse.Studyroom( | ||
ms.getStudyroom().getStudyroomId(), | ||
ms.getStudyroom().getStudyroomProfile() | ||
)).collect(Collectors.toList()); | ||
|
||
return new MemberStudyroomListResponse(studyroomList); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
엇, log 가 아래에 있어서 위의 쿼리문들이 전부 실행된 이후에 로그가 찍히는데 혹시 의도하신건가요?? 로그찍는 스타일은 사람마다 다르니까 이거는 정말 궁금해서 물어봅니더!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵! 기본적으로 메서드 로그는 제공되기때문에
저는 정상적으로 서비스단 메소드가 실행되어야
컨트롤러가 돈다고 판단하기위해 디버깅용 로그를 찍어두었습니다!