Skip to content

Commit

Permalink
[REFACTOR] #30 - 소모임 수정 시 본인만 수정 가능 하도록 변경
Browse files Browse the repository at this point in the history
- 소모임을 작성한 memberId가 일치 하는 경우에만 수정이 가능하도록 변경
  • Loading branch information
aelimited committed May 29, 2024
1 parent c109d77 commit f58d837
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Club toClubEntity(ClubCreateRequest request, Long memberId) {
return club;
}

public Club updateClubEntity(Club updateClub, ClubUpdateRequest updateRequest) {
public Club updateClubEntity(Club updateClub, ClubUpdateRequest updateRequest,Long memberId) {
ClubType category = ClubType.fromKor(String.valueOf(updateRequest.clubType()));
return Club.builder()
.id(updateClub.getId())
Expand All @@ -68,6 +68,8 @@ public Club updateClubEntity(Club updateClub, ClubUpdateRequest updateRequest) {
.detailedIntroduction(updateRequest.detailedIntroduction())
.applicationIntroduction(updateRequest.applicationIntroduction())
.clubThumbnail(updateRequest.clubThumbnail())
.member(
Member.builder().id(memberId).build())
.build();
}

Expand Down
24 changes: 17 additions & 7 deletions src/main/java/com/core/linkup/club/service/ClubService.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,36 @@ public Page<ClubSearchResponse> findClubs(Pageable pageable, ClubSearchRequest r
}

public ClubSearchResponse createClub(MemberDetails member, ClubCreateRequest request) {
if (member == null) {
throw new BaseException(BaseResponseStatus.UNREGISTERD_MEMBER);
}

Long memberId = member.getId();
Long memberId = getMemberId(member);
Club club = clubConverter.toClubEntity(request, memberId);
Club savedClub = clubRepository.save(club);

return clubConverter.toClubResponse(savedClub);
}

public ClubSearchResponse updateClub(MemberDetails member, Long clubId, ClubUpdateRequest updateRequest) {

Long memberId = getMemberId(member);
Club existingClub = clubRepository.findById(clubId)
.orElseThrow(() -> new BaseException(BaseResponseStatus.INVALID_CLUB_ID));
Club updatedClub = clubConverter.updateClubEntity(existingClub, updateRequest);

if (!existingClub.getMember().getId().equals(memberId)) {
throw new BaseException(BaseResponseStatus.INVALID_MEMBER);
}

Club updatedClub = clubConverter.updateClubEntity(existingClub, updateRequest, memberId);
Club savedClub = clubRepository.save(updatedClub);
return clubConverter.toClubResponse(savedClub);
}

private static Long getMemberId(MemberDetails member) {
if (member == null) {
throw new BaseException(BaseResponseStatus.UNREGISTERD_MEMBER);
}

Long memberId = member.getId();
return memberId;
}

public void delete(MemberDetails member, Long clubId) {
clubRepository.deleteById(clubId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public enum BaseResponseStatus {

INVALID_OFFICEBUILDING_ID(false, INTERNAL_SERVER_ERROR.value(), "존재하지 않는 공유오피스 입니다." ),
INVALID_CLUB_ID(false, BAD_REQUEST.value(), "존재하지 않는 소모임입니다."),
INVALID_REQUEST(false, INTERNAL_SERVER_ERROR.value(),"잘못된 요청입니다.")
INVALID_REQUEST(false, INTERNAL_SERVER_ERROR.value(),"잘못된 요청입니다."),
INVALID_MEMBER(false, INTERNAL_SERVER_ERROR.value(), "로그인된 사용자와 일치하지 않습니다.")
;

private final boolean isSuccess;
Expand Down

0 comments on commit f58d837

Please sign in to comment.