diff --git a/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java b/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java index 36e3d80..1a83578 100644 --- a/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java +++ b/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java @@ -16,7 +16,7 @@ public interface MemberstudyroomRepository extends JpaRepository findRoleByMemberIdAndStudyroomId(long studyroomId, long memberId); - @Transactional + @Modifying @Query("UPDATE MemberStudyroom ms SET ms.status = 'DELETE' WHERE ms.studyroom.studyroomId = :studyroomId") int deleteMemberStudyroom(long studyroomId); diff --git a/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java b/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java index 4aa27f2..d2d0865 100644 --- a/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java +++ b/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java @@ -12,7 +12,6 @@ @Repository @Transactional(readOnly = true) public interface StudyroomRepository extends JpaRepository { - @Transactional @Modifying @Query("UPDATE Studyroom sr SET sr.status = 'DELETE' WHERE sr.studyroomId = :studyroomId") int deleteStudyroom(long studyroomId); diff --git a/src/main/java/com/linkode/api_server/service/StudyroomService.java b/src/main/java/com/linkode/api_server/service/StudyroomService.java index 20a6aac..40f2947 100644 --- a/src/main/java/com/linkode/api_server/service/StudyroomService.java +++ b/src/main/java/com/linkode/api_server/service/StudyroomService.java @@ -29,6 +29,7 @@ public class StudyroomService { @Autowired private MemberRepository memberRepository; + @Transactional public BaseExceptionResponseStatus deleteStudyroom(long studyroomId, long memberId) { @@ -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){ log.info("Success delete studyRoom in Service layer"); return BaseExceptionResponseStatus.SUCCESS; }else {