diff --git a/src/main/java/com/example/likelion12/common/response/status/BaseExceptionResponseStatus.java b/src/main/java/com/example/likelion12/common/response/status/BaseExceptionResponseStatus.java index f44af0a..fcde466 100644 --- a/src/main/java/com/example/likelion12/common/response/status/BaseExceptionResponseStatus.java +++ b/src/main/java/com/example/likelion12/common/response/status/BaseExceptionResponseStatus.java @@ -49,7 +49,8 @@ public enum BaseExceptionResponseStatus implements ResponseStatus{ ALREADY_EXIST_IN_SOCIALRING(8003, HttpStatus.BAD_REQUEST.value(), "해당 소셜링에 이미 등록된 멤버입니다."), N0T_EXIST_JOIN_SOCIALRING(8004, HttpStatus.BAD_REQUEST.value(), "참가 중인 소셜링이 존재하지 않습니다."), N0T_EXIST_JOIN_BEFORE_SOCIALRING(8005, HttpStatus.BAD_REQUEST.value(), "참가 예정인 소셜링이 존재 하지않습니다."), - N0T_EXIST_JOIN_COMPLETE_SOCIALRING(8005, HttpStatus.BAD_REQUEST.value(), "참가 완료한 소셜링이 존재 하지않습니다."), + N0T_EXIST_JOIN_COMPLETE_SOCIALRING(8006, HttpStatus.BAD_REQUEST.value(), "참가 완료한 소셜링이 존재 하지않습니다."), + CANNOT_CANCEL_BY_CAPTAIN(8007, HttpStatus.BAD_REQUEST.value(), "소셜링 모임장은 소셜링을 나갈 수 없습니다. 소셜링 삭제를 이용해주세요"), /** * 9000 : crew 관련 diff --git a/src/main/java/com/example/likelion12/controller/SocialringController.java b/src/main/java/com/example/likelion12/controller/SocialringController.java index 7f5f753..672623d 100644 --- a/src/main/java/com/example/likelion12/controller/SocialringController.java +++ b/src/main/java/com/example/likelion12/controller/SocialringController.java @@ -97,4 +97,17 @@ public BaseResponse deleteSocialring(@RequestHeader("Authorization") Strin socialringService.deleteSocialring(memberId, socialringId); return new BaseResponse<>(BaseExceptionResponseStatus.SUCCESS, null); } + + /** + * 소셜링 취소하기 + */ + @PatchMapping("/cancel") + public BaseResponse cancelSocialring(@RequestHeader("Authorization") String authorization, + @RequestParam("socialringId") Long socialringId) { + log.info("[SocialringController.cancelSocialring]"); + Long memberId = jwtProvider.extractIdFromHeader(authorization); + socialringService.cancelSocialring(memberId, socialringId); + return new BaseResponse<>(BaseExceptionResponseStatus.SUCCESS, null); + } + } diff --git a/src/main/java/com/example/likelion12/domain/MemberSocialring.java b/src/main/java/com/example/likelion12/domain/MemberSocialring.java index 2304e8d..b8bfbae 100644 --- a/src/main/java/com/example/likelion12/domain/MemberSocialring.java +++ b/src/main/java/com/example/likelion12/domain/MemberSocialring.java @@ -46,6 +46,11 @@ public MemberSocialring(BaseRole baseRole, Socialring socialring, Member member, this.status = baseStatus; } + // 상태를 'delete'로 변경하는 메서드 + public void setStatusToDelete() { + this.status = BaseStatus.DELETE; + } + public void setStatus(BaseStatus status) { this.status = status; } diff --git a/src/main/java/com/example/likelion12/service/SocialringService.java b/src/main/java/com/example/likelion12/service/SocialringService.java index 6a9d104..98fe710 100644 --- a/src/main/java/com/example/likelion12/service/SocialringService.java +++ b/src/main/java/com/example/likelion12/service/SocialringService.java @@ -4,6 +4,7 @@ import com.example.likelion12.domain.*; import com.example.likelion12.domain.base.BaseGender; import com.example.likelion12.domain.base.BaseLevel; +import com.example.likelion12.domain.base.BaseRole; import com.example.likelion12.domain.base.BaseStatus; import com.example.likelion12.dto.socialring.*; import com.example.likelion12.repository.*; @@ -368,4 +369,37 @@ public void deleteSocialring(Long memberId, Long socialringId) { memberSocialringRepository.save(memberSocialringEntry); } } + + /** + * 소셜링 취소 + */ + @Transactional + public void cancelSocialring(Long memberId, Long socialringId) { + log.info("[SocialringService.cancelSocialring]"); + + // 소셜링을 취소하고자 하는 멤버 찾고 + Member member = memberRepository.findByMemberIdAndStatus(memberId, BaseStatus.ACTIVE) + .orElseThrow(() -> new MemberException(CANNOT_FOUND_MEMBER)); + + // 취소하고자 하는 소셜링 찾고 + Socialring socialring = socialringRepository.findBySocialringIdAndStatus(socialringId, BaseStatus.ACTIVE) + .orElseThrow(() -> new SocialringException(CANNOT_FOUND_SOCIALRING)); + + // 해당 소셜링에 등록된 멤버 소셜링 중, 취소할 멤버의 멤버소셜링 값을 가져와서 + MemberSocialring memberSocialring = memberSocialringRepository.findByMember_MemberIdAndSocialring_SocialringIdAndStatus(memberId, + socialringId, BaseStatus.ACTIVE).orElseThrow(() -> new MemberSocialringException(CANNOT_FOUND_MEMBERSOCIALRING)); + + // 가져온 멤버 소셜링의 값으로 캡틴인지 확인하고 + memberSocialringService.ConfirmCaptainMemberSocialring(memberSocialring); + + // 캡틴인 경우 예외 발생 + if (memberSocialring.getRole() == BaseRole.CAPTAIN) { + throw new MemberSocialringException(CANNOT_CANCEL_BY_CAPTAIN); + } + + // 캡틴이 아닌경우 정상적으로 상태를 DELETE로 변경 + memberSocialring.setStatusToDelete(); + memberSocialringRepository.save(memberSocialring); + } + } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index fc45c65..0f93bb8 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -27,7 +27,6 @@ spring: kakao: client-id: ${CLIENT_ID} redirect-uri: http://43.202.94.241:8080/auth/kakao/callback - --- jwt: secret: ${JWT_SECRET}