Skip to content

Commit

Permalink
Merge pull request #77 from aelimited/feature/#56-clubRefeatoring
Browse files Browse the repository at this point in the history
[FEAT] #56 - 정기모임 수정/삭제 추가
  • Loading branch information
aelimited authored Jun 6, 2024
2 parents 8d1de08 + 2062f57 commit 59df441
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -48,4 +49,26 @@ public BaseResponse<ClubMeetingResponse> findMeeting(
ClubMeetingResponse response = clubMeetingService.findMeeting(memberDetails, clubId, meetingId);
return BaseResponse.response(response);
}

//정기모임 수정
@PutMapping("/{club_id}/meeting/{meeting_id}")
public BaseResponse<ClubMeetingResponse> 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<Void> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@Entity(name = "club_meeting")
@Getter
@SuperBuilder
@SuperBuilder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class ClubMeeting extends BaseEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface ClubMeetingRepository extends JpaRepository<ClubMeeting, Long> {

List<ClubMeeting> findByClubId(Long clubId);
Optional<ClubMeeting> findByIdAndClubId(Long id, Long clubId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public ClubMeetingResponse createMeeting(MemberDetails memberDetails, Long clubI
return clubMeetingConverter.toMeetingResponse(savedMeeting, member);
}

//정기모임 조회
public List<ClubMeetingResponse> findAllMeetings(MemberDetails memberDetails, Long clubId) {
Long memberId = memberDetails.getId();

Expand All @@ -66,7 +67,6 @@ public List<ClubMeetingResponse> findAllMeetings(MemberDetails memberDetails, Lo

return responses;
}

public ClubMeetingResponse findMeeting(MemberDetails memberDetails, Long clubId, Long meetingId) {
Long memberId = memberDetails.getId();

Expand All @@ -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));
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(), "로그인된 사용자와 일치하지 않습니다."),
Expand Down

0 comments on commit 59df441

Please sign in to comment.