Skip to content

Commit

Permalink
Merge pull request #49 from aelimited/feature/#30-clubregister
Browse files Browse the repository at this point in the history
소모임 수정시 멤버 확인
  • Loading branch information
c0smosaur authored May 30, 2024
2 parents f997735 + 360776f commit eba11ec
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.core.linkup.common.exception.BaseException;
import com.core.linkup.common.response.BaseResponseStatus;
import com.core.linkup.member.entity.Member;
import com.core.linkup.security.MemberDetails;

@Converter
public class ClubConverter {
Expand All @@ -24,7 +25,7 @@ public ClubSearchResponse toClubResponse(Club club) {
}


public Club toClubEntity(ClubCreateRequest request, Long memberId) {
public Club toClubEntity(ClubCreateRequest request, MemberDetails member) {
ClubType category;
try {
category = ClubType.fromKor(String.valueOf(request.clubType()));
Expand All @@ -40,8 +41,7 @@ public Club toClubEntity(ClubCreateRequest request, Long memberId) {
.detailedIntroduction(request.detailedIntroduction())
.applicationIntroduction(request.applicationIntroduction())
.clubThumbnail(request.clubThumbnail())
.member(
Member.builder().id(memberId).build())
.member(member.getMember())
.build();

//TODO : list로 question 받는거 해야 함, clubid르 null로 받아옴
Expand All @@ -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,MemberDetails member) {
ClubType category = ClubType.fromKor(String.valueOf(updateRequest.clubType()));
return Club.builder()
.id(updateClub.getId())
Expand All @@ -68,6 +68,7 @@ public Club updateClubEntity(Club updateClub, ClubUpdateRequest updateRequest) {
.detailedIntroduction(updateRequest.detailedIntroduction())
.applicationIntroduction(updateRequest.applicationIntroduction())
.clubThumbnail(updateRequest.clubThumbnail())
.member(member.getMember())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.stream.Collectors;

@Repository
@RequiredArgsConstructor
Expand All @@ -33,6 +34,13 @@ public Page<Club> findSearchClubs(ClubSearchRequest request, Pageable pageable)
ClubType clubType = ClubType.fromKor(request.getClubType());
booleanBuilder.and(club.category.eq(String.valueOf(clubType)));
}
//중복 조회 가능 하도록 하는 로직
// if (request.getClubType() != null && !request.getClubType().isEmpty()) {
// List<ClubType> clubTypes = request.getClubType().stream()
// .map(ClubType::fromKor)
// .toList();
// booleanBuilder.and(club.category.in(String.valueOf(clubTypes)));
// }

List<Club> clubs = queryFactory.selectFrom(club)
.where(booleanBuilder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import lombok.*;

import java.util.List;

@Getter
@RequiredArgsConstructor
@AllArgsConstructor
Expand All @@ -10,5 +12,6 @@ public class ClubSearchRequest {

private Long officeBuildingId;
private String clubType;
// private List<String> clubType;

}
26 changes: 18 additions & 8 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();
Club club = clubConverter.toClubEntity(request, memberId);
Long memberId = getMemberId(member);
Club club = clubConverter.toClubEntity(request, member);
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, member);
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 eba11ec

Please sign in to comment.