From e1489dd85a8ccbf9af0ae84abee42483a7a73c96 Mon Sep 17 00:00:00 2001 From: oosedus Date: Tue, 30 Jul 2024 21:20:44 +0900 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20=EB=A6=AC=EB=B7=B0=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=EC=97=90=20transactional=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/likelion/MZConnent/service/review/ReviewService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/likelion/MZConnent/service/review/ReviewService.java b/src/main/java/likelion/MZConnent/service/review/ReviewService.java index 072fecc..93cdd4d 100644 --- a/src/main/java/likelion/MZConnent/service/review/ReviewService.java +++ b/src/main/java/likelion/MZConnent/service/review/ReviewService.java @@ -1,5 +1,6 @@ package likelion.MZConnent.service.review; +import jakarta.transaction.Transactional; import likelion.MZConnent.domain.culture.Culture; import likelion.MZConnent.domain.member.Member; import likelion.MZConnent.domain.review.Review; @@ -29,6 +30,7 @@ @Service @Slf4j @RequiredArgsConstructor +@Transactional public class ReviewService { private final ReviewRepository reviewRepository; private final S3ImageService s3ImageService; From 566e408bd7c599b01c0e62b48e1c57fe95b4f0c3 Mon Sep 17 00:00:00 2001 From: oosedus Date: Tue, 30 Jul 2024 22:18:11 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=EB=AA=A8=EC=9E=84=20=EB=A7=88?= =?UTF-8?q?=EA=B0=90=ED=95=98=EA=B8=B0=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MZConnent/api/club/MyClubController.java | 8 ++++++ .../MZConnent/service/club/MyClubService.java | 26 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/main/java/likelion/MZConnent/api/club/MyClubController.java b/src/main/java/likelion/MZConnent/api/club/MyClubController.java index 5d05380..7190c70 100644 --- a/src/main/java/likelion/MZConnent/api/club/MyClubController.java +++ b/src/main/java/likelion/MZConnent/api/club/MyClubController.java @@ -14,6 +14,8 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; +import java.util.Map; + @Slf4j @RequiredArgsConstructor @RestController @@ -46,4 +48,10 @@ public ResponseEntity getMemberRateAndCount(@AuthenticationP return ResponseEntity.ok(response); } + @PostMapping("/api/clubs/{clubId}/close") + public ResponseEntity closeClub(@AuthenticationPrincipal UserPrinciple userPrinciple, @PathVariable Long clubId) { + myClubService.closeClub(userPrinciple.getEmail(), clubId); + return ResponseEntity.ok(Map.of("messege","모임 마감 성공")); + } + } diff --git a/src/main/java/likelion/MZConnent/service/club/MyClubService.java b/src/main/java/likelion/MZConnent/service/club/MyClubService.java index 6299c06..d0076c8 100644 --- a/src/main/java/likelion/MZConnent/service/club/MyClubService.java +++ b/src/main/java/likelion/MZConnent/service/club/MyClubService.java @@ -1,10 +1,13 @@ package likelion.MZConnent.service.club; import likelion.MZConnent.domain.club.Club; +import likelion.MZConnent.domain.club.ClubMember; +import likelion.MZConnent.domain.club.ClubRole; import likelion.MZConnent.domain.member.Member; import likelion.MZConnent.dto.club.SelfIntroductionDto; import likelion.MZConnent.dto.club.response.MyClubDetailResponse; import likelion.MZConnent.dto.club.response.MyClubSimpleResponse; +import likelion.MZConnent.repository.club.ClubRepository; import likelion.MZConnent.repository.member.MemberRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -18,6 +21,7 @@ @Slf4j public class MyClubService { private final MemberRepository memberRepository; + private final ClubRepository clubRepository; public MyClubSimpleResponse getMyClubs(String email) { Member member = getMemberByEmail(email); @@ -105,4 +109,26 @@ private List convertToMemberDtos(Club club .build()) .collect(Collectors.toList()); } + + public void closeClub(String email, Long clubId) { + Member member = getMemberByEmail(email); + ClubMember clubMember = getClubMemberByMemberAndId(member, clubId); + Club club = clubRepository.findById(clubId) + .orElseThrow(() -> new IllegalArgumentException("해당 클럽을 찾을 수 없습니다.")); + + // 클럽장이 아닌 경우 예외 처리 + if (!clubMember.getClubRole().equals(ClubRole.LEADER)){ + throw new IllegalArgumentException("클럽장만 클럽을 종료할 수 있습니다."); + } + + club.setStatus("CLOSE"); + clubRepository.save(club); + } + + private ClubMember getClubMemberByMemberAndId(Member member, Long clubId) { + return member.getClubMembers().stream() + .filter(cm -> cm.getClub().getClubId().equals(clubId)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("해당 멤버가 가입된 모임이 아닙니다.")); + } } From 872dfea836c3663d18c4f83ac23afde5b1fb528d Mon Sep 17 00:00:00 2001 From: oosedus Date: Tue, 30 Jul 2024 23:43:46 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=EB=A9=A4=EB=B2=84=20=EC=B6=94?= =?UTF-8?q?=EB=B0=A9=ED=95=98=EA=B8=B0=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MZConnent/api/club/MyClubController.java | 5 +++ .../MZConnent/domain/manner/Manner.java | 4 ++- .../repository/manner/MannerRepository.java | 2 ++ .../MZConnent/service/club/MyClubService.java | 32 +++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/main/java/likelion/MZConnent/api/club/MyClubController.java b/src/main/java/likelion/MZConnent/api/club/MyClubController.java index 7190c70..1353b99 100644 --- a/src/main/java/likelion/MZConnent/api/club/MyClubController.java +++ b/src/main/java/likelion/MZConnent/api/club/MyClubController.java @@ -54,4 +54,9 @@ public ResponseEntity closeClub(@AuthenticationPrincipal UserPrinciple userPrinc return ResponseEntity.ok(Map.of("messege","모임 마감 성공")); } + @DeleteMapping("/api/clubs/{clubId}/members/{memberId}") + public ResponseEntity deleteMember(@AuthenticationPrincipal UserPrinciple userPrinciple, @PathVariable Long clubId, @PathVariable Long memberId) { + myClubService.deleteClubMember(userPrinciple.getEmail(), clubId, memberId); + return ResponseEntity.ok(Map.of("messege","멤버 추방 성공")); + } } diff --git a/src/main/java/likelion/MZConnent/domain/manner/Manner.java b/src/main/java/likelion/MZConnent/domain/manner/Manner.java index fca4251..befdedc 100644 --- a/src/main/java/likelion/MZConnent/domain/manner/Manner.java +++ b/src/main/java/likelion/MZConnent/domain/manner/Manner.java @@ -9,9 +9,11 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; @Entity @Getter +@Setter @NoArgsConstructor public class Manner { @Id @@ -26,7 +28,7 @@ public class Manner { private Member member; @ManyToOne - @JoinColumn(name = "clubMemberId", nullable = false) + @JoinColumn(name = "clubMemberId", nullable = true) private ClubMember clubMember; @Builder diff --git a/src/main/java/likelion/MZConnent/repository/manner/MannerRepository.java b/src/main/java/likelion/MZConnent/repository/manner/MannerRepository.java index 29a4a3e..9a6b0e0 100644 --- a/src/main/java/likelion/MZConnent/repository/manner/MannerRepository.java +++ b/src/main/java/likelion/MZConnent/repository/manner/MannerRepository.java @@ -7,9 +7,11 @@ import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Map; @Repository public interface MannerRepository extends JpaRepository { long countByMemberAndClubMember(Member member, ClubMember clubMember); List findByMember(Member member); + List findByClubMember(ClubMember targetClubMember); } diff --git a/src/main/java/likelion/MZConnent/service/club/MyClubService.java b/src/main/java/likelion/MZConnent/service/club/MyClubService.java index d0076c8..4f67387 100644 --- a/src/main/java/likelion/MZConnent/service/club/MyClubService.java +++ b/src/main/java/likelion/MZConnent/service/club/MyClubService.java @@ -1,13 +1,17 @@ package likelion.MZConnent.service.club; +import jakarta.transaction.Transactional; import likelion.MZConnent.domain.club.Club; import likelion.MZConnent.domain.club.ClubMember; import likelion.MZConnent.domain.club.ClubRole; +import likelion.MZConnent.domain.manner.Manner; import likelion.MZConnent.domain.member.Member; import likelion.MZConnent.dto.club.SelfIntroductionDto; import likelion.MZConnent.dto.club.response.MyClubDetailResponse; import likelion.MZConnent.dto.club.response.MyClubSimpleResponse; +import likelion.MZConnent.repository.club.ClubMemberRepository; import likelion.MZConnent.repository.club.ClubRepository; +import likelion.MZConnent.repository.manner.MannerRepository; import likelion.MZConnent.repository.member.MemberRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -18,10 +22,13 @@ @Service @RequiredArgsConstructor +@Transactional @Slf4j public class MyClubService { private final MemberRepository memberRepository; private final ClubRepository clubRepository; + private final ClubMemberRepository clubMemberRepository; + private final MannerRepository mannerRepository; public MyClubSimpleResponse getMyClubs(String email) { Member member = getMemberByEmail(email); @@ -131,4 +138,29 @@ private ClubMember getClubMemberByMemberAndId(Member member, Long clubId) { .findFirst() .orElseThrow(() -> new IllegalArgumentException("해당 멤버가 가입된 모임이 아닙니다.")); } + + public void deleteClubMember(String email, Long clubId, Long targetMemberId) { + Member member = getMemberByEmail(email); + Club club = clubRepository.findById(clubId) + .orElseThrow(() -> new IllegalArgumentException("해당 클럽을 찾을 수 없습니다.")); + Member targetMember = memberRepository.findById(targetMemberId) + .orElseThrow(() -> new IllegalArgumentException("해당 멤버를 찾을 수 없습니다.")); + + ClubMember clubMember = getClubMemberByMemberAndId(member, clubId); + ClubMember targetClubMember = getClubMemberByMemberAndId(targetMember, clubId); + + // 클럽장이 아닌 경우 예외 처리 + if (!clubMember.getClubRole().equals(ClubRole.LEADER)){ + throw new IllegalArgumentException("클럽장만 멤버를 삭제할 수 있습니다."); + } + + // 해당 클럽 멤버와 관련된 manner 엔티티의 clubMember 필드를 null로 설정 + List manners = mannerRepository.findByClubMember(targetClubMember); + manners.forEach(manner -> manner.setClubMember(null)); + mannerRepository.saveAll(manners); + + clubMemberRepository.delete(targetClubMember); + club.setCurrentParticipant(club.getCurrentParticipant() - 1); + clubRepository.save(club); + } }