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
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -16,7 +16,7 @@ public interface MemberstudyroomRepository extends JpaRepository<MemberStudyroom

@Query("SELECT ms.role FROM MemberStudyroom ms WHERE ms.studyroom.studyroomId = :studyroomId AND ms.member.memberId = :memberId")
Optional<MemberRole> findRoleByMemberIdAndStudyroomId(long studyroomId, long memberId);
@Transactional

@Modifying
@Query("UPDATE MemberStudyroom ms SET ms.status = 'DELETE' WHERE ms.studyroom.studyroomId = :studyroomId")
int deleteMemberStudyroom(long studyroomId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
@Repository
@Transactional(readOnly = true)
public interface StudyroomRepository extends JpaRepository<Studyroom, Long> {
@Transactional
@Modifying
@Query("UPDATE Studyroom sr SET sr.status = 'DELETE' WHERE sr.studyroomId = :studyroomId")
int deleteStudyroom(long studyroomId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class StudyroomService {
@Autowired
private MemberRepository memberRepository;

@Transactional
public BaseExceptionResponseStatus deleteStudyroom(long studyroomId, long memberId) {


Expand All @@ -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.

넵 그렇습니다!

log.info("Success delete studyRoom in Service layer");
return BaseExceptionResponseStatus.SUCCESS;
}else {
Expand Down
Loading