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 : 스터디룸 탈퇴 API 구현 #27

Merged
merged 9 commits into from
Jul 15, 2024

Conversation

Mouon
Copy link
Member

@Mouon Mouon commented Jul 14, 2024

요약 (Summary)

  • 스터디룸 탈퇴 API를 구현하였습니다.
  • 소켓에서 유저의 세션이 유저와 맴버기반으로 관리되었어야하는데 기존에는 유저아이디로만 관리되어 각각의 스터디룸에대한 유저 상태를 부적절하게 관리고있었습니다. 이를 맵의 키값을 유저아이디_스터디룸아이디로설정 하므로써 해결하였습니다.
  • 메모리 누수 방지를 위해 소켓 연결이 끊어지면 스터디룸맵에서 유저 세션은 삭제됩니다. 또한 스터디룸맵이 비어있으면 스터디룸 맵또한 삭제됩니다.
  • 유저 탈퇴가 방장은 이루어지지 않게하기위한 예외를 추가하였습니다.
  • 응답시 변경된 스터디룸 리스트를 반환하도록 수정하였습니다.
  • 맴버스터디룸 레포지토리에 findByMemberIdAndStatus를 추가하였습니다.

🔑 변경 사항 (Key Changes)

  • MemberstudyroomRepository : updateMemberstudyroomStatus를 작성하였습니다. 이는 맴버아이디 스터디룸아이디 기반으로 활성상태의 스터디룸을 찾아 업데이트 합니다.
  • MemberStudyroomService : 서비스단에 leaveStudyroom를 작성하였습니다. 유효한 맴버 스터디룸관계를 찾아 업데이트하도록하였습니다.
    • 작성시 기존에 작성해주신 레포지토리 메서드를 활용하였습니다.
    • 상황에따라 적절한 예외를 던지도록 하였고 catch문으로 예외를 잡아 적절하게 처리해보았습니다.
  • MemberStudyroomService : getMemberStudyroomList을 작성하였습니다. 맴버 아이디 기반으로 스터디룸 목록을 조회합니다.

📝 리뷰 요구사항 (To Reviewers)

  • 예외처리가 적절한지
  • 정상적으로 테이블상에 반영되는지
  • 방장은 탈퇴가 거부되는지
  • 명세서 내용은 적절하며, 명세서대로 반환되는지
스크린샷 2024-07-15 오후 2 58 41

확인 방법

쿼리문

use linkode;

INSERT INTO avatar (created_at, modified_at, avatar_img, status) VALUES
('2024-06-30 12:00:00.000000', '2024-06-30 12:30:00.000000', 'img1.png', 'ACTIVE');
INSERT INTO avatar (created_at, modified_at, avatar_img, status) VALUES
('2024-06-30 12:00:00.000000', '2024-06-30 12:30:00.000000', 'img2.png', 'ACTIVE');
INSERT INTO avatar (created_at, modified_at, avatar_img, status) VALUES
('2024-06-30 12:00:00.000000', '2024-06-30 12:30:00.000000', 'img3.png', 'ACTIVE');
INSERT INTO avatar (created_at, modified_at, avatar_img, status) VALUES
('2024-06-30 12:00:00.000000', '2024-06-30 12:30:00.000000', 'img4.png', 'ACTIVE');

INSERT INTO color (created_at, modified_at, hex_code, status) VALUES
('2024-06-30 12:00:00.000000', '2024-06-30 12:30:00.000000', '헥스코드1', 'ACTIVE');
INSERT INTO color (created_at, modified_at, hex_code, status) VALUES
('2024-06-30 12:00:00.000000', '2024-06-30 12:30:00.000000', '헥스코드2', 'ACTIVE');
INSERT INTO color (created_at, modified_at, hex_code, status) VALUES
('2024-06-30 12:00:00.000000', '2024-06-30 12:30:00.000000', '헥스코드3', 'ACTIVE');
INSERT INTO color (created_at, modified_at, hex_code, status) VALUES
('2024-06-30 12:00:00.000000', '2024-06-30 12:30:00.000000', '헥스코드4', 'ACTIVE');
INSERT INTO color (created_at, modified_at, hex_code, status) VALUES
('2024-06-30 12:00:00.000000', '2024-06-30 12:30:00.000000', '헥스코드5', 'ACTIVE');

INSERT INTO member (created_at, modified_at, avatar_id, github_id, nickname, color_id,status) VALUES
('2024-06-30 12:00:00.000000', '2024-06-30 12:30:00.000000', 1, 'jsilver01','두바이2', 1, 'ACTIVE');
INSERT INTO member (created_at, modified_at, avatar_id, github_id, nickname, color_id,status) VALUES
('2024-06-30 12:00:00.000000', '2024-06-30 12:30:00.000000', 1, 'Mouon','두바이', 1, 'ACTIVE');

INSERT INTO member (created_at, modified_at, avatar_id, github_id, nickname, color_id,status) VALUES
('2024-06-30 12:00:00.000000', '2024-06-30 12:30:00.000000', 1, 'Linkode','클론', 1, 'ACTIVE');
INSERT INTO member (created_at, modified_at, avatar_id, github_id, nickname, color_id,status) VALUES
('2024-06-30 12:00:00.000000', '2024-06-30 12:30:00.000000', 1, 'Linkode1','클론1', 1, 'ACTIVE');
INSERT INTO member (created_at, modified_at, avatar_id, github_id, nickname, color_id,status) VALUES
('2024-06-30 12:00:00.000000', '2024-06-30 12:30:00.000000', 1, 'Linkode2','클론2', 1, 'ACTIVE');

INSERT INTO studyroom (created_at, modified_at, studyroom_name, studyroom_profile, status) VALUES
('2024-07-04 12:00:00.000000', '2024-07-04 12:00:00.000000', 'New Studyroom', 'Profile for New Studyroom', 'ACTIVE');
INSERT INTO studyroom (created_at, modified_at, studyroom_name, studyroom_profile, status) VALUES
('2024-07-04 12:00:00.000000', '2024-07-04 12:00:00.000000', 'New Studyroom2', 'Profile for New Studyroom', 'ACTIVE');
INSERT INTO studyroom (created_at, modified_at, studyroom_name, studyroom_profile, status) VALUES
('2024-07-04 12:00:00.000000', '2024-07-04 12:00:00.000000', 'New Studyroom3', 'Profile for New Studyroom', 'ACTIVE');



INSERT INTO member_studyroom (created_at, modified_at, member_id, studyroom_id, role, status) VALUES
('2024-07-04 12:00:00.000000', '2024-07-04 12:00:00.000000', 1, 1, 'CAPTAIN', 'ACTIVE');
INSERT INTO member_studyroom (created_at, modified_at, member_id, studyroom_id, role, status) VALUES
('2024-07-04 12:00:00.000000', '2024-07-04 12:00:00.000000', 2, 1, 'CREW', 'ACTIVE');
INSERT INTO member_studyroom (created_at, modified_at, member_id, studyroom_id, role, status) VALUES
('2024-07-04 12:00:00.000000', '2024-07-04 12:00:00.000000', 3, 1, 'CREW', 'ACTIVE');
INSERT INTO member_studyroom (created_at, modified_at, member_id, studyroom_id, role, status) VALUES
('2024-07-04 12:00:00.000000', '2024-07-04 12:00:00.000000', 1, 2, 'CAPTAIN', 'ACTIVE');
INSERT INTO member_studyroom (created_at, modified_at, member_id, studyroom_id, role, status) VALUES
('2024-07-04 12:00:00.000000', '2024-07-04 12:00:00.000000', 2, 2, 'CREW', 'ACTIVE');
INSERT INTO member_studyroom (created_at, modified_at, member_id, studyroom_id, role, status) VALUES
('2024-07-04 12:00:00.000000', '2024-07-04 12:00:00.000000', 3, 2, 'CREW', 'ACTIVE');
INSERT INTO member_studyroom (created_at, modified_at, member_id, studyroom_id, role, status) VALUES
('2024-07-04 12:00:00.000000', '2024-07-04 12:00:00.000000', 2, 3, 'CAPTAIN', 'ACTIVE');
INSERT INTO member_studyroom (created_at, modified_at, member_id, studyroom_id, role, status) VALUES
('2024-07-04 12:00:00.000000', '2024-07-04 12:00:00.000000', 1, 3, 'CREW', 'ACTIVE');
INSERT INTO member_studyroom (created_at, modified_at, member_id, studyroom_id, role, status) VALUES
('2024-07-04 12:00:00.000000', '2024-07-04 12:00:00.000000', 3, 3, 'CREW', 'ACTIVE');

주소

http://localhost:8080/studyroom/leave?studyroomId=1
http://localhost:8080/studyroom/leave?studyroomId=2
http://localhost:8080/studyroom/leave?studyroomId=3

스터디원일때만 탈퇴가 가능합니다!

@jsilver01
Copy link
Member

메모리 누수 방지를 위해 소켓 연결이 끊어지면 스터디룸맵에서 유저 세션은 삭제됩니다. 또한 스터디룸맵이 비어있으면 스터디룸 맵또한 삭제됩니다. 이 부분이 그때 말해줬던 부분에서 수정된 부분인건가요?? 원래는 스터디룸이 비어있다고해서 스터디룸이 삭제되는건 아니라고 했던거 같은데 이 부분이 비어있으면 사라지는거로 수정된 건가요???

@jsilver01
Copy link
Member

스크린샷 2024-07-14 오후 11 32 25 스크린샷 2024-07-14 오후 11 32 44 스크린샷 2024-07-14 오후 11 35 16 스크린샷 2024-07-14 오후 11 35 59

셀렉트문 하나, 업데이트문 하나 날라가는 것 확인했습니다! 별 문제사항없이 코드 동작하는 것 확인했습니다.

@Mouon
Copy link
Member Author

Mouon commented Jul 15, 2024

메모리 누수 방지를 위해 소켓 연결이 끊어지면 스터디룸맵에서 유저 세션은 삭제됩니다. 또한 스터디룸맵이 비어있으면 스터디룸 맵또한 삭제됩니다. 이 부분이 그때 말해줬던 부분에서 수정된 부분인건가요?? 원래는 스터디룸이 비어있다고해서 스터디룸이 삭제되는건 아니라고 했던거 같은데 이 부분이 비어있으면 사라지는거로 수정된 건가요???

넵 맞습니다.

*
* 스트림 문법으로 매핑
* */
public MemberStudyroomListResponse getMemberStudyroomList(long memberId){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분에서 셀렉트문이 하나 더 날라갈 것 같은데 방장이라면 기존 스터디룸과 달라질 부분이 없으니 CAPTAIN 이라면 그냥 null 로 반환하는 것은 어떨까요??? 근데 또 생각해보면 그 사이에 다른 스터디룸에서 업데이트 된 것을 여기서 채워넣을 수 있어서 좋은 방법인 것 같기두 합니다!

Copy link
Member Author

@Mouon Mouon Jul 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엇 저도 그 부분에대해 고민하였었는데
방장일때 탈퇴가 이루어지지 않아 변경되지않은 리스트또한 상태또한 검증될필요가 있다고 판단하여 일관성있게 반환하도록 하였습니다!
또한 탈퇴 API가 일관되게 최신 스터디룸 리스트 조회기능을 하는게 나을것 같다고 생각했었습니다!

long memberId = jwtProvider.extractIdFromHeader(authorization);
BaseExceptionResponseStatus responseStatus = memberStudyroomService.leaveStudyroom(studyroomId,memberId);
MemberStudyroomListResponse latestStudyroomList = memberStudyroomService.getMemberStudyroomList(memberId);
log.info("Run leaveStudyroom API ");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엇, log 가 아래에 있어서 위의 쿼리문들이 전부 실행된 이후에 로그가 찍히는데 혹시 의도하신건가요?? 로그찍는 스타일은 사람마다 다르니까 이거는 정말 궁금해서 물어봅니더!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵! 기본적으로 메서드 로그는 제공되기때문에
저는 정상적으로 서비스단 메소드가 실행되어야
컨트롤러가 돈다고 판단하기위해 디버깅용 로그를 찍어두었습니다!

@jsilver01
Copy link
Member

jsilver01 commented Jul 15, 2024

반환은 문제없이 됩니다!! 수고하셨습니당🥰

@jsilver01 jsilver01 merged commit f03421b into develop Jul 15, 2024
@jsilver01 jsilver01 deleted the LINKODE-14-BE-API-스터디룸-탈퇴 branch July 15, 2024 12:47
@Mouon Mouon added the Feature Make Feat label Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Make Feat
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants