Skip to content

Commit

Permalink
Merge pull request #72 from aelimited/feature/#56-clubRefeatoring
Browse files Browse the repository at this point in the history
소모임 관련 파일 구조 변경 및 정기모임 기능 추가
  • Loading branch information
aelimited authored Jun 6, 2024
2 parents d94e8fc + 14494d0 commit 8d1de08
Show file tree
Hide file tree
Showing 52 changed files with 608 additions and 363 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.core.linkup.club.controller;
package com.core.linkup.club.club.controller;

import com.core.linkup.club.requset.ClubApplicationRequest;
import com.core.linkup.club.requset.ClubCreateRequest;
import com.core.linkup.club.requset.ClubSearchRequest;
import com.core.linkup.club.requset.ClubUpdateRequest;
import com.core.linkup.club.response.ClubApplicationResponse;
import com.core.linkup.club.response.ClubSearchResponse;
import com.core.linkup.club.service.ClubService;
import com.core.linkup.club.club.request.ClubApplicationRequest;
import com.core.linkup.club.club.request.ClubCreateRequest;
import com.core.linkup.club.club.request.ClubSearchRequest;
import com.core.linkup.club.club.request.ClubUpdateRequest;
import com.core.linkup.club.club.response.ClubApplicationResponse;
import com.core.linkup.club.club.response.ClubSearchResponse;
import com.core.linkup.club.club.service.ClubService;
import com.core.linkup.common.response.BaseResponse;
import com.core.linkup.common.response.BaseResponseStatus;
import com.core.linkup.security.MemberDetails;
Expand Down Expand Up @@ -104,8 +104,8 @@ public BaseResponse<List<ClubApplicationResponse>> findClubApplications(
//내가 지원한 소모임 전체 조회
@GetMapping
public BaseResponse<List<ClubApplicationResponse>> findMyApplicationList(
@AuthenticationPrincipal MemberDetails member
){
@AuthenticationPrincipal MemberDetails member
) {
List<ClubApplicationResponse> response = clubService.findMyClubApplicationList(member);
return BaseResponse.response(response);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.core.linkup.club.converter;
package com.core.linkup.club.club.converter;

import com.core.linkup.club.entity.Club;
import com.core.linkup.club.entity.ClubAnswer;
import com.core.linkup.club.entity.ClubMember;
import com.core.linkup.club.entity.ClubQuestion;
import com.core.linkup.club.requset.*;
import com.core.linkup.club.response.ClubAnswerResponse;
import com.core.linkup.club.response.ClubApplicationResponse;
import com.core.linkup.club.response.ClubSearchResponse;
import com.core.linkup.club.club.entity.Club;
import com.core.linkup.club.club.entity.ClubAnswer;
import com.core.linkup.club.club.entity.ClubMember;
import com.core.linkup.club.club.entity.ClubQuestion;
import com.core.linkup.club.club.request.*;
import com.core.linkup.club.club.response.ClubAnswerResponse;
import com.core.linkup.club.club.response.ClubApplicationResponse;
import com.core.linkup.club.club.response.ClubMemberResponse;
import com.core.linkup.club.club.response.ClubSearchResponse;
import com.core.linkup.common.annotation.Converter;
import com.core.linkup.common.entity.enums.ClubType;
import com.core.linkup.common.exception.BaseException;
Expand All @@ -16,14 +17,13 @@
import com.core.linkup.security.MemberDetails;

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

@Converter
public class ClubConverter {

public ClubSearchResponse toClubResponse(Club club) {
Member member = club.getMember();

public ClubSearchResponse toClubResponses(Club club, Member member) {
return ClubSearchResponse.builder()
.id(club.getId())
.title(club.getTitle())
Expand All @@ -36,6 +36,32 @@ public ClubSearchResponse toClubResponse(Club club) {
.build();
}

public ClubSearchResponse toClubResponse(Club club, Member member, List<ClubMember> clubMembers, Map<Long, Member> memberMap) {
List<ClubMemberResponse> clubMemberResponses = clubMembers.stream()
.map(clubMember -> {
Member memberDetail = memberMap.get(clubMember.getMemberId());
return ClubMemberResponse.builder()
.clubId(clubMember.getClubId())
.memberId(clubMember.getMemberId())
.memberName(memberDetail != null ? memberDetail.getName() : null)
.profileImage(memberDetail != null ? memberDetail.getProfileImage() : null)
.introduction(clubMember.getIntroduction())
.build();
})
.collect(Collectors.toList());

return ClubSearchResponse.builder()
.id(club.getId())
.title(club.getTitle())
.introduction(club.getIntroduction())
.clubType(club.getCategory())
.recruitCount(club.getRecruitCount())
.memberId(member.getId())
.memberName(member.getName())
.profileImage(member.getProfileImage())
.clubMembers(clubMemberResponses)
.build();
}

public Club toClubEntity(ClubCreateRequest request, MemberDetails member) {
ClubType category;
Expand All @@ -44,7 +70,7 @@ public Club toClubEntity(ClubCreateRequest request, MemberDetails member) {
} catch (IllegalArgumentException e) {
throw new BaseException(BaseResponseStatus.INVALID_REQUEST);
}
Club club = Club.builder()
return Club.builder()
.category(String.valueOf(category))
.clubAccessibility(request.clubAccessibility())
.title(request.title())
Expand All @@ -53,22 +79,20 @@ public Club toClubEntity(ClubCreateRequest request, MemberDetails member) {
.detailedIntroduction(request.detailedIntroduction())
.applicationIntroduction(request.applicationIntroduction())
.clubThumbnail(request.clubThumbnail())
.member(member.getMember())
.memberId(member.getMember().getId())
.build();

return club;
}

public ClubQuestion toClubQuestionEntity(ClubQuestionRequest request, Club club) {
return ClubQuestion.builder()
.club(club)
.clubId(club.getId())
.question(request.getQuestion())
.qorders(request.getQorders())
.build();
}


public Club updateClubEntity(Club updateClub, ClubUpdateRequest updateRequest,MemberDetails member) {
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 @@ -79,38 +103,38 @@ public Club updateClubEntity(Club updateClub, ClubUpdateRequest updateRequest,Me
.detailedIntroduction(updateRequest.detailedIntroduction())
.applicationIntroduction(updateRequest.applicationIntroduction())
.clubThumbnail(updateRequest.clubThumbnail())
.member(member.getMember())
.memberId(updateClub.getMemberId())
.build();
}


//소모임 가입
public ClubMember toClubMember(Club club, Member member, ClubApplicationRequest request) {
return new ClubMember(club, member, request.getIntroduction(), false);
return new ClubMember(club.getId(), member.getId(), request.getIntroduction(), false);
}

public ClubApplicationResponse toClubApplicationResponse(ClubMember clubMember, List<ClubAnswer> clubAnswers) {
List<ClubAnswerResponse> answerResponses = clubAnswers.stream()
.map(this::toClubAnswerResponse)
.collect(Collectors.toList());

return ClubApplicationResponse.builder()
.id(clubMember.getId()) // clubMemberId
.clubId(clubMember.getClub().getId())
.memberId(clubMember.getMember().getId())
.clubId(clubMember.getClubId())
.memberId(clubMember.getMemberId())
.introduction(clubMember.getIntroduction())
.approval(clubMember.getApproval())
.clubAnswer(answerResponses)
.build();
}

public ClubAnswer toClubAnswerEntity(ClubAnswerRequest request, Club club, ClubMember clubMember) {
return new ClubAnswer(club, clubMember, request.getAnswer(), request.getQorders());
public ClubAnswer toClubAnswerEntity(ClubAnswerRequest request, ClubMember clubMember) {
return new ClubAnswer(clubMember.getClubId(), clubMember.getId(), request.getAnswer(), request.getQorders());
}

private ClubAnswerResponse toClubAnswerResponse(ClubAnswer clubAnswer) {
return ClubAnswerResponse.builder()
.id(clubAnswer.getId())
.answer(clubAnswer.getAnswer())
.qorders(clubAnswer.getQorders())
.build();
return ClubAnswerResponse.builder()
.id(clubAnswer.getId())
.answer(clubAnswer.getAnswer())
.qorders(clubAnswer.getQorders())
.build();
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/core/linkup/club/club/entity/Club.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.core.linkup.club.club.entity;

import com.core.linkup.common.entity.BaseEntity;
import jakarta.persistence.Entity;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Entity(name = "club")
@NoArgsConstructor
@AllArgsConstructor
@Getter
@SuperBuilder(toBuilder = true)
public class Club extends BaseEntity {

private Long memberId;
private Boolean clubAccessibility;
private String category;
private Integer recruitCount;
private String title;
private String introduction;
private String detailedIntroduction;
private String clubThumbnail;
private String applicationIntroduction;

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.core.linkup.club.entity;
package com.core.linkup.club.club.entity;

import com.core.linkup.common.entity.BaseEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -14,14 +12,8 @@
@Getter
public class ClubAnswer extends BaseEntity {

@ManyToOne
@JoinColumn(name = "club_id")
private Club club;

@ManyToOne
@JoinColumn(name = "club_member_id")
private ClubMember clubMember;

private Long clubId;
private Long memberId;
private String answer;
private Integer qorders;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.core.linkup.club.entity;
package com.core.linkup.club.club.entity;

import com.core.linkup.common.entity.BaseEntity;
import com.core.linkup.member.entity.Member;
import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -15,14 +12,8 @@
@Getter
public class ClubMember extends BaseEntity {

@ManyToOne
@JoinColumn(name = "club_id")
private Club club;

@ManyToOne
@JoinColumn(name = "member_id")
private Member member;

private Long clubId;
private Long memberId;
private String introduction;
private Boolean approval;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.core.linkup.club.entity;
package com.core.linkup.club.club.entity;

import com.core.linkup.common.entity.BaseEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToOne;
import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Entity(name = "club_question")
Expand All @@ -13,9 +14,7 @@
@SuperBuilder
public class ClubQuestion extends BaseEntity {

@ManyToOne
private Club club;

private Long clubId;
private String question;
private Integer qorders;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.core.linkup.club.club.repository;

import com.core.linkup.club.club.entity.ClubAnswer;
import com.core.linkup.club.club.entity.ClubMember;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface ClubAnswerRepository extends JpaRepository<ClubAnswer, Long> {
List<ClubAnswer> findByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.core.linkup.club.repository;
package com.core.linkup.club.club.repository;

import com.core.linkup.club.entity.Club;
import com.core.linkup.club.requset.ClubSearchRequest;
import com.core.linkup.club.club.entity.Club;
import com.core.linkup.club.club.request.ClubSearchRequest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.core.linkup.club.repository;
package com.core.linkup.club.club.repository;

import com.core.linkup.club.entity.Club;
import com.core.linkup.club.entity.QClub;
import com.core.linkup.club.requset.ClubSearchRequest;
import com.core.linkup.club.club.entity.Club;
import com.core.linkup.club.club.entity.QClub;
import com.core.linkup.club.club.request.ClubSearchRequest;
import com.core.linkup.common.entity.enums.ClubType;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.jpa.impl.JPAQueryFactory;
Expand All @@ -14,8 +14,6 @@

import java.util.List;

import static com.core.linkup.member.entity.QMember.member;

@Repository
@RequiredArgsConstructor
public class ClubCustomRepositoryImpl implements ClubCustomRepository {
Expand All @@ -28,28 +26,19 @@ public Page<Club> findSearchClubs(ClubSearchRequest request, Pageable pageable)

BooleanBuilder booleanBuilder = new BooleanBuilder();

// if (request.getOfficeBuildingId() != null) {
// booleanBuilder.and(club.officeBuilding.id.eq(request.getOfficeBuildingId()));
// }
if (request.getClubType() != null && !request.getClubType().isEmpty()) {
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)
.leftJoin(club.member, member)
.fetchJoin()
.where(booleanBuilder)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
// List<Club> clubs = queryFactory.selectFrom(club)
// .leftJoin(club.member, member)
// .fetchJoin()
// .where(booleanBuilder)
// .offset(pageable.getOffset())
// .limit(pageable.getPageSize())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.core.linkup.club.club.repository;

import com.core.linkup.club.club.entity.ClubMember;
import org.springframework.data.jpa.repository.JpaRepository;

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

public interface ClubMemberRepository extends JpaRepository<ClubMember, Long> {
List<ClubMember> findByMemberId(Long memberId);

List<ClubMember> findByClubId(Long clubId);

Optional<ClubMember> findByClubIdAndMemberId(Long clubId, Long memberId);

Optional<ClubMember> findByMemberIdAndClubId(Long memberId, Long clubId);
}
Loading

0 comments on commit 8d1de08

Please sign in to comment.