From f19943ee8e32cc56cd020912b24fcc3c3880b658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=90=EB=AA=85=EC=A7=84?= Date: Fri, 2 Aug 2024 18:06:09 +0900 Subject: [PATCH 01/29] =?UTF-8?q?feat=20:=20=EB=A6=AC=EB=B7=B0=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/ReviewException.java | 7 +++++++ .../controller/ReviewController.java | 21 +++++++++++++++++++ .../likelion12/service/ReviewService.java | 18 ++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 src/main/java/com/example/likelion12/common/exception/ReviewException.java diff --git a/src/main/java/com/example/likelion12/common/exception/ReviewException.java b/src/main/java/com/example/likelion12/common/exception/ReviewException.java new file mode 100644 index 0000000..0d53893 --- /dev/null +++ b/src/main/java/com/example/likelion12/common/exception/ReviewException.java @@ -0,0 +1,7 @@ +package com.example.likelion12.common.exception; + +public class ReviewException extends RuntimeException { + public ReviewException(String message) { + super(message); + } +} diff --git a/src/main/java/com/example/likelion12/controller/ReviewController.java b/src/main/java/com/example/likelion12/controller/ReviewController.java index dc24029..5425f84 100644 --- a/src/main/java/com/example/likelion12/controller/ReviewController.java +++ b/src/main/java/com/example/likelion12/controller/ReviewController.java @@ -29,4 +29,25 @@ public BaseResponse createReview(@RequestHeader("Authorizati PostReviewResponse response = new PostReviewResponse(reviewId); return new BaseResponse<>(response); } + + @PatchMapping("/delete") + public BaseResponse deleteReview(@RequestHeader("Authorization") String authorization, + @RequestParam("review-id") Long reviewId) { + Long memberId = jwtProvider.extractIdFromHeader(authorization); + + + boolean isDeleted = reviewService.deleteReview(reviewId, memberId); + if (isDeleted) { + // 삭제 성공 시 응답 생성 + return new BaseResponse<>("리뷰를 성공적으로 삭제했습니다"); + } + else { + // 삭제 실패 시 응답 생성 + return new BaseResponse<>("리뷰가 삭제되지 않았습니다"); + } + + + + } + } diff --git a/src/main/java/com/example/likelion12/service/ReviewService.java b/src/main/java/com/example/likelion12/service/ReviewService.java index 4a4cead..a8595b9 100644 --- a/src/main/java/com/example/likelion12/service/ReviewService.java +++ b/src/main/java/com/example/likelion12/service/ReviewService.java @@ -1,6 +1,7 @@ package com.example.likelion12.service; import com.example.likelion12.common.exception.MemberException; +import com.example.likelion12.common.exception.ReviewException; import com.example.likelion12.domain.Facility; import com.example.likelion12.domain.Member; import com.example.likelion12.domain.Review; @@ -45,4 +46,21 @@ public Long createReview(Long facilityId, int ranking, String comment , Long mem return savedReview.getReviewId(); } + + @Transactional + public boolean deleteReview(Long reviewId, Long memberId) { + + Member member = memberRepository.findByMemberIdAndStatus(memberId, BaseStatus.ACTIVE) + .orElseThrow(()-> new MemberException(CANNOT_FOUND_MEMBER)); + + // 리뷰가 존재하는지 확인 + boolean reviewExists = reviewRepository.existsById(reviewId); + if (!reviewExists) { + throw new ReviewException("리뷰를 찾을 수 없습니다."); + } + + // 리뷰삭제 + reviewRepository.deleteById(reviewId); + return true; + } } From 816438041c2d2c24b48a31a6a58f5dfc85be033f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=90=EB=AA=85=EC=A7=84?= Date: Fri, 2 Aug 2024 19:40:32 +0900 Subject: [PATCH 02/29] =?UTF-8?q?feat=20:=20application.yml=20=EB=A1=9C?= =?UTF-8?q?=EC=BB=AC=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index fc45c65..aa84b1a 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -26,7 +26,7 @@ spring: registration: kakao: client-id: ${CLIENT_ID} - redirect-uri: http://43.202.94.241:8080/auth/kakao/callback + redirect-uri: http://localhost:8080/auth/kakao/callback --- jwt: From 5c8c2c9146c9d2f7fec31b97278be69391a59c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=90=EB=AA=85=EC=A7=84?= Date: Fri, 2 Aug 2024 19:56:00 +0900 Subject: [PATCH 03/29] =?UTF-8?q?Related=20to=20#26:=20=EC=9D=B4=EC=8A=88?= =?UTF-8?q?=20#26=EA=B3=BC=20=EA=B4=80=EB=A0=A8=EB=90=9C=20=EC=9E=91?= =?UTF-8?q?=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/likelion12/controller/ReviewController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/example/likelion12/controller/ReviewController.java b/src/main/java/com/example/likelion12/controller/ReviewController.java index 5425f84..fe40f77 100644 --- a/src/main/java/com/example/likelion12/controller/ReviewController.java +++ b/src/main/java/com/example/likelion12/controller/ReviewController.java @@ -28,6 +28,7 @@ public BaseResponse createReview(@RequestHeader("Authorizati memberId); PostReviewResponse response = new PostReviewResponse(reviewId); return new BaseResponse<>(response); + } @PatchMapping("/delete") From 57393e018564918cf854f82816450a3d83af7cce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=90=EB=AA=85=EC=A7=84?= Date: Fri, 2 Aug 2024 22:32:56 +0900 Subject: [PATCH 04/29] =?UTF-8?q?feat=20:=20update=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ReviewController.java | 12 ++++++++ .../com/example/likelion12/domain/Review.java | 8 ++++++ .../repository/ReviewRepository.java | 18 ++++++++---- .../likelion12/service/ReviewService.java | 28 +++++++++++++++++++ 4 files changed, 61 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/example/likelion12/controller/ReviewController.java b/src/main/java/com/example/likelion12/controller/ReviewController.java index fe40f77..16f2c6c 100644 --- a/src/main/java/com/example/likelion12/controller/ReviewController.java +++ b/src/main/java/com/example/likelion12/controller/ReviewController.java @@ -46,9 +46,21 @@ public BaseResponse deleteReview(@RequestHeader("Authorization") String // 삭제 실패 시 응답 생성 return new BaseResponse<>("리뷰가 삭제되지 않았습니다"); } + } + @PatchMapping + public BaseResponse updateReview(@RequestHeader("Authorization") String authorization, + @RequestParam("review-id") Long reviewId, + @RequestBody PostReviewRequest postReviewRequest) { + Long memberId = jwtProvider.extractIdFromHeader(authorization); + reviewService.updateReview(reviewId, + postReviewRequest.getFacilityId(), + postReviewRequest.getRanking(), + postReviewRequest.getComment(), + memberId); + return new BaseResponse<>("리뷰가 성공적으로 업데이트되었습니다"); } } diff --git a/src/main/java/com/example/likelion12/domain/Review.java b/src/main/java/com/example/likelion12/domain/Review.java index 84e5024..5cda297 100644 --- a/src/main/java/com/example/likelion12/domain/Review.java +++ b/src/main/java/com/example/likelion12/domain/Review.java @@ -48,4 +48,12 @@ public void setReview(Facility facility , int ranking, String comment , Member m this.comment = comment; this.member = member; } + + public void updateReview(Facility facility , int ranking, String comment ) + { + this.facility = facility; + this.ranking = ranking; + this.comment = comment; + } + } diff --git a/src/main/java/com/example/likelion12/repository/ReviewRepository.java b/src/main/java/com/example/likelion12/repository/ReviewRepository.java index 9cc06dd..5878919 100644 --- a/src/main/java/com/example/likelion12/repository/ReviewRepository.java +++ b/src/main/java/com/example/likelion12/repository/ReviewRepository.java @@ -1,7 +1,11 @@ package com.example.likelion12.repository; +import com.example.likelion12.domain.Facility; import com.example.likelion12.domain.Review; +import io.lettuce.core.dynamic.annotation.Param; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @Repository @@ -11,10 +15,14 @@ public interface ReviewRepository extends JpaRepository { // 기본적으로 JpaRepository의 save() 메서드를 사용하여 작성할 수 있습니다. // 예: reviewRepository.save(review); - // 리뷰 수정 - // 기본적으로 JpaRepository의 save() 메서드를 사용하여 수정할 수 있습니다. - // 예: reviewRepository.save(updatedReview); - - // 리뷰 삭제 + // 리뷰 삭제 -> 스프링에서 자동으로 구현해줌 void deleteById(Long reviewId); + + // 리뷰 수정 -> 기본적인 CRUD외에는 내가 직접 구현해야함 -> 쿼리로 수정하는 방식 선택 + @Modifying + @Query("UPDATE Review r SET r.ranking = :ranking, r.comment = :comment, r.facility = :facility WHERE r.id = :reviewId") + void updateReview(@Param("reviewId") Long reviewId, + @Param("ranking") int ranking, + @Param("comment") String comment, + @Param("facility") Facility facility); } diff --git a/src/main/java/com/example/likelion12/service/ReviewService.java b/src/main/java/com/example/likelion12/service/ReviewService.java index a8595b9..50b8a57 100644 --- a/src/main/java/com/example/likelion12/service/ReviewService.java +++ b/src/main/java/com/example/likelion12/service/ReviewService.java @@ -63,4 +63,32 @@ public boolean deleteReview(Long reviewId, Long memberId) { reviewRepository.deleteById(reviewId); return true; } + + @Transactional + public void updateReview(Long reviewId , Long facilityId, int ranking, String comment, Long memberId) { + + // review_id로 review찾고 + Review review = reviewRepository.findById(reviewId) + .orElseThrow(() -> new ReviewException("리뷰를 찾을 수 없습니다.")); + // memberId로 member 확인 + Member member = memberRepository.findByMemberIdAndStatus(memberId, BaseStatus.ACTIVE) + .orElseThrow(() -> new MemberException(CANNOT_FOUND_MEMBER)); + // facilityId로 facility 찾고 + Facility facility = facilityRepository.findById(facilityId) + .orElseThrow(() -> new IllegalArgumentException("Invalid facility ID")); + + // 리뷰가 작성한 member와 동일한지 확인 + //if (!review.getMember().equals(member)) { + // throw new ReviewException("리뷰를 수정할 권한이 없습니다."); + //} + + // 받은값들로 review 수정해서 + review.updateReview(facility, ranking, comment); + + // 레퍼지토리에 저장하고 + reviewRepository.updateReview(reviewId, ranking, comment , facility); + + // 성공Response 반환 + + } } From d41561084325b446399b862a053914b89797f03a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=90=EB=AA=85=EC=A7=84?= Date: Thu, 1 Aug 2024 18:35:20 +0900 Subject: [PATCH 05/29] inint --- .../example/likelion12/repository/MemberRepository.java | 7 +++++++ .../java/com/example/likelion12/service/MemberService.java | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/src/main/java/com/example/likelion12/repository/MemberRepository.java b/src/main/java/com/example/likelion12/repository/MemberRepository.java index bc3b2b5..90b4b8c 100644 --- a/src/main/java/com/example/likelion12/repository/MemberRepository.java +++ b/src/main/java/com/example/likelion12/repository/MemberRepository.java @@ -3,6 +3,8 @@ import com.example.likelion12.domain.Member; import com.example.likelion12.domain.base.BaseStatus; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import java.util.Optional; @@ -13,4 +15,9 @@ public interface MemberRepository extends JpaRepository { Optional findByEmailAndStatus(String email, BaseStatus status); Optional findByMemberIdAndStatus(Long memberId, BaseStatus status); boolean existsByEmailAndStatus(String email, BaseStatus status); + + @Modifying + @Query("Delete From Member m Where m.memberId = :memberId") + void deleteByMemberId(Long memberId); + } diff --git a/src/main/java/com/example/likelion12/service/MemberService.java b/src/main/java/com/example/likelion12/service/MemberService.java index c22b680..55dbc64 100644 --- a/src/main/java/com/example/likelion12/service/MemberService.java +++ b/src/main/java/com/example/likelion12/service/MemberService.java @@ -62,4 +62,8 @@ public PostSignupResponse signUp(PostSignupRequest postSignupRequest){ return new PostSignupResponse(member.getMemberId(), accessToken); } } + + /** + * 회원탈퇴 + */ } From 49efefb7107fd67d348793f055b32ede3ae3fcca Mon Sep 17 00:00:00 2001 From: hd0rable Date: Fri, 2 Aug 2024 23:59:58 +0900 Subject: [PATCH 06/29] =?UTF-8?q?feat=20:=20Member=20crew=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=ED=81=AC=EB=A3=A8=20=EC=82=AD=EC=A0=9C=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/response/status/BaseExceptionResponseStatus.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 2785144..86e57c9 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 @@ -43,7 +43,7 @@ public enum BaseExceptionResponseStatus implements ResponseStatus{ * 8000: membersocialring 관련 */ CANNOT_FOUND_MEMBERSOCIALRING(8000, HttpStatus.BAD_REQUEST.value(), "해당하는 멤버소셜링을 찾을 수 없습니다."), - CANNOT_MEMBERSOCIALRING_CAPTAIN(8001, HttpStatus.BAD_REQUEST.value(), "소셜링 수정,삭제에 접근할수없는 권한입니다."), + NOT_MEMBERSOCIALRING_CAPTAIN(8001, HttpStatus.BAD_REQUEST.value(), "소셜링 수정,삭제에 접근할수없는 권한입니다."), /** * 9000 : crew 관련 @@ -58,7 +58,9 @@ public enum BaseExceptionResponseStatus implements ResponseStatus{ */ CANNOT_FOUND_MEMBERCREW(10000, HttpStatus.BAD_REQUEST.value(), "멤버_크루를 찾을 수 없습니다."), CANNOT_FOUND_MEMBERCREW_LIST(10001, HttpStatus.BAD_REQUEST.value(), "멤버_크루 리스트를 찾을 수 없습니다."), - ALREADY_EXIST(10002, HttpStatus.BAD_REQUEST.value(), "이미 등록된 멤버입니다."); + ALREADY_EXIST(10002, HttpStatus.BAD_REQUEST.value(), "이미 등록된 멤버입니다."), + NOT_MEMBERCREW_CAPTAIN(10003, HttpStatus.BAD_REQUEST.value(), "크루 수정,삭제에 접근할수없는 권한입니다."), + NOT_CREW_MEMBERCREW(10004, HttpStatus.BAD_REQUEST.value(), "해당 크루에 참여 상태가 아닙니다."); From 11dd135e4e3cc9d109053d29c0f5a662e64f47a2 Mon Sep 17 00:00:00 2001 From: hd0rable Date: Sat, 3 Aug 2024 00:00:21 +0900 Subject: [PATCH 07/29] =?UTF-8?q?feat=20:=20CrewController.deleteCrew=20?= =?UTF-8?q?=ED=81=AC=EB=A3=A8=20=EC=82=AD=EC=A0=9C=20=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A1=A4=EB=9F=AC=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../likelion12/controller/CrewController.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/example/likelion12/controller/CrewController.java b/src/main/java/com/example/likelion12/controller/CrewController.java index 77f0cf3..bd1a138 100644 --- a/src/main/java/com/example/likelion12/controller/CrewController.java +++ b/src/main/java/com/example/likelion12/controller/CrewController.java @@ -53,4 +53,16 @@ public BaseResponse joinCrew(@RequestHeader("Authorization") String author return new BaseResponse<>(null); } + /** + * 크루 삭제하기 + */ + @PatchMapping("/delete") + public BaseResponse deleteCrew(@RequestHeader("Authorization") String authorization, + @RequestParam Long crewId){ + log.info("[CrewController.deleteCrew]"); + Long memberId = jwtProvider.extractIdFromHeader(authorization); + crewService.deleteCrew(memberId,crewId); + return new BaseResponse<>(null); + } + } From 72cf2a35f7ff1ed2f0c9b1f3e879d4cf172f23c4 Mon Sep 17 00:00:00 2001 From: hd0rable Date: Sat, 3 Aug 2024 00:01:40 +0900 Subject: [PATCH 08/29] =?UTF-8?q?feat=20:=20MemberCrewService.ConfirmCapta?= =?UTF-8?q?inMemberCrew=20=ED=81=AC=EB=A3=A8=EB=A5=BC=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20=EA=B6=8C=ED=95=9C=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80?= =?UTF-8?q?=EC=82=AC=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../likelion12/service/MemberCrewService.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/com/example/likelion12/service/MemberCrewService.java b/src/main/java/com/example/likelion12/service/MemberCrewService.java index 76ff42b..39c4e2e 100644 --- a/src/main/java/com/example/likelion12/service/MemberCrewService.java +++ b/src/main/java/com/example/likelion12/service/MemberCrewService.java @@ -1,5 +1,6 @@ package com.example.likelion12.service; +import com.example.likelion12.common.exception.MemberCrewException; import com.example.likelion12.domain.Crew; import com.example.likelion12.domain.Member; import com.example.likelion12.domain.MemberCrew; @@ -11,6 +12,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import static com.example.likelion12.common.response.status.BaseExceptionResponseStatus.NOT_MEMBERCREW_CAPTAIN; + @Slf4j @Service @RequiredArgsConstructor @@ -38,4 +41,15 @@ public void createMemberCrew(Member member, Crew crew){ MemberCrew memberCrew = new MemberCrew(BaseRole.CREW ,crew,member, BaseStatus.ACTIVE); memberCrewRepository.save(memberCrew); } + + /** + * 크루 수정,삭제 시 접근하는 member가 CAPTAIN 인지 확인 + */ + public void ConfirmCaptainMemberCrew(MemberCrew memberCrew) { + log.info("[MemberCrewService.ConfirmCaptainMemberCrew]"); + + if (!BaseRole.CAPTAIN.equals(memberCrew.getRole())) { + throw new MemberCrewException(NOT_MEMBERCREW_CAPTAIN); + } + } } From 216440010e3d5a818bbb70f5ac2cc54ec31704b6 Mon Sep 17 00:00:00 2001 From: hd0rable Date: Sat, 3 Aug 2024 00:02:18 +0900 Subject: [PATCH 09/29] =?UTF-8?q?refator=20:=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/likelion12/service/MemberSocialringService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/likelion12/service/MemberSocialringService.java b/src/main/java/com/example/likelion12/service/MemberSocialringService.java index 645ba19..ebd88b7 100644 --- a/src/main/java/com/example/likelion12/service/MemberSocialringService.java +++ b/src/main/java/com/example/likelion12/service/MemberSocialringService.java @@ -10,7 +10,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.example.likelion12.common.response.status.BaseExceptionResponseStatus.CANNOT_MEMBERSOCIALRING_CAPTAIN; +import static com.example.likelion12.common.response.status.BaseExceptionResponseStatus.NOT_MEMBERSOCIALRING_CAPTAIN; @Slf4j @Service @@ -37,7 +37,7 @@ public void ConfirmCaptainMemberSocialring(MemberSocialring memberSocialring){ log.info("[MemberSocialringService.ConfirmCaptainMemberSocialring]"); if (!BaseRole.CAPTAIN.equals(memberSocialring.getRole())) { - throw new MemberSocialringException(CANNOT_MEMBERSOCIALRING_CAPTAIN); + throw new MemberSocialringException(NOT_MEMBERSOCIALRING_CAPTAIN); } } From 4f488c439e29befdd4fa7c76fc4a65846b8f8458 Mon Sep 17 00:00:00 2001 From: hd0rable Date: Sat, 3 Aug 2024 00:02:58 +0900 Subject: [PATCH 10/29] =?UTF-8?q?feat=20:=20CrewService.deleteCrew=20?= =?UTF-8?q?=ED=81=AC=EB=A3=A8=20=EC=82=AD=EC=A0=9C=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../likelion12/service/CrewService.java | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/likelion12/service/CrewService.java b/src/main/java/com/example/likelion12/service/CrewService.java index aeedf57..c1931e6 100644 --- a/src/main/java/com/example/likelion12/service/CrewService.java +++ b/src/main/java/com/example/likelion12/service/CrewService.java @@ -4,7 +4,6 @@ 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.crew.GetCrewDetailResponse; import com.example.likelion12.dto.crew.PostCrewRequest; @@ -13,7 +12,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Pageable; -import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -151,4 +149,38 @@ public void joinCrew(Long memberId, Long crewId){ throw new CrewException(ALREADY_FULL_CREW); } } + + /** + * 크루 삭제하기 + */ + @Transactional + public void deleteCrew(Long memberId, Long crewId) { + log.info("[CrewService.deleteCrew]"); + + // 크루를 삭제하고자 하는 member + Member member = memberRepository.findByMemberIdAndStatus(memberId, BaseStatus.ACTIVE) + .orElseThrow(()-> new MemberException(CANNOT_FOUND_MEMBER)); + + //삭제하고자 하는 크루 + Crew crew = crewRepository.findByCrewIdAndStatus(crewId, BaseStatus.ACTIVE) + .orElseThrow(()->new CrewException(CANNOT_FOUND_CREW)); + + //삭제하고자 하는 크루의 멤버크루 + //해당크루와 관계없음(해당크루에 등록되있지 않음), 멤버크루가 존재하지않음 + MemberCrew memberCrew = memberCrewRepository.findByMember_MemberIdAndCrew_CrewIdAndStatus( memberId, crewId, BaseStatus.ACTIVE) + .orElseThrow(()->new MemberCrewException(NOT_CREW_MEMBERCREW)); + + //멤버가 CAPTAIN 권한인지 유효성 검사 + memberCrewService.ConfirmCaptainMemberCrew(memberCrew); + + //삭제하고자 하는 크루의 멤버크루리스트 + List memberCrewList = memberCrewRepository.findByCrew_CrewIdAndStatus(crewId, BaseStatus.ACTIVE) + .orElseThrow(()->new MemberCrewException(CANNOT_FOUND_MEMBERCREW_LIST)); + + // 멤버 크루리스트 삭제 + memberCrewList.forEach(mc -> memberCrewRepository.delete(mc)); + + //크루 삭제 + crewRepository.delete(crew); + } } From 7b9fc58a70cffd09cdcd70174a935af96846e7e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=90=EB=AA=85=EC=A7=84?= Date: Sat, 3 Aug 2024 00:32:56 +0900 Subject: [PATCH 11/29] =?UTF-8?q?feat=20:=20=ED=9A=8C=EC=9B=90=ED=83=88?= =?UTF-8?q?=ED=87=B4=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberController.java | 14 ++++++++++---- .../com/example/likelion12/domain/Member.java | 4 ++++ .../likelion12/service/MemberService.java | 19 +++++++++++++++++++ .../likelion12/service/TokenService.java | 4 ++-- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/example/likelion12/controller/MemberController.java b/src/main/java/com/example/likelion12/controller/MemberController.java index 867f65c..7ceb43c 100644 --- a/src/main/java/com/example/likelion12/controller/MemberController.java +++ b/src/main/java/com/example/likelion12/controller/MemberController.java @@ -4,12 +4,10 @@ import com.example.likelion12.dto.member.PostSignupRequest; import com.example.likelion12.dto.member.PostSignupResponse; import com.example.likelion12.service.MemberService; +import com.example.likelion12.util.JwtProvider; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @Slf4j @RestController @@ -18,10 +16,18 @@ public class MemberController { private final MemberService memberService; + private final JwtProvider jwtProvider; @PostMapping("/signup") public BaseResponse signUp(@RequestBody PostSignupRequest postSignupRequest){ log.info("[MemberController.signUp]"); return new BaseResponse<>(memberService.signUp(postSignupRequest)); } + + @PatchMapping("/signout") + public BaseResponse signOut(@RequestHeader("Authorization") String authorization){ + Long memberId = jwtProvider.extractIdFromHeader(authorization); + memberService.signOut(memberId); + return new BaseResponse<>("회원탈퇴 되었습니다"); + } } diff --git a/src/main/java/com/example/likelion12/domain/Member.java b/src/main/java/com/example/likelion12/domain/Member.java index 26a1878..5efbd3e 100644 --- a/src/main/java/com/example/likelion12/domain/Member.java +++ b/src/main/java/com/example/likelion12/domain/Member.java @@ -67,4 +67,8 @@ public Member(String memberName, String email, String memberImg, BaseGender gend this.status = status; this.exercise = exercise; } + + public void setStatus(BaseStatus status) { + this.status = status; + } } diff --git a/src/main/java/com/example/likelion12/service/MemberService.java b/src/main/java/com/example/likelion12/service/MemberService.java index 55dbc64..15e936e 100644 --- a/src/main/java/com/example/likelion12/service/MemberService.java +++ b/src/main/java/com/example/likelion12/service/MemberService.java @@ -66,4 +66,23 @@ public PostSignupResponse signUp(PostSignupRequest postSignupRequest){ /** * 회원탈퇴 */ + @Transactional + public Long signOut(Long memberId) { + log.info("[MemberService.deleteMember] memberId: {}", memberId); + + // 회원을 찾고 + Member member = memberRepository.findById(memberId).orElse(null); + + // 회원 상태를 Delete 변경하고 + member.setStatus(BaseStatus.DELETE); + memberRepository.save(member); + + // 토큰 무효화 + tokenService.invalidateToken(memberId); + + log.info("[MemberService.deleteMember] 회원 탈퇴 완료: {}", memberId); + + return memberId; + } + } diff --git a/src/main/java/com/example/likelion12/service/TokenService.java b/src/main/java/com/example/likelion12/service/TokenService.java index 86e9862..c485f46 100644 --- a/src/main/java/com/example/likelion12/service/TokenService.java +++ b/src/main/java/com/example/likelion12/service/TokenService.java @@ -29,8 +29,8 @@ public boolean checkTokenExists(String token) { return result != null && result; } - public void invalidateToken(String githubId) { + public void invalidateToken(Long memberId) { // redis 에서 토큰 삭제 - redisTemplate.delete(githubId); + redisTemplate.delete(String.valueOf(memberId)); } } From ce45e79cc0972924f674f14bebc67c52de8b1fbb Mon Sep 17 00:00:00 2001 From: hd0rable Date: Sat, 3 Aug 2024 01:20:59 +0900 Subject: [PATCH 12/29] =?UTF-8?q?feat=20:=20CrewController.deleteCrew=20?= =?UTF-8?q?=ED=81=AC=EB=A3=A8=20=ED=83=88=ED=87=B4=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../likelion12/controller/CrewController.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/example/likelion12/controller/CrewController.java b/src/main/java/com/example/likelion12/controller/CrewController.java index bd1a138..6eaf155 100644 --- a/src/main/java/com/example/likelion12/controller/CrewController.java +++ b/src/main/java/com/example/likelion12/controller/CrewController.java @@ -65,4 +65,16 @@ public BaseResponse deleteCrew(@RequestHeader("Authorization") String auth return new BaseResponse<>(null); } + /** + * 크루 탈퇴하기 + */ + @PatchMapping("/cancel") + public BaseResponse cancelCrew(@RequestHeader("Authorization") String authorization, + @RequestParam Long crewId){ + log.info("[CrewController.deleteCrew]"); + Long memberId = jwtProvider.extractIdFromHeader(authorization); + crewService.cancelCrew(memberId,crewId); + return new BaseResponse<>(null); + } + } From 79bda3ebd3fbebc411a5811856c5c7fb0eb8b7b7 Mon Sep 17 00:00:00 2001 From: hd0rable Date: Sat, 3 Aug 2024 01:21:25 +0900 Subject: [PATCH 13/29] =?UTF-8?q?feat=20:=20CrewService.cancelCrew=20?= =?UTF-8?q?=ED=81=AC=EB=A3=A8=20=ED=83=88=ED=87=B4=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EC=9E=91=EC=84=B1=20=EC=A4=91..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../likelion12/service/CrewService.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/java/com/example/likelion12/service/CrewService.java b/src/main/java/com/example/likelion12/service/CrewService.java index c1931e6..5ece7d8 100644 --- a/src/main/java/com/example/likelion12/service/CrewService.java +++ b/src/main/java/com/example/likelion12/service/CrewService.java @@ -183,4 +183,32 @@ public void deleteCrew(Long memberId, Long crewId) { //크루 삭제 crewRepository.delete(crew); } + + /** + * 크루 탈퇴하기 + */ + @Transactional + public void cancelCrew(Long memberId, Long crewId) { + log.info("[CrewService.cancelCrew]"); + + // 크루를 탈퇴하고자 하는 member + Member member = memberRepository.findByMemberIdAndStatus(memberId, BaseStatus.ACTIVE) + .orElseThrow(()-> new MemberException(CANNOT_FOUND_MEMBER)); + + //탈퇴하고자 하는 크루 + Crew crew = crewRepository.findByCrewIdAndStatus(crewId, BaseStatus.ACTIVE) + .orElseThrow(()->new CrewException(CANNOT_FOUND_CREW)); + + //탈퇴하고자 하는 크루의 멤버크루 + //해당크루와 관계없음(해당크루에 등록되있지 않음), 멤버크루가 존재하지않음 + MemberCrew memberCrew = memberCrewRepository.findByMember_MemberIdAndCrew_CrewIdAndStatus( memberId, crewId, BaseStatus.ACTIVE) + .orElseThrow(()->new MemberCrewException(NOT_CREW_MEMBERCREW)); + + //CAPTAIN일 경우 크루 삭제 + if(memberCrewService.ConfirmCaptainMemberCrew(memberCrew)) + deleteCrew(memberId,crewId); + else //크루 탈퇴 + memberCrewRepository.delete(memberCrew); + + } } From 79f760f2f1037aca663330df6bd6773b46e62675 Mon Sep 17 00:00:00 2001 From: hd0rable Date: Sat, 3 Aug 2024 01:21:46 +0900 Subject: [PATCH 14/29] =?UTF-8?q?fix=20:=20ConfirmCaptainMemberCrew=20bool?= =?UTF-8?q?ean=20=EA=B0=92=20=EB=B0=98=ED=99=98=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/likelion12/service/MemberCrewService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/likelion12/service/MemberCrewService.java b/src/main/java/com/example/likelion12/service/MemberCrewService.java index 39c4e2e..3c7c31d 100644 --- a/src/main/java/com/example/likelion12/service/MemberCrewService.java +++ b/src/main/java/com/example/likelion12/service/MemberCrewService.java @@ -43,13 +43,14 @@ public void createMemberCrew(Member member, Crew crew){ } /** - * 크루 수정,삭제 시 접근하는 member가 CAPTAIN 인지 확인 + * 크루 수정,삭제 시 접근하는 member가 CAPTAIN 인지 확인 */ - public void ConfirmCaptainMemberCrew(MemberCrew memberCrew) { + public boolean ConfirmCaptainMemberCrew(MemberCrew memberCrew) { log.info("[MemberCrewService.ConfirmCaptainMemberCrew]"); if (!BaseRole.CAPTAIN.equals(memberCrew.getRole())) { throw new MemberCrewException(NOT_MEMBERCREW_CAPTAIN); } + return true; } } From 1b3caf530c113bc64c5519f43923d751a26c7fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=90=EB=AA=85=EC=A7=84?= Date: Sat, 3 Aug 2024 03:15:19 +0900 Subject: [PATCH 15/29] =?UTF-8?q?feat=20:=20ReviewException,=20ReviewExcep?= =?UTF-8?q?tionControllerAdvice=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/ReviewException.java | 16 +++++++++++-- .../ReviewExceptionControllerAdvice.java | 23 +++++++++++++++++++ .../status/BaseExceptionResponseStatus.java | 7 +++++- .../likelion12/service/ReviewService.java | 3 ++- 4 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/example/likelion12/common/exception_handler/ReviewExceptionControllerAdvice.java diff --git a/src/main/java/com/example/likelion12/common/exception/ReviewException.java b/src/main/java/com/example/likelion12/common/exception/ReviewException.java index 0d53893..041324c 100644 --- a/src/main/java/com/example/likelion12/common/exception/ReviewException.java +++ b/src/main/java/com/example/likelion12/common/exception/ReviewException.java @@ -1,7 +1,19 @@ package com.example.likelion12.common.exception; -public class ReviewException extends RuntimeException { - public ReviewException(String message) { +import com.example.likelion12.common.response.status.ResponseStatus; +import lombok.Getter; + +@Getter +public class ReviewException extends RuntimeException{ + private final ResponseStatus exceptionStatus; + + public ReviewException(ResponseStatus exceptionStatus) { + super(exceptionStatus.getMessage()); + this.exceptionStatus = exceptionStatus; + } + + public ReviewException(ResponseStatus exceptionStatus, String message) { super(message); + this.exceptionStatus = exceptionStatus; } } diff --git a/src/main/java/com/example/likelion12/common/exception_handler/ReviewExceptionControllerAdvice.java b/src/main/java/com/example/likelion12/common/exception_handler/ReviewExceptionControllerAdvice.java new file mode 100644 index 0000000..e50ed26 --- /dev/null +++ b/src/main/java/com/example/likelion12/common/exception_handler/ReviewExceptionControllerAdvice.java @@ -0,0 +1,23 @@ +package com.example.likelion12.common.exception_handler; + +import com.example.likelion12.common.exception.MemberCrewException; +import com.example.likelion12.common.exception.ReviewException; +import com.example.likelion12.common.response.BaseErrorResponse; +import jakarta.annotation.Priority; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@Slf4j +@Priority(0) +@RestControllerAdvice +public class ReviewExceptionControllerAdvice { + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(ReviewException.class) + public BaseErrorResponse handle_ReviewException(ReviewException e) { + log.error("[handle_ReviewException]", e); + return new BaseErrorResponse(e.getExceptionStatus(), e.getMessage()); + } +} 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 2785144..6a7dd56 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 @@ -58,7 +58,12 @@ public enum BaseExceptionResponseStatus implements ResponseStatus{ */ CANNOT_FOUND_MEMBERCREW(10000, HttpStatus.BAD_REQUEST.value(), "멤버_크루를 찾을 수 없습니다."), CANNOT_FOUND_MEMBERCREW_LIST(10001, HttpStatus.BAD_REQUEST.value(), "멤버_크루 리스트를 찾을 수 없습니다."), - ALREADY_EXIST(10002, HttpStatus.BAD_REQUEST.value(), "이미 등록된 멤버입니다."); + ALREADY_EXIST(10002, HttpStatus.BAD_REQUEST.value(), "이미 등록된 멤버입니다."), + + /** + * 11000 : Review 관련 + */ + CANNOT_FOUND_REVIEW(11000, HttpStatus.BAD_REQUEST.value(), "리뷰를 찾을 수 없습니다."); diff --git a/src/main/java/com/example/likelion12/service/ReviewService.java b/src/main/java/com/example/likelion12/service/ReviewService.java index a8595b9..d7c2adb 100644 --- a/src/main/java/com/example/likelion12/service/ReviewService.java +++ b/src/main/java/com/example/likelion12/service/ReviewService.java @@ -14,6 +14,7 @@ import org.springframework.stereotype.Service; import static com.example.likelion12.common.response.status.BaseExceptionResponseStatus.CANNOT_FOUND_MEMBER; +import static com.example.likelion12.common.response.status.BaseExceptionResponseStatus.CANNOT_FOUND_REVIEW; @Service public class ReviewService { @@ -56,7 +57,7 @@ public boolean deleteReview(Long reviewId, Long memberId) { // 리뷰가 존재하는지 확인 boolean reviewExists = reviewRepository.existsById(reviewId); if (!reviewExists) { - throw new ReviewException("리뷰를 찾을 수 없습니다."); + throw new ReviewException(CANNOT_FOUND_REVIEW); } // 리뷰삭제 From 89f90578fb383950c4a68d282cfd1d4355a03bee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=90=EB=AA=85=EC=A7=84?= Date: Sat, 3 Aug 2024 03:24:04 +0900 Subject: [PATCH 16/29] =?UTF-8?q?[=EB=A6=AC=EB=B7=B0=EC=9E=91=EC=84=B1]=20?= =?UTF-8?q?fix=20:=20=EC=9E=98=EB=AA=BB=EB=90=9C=20facility=5Fid=EB=A1=9C?= =?UTF-8?q?=20=EC=9A=94=EC=B2=AD=EC=8B=9C=20=20403=EC=97=90=EB=9F=AC=20->?= =?UTF-8?q?=20=EC=98=88=EC=99=B8=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/likelion12/service/ReviewService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/likelion12/service/ReviewService.java b/src/main/java/com/example/likelion12/service/ReviewService.java index d7c2adb..58f725c 100644 --- a/src/main/java/com/example/likelion12/service/ReviewService.java +++ b/src/main/java/com/example/likelion12/service/ReviewService.java @@ -1,5 +1,6 @@ package com.example.likelion12.service; +import com.example.likelion12.common.exception.FacilityException; import com.example.likelion12.common.exception.MemberException; import com.example.likelion12.common.exception.ReviewException; import com.example.likelion12.domain.Facility; @@ -13,8 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import static com.example.likelion12.common.response.status.BaseExceptionResponseStatus.CANNOT_FOUND_MEMBER; -import static com.example.likelion12.common.response.status.BaseExceptionResponseStatus.CANNOT_FOUND_REVIEW; +import static com.example.likelion12.common.response.status.BaseExceptionResponseStatus.*; @Service public class ReviewService { @@ -36,7 +36,7 @@ public Long createReview(Long facilityId, int ranking, String comment , Long mem // facilityId로 facility 찾고 Facility facility = facilityRepository.findById(facilityId) - .orElseThrow(() -> new IllegalArgumentException("Invalid facility ID")); + .orElseThrow(() -> new FacilityException(CANOOT_FOUND_FACILITY)); //리뷰에 받아온 값들 넣고 Review review = new Review(); From bc853d46a689dd6502ddead8bef3b1949ee74953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=90=EB=AA=85=EC=A7=84?= Date: Sat, 3 Aug 2024 03:55:37 +0900 Subject: [PATCH 17/29] =?UTF-8?q?[=EB=A6=AC=EB=B7=B0=EC=9E=91=EC=84=B1]=20?= =?UTF-8?q?fix=20:=20=EA=B0=99=EC=9D=80=EB=A9=A4=EB=B2=84=EA=B0=80=20?= =?UTF-8?q?=EA=B0=99=EC=9D=80=20=EC=B2=B4=EC=9C=A1=EA=B4=80=EC=97=90=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=EB=A5=BC=20=EC=9E=91=EC=84=B1=ED=95=98?= =?UTF-8?q?=EB=A9=B4=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20=ED=9B=84=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=EC=9C=BC=EB=A1=9C=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=95=88=EB=82=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/response/status/BaseExceptionResponseStatus.java | 4 +++- src/main/java/com/example/likelion12/domain/Facility.java | 2 +- src/main/java/com/example/likelion12/domain/Review.java | 2 +- .../com/example/likelion12/repository/ReviewRepository.java | 5 +++++ .../java/com/example/likelion12/service/ReviewService.java | 5 +++++ 5 files changed, 15 insertions(+), 3 deletions(-) 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 6a7dd56..4c20aa5 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 @@ -63,7 +63,9 @@ public enum BaseExceptionResponseStatus implements ResponseStatus{ /** * 11000 : Review 관련 */ - CANNOT_FOUND_REVIEW(11000, HttpStatus.BAD_REQUEST.value(), "리뷰를 찾을 수 없습니다."); + CANNOT_FOUND_REVIEW(11000, HttpStatus.BAD_REQUEST.value(), "리뷰를 찾을 수 없습니다."), + ALREADY_EXIST_REVIEW(11001, HttpStatus.BAD_REQUEST.value(), "이미 등록한 리뷰가 있습니다. 수정으로 작성해주세요"); + diff --git a/src/main/java/com/example/likelion12/domain/Facility.java b/src/main/java/com/example/likelion12/domain/Facility.java index ae45590..20cf1f1 100644 --- a/src/main/java/com/example/likelion12/domain/Facility.java +++ b/src/main/java/com/example/likelion12/domain/Facility.java @@ -24,7 +24,7 @@ public class Facility extends BaseTime { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "facility_id", nullable = false) - private long facilityId; + private Long facilityId; @Column(nullable = false) private String facilityName; diff --git a/src/main/java/com/example/likelion12/domain/Review.java b/src/main/java/com/example/likelion12/domain/Review.java index 84e5024..0c1929f 100644 --- a/src/main/java/com/example/likelion12/domain/Review.java +++ b/src/main/java/com/example/likelion12/domain/Review.java @@ -19,7 +19,7 @@ public class Review extends BaseTime { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "review_id", nullable = false) - private long reviewId; + private Long reviewId; @Column(nullable = false) private String comment; diff --git a/src/main/java/com/example/likelion12/repository/ReviewRepository.java b/src/main/java/com/example/likelion12/repository/ReviewRepository.java index 9cc06dd..14b55bf 100644 --- a/src/main/java/com/example/likelion12/repository/ReviewRepository.java +++ b/src/main/java/com/example/likelion12/repository/ReviewRepository.java @@ -1,5 +1,7 @@ package com.example.likelion12.repository; +import com.example.likelion12.domain.Facility; +import com.example.likelion12.domain.Member; import com.example.likelion12.domain.Review; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -17,4 +19,7 @@ public interface ReviewRepository extends JpaRepository { // 리뷰 삭제 void deleteById(Long reviewId); + + // 중복 검사 + boolean existsByMemberAndFacility(Member member, Facility facility); } diff --git a/src/main/java/com/example/likelion12/service/ReviewService.java b/src/main/java/com/example/likelion12/service/ReviewService.java index 58f725c..b227660 100644 --- a/src/main/java/com/example/likelion12/service/ReviewService.java +++ b/src/main/java/com/example/likelion12/service/ReviewService.java @@ -38,6 +38,11 @@ public Long createReview(Long facilityId, int ranking, String comment , Long mem Facility facility = facilityRepository.findById(facilityId) .orElseThrow(() -> new FacilityException(CANOOT_FOUND_FACILITY)); + // 이미 같은 멤버가 같은 체육관에 리뷰를 작성하면 예외를 발생시키고 + if (reviewRepository.existsByMemberAndFacility(member, facility)) { + throw new ReviewException(ALREADY_EXIST_REVIEW); + } + //리뷰에 받아온 값들 넣고 Review review = new Review(); review.setReview(facility, ranking, comment, member); From 232d5f8546cb08faed8f1d5f77a132982a576dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=90=EB=AA=85=EC=A7=84?= Date: Sat, 3 Aug 2024 04:29:32 +0900 Subject: [PATCH 18/29] =?UTF-8?q?[=EB=A6=AC=EB=B7=B0=EC=9E=91=EC=84=B1]=20?= =?UTF-8?q?fix=20:=20=EB=A6=AC=EB=B7=B0=EC=A0=90=EC=88=98=EA=B0=80=201~5?= =?UTF-8?q?=EC=A0=90=EC=9C=BC=EB=A1=9C=20=ED=95=9C=EC=A0=95=EB=90=A8.=20?= =?UTF-8?q?=EA=B7=B8=20=EC=9D=B4=EC=83=81=20=EC=9D=B4=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/status/BaseExceptionResponseStatus.java | 4 ++-- src/main/java/com/example/likelion12/domain/Review.java | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) 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 4c20aa5..40d6087 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 @@ -64,8 +64,8 @@ public enum BaseExceptionResponseStatus implements ResponseStatus{ * 11000 : Review 관련 */ CANNOT_FOUND_REVIEW(11000, HttpStatus.BAD_REQUEST.value(), "리뷰를 찾을 수 없습니다."), - ALREADY_EXIST_REVIEW(11001, HttpStatus.BAD_REQUEST.value(), "이미 등록한 리뷰가 있습니다. 수정으로 작성해주세요"); - + ALREADY_EXIST_REVIEW(11001, HttpStatus.BAD_REQUEST.value(), "이미 등록한 리뷰가 있습니다. 수정으로 작성해주세요"), + CANNOT_SET_SCORE(11002, HttpStatus.BAD_REQUEST.value(), "점수가 너무 높거나 낮습니다. 1~5점으로 평가해주세요"); // 추가된 상수 diff --git a/src/main/java/com/example/likelion12/domain/Review.java b/src/main/java/com/example/likelion12/domain/Review.java index 0c1929f..be27afe 100644 --- a/src/main/java/com/example/likelion12/domain/Review.java +++ b/src/main/java/com/example/likelion12/domain/Review.java @@ -1,5 +1,6 @@ package com.example.likelion12.domain; +import com.example.likelion12.common.exception.ReviewException; import com.example.likelion12.domain.base.BaseStatus; import com.example.likelion12.domain.base.BaseTime; import jakarta.persistence.*; @@ -8,6 +9,7 @@ import lombok.NoArgsConstructor; import lombok.Setter; +import static com.example.likelion12.common.response.status.BaseExceptionResponseStatus.CANNOT_SET_SCORE; import static jakarta.persistence.FetchType.LAZY; @Entity @@ -43,6 +45,11 @@ public class Review extends BaseTime { public void setReview(Facility facility , int ranking, String comment , Member member) { + // 리뷰 점수 1~5 로 한정하기위해 검증하는 함수 + if (ranking < 1 || ranking > 5) { + throw new ReviewException(CANNOT_SET_SCORE); + } + this.facility = facility; this.ranking = ranking; this.comment = comment; From 38ab843ec39c14ef53fff518c0d886cdcb2a2738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=90=EB=AA=85=EC=A7=84?= Date: Sat, 3 Aug 2024 04:45:52 +0900 Subject: [PATCH 19/29] =?UTF-8?q?fix=20:=20=EB=A6=AC=EB=B7=B0=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=EC=8B=9C=20DB=EC=82=AD=EC=A0=9C=20->=20DB=20=EC=9C=A0?= =?UTF-8?q?=EC=A7=80,state=EB=A7=8C=20delete=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/likelion12/domain/Review.java | 4 ++++ .../com/example/likelion12/service/ReviewService.java | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/likelion12/domain/Review.java b/src/main/java/com/example/likelion12/domain/Review.java index be27afe..0ace6b6 100644 --- a/src/main/java/com/example/likelion12/domain/Review.java +++ b/src/main/java/com/example/likelion12/domain/Review.java @@ -55,4 +55,8 @@ public void setReview(Facility facility , int ranking, String comment , Member m this.comment = comment; this.member = member; } + + public void setStatus(BaseStatus status) { + this.status = status; + } } diff --git a/src/main/java/com/example/likelion12/service/ReviewService.java b/src/main/java/com/example/likelion12/service/ReviewService.java index b227660..dc4dd1a 100644 --- a/src/main/java/com/example/likelion12/service/ReviewService.java +++ b/src/main/java/com/example/likelion12/service/ReviewService.java @@ -15,6 +15,7 @@ import org.springframework.stereotype.Service; import static com.example.likelion12.common.response.status.BaseExceptionResponseStatus.*; +import static com.example.likelion12.domain.base.BaseStatus.DELETE; @Service public class ReviewService { @@ -65,8 +66,13 @@ public boolean deleteReview(Long reviewId, Long memberId) { throw new ReviewException(CANNOT_FOUND_REVIEW); } - // 리뷰삭제 - reviewRepository.deleteById(reviewId); + //리뷰id로 리뷰 찾고 + Review review = reviewRepository.findById(reviewId) + .orElseThrow(() -> new ReviewException(CANNOT_FOUND_REVIEW)); + + // 찾은 리뷰의 상태를 Delete로 변경하고 + review.setStatus(DELETE); + return true; } } From c0c7f6872d618ecb46e1f8eeceb9565ed0c21d67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=90=EB=AA=85=EC=A7=84?= Date: Sat, 3 Aug 2024 11:51:30 +0900 Subject: [PATCH 20/29] =?UTF-8?q?fix=20:=20null=EA=B0=92=EC=9D=B4=20?= =?UTF-8?q?=EB=93=A4=EC=96=B4=EC=98=A4=EB=A9=B4=20=EA=B8=B0=EC=A1=B4?= =?UTF-8?q?=EC=9D=98=20=EA=B0=92=EC=9D=84=20=EC=9C=A0=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../status/BaseExceptionResponseStatus.java | 2 +- .../com/example/likelion12/domain/Review.java | 22 ++++++++++++++++- .../repository/ReviewRepository.java | 6 ++++- .../likelion12/service/ReviewService.java | 24 ++++++++++++------- 4 files changed, 43 insertions(+), 11 deletions(-) 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 6280f7d..4033fe0 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 @@ -61,7 +61,7 @@ public enum BaseExceptionResponseStatus implements ResponseStatus{ */ CANNOT_FOUND_MEMBERCREW(10000, HttpStatus.BAD_REQUEST.value(), "멤버_크루를 찾을 수 없습니다."), CANNOT_FOUND_MEMBERCREW_LIST(10001, HttpStatus.BAD_REQUEST.value(), "멤버_크루 리스트를 찾을 수 없습니다."), - ALREADY_EXIST_IN_CREW(10002, HttpStatus.BAD_REQUEST.value(), "해당 크루에 이미 등록된 멤버입니다."); + ALREADY_EXIST_IN_CREW(10002, HttpStatus.BAD_REQUEST.value(), "해당 크루에 이미 등록된 멤버입니다."), /** * 11000 : Review 관련 diff --git a/src/main/java/com/example/likelion12/domain/Review.java b/src/main/java/com/example/likelion12/domain/Review.java index c4394d8..06407cc 100644 --- a/src/main/java/com/example/likelion12/domain/Review.java +++ b/src/main/java/com/example/likelion12/domain/Review.java @@ -63,8 +63,28 @@ public void updateReview(Facility facility , int ranking, String comment ) this.comment = comment; } - public void setStatus(BaseStatus status) { this.status = status; } + + public void setRanking(Integer ranking) { + if (ranking != null) { + // 랭킹이 1~5 범위에 있어야 함 + if (ranking < 1 || ranking > 5) { + throw new ReviewException(CANNOT_SET_SCORE); + } + this.ranking = ranking; + } + // ranking이 null인 경우, 기존 값을 그대로 유지합니다. + } + + // 코멘트 설정 메서드 + public void setComment(String comment) { + this.comment = comment != null ? comment : this.comment; // 기존 값 유지 + } + + // 시설 설정 메서드 + public void setFacility(Facility facility) { + this.facility = facility != null ? facility : this.facility; // 기존 값 유지 + } } diff --git a/src/main/java/com/example/likelion12/repository/ReviewRepository.java b/src/main/java/com/example/likelion12/repository/ReviewRepository.java index e4811a5..e1a8a64 100644 --- a/src/main/java/com/example/likelion12/repository/ReviewRepository.java +++ b/src/main/java/com/example/likelion12/repository/ReviewRepository.java @@ -16,7 +16,11 @@ public interface ReviewRepository extends JpaRepository { // 기본적으로 JpaRepository의 save() 메서드를 사용하여 작성할 수 있습니다. // 예: reviewRepository.save(review); - // 리뷰 삭제 -> 스프링에서 자동으로 구현해줌 + // 리뷰 수정 + // 기본적으로 JpaRepository의 save() 메서드를 사용하여 수정할 수 있습니다. + // 예: reviewRepository.save(updatedReview); + + // 리뷰 삭제 void deleteById(Long reviewId); // 리뷰 수정 -> 기본적인 CRUD외에는 내가 직접 구현해야함 -> 쿼리로 수정하는 방식 선택 diff --git a/src/main/java/com/example/likelion12/service/ReviewService.java b/src/main/java/com/example/likelion12/service/ReviewService.java index 014f8d8..9b3254d 100644 --- a/src/main/java/com/example/likelion12/service/ReviewService.java +++ b/src/main/java/com/example/likelion12/service/ReviewService.java @@ -77,30 +77,38 @@ public boolean deleteReview(Long reviewId, Long memberId) { } @Transactional - public void updateReview(Long reviewId , Long facilityId, int ranking, String comment, Long memberId) { + public void updateReview(Long reviewId , Long facilityId, Integer ranking , String comment, Long memberId) { // review_id로 review찾고 Review review = reviewRepository.findById(reviewId) - .orElseThrow(() -> new ReviewException("리뷰를 찾을 수 없습니다.")); + .orElseThrow(() -> new ReviewException(CANNOT_FOUND_REVIEW)); // memberId로 member 확인 Member member = memberRepository.findByMemberIdAndStatus(memberId, BaseStatus.ACTIVE) .orElseThrow(() -> new MemberException(CANNOT_FOUND_MEMBER)); // facilityId로 facility 찾고 Facility facility = facilityRepository.findById(facilityId) - .orElseThrow(() -> new IllegalArgumentException("Invalid facility ID")); + .orElseThrow(() -> new FacilityException(CANOOT_FOUND_FACILITY)); // 리뷰가 작성한 member와 동일한지 확인 //if (!review.getMember().equals(member)) { // throw new ReviewException("리뷰를 수정할 권한이 없습니다."); //} - // 받은값들로 review 수정해서 - review.updateReview(facility, ranking, comment); + // 받은 값들로 review 수정하기 + if (ranking != null) { // ranking이 null이 아닌 경우에만 수정 + review.setRanking(ranking); + } + if (comment != null && !comment.trim().isEmpty()) { // comment가 null이 아니고 빈 문자열이 아닌 경우에만 수정 + review.setComment(comment); + } + if (facility != null) { // facility가 null이 아닌 경우에만 수정 + review.setFacility(facility); + } + - // 레퍼지토리에 저장하고 - reviewRepository.updateReview(reviewId, ranking, comment , facility); + // 수정된 리뷰 저장하기 + reviewRepository.save(review); - // 성공Response 반환 } } From 88860e3dc964b8ca955b7e94beaeca653abd2cab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=90=EB=AA=85=EC=A7=84?= Date: Sat, 3 Aug 2024 15:45:16 +0900 Subject: [PATCH 21/29] =?UTF-8?q?feat=20:=20=EC=86=8C=EC=85=9C=EB=A7=81=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SocialringController.java | 12 ++++++++ .../example/likelion12/domain/Socialring.java | 5 ++++ .../likelion12/service/SocialringService.java | 29 +++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/src/main/java/com/example/likelion12/controller/SocialringController.java b/src/main/java/com/example/likelion12/controller/SocialringController.java index e4c8f37..6ef8218 100644 --- a/src/main/java/com/example/likelion12/controller/SocialringController.java +++ b/src/main/java/com/example/likelion12/controller/SocialringController.java @@ -66,4 +66,16 @@ public BaseResponse joinSocialring(@RequestHeader("Authorization") String socialringService.joinSocialring(memberId, socialringId); return new BaseResponse<>(BaseExceptionResponseStatus.SUCCESS, null); } + + /** + * 소셜링 삭제하기 + */ + @PatchMapping("/delete") + public BaseResponse deleteSocialring(@RequestHeader("Authorization") String authorization, + @RequestParam("socialringId") Long socialringId) { + log.info("[SocialringController.deleteSocialring]"); + Long memberId = jwtProvider.extractIdFromHeader(authorization); + socialringService.deleteSocialring(memberId, socialringId); + return new BaseResponse<>(BaseExceptionResponseStatus.SUCCESS, null); + } } diff --git a/src/main/java/com/example/likelion12/domain/Socialring.java b/src/main/java/com/example/likelion12/domain/Socialring.java index a29c2c3..71ddc81 100644 --- a/src/main/java/com/example/likelion12/domain/Socialring.java +++ b/src/main/java/com/example/likelion12/domain/Socialring.java @@ -5,6 +5,7 @@ import com.example.likelion12.domain.base.BaseStatus; import com.example.likelion12.domain.base.BaseTime; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.databind.ser.Serializers; import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; @@ -114,4 +115,8 @@ public void UpdateSocialringInfo(String newSocialringName, String newSocialringI this.exercise = exercise; } + + 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 45be792..e894ef5 100644 --- a/src/main/java/com/example/likelion12/service/SocialringService.java +++ b/src/main/java/com/example/likelion12/service/SocialringService.java @@ -21,6 +21,7 @@ import java.util.stream.Collectors; import static com.example.likelion12.common.response.status.BaseExceptionResponseStatus.*; +import static com.example.likelion12.domain.base.BaseStatus.DELETE; @Slf4j @Service @@ -228,4 +229,32 @@ public void joinSocialring(Long memberId, Long socialringId) { throw new SocialringException(ALREADY_FULL_SOCIALRING); } } + + /** + * 소셜링 삭제하기 + */ + @Transactional + public void deleteSocialring(Long memberId, Long socialringId) { + log.info("[SocialringService.deleteSocialring]"); + + // 소셜링을 삭제하고자 하는 멤버를 찾기 + 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)); + + // 접근 멤버가 CAPTAIN인지 유효성 검사 + memberSocialringService.ConfirmCaptainMemberSocialring(memberSocialring); + + // 소셜링 상태를 DELETE로 변경 + socialring.setStatus(DELETE); + socialringRepository.save(socialring); + + } } From e326d938a78a820bc2a9683758007dbd262722d0 Mon Sep 17 00:00:00 2001 From: jungeun Date: Sat, 3 Aug 2024 19:24:24 +0900 Subject: [PATCH 22/29] =?UTF-8?q?feat=20:=20ddl-auto=20update=20=EB=A1=9C?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-prod.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 6b8d85f..11b5968 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -10,7 +10,7 @@ spring: enabled: false jpa: hibernate: - ddl-auto: create + ddl-auto: update properties: hibernate: format_sql: true From bca1f6989553f79b704685d1a1966284538008be Mon Sep 17 00:00:00 2001 From: hd0rable Date: Sat, 3 Aug 2024 22:08:18 +0900 Subject: [PATCH 23/29] =?UTF-8?q?fix=20:=20=EB=A0=88=ED=8F=AC=EC=A7=80?= =?UTF-8?q?=ED=86=A0=EB=A6=AC=EC=97=90=EC=84=9C=20delete=EA=B0=80=20?= =?UTF-8?q?=EC=95=84=EB=8B=8C=20=EC=83=81=ED=83=9C=EB=A5=BC=20DELETE?= =?UTF-8?q?=EB=A1=9C=20=EB=B0=94=EA=BE=B8=EB=8A=94=EA=B2=83=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/likelion12/domain/Crew.java | 4 ++++ .../java/com/example/likelion12/domain/MemberCrew.java | 4 ++++ .../java/com/example/likelion12/service/CrewService.java | 9 ++++++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/likelion12/domain/Crew.java b/src/main/java/com/example/likelion12/domain/Crew.java index b647e5c..e37a203 100644 --- a/src/main/java/com/example/likelion12/domain/Crew.java +++ b/src/main/java/com/example/likelion12/domain/Crew.java @@ -91,4 +91,8 @@ public Crew(String crewName, String crewImg, int totalRecruits, int crewCost, this.exercise = exercise; this.status = status; } + + public void DeleteCrewInfo(BaseStatus status) { + this.status= status; + } } diff --git a/src/main/java/com/example/likelion12/domain/MemberCrew.java b/src/main/java/com/example/likelion12/domain/MemberCrew.java index 183d64c..0ff72a3 100644 --- a/src/main/java/com/example/likelion12/domain/MemberCrew.java +++ b/src/main/java/com/example/likelion12/domain/MemberCrew.java @@ -45,4 +45,8 @@ public MemberCrew (BaseRole role, Crew crew, Member member, BaseStatus status){ this.member = member; this.status = status; } + + public void DeleteMemberCrewInfo(BaseStatus status) { + this.status= status; + } } diff --git a/src/main/java/com/example/likelion12/service/CrewService.java b/src/main/java/com/example/likelion12/service/CrewService.java index 5ece7d8..bc05a90 100644 --- a/src/main/java/com/example/likelion12/service/CrewService.java +++ b/src/main/java/com/example/likelion12/service/CrewService.java @@ -178,10 +178,13 @@ public void deleteCrew(Long memberId, Long crewId) { .orElseThrow(()->new MemberCrewException(CANNOT_FOUND_MEMBERCREW_LIST)); // 멤버 크루리스트 삭제 - memberCrewList.forEach(mc -> memberCrewRepository.delete(mc)); - + for(MemberCrew membercrew: memberCrewList) { + membercrew.DeleteMemberCrewInfo(BaseStatus.DELETE); + memberCrewRepository.save(membercrew); + } //크루 삭제 - crewRepository.delete(crew); + crew.DeleteCrewInfo(BaseStatus.DELETE); + crewRepository.save(crew); } /** From 6910a0866b0155c8300088b226009f737edffcee Mon Sep 17 00:00:00 2001 From: jungeun Date: Sat, 3 Aug 2024 23:15:59 +0900 Subject: [PATCH 24/29] =?UTF-8?q?fix=20:=20=EC=B6=A9=EB=8F=8C=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0=ED=95=98=EB=A9=B4=EC=84=9C=20=EC=9E=98=EB=AA=BB=20?= =?UTF-8?q?=EC=A7=80=EC=9A=B4=EA=B1=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/response/status/BaseExceptionResponseStatus.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 2708512..08b3ac6 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 @@ -44,7 +44,7 @@ public enum BaseExceptionResponseStatus implements ResponseStatus{ * 8000: member socialring 관련 */ CANNOT_FOUND_MEMBERSOCIALRING(8000, HttpStatus.BAD_REQUEST.value(), "해당하는 멤버소셜링을 찾을 수 없습니다."), - CANNOT_MEMBERSOCIALRING_CAPTAIN(8001, HttpStatus.BAD_REQUEST.value(), "소셜링 수정,삭제에 접근할수없는 권한입니다."), + NOT_MEMBERSOCIALRING_CAPTAIN(8001, HttpStatus.BAD_REQUEST.value(), "소셜링 수정,삭제에 접근할수없는 권한입니다."), CANNOT_FOUND_MEMBERSOCIALRING_LIST(8002, HttpStatus.BAD_REQUEST.value(), "해당하는 멤버소셜링 리스트를 찾을 수 없습니다."), ALREADY_EXIST_IN_SOCIALRING(8003, HttpStatus.BAD_REQUEST.value(), "해당 소셜링에 이미 등록된 멤버입니다."), @@ -63,7 +63,7 @@ public enum BaseExceptionResponseStatus implements ResponseStatus{ CANNOT_FOUND_MEMBERCREW_LIST(10001, HttpStatus.BAD_REQUEST.value(), "멤버_크루 리스트를 찾을 수 없습니다."), ALREADY_EXIST_IN_CREW(10002, HttpStatus.BAD_REQUEST.value(), "해당 크루에 이미 등록된 멤버입니다."), NOT_MEMBERCREW_CAPTAIN(10003, HttpStatus.BAD_REQUEST.value(), "크루 수정,삭제에 접근할수없는 권한입니다."), - NOT_CREW_MEMBERCREW(10004, HttpStatus.BAD_REQUEST.value(), "해당 크루에 참여 상태가 아닙니다."); + NOT_CREW_MEMBERCREW(10004, HttpStatus.BAD_REQUEST.value(), "해당 크루에 참여 상태가 아닙니다."), /** * 11000 : Review 관련 From b6c28754800cccf36dfd77713ae911a2e4994f69 Mon Sep 17 00:00:00 2001 From: jungeun Date: Sun, 4 Aug 2024 00:51:38 +0900 Subject: [PATCH 25/29] =?UTF-8?q?feat=20:=20MemberController.logout=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../likelion12/controller/MemberController.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/likelion12/controller/MemberController.java b/src/main/java/com/example/likelion12/controller/MemberController.java index 7ceb43c..324d87f 100644 --- a/src/main/java/com/example/likelion12/controller/MemberController.java +++ b/src/main/java/com/example/likelion12/controller/MemberController.java @@ -4,7 +4,7 @@ import com.example.likelion12.dto.member.PostSignupRequest; import com.example.likelion12.dto.member.PostSignupResponse; import com.example.likelion12.service.MemberService; -import com.example.likelion12.util.JwtProvider; +import com.example.likelion12.util.*; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; @@ -18,6 +18,9 @@ public class MemberController { private final MemberService memberService; private final JwtProvider jwtProvider; + /** + * 회원가입 + */ @PostMapping("/signup") public BaseResponse signUp(@RequestBody PostSignupRequest postSignupRequest){ log.info("[MemberController.signUp]"); @@ -30,4 +33,15 @@ public BaseResponse signOut(@RequestHeader("Authorization") String autho memberService.signOut(memberId); return new BaseResponse<>("회원탈퇴 되었습니다"); } + + /** + * 로그아웃 + */ + @PostMapping("/logout") + public BaseResponse logout(@RequestHeader("Authorization") String authorization){ + log.info("[MemberController.logout]"); + Long memberId = jwtProvider.extractIdFromHeader(authorization); + memberService.logout(memberId); + return new BaseResponse<>(null); + } } From 044da5cc12d679b84a583bcb4f631bc112c8ab16 Mon Sep 17 00:00:00 2001 From: jungeun Date: Sun, 4 Aug 2024 00:51:54 +0900 Subject: [PATCH 26/29] =?UTF-8?q?feat=20:=20MemberService.logout=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/likelion12/service/MemberService.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/likelion12/service/MemberService.java b/src/main/java/com/example/likelion12/service/MemberService.java index 15e936e..23bd9e0 100644 --- a/src/main/java/com/example/likelion12/service/MemberService.java +++ b/src/main/java/com/example/likelion12/service/MemberService.java @@ -16,8 +16,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.example.likelion12.common.response.status.BaseExceptionResponseStatus.ALREADY_EXIST_EMAIL; -import static com.example.likelion12.common.response.status.BaseExceptionResponseStatus.CANNOT_FOUND_EXERCISE; +import static com.example.likelion12.common.response.status.BaseExceptionResponseStatus.*; @Slf4j @Service @@ -85,4 +84,16 @@ public Long signOut(Long memberId) { return memberId; } + /** + * 로그아웃 + */ + public void logout(Long memberId){ + log.info("[MemberService.logout]"); + if(memberRepository.findByMemberIdAndStatus(memberId, BaseStatus.ACTIVE).isPresent()){ + tokenService.invalidateToken(memberId); + }else{ + throw new MemberException(CANNOT_FOUND_MEMBER); + } + } + } From 9d17c1753b5c66138987a6ded2edece894b61cdd Mon Sep 17 00:00:00 2001 From: jungeun Date: Sun, 4 Aug 2024 00:52:39 +0900 Subject: [PATCH 27/29] =?UTF-8?q?feat=20:=20MemberController.logout=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/likelion12/controller/MemberController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/example/likelion12/controller/MemberController.java b/src/main/java/com/example/likelion12/controller/MemberController.java index 324d87f..20121c9 100644 --- a/src/main/java/com/example/likelion12/controller/MemberController.java +++ b/src/main/java/com/example/likelion12/controller/MemberController.java @@ -44,4 +44,5 @@ public BaseResponse logout(@RequestHeader("Authorization") String authoriz memberService.logout(memberId); return new BaseResponse<>(null); } + } From b557ff728a14ddac89b2fc0dd5b93eb95117fc3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=90=EB=AA=85=EC=A7=84?= Date: Sun, 4 Aug 2024 20:46:48 +0900 Subject: [PATCH 28/29] =?UTF-8?q?Feat=20:=20=EC=86=8C=EC=85=9C=EB=A7=81=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=EC=8B=9C=20=EB=A9=A4=EB=B2=84=EC=86=8C?= =?UTF-8?q?=EC=85=9C=EB=A7=81=EC=9D=98=20State=20=EB=8F=84=20Delete=20?= =?UTF-8?q?=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/likelion12/domain/MemberSocialring.java | 4 ++++ .../example/likelion12/service/SocialringService.java | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/main/java/com/example/likelion12/domain/MemberSocialring.java b/src/main/java/com/example/likelion12/domain/MemberSocialring.java index a60cde3..2304e8d 100644 --- a/src/main/java/com/example/likelion12/domain/MemberSocialring.java +++ b/src/main/java/com/example/likelion12/domain/MemberSocialring.java @@ -45,4 +45,8 @@ public MemberSocialring(BaseRole baseRole, Socialring socialring, Member member, this.member = member; this.status = baseStatus; } + + 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 e894ef5..ee73867 100644 --- a/src/main/java/com/example/likelion12/service/SocialringService.java +++ b/src/main/java/com/example/likelion12/service/SocialringService.java @@ -256,5 +256,14 @@ public void deleteSocialring(Long memberId, Long socialringId) { socialring.setStatus(DELETE); socialringRepository.save(socialring); + // 소설링이 참조하고 있는 멤버 소셜링의 상태를 전부 DELETE로 변경 + // 소셜링에 등록된 멤버 리스트 추출 + List memberSocialringList = memberSocialringRepository.findBySocialring_SocialringIdAndStatus + (socialringId, BaseStatus.ACTIVE).orElseThrow(()-> new MemberSocialringException( CANNOT_FOUND_MEMBERSOCIALRING_LIST)); + // 해당 리스트의 멤버의 상태를 DELETE로 변경 + for (MemberSocialring memberSocialringEntry : memberSocialringList) { + memberSocialringEntry.setStatus(DELETE); + memberSocialringRepository.save(memberSocialringEntry); + } } } From 365de288782b925e68a749ae1a49bb16a08b167f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=90=EB=AA=85=EC=A7=84?= Date: Sun, 4 Aug 2024 20:57:58 +0900 Subject: [PATCH 29/29] =?UTF-8?q?application.yml=20=EB=A1=9C=EC=BB=AC?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=84=9C=EB=B2=84=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 9e8578a..fc45c65 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -26,8 +26,7 @@ spring: registration: kakao: client-id: ${CLIENT_ID} -# redirect-uri: http://43.202.94.241:8080/auth/kakao/callback - redirect-uri: http://localhost:8080/auth/kakao/callback + redirect-uri: http://43.202.94.241:8080/auth/kakao/callback --- jwt: