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

Refactor : 삭제 API 수정 #16

Merged

Conversation

Mouon
Copy link
Member

@Mouon Mouon commented Jul 6, 2024

트랜잭션 범워 수정

요약 (Summary)

  • 두개의 쿼리리를 하나의 트랜잭션안에서 수행하도록 수정하였습니다.
  • 서비스계층의 조건 문도 추가하였습니다.
  • 말씀드린 쿼리 줄이기는 실패하였습니다..

🔑 변경 사항 (Key Changes)

  • MemberstudyroomRepository : deleteMemberStudyroom의 트랜잭션 어노테이션을 삭제하였습니다.
  • StudyroomRepository : deleteStudyroom의 트랜잭션 어노테이션을 삭제하였습니다.
  • StudyroomService : deleteStudyroom 트랜잭션 어노테이션을 추가하였습니다.

📝 리뷰 요구사항 (To Reviewers)

  • 명세서 대로 반환되는지
스크린샷 2024-07-06 오후 11 20 43
  • 스터디룸과 멤버 스터디룸 상태가 정상적으로 변경 되는지

확인 방법

.yml을 자신의 로컬에맞게 변경하세요

쿼리문

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 member (created_at, modified_at, avatar_id, github_id, nickname, color,status) VALUES
('2024-06-30 12:00:00.000000', '2024-06-30 12:30:00.000000', 1, 'Mouon', '두바이초콜릿','#FFFFF', 'ACTIVE');
INSERT INTO member (created_at, modified_at, avatar_id, github_id, nickname, color,status) VALUES
('2024-06-30 12:00:00.000000', '2024-06-30 12:30:00.000000', 1, 'jsilver01', '애플코드','#FFFFF', '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 Studyroom 2', '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 Studyroom 3', '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', 1, 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', 1, 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', 2, 1, 'CAPTAIN', 'ACTIVE');

SELECT * FROM member_studyroom WHERE studyroom_id=2 AND member_id=1;
SELECT * FROM member_studyroom;
SELECT * FROM studyroom;

소셜로그인 주소

https://github.com/login/oauth/authorize?client_id=Ov23liH7OLp2842PXbKI&scope=user:email

API 요청 주소 [PATCH}

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

studyroomId=2 에서는 방장이 아니라 삭제되지 않아야합니다.
요청 실패 로그 메세지
스크린샷 2024-07-05 오전 1 06 48

포스트맨 예시

스크린샷 2024-07-05 오전 12 14 10 스크린샷 2024-07-05 오전 12 37 00 스크린샷 2024-07-05 오전 12 55 48

워크벤치에서 상태가 변한 모습
스크린샷 2024-07-05 오전 12 56 36

@@ -45,8 +46,7 @@ public BaseExceptionResponseStatus deleteStudyroom(long studyroomId, long member
MemberRole memberRole = optionalMemberRole.orElseThrow(() -> new IllegalArgumentException("Error because of Invalid Member Id or Invalid StudyRoom Id"));

if (memberRole .equals(MemberRole.CAPTAIN)) {
if(studyroomRepository.deleteStudyroom(studyroomId)==1){
memberstudyroomRepository.deleteMemberStudyroom(studyroomId);
if(studyroomRepository.deleteStudyroom(studyroomId)==1 && memberstudyroomRepository.deleteMemberStudyroom(studyroomId)>0){
Copy link
Member

Choose a reason for hiding this comment

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

이 조건문에서 id 가 0 보다 크다라는 조건은 왜 추가되었는지 궁금합니다!(순수궁금..)

Copy link
Member Author

Choose a reason for hiding this comment

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

deleteMemberStudyroom메서드의 결과가 변경된 엔티티들의 갯수를 반환하는데 방장포한 1명이상은 병경되야 성공이라고 판단하기 위해 추가해보았습니다!

Copy link
Member

Choose a reason for hiding this comment

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

아 그러면 기능적인 면이라기보다 혹시나 변경되지 않는 오류에 대한 예외처리를 위해 추가하신건가요??

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 jsilver01 merged commit 54fd4e6 into develop Jul 7, 2024
@jsilver01 jsilver01 deleted the LINKODE-64-BE-스터디룸-삭제-수정작업-API branch July 7, 2024 05:50
@Mouon Mouon added the refactoring Good for newcomers label Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Good for newcomers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants