From 2062f579f489cf8437535d28bf45f4fa0018e51c Mon Sep 17 00:00:00 2001 From: aelimited Date: Thu, 6 Jun 2024 18:15:29 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20#56=20-=20=EC=A0=95=EA=B8=B0=EB=AA=A8?= =?UTF-8?q?=EC=9E=84=20=EC=88=98=EC=A0=95/=EC=82=AD=EC=A0=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 정기모임 수정 및 삭제 하는 기능 추가 --- .../controller/ClubMeetingController.java | 25 +++++++++++- .../converter/ClubMeetingConverter.java | 14 ++++++- .../club/clubmeeting/entity/ClubMeeting.java | 2 +- .../repository/ClubMeetingRepository.java | 2 + .../service/ClubMeetingService.java | 40 ++++++++++++++++++- .../common/response/BaseResponseStatus.java | 1 + 6 files changed, 80 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/core/linkup/club/clubmeeting/controller/ClubMeetingController.java b/src/main/java/com/core/linkup/club/clubmeeting/controller/ClubMeetingController.java index 1190d49..9174fc1 100644 --- a/src/main/java/com/core/linkup/club/clubmeeting/controller/ClubMeetingController.java +++ b/src/main/java/com/core/linkup/club/clubmeeting/controller/ClubMeetingController.java @@ -1,9 +1,10 @@ package com.core.linkup.club.clubmeeting.controller; -import com.core.linkup.club.clubmeeting.response.ClubMeetingResponse; import com.core.linkup.club.clubmeeting.request.ClubMeetingRequest; +import com.core.linkup.club.clubmeeting.response.ClubMeetingResponse; import com.core.linkup.club.clubmeeting.service.ClubMeetingService; import com.core.linkup.common.response.BaseResponse; +import com.core.linkup.common.response.BaseResponseStatus; import com.core.linkup.security.MemberDetails; import lombok.RequiredArgsConstructor; import org.springframework.security.core.annotation.AuthenticationPrincipal; @@ -48,4 +49,26 @@ public BaseResponse findMeeting( ClubMeetingResponse response = clubMeetingService.findMeeting(memberDetails, clubId, meetingId); return BaseResponse.response(response); } + + //정기모임 수정 + @PutMapping("/{club_id}/meeting/{meeting_id}") + public BaseResponse updateMeeting( + @AuthenticationPrincipal MemberDetails memberDetails, + @PathVariable("club_id") Long clubId, + @PathVariable("meeting_id") Long meetingId, + @RequestBody ClubMeetingRequest request + ) { + ClubMeetingResponse response = clubMeetingService.updateMeeting(memberDetails, clubId, meetingId, request); + return BaseResponse.response(response); + } + + @DeleteMapping("/{club_id}/meeting/{meeting_id}") + public BaseResponse deleteMeeting( + @AuthenticationPrincipal MemberDetails memberDetails, + @PathVariable("club_id") Long clubId, + @PathVariable("meeting_id") Long meetingId + ) { + clubMeetingService.deleteMeeting(memberDetails, clubId, meetingId); + return BaseResponse.response(BaseResponseStatus.DELETE_SUCCESS); + } } diff --git a/src/main/java/com/core/linkup/club/clubmeeting/converter/ClubMeetingConverter.java b/src/main/java/com/core/linkup/club/clubmeeting/converter/ClubMeetingConverter.java index b6132b2..675ffe8 100644 --- a/src/main/java/com/core/linkup/club/clubmeeting/converter/ClubMeetingConverter.java +++ b/src/main/java/com/core/linkup/club/clubmeeting/converter/ClubMeetingConverter.java @@ -13,7 +13,7 @@ public class ClubMeetingConverter { public ClubMeeting toMeetingEntity(ClubMeetingRequest request, Club club) { return ClubMeeting.builder() .title(request.title()) - .date(request.date()) + .date(request.date()) //정기모임 시간 .meetingLocation(request.meetingLocation()) .maxCapacity(request.maxCapacity()) .fee(request.fee()) @@ -33,4 +33,16 @@ public ClubMeetingResponse toMeetingResponse(ClubMeeting clubMeeting, Member mem .memberImage(member.getProfileImage()) .build(); } + public ClubMeeting toUpdateMeetingEntity(ClubMeeting clubMeeting, ClubMeetingRequest request) { + return ClubMeeting.builder() + .title(request.title()) + .date(request.date()) //정기 모임 시간 + .meetingLocation(request.meetingLocation()) + .maxCapacity(request.maxCapacity()) + .fee(request.fee()) + .clubId(clubMeeting.getClubId()) + .memberId(clubMeeting.getMemberId()) + .build(); + } + } diff --git a/src/main/java/com/core/linkup/club/clubmeeting/entity/ClubMeeting.java b/src/main/java/com/core/linkup/club/clubmeeting/entity/ClubMeeting.java index f042341..8eea605 100644 --- a/src/main/java/com/core/linkup/club/clubmeeting/entity/ClubMeeting.java +++ b/src/main/java/com/core/linkup/club/clubmeeting/entity/ClubMeeting.java @@ -12,7 +12,7 @@ @Entity(name = "club_meeting") @Getter -@SuperBuilder +@SuperBuilder(toBuilder = true) @NoArgsConstructor @AllArgsConstructor public class ClubMeeting extends BaseEntity { diff --git a/src/main/java/com/core/linkup/club/clubmeeting/repository/ClubMeetingRepository.java b/src/main/java/com/core/linkup/club/clubmeeting/repository/ClubMeetingRepository.java index 9db2e58..ae6bbc9 100644 --- a/src/main/java/com/core/linkup/club/clubmeeting/repository/ClubMeetingRepository.java +++ b/src/main/java/com/core/linkup/club/clubmeeting/repository/ClubMeetingRepository.java @@ -5,9 +5,11 @@ import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Optional; @Repository public interface ClubMeetingRepository extends JpaRepository { List findByClubId(Long clubId); + Optional findByIdAndClubId(Long id, Long clubId); } diff --git a/src/main/java/com/core/linkup/club/clubmeeting/service/ClubMeetingService.java b/src/main/java/com/core/linkup/club/clubmeeting/service/ClubMeetingService.java index fe36b98..0decb1c 100644 --- a/src/main/java/com/core/linkup/club/clubmeeting/service/ClubMeetingService.java +++ b/src/main/java/com/core/linkup/club/clubmeeting/service/ClubMeetingService.java @@ -49,6 +49,7 @@ public ClubMeetingResponse createMeeting(MemberDetails memberDetails, Long clubI return clubMeetingConverter.toMeetingResponse(savedMeeting, member); } + //정기모임 조회 public List findAllMeetings(MemberDetails memberDetails, Long clubId) { Long memberId = memberDetails.getId(); @@ -66,7 +67,6 @@ public List findAllMeetings(MemberDetails memberDetails, Lo return responses; } - public ClubMeetingResponse findMeeting(MemberDetails memberDetails, Long clubId, Long meetingId) { Long memberId = memberDetails.getId(); @@ -86,6 +86,33 @@ public ClubMeetingResponse findMeeting(MemberDetails memberDetails, Long clubId, return clubMeetingConverter.toMeetingResponse(clubMeeting, member); } + //정기모임 수정 + public ClubMeetingResponse updateMeeting(MemberDetails memberDetails, Long clubId, Long meetingId, ClubMeetingRequest request) { + Long memberId = memberDetails.getId(); + + validateClubMember(clubId, memberId); + validateClub(clubId); + + ClubMeeting clubMeeting = validateMeeting(clubId, meetingId, memberId); + + clubMeeting = clubMeetingConverter.toUpdateMeetingEntity(clubMeeting, request); + Member member = validateMember(memberId); + ClubMeeting updatedMeeting = clubMeetingRepository.save(clubMeeting); + + return clubMeetingConverter.toMeetingResponse(updatedMeeting, member); + } + + // 정기모임 삭제 + public void deleteMeeting(MemberDetails memberDetails, Long clubId, Long meetingId) { + Long memberId = memberDetails.getId(); + + validateClubMember(clubId, memberId); + validateClub(clubId); + + ClubMeeting clubMeeting = validateMeeting(clubId, meetingId, memberId); + + clubMeetingRepository.delete(clubMeeting); + } private Member validateMember(Long memberId) { Member member = memberRepository.findById(memberId) .orElseThrow(() -> new BaseException(BaseResponseStatus.INVALID_MEMBER)); @@ -102,4 +129,15 @@ private void validateClubMember(Long clubId, Long memberId) { ClubMember clubMember = clubMemberRepository.findByMemberIdAndClubId(memberId, clubId) .orElseThrow(() -> new BaseException(BaseResponseStatus.INVALID_CLUB_MEMBER)); } + + private ClubMeeting validateMeeting(Long clubId, Long meetingId, Long memberId) { + ClubMeeting clubMeeting = clubMeetingRepository.findByIdAndClubId(meetingId, clubId) + .orElseThrow(() -> new BaseException(BaseResponseStatus.INVALID_CLUB_MEETING)); + + // 현재 로그인한 사용자와 정기모임 생성자가 동일한지 확인 + if (!clubMeeting.getMemberId().equals(memberId)) { + throw new BaseException(BaseResponseStatus.INVALID_CLUB_MEETING_OWNER); + } + return clubMeeting; + } } diff --git a/src/main/java/com/core/linkup/common/response/BaseResponseStatus.java b/src/main/java/com/core/linkup/common/response/BaseResponseStatus.java index 2033340..1fe46b5 100644 --- a/src/main/java/com/core/linkup/common/response/BaseResponseStatus.java +++ b/src/main/java/com/core/linkup/common/response/BaseResponseStatus.java @@ -44,6 +44,7 @@ public enum BaseResponseStatus { INVALID_COMMENT_ID(false, NOT_FOUND.value(), "댓글이 존재하는지 확인해주세요."), INVALID_CLUB_MEMBER(false, NOT_FOUND.value(), "소모임에 등록된 회원이 아닙니다."), INVALID_CLUB_MEETING(false, NOT_FOUND.value(), "소모임에 등록된 정기모임이 아닙니다."), + INVALID_CLUB_MEETING_OWNER(false, NOT_FOUND.value(), "소모임 공지사항 작성자가 입니다."), INVALID_REQUEST(false, INTERNAL_SERVER_ERROR.value(), "잘못된 요청입니다."), INVALID_MEMBER(false, INTERNAL_SERVER_ERROR.value(), "로그인된 사용자와 일치하지 않습니다."),