Skip to content

Commit

Permalink
feat: 티어 증가하는 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
CFalws committed Aug 9, 2023
1 parent 205c30d commit 27115b8
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Member extends BaseEntity {

private static final int MASTER_NUMBER = 0;
private static final int PARTICIPANT_NUMBER = 1;
private static final int MAXIMUM_TIER = 5;

@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
Expand Down Expand Up @@ -79,6 +80,12 @@ public String getIntroduction() {
return introduction.getIntroduction();
}

public void updateTier() {
if (tier < MAXIMUM_TIER) {
tier += 1;
}
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ public RoundOfMember findRoundOfMemberBy(Member member) {
);
}

public void updateTier() {
for (RoundOfMember roundOfMember : roundOfMembers) {
roundOfMember.updateTier();
}
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,8 @@ private OptionalTodo findOptionalTodoById(Long todoId) {
public boolean isMemberEquals(Member member) {
return this.member.equals(member);
}

public void updateTier() {
member.updateTier();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.yigongil.backend.exception.InvalidNumberOfMaximumStudyMember;
import com.yigongil.backend.exception.InvalidProcessingStatusException;
import com.yigongil.backend.exception.InvalidStudyNameLengthException;
import com.yigongil.backend.exception.RoundNotFoundException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
Expand Down Expand Up @@ -171,15 +170,6 @@ public Integer calculateAverageTier() {
return currentRound.calculateAverageTier();
}

public Round findRoundById(Long roundId) {
return rounds.stream()
.filter(round -> round.getId().equals(roundId))
.findAny()
.orElseThrow(
() -> new RoundNotFoundException("스터디에 해당 회차가 존재하지 않습니다.", roundId)
);
}

public void addMember(Member member) {
validateStudyProcessingStatus();
validateMemberSize();
Expand Down Expand Up @@ -242,6 +232,7 @@ private void updateCurrentRound(Round upcomingRound) {

private void finishStudy() {
this.processingStatus = ProcessingStatus.END;
currentRound.updateTier();
}

public void startStudy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

import com.yigongil.backend.domain.member.Member;
import com.yigongil.backend.domain.round.Round;
import com.yigongil.backend.domain.roundofmember.RoundOfMember;
import com.yigongil.backend.exception.InvalidMemberSizeException;
import com.yigongil.backend.exception.InvalidProcessingStatusException;
import com.yigongil.backend.fixture.MemberFixture;
import com.yigongil.backend.fixture.StudyFixture;
import java.time.LocalDateTime;
import java.util.List;
import org.junit.jupiter.api.Test;

class StudyTest {
Expand Down Expand Up @@ -54,6 +56,33 @@ class StudyTest {
assertThat(study.getProcessingStatus()).isSameAs(ProcessingStatus.END);
}

@Test
void 스터디를_성공적으로_완수하면_티어가_한다() {
// given
Study study = StudyFixture.자바_스터디_모집중.toStudy();
study.updateToNextRound();
study.updateToNextRound();
List<Integer> expected = study.getCurrentRound()
.getRoundOfMembers()
.stream()
.map(RoundOfMember::getMember)
.map(Member::getTier)
.map(tier -> tier < 5 ? tier + 1 : tier)
.toList();

// when
study.updateToNextRound();
List<Integer> actual = study.getCurrentRound()
.getRoundOfMembers()
.stream()
.map(RoundOfMember::getMember)
.map(Member::getTier)
.toList();

// then
assertThat(actual).isEqualTo(expected);
}

@Test
void 스터디의_현재_라운드가_종료되는_날이면_true_반환한다() {
// given
Expand Down Expand Up @@ -113,12 +142,9 @@ class StudyTest {
void 정원이_가__스터디에_Member_하면_예외가_발생한다() {
// given
Study study = StudyFixture.자바_스터디_모집중_정원_2.toStudy();
Member member1 = MemberFixture.폰노이만.toMember();
Member member2 = MemberFixture.마틴파울러.toMember();

// when
study.addMember(member1);

// then
assertThatThrownBy(() -> study.addMember(member2))
.isInstanceOf(InvalidMemberSizeException.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Round toRound() {
.roundNumber(roundNumber)
.master(master)
.endAt(LocalDateTime.now())
.roundOfMembers(new ArrayList<>(List.of(RoundOfMemberFixture.김진우_라운드_삼.toRoundOfMember())))
.roundOfMembers(new ArrayList<>(List.of(RoundOfMemberFixture.김진우_라운드_삼.toRoundOfMember(), RoundOfMemberFixture.노이만_라오멤.toRoundOfMember())))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
public enum RoundOfMemberFixture {

김진우_라운드_삼(1L, MemberFixture.김진우.toMember(), false),
노이만_라오멤(1L, MemberFixture.폰노이만.toMember(), false),
;

private final Long id;
Expand Down

0 comments on commit 27115b8

Please sign in to comment.