Skip to content

Commit

Permalink
feat : ClubRequest Club Id 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
Changha-dev committed Nov 25, 2023
1 parent e6b7439 commit 7692b10
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 18 deletions.
35 changes: 24 additions & 11 deletions src/main/java/com/donggram/back/entity/Club.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.donggram.back.dto.ClubDetailsDto;
import com.donggram.back.dto.ClubProfileUpdateDto;
import com.donggram.back.dto.ProfileUpdateDto;
import com.donggram.back.repository.CollegeRepository;
import com.donggram.back.repository.DivisionRepository;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -46,6 +48,11 @@ public class Club {
@JoinColumn(name = "imageClub_id")
private ImageClub imageClub;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "clubRequest_id")
private ClubRequest clubRequest;


//일대다, 양방향
@JsonIgnore
@OneToMany(mappedBy = "club")
Expand All @@ -68,17 +75,23 @@ public void setImageClub(ImageClub imageClub) {
this.imageClub = imageClub;
}

public void updateClubProfile(ClubProfileUpdateDto clubProfileUpdateDto) {
public void updateClubProfile(ClubProfileUpdateDto clubProfileUpdateDto, CollegeRepository collegeRepository, DivisionRepository divisionRepository) {
this.clubName = clubProfileUpdateDto.getClubName();
// this.college = clubProfileUpdateDto.getCollege();
// this.division = clubProfileUpdateDto.getDivision();
//
//
//
// // 역할 정보를 업데이트
// if (profileUpdateDto.getRole() != null) {
// this.roles.clear(); // 기존 역할 정보 모두 삭제
// this.roles.addAll(Collections.singleton(profileUpdateDto.getRole())); // 새로운 역할 정보 추가
// }

if(clubProfileUpdateDto.getCollege() != null){
College college = collegeRepository.findByName(clubProfileUpdateDto.getCollege()).orElseThrow(() -> new RuntimeException("해당 단과대가 존재하지 않습니다."));
this.college = college;
}
if(clubProfileUpdateDto.getDivision() != null){
Division division = divisionRepository.findByName(clubProfileUpdateDto.getDivision()).orElseThrow(() -> new RuntimeException("해당 분과가 존재하지 않습니다."));
this.division =division;
}

this.content = clubProfileUpdateDto.getContent();
this.clubName = clubProfileUpdateDto.getClubName();
this.clubCreated = clubProfileUpdateDto.getClubCreated();
this.isRecruitment = clubProfileUpdateDto.isRecruitment();
this.recruitment_period = clubProfileUpdateDto.getRecruitmentPeriod();

}
}
3 changes: 3 additions & 0 deletions src/main/java/com/donggram/back/entity/ClubRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public class ClubRequest {
@Enumerated(EnumType.STRING)
private RequestStatus status;

@OneToOne(mappedBy = "clubRequest", fetch = FetchType.LAZY)
private Club club;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;
Expand Down
22 changes: 17 additions & 5 deletions src/main/java/com/donggram/back/service/AdminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ public ResponseDto getClubDetails(Long clubId){
}

@Transactional
public ResponseDto approve(Long clubId) {
public ResponseDto approve(Long clubRequestId) {

ClubRequest clubRequest = clubRequestRepository.findById(clubId)
ClubRequest clubRequest = clubRequestRepository.findById(clubRequestId)
.orElseThrow(() -> new RuntimeException("해당 동아리 생성 요청이 존재하지 않습니다."));

// 동아리 상태 변경
Expand All @@ -198,6 +198,7 @@ public ResponseDto approve(Long clubId) {
.clubJoinList(new ArrayList<>())
.isRecruitment(clubRequest.isRecruitment())
.clubCreated(clubRequest.getClub_created())
.clubRequest(clubRequest)
.build();

club.setImageClub(clubRequest.getImageClub());
Expand All @@ -221,8 +222,8 @@ public ResponseDto approve(Long clubId) {
}

@Transactional
public ResponseDto reject(Long clubId){
ClubRequest clubRequest = clubRequestRepository.findById(clubId)
public ResponseDto reject(Long clubRequestId){
ClubRequest clubRequest = clubRequestRepository.findById(clubRequestId)
.orElseThrow(() -> new RuntimeException("해당 동아리 생성 요청이 존재하지 않습니다."));

clubRequest.updateStatus(RequestStatus.rejected);
Expand All @@ -234,9 +235,17 @@ public ResponseDto reject(Long clubId){
}

@Transactional
public ResponseDto getAllMemberBySelectedClub(Long clubId){
public ResponseDto getAllMemberBySelectedClub(Long clubRequestId){
List<ClubMemberDto> clubMemberDtos = new ArrayList<>();

//받아오는게 ClubRequestId

ClubRequest clubRequest = clubRequestRepository.findById(clubRequestId).orElseThrow(() -> new RuntimeException("해당 동아리요청 엔티티가 존재하지 않습니다."));

//보내줘야 되는게 clubId

long clubId = clubRequest.getClub().getId();

Club club = clubRepository.findById(clubId).orElseThrow(() -> new RuntimeException("해당 동아리가 존재하지 않습니다."));
for ( ClubJoin clubJoin : club.getClubJoinList()) {
ClubMemberDto clubMemberDto = ClubMemberDto.builder()
Expand All @@ -257,6 +266,9 @@ public ResponseDto getAllMemberBySelectedClub(Long clubId){
.build();
}

// @Transactional
// public ResponseDto updateClubDetails(Long clubId){}

}


Expand Down
18 changes: 16 additions & 2 deletions src/main/java/com/donggram/back/service/ClubService.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,14 @@ public ResponseDto getClubDetails(Long clubId){
}

@Transactional
public ResponseDto approveMember(Long memberId, Long clubId){
public ResponseDto approveMember(Long memberId, Long clubRequestId){


ClubRequest clubRequest = clubRequestRepository.findById(clubRequestId)
.orElseThrow(() -> new RuntimeException("해당 동아리 요청 엔티티가 존재하지 않습니다."));

long clubId = clubRequest.getClub().getId();

ClubJoin clubJoin = clubJoinRepository.findByMemberIdAndClubId(memberId, clubId)
.orElseThrow(() -> new RuntimeException("해당 멤버의 동아리 가입신청이 존재하지 않습니다."));

Expand All @@ -162,7 +169,14 @@ public ResponseDto approveMember(Long memberId, Long clubId){
}

@Transactional
public ResponseDto memberReject(Long memberId, Long clubId){
public ResponseDto memberReject(Long memberId, Long clubRequestId){


ClubRequest clubRequest = clubRequestRepository.findById(clubRequestId)
.orElseThrow(() -> new RuntimeException("해당 동아리 요청 엔티티가 존재하지 않습니다."));

long clubId = clubRequest.getClub().getId();

ClubJoin clubJoin = clubJoinRepository.findByMemberIdAndClubId(memberId, clubId)
.orElseThrow(() -> new RuntimeException("해당 멤버의 동아리 가입신청이 존재하지 않습니다."));

Expand Down

0 comments on commit 7692b10

Please sign in to comment.