Skip to content

Commit

Permalink
✨ 프로젝트 탈퇴 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
rilac1 committed Feb 23, 2023
1 parent 5b7c0f0 commit 89b64b0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
import yapp.allround3.member.domain.Member;
import yapp.allround3.member.repository.MemberRepository;
import yapp.allround3.participant.domain.Participant;
import yapp.allround3.participant.repository.ParticipantRepository;
import yapp.allround3.participant.service.ParticipantService;

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

@Service
@RequiredArgsConstructor
@Transactional(readOnly=true)
public class MemberService {
private final MemberRepository memberRepository;
private final ParticipantRepository participantRepository;

private final ParticipantService participantService;


public Member findMemberById(Long id){
Expand Down Expand Up @@ -57,7 +57,6 @@ public void withdraw(Long memberId) {
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new CustomException("해당 멤버가 존재하지 않습니다."));
member.withdraw();
participantRepository.findByMember(member)
.forEach(Participant::withdrawProject);
participantService.withdrawAllProjects(member);
}
}
15 changes: 8 additions & 7 deletions src/main/java/yapp/allround3/participant/domain/Participant.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,22 @@ public void changeLeader(Participant former) {
this.leader = false;
}

public void withdrawProject() {
public void withdraw() {
participantStatus = ParticipantStatus.WITHDRAWAL;
}

public void joinProject() {
public void join() {
participantStatus = ParticipantStatus.NORMAL;
}

@Override
public String toString() {
return "Participant{" +
"id=" + id +
", project=" + project.getId() +
", member=" + member.getId() +
", leader=" + leader +
'}';
"id=" + id +
", project=" + project.getId() +
", member=" + member.getId() +
", leader=" + leader +
", status=" + participantStatus +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,28 @@ public void joinProject(Long projectId, Long memberId) {
throw new CustomException("이미 가입된 참여자에요");
}

participant.joinProject();
participantRepository.save(participant);
participant.join();

taskRepository.findTasksByProjectId(projectId)
.forEach(task -> {
task.addFeedbackRequiredPersonnel();
taskRepository.save(task);
}
);
.forEach(Task::addFeedbackRequiredPersonnel);
}

@Transactional
public void withdrawProject(Long participantId) {
Participant participant = findParticipantById(participantId);

participant.withdraw();

taskRepository.findTasksByProjectId(participant.getProject().getId())
.forEach(Task::subtractFeedbackRequiredPersonnel);
}

@Transactional
public void withdrawAllProjects(Member member) {
List<Participant> participants = participantRepository.findByMember(member);
participants.stream()
.map(Participant::getId)
.forEach(this::withdrawProject);
}

@Transactional
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/yapp/allround3/task/domain/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public void updateFeedbackRequestedDate(LocalDate feedbackRequestedDate){
public void addFeedbackRequiredPersonnel(){
this.feedbackRequiredPersonnel += 1;
}

public void subtractFeedbackRequiredPersonnel(){
this.feedbackRequiredPersonnel -= 1;
}

@Override
public String toString() {
return "Task{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import yapp.allround3.participant.domain.Participant;
import yapp.allround3.task.domain.Task;

Expand Down

0 comments on commit 89b64b0

Please sign in to comment.