Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/main/java/com/debatetimer/domain/customize/Bell.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.debatetimer.domain.customize;

import com.debatetimer.exception.custom.DTClientErrorException;
import com.debatetimer.exception.errorcode.ClientErrorCode;
import lombok.Getter;

@Getter
public class Bell {

public static final int MAX_BELL_COUNT = 3;

private final int time;
private final int count;

public Bell(int time, int count) {
validateTime(time);
validateCount(count);
this.time = time;
this.count = count;
}

private void validateTime(int time) {
if (time < 0) {
throw new DTClientErrorException(ClientErrorCode.INVALID_BELL_TIME);
}
}

private void validateCount(int count) {
if (count <= 0 || count > MAX_BELL_COUNT) {
throw new DTClientErrorException(ClientErrorCode.INVALID_BELL_COUNT);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import com.debatetimer.exception.custom.DTClientErrorException;
import com.debatetimer.exception.errorcode.ClientErrorCode;
import java.util.List;
import org.springframework.lang.Nullable;

public abstract class CustomizeTimeBoxDomain {
public abstract class CustomizeTimeBox {

public static final int SPEECH_TYPE_MAX_LENGTH = 10;
public static final int SPEAKER_MAX_LENGTH = 5;
Expand All @@ -16,7 +17,7 @@ public abstract class CustomizeTimeBoxDomain {
@Nullable
private final String speaker;

protected CustomizeTimeBoxDomain(Stance stance, String speechType, @Nullable String speaker) {
protected CustomizeTimeBox(Stance stance, String speechType, @Nullable String speaker) {
validateStance(stance);
validateSpeechType(speechType);
validateSpeaker(speaker);
Expand Down Expand Up @@ -69,4 +70,6 @@ public final String getSpeaker() {

@Nullable
public abstract Integer getTimePerSpeaking();

public abstract List<Bell> getBells();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.debatetimer.domain.customize;

import com.debatetimer.entity.customize.CustomizeTimeBoxEntity;
import java.util.Comparator;
import java.util.List;
import lombok.Getter;

@Getter
public class CustomizeTimeBoxEntities {

private static final Comparator<CustomizeTimeBoxEntity> TIME_BOX_COMPARATOR = Comparator
.comparing(CustomizeTimeBoxEntity::getSequence);

private final List<CustomizeTimeBoxEntity> timeBoxes;

public CustomizeTimeBoxEntities(List<CustomizeTimeBoxEntity> timeBoxes) {
this.timeBoxes = timeBoxes.stream()
.sorted(TIME_BOX_COMPARATOR)
.toList();
}
Comment on lines +8 to +20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

음... 이건 좀 궁금하네요. entity의 일급 컬렉션을 domain에 위치시킨 이유가 뭔가요?
이건 저도 확신이 안서서 적은 질문입니다

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그게... 지금 해당 객체가 가지고 있는게 Entity 거덩요? 그런데 얘가 지금 ServiceV1에서는 도메인처럼 사용되고 있어요.
그래서 얘를 엔티티로 옮길까 하다가 (어짜피 곧 지워질 거기도 하고... 지금 ServiceV1에서는 도메인으로 쓰이기도 하고...) 일단 냅뒀습니다. 그래도 V2에서 사용하는 객체와 구분하기 위해서 이름은 바꿨습니다.
해당 부분은 V1까지 중복적으로 가지고 가다가, V2 적용 시점에 지울 것 같습니다. 구분을 위한 더 좋은 대안이 있다면 알려주세요!

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

import com.debatetimer.exception.custom.DTClientErrorException;
import com.debatetimer.exception.errorcode.ClientErrorCode;
import java.util.List;
import org.springframework.lang.Nullable;

public final class NormalTimeBoxDomain extends CustomizeTimeBoxDomain {
public final class NormalTimeBox extends CustomizeTimeBox {

private final int time;
private final List<Bell> bells;

public NormalTimeBoxDomain(Stance stance, String speechType, @Nullable String speaker, Integer time) {
public NormalTimeBox(Stance stance, String speechType, @Nullable String speaker, Integer time, List<Bell> bells) {
super(stance, speechType, speaker);

validateTime(time);
this.time = time;
this.bells = bells;
}

private void validateTime(Integer time) {
Expand Down Expand Up @@ -47,4 +49,9 @@ public Integer getTimePerTeam() {
public Integer getTimePerSpeaking() {
return null;
}

@Override
public List<Bell> getBells() {
return bells;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

import com.debatetimer.exception.custom.DTClientErrorException;
import com.debatetimer.exception.errorcode.ClientErrorCode;
import java.util.Collections;
import java.util.List;
import org.springframework.lang.Nullable;

public class TimeBasedTimeBoxDomain extends CustomizeTimeBoxDomain {
public class TimeBasedTimeBox extends CustomizeTimeBox {

private final int timePerTeam;

@Nullable
private final Integer timePerSpeaking;

public TimeBasedTimeBoxDomain(Stance stance,
String speechType,
@Nullable String speaker,
Integer timePerTeam,
@Nullable Integer timePerSpeaking) {
public TimeBasedTimeBox(Stance stance,
String speechType,
@Nullable String speaker,
Integer timePerTeam,
@Nullable Integer timePerSpeaking) {
super(stance, speechType, speaker);

validateTimes(timePerTeam, timePerSpeaking);
Expand Down Expand Up @@ -69,4 +71,9 @@ public Integer getTimePerTeam() {
public Integer getTimePerSpeaking() {
return timePerSpeaking;
}

@Override
public List<Bell> getBells() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package com.debatetimer.dto.customize.request;

import com.debatetimer.domain.customize.Bell;

public record BellRequest(
int time,
int count
) {

public Bell toDomain() {
return new Bell(time, count);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.debatetimer.dto.customize.request;

import com.debatetimer.domain.customize.CustomizeTable;
import com.debatetimer.domain.customize.CustomizeTimeBoxes;
import com.debatetimer.domain.customize.CustomizeTimeBox;
import com.debatetimer.domain.customize.CustomizeTimeBoxEntities;
import com.debatetimer.domain.member.Member;
import jakarta.validation.Valid;
import java.util.List;
Expand All @@ -13,13 +14,19 @@ public record CustomizeTableCreateRequest(
@Valid List<CustomizeTimeBoxCreateRequest> table
) {

public CustomizeTimeBoxEntities toTimeBoxes(CustomizeTable customizeTable) {
return IntStream.range(0, table.size())
.mapToObj(i -> table.get(i).toTimeBox(customizeTable, i + 1))
.collect(Collectors.collectingAndThen(Collectors.toList(), CustomizeTimeBoxEntities::new));
}

public CustomizeTable toTable(Member member) {
return info.toTable(member);
}

public CustomizeTimeBoxes toTimeBoxes(CustomizeTable customizeTable) {
return IntStream.range(0, table.size())
.mapToObj(i -> table.get(i).toTimeBox(customizeTable, i + 1))
.collect(Collectors.collectingAndThen(Collectors.toList(), CustomizeTimeBoxes::new));
public List<CustomizeTimeBox> toTimeBoxList() { // TODO 메서드 네이밍 변경 toTimeBoxList() -> toTimeBoxes()
return table.stream()
.map(CustomizeTimeBoxCreateRequest::toDomain)
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.debatetimer.dto.customize.request;

import com.debatetimer.domain.customize.Bell;
import com.debatetimer.domain.customize.CustomizeBoxType;
import com.debatetimer.domain.customize.CustomizeTable;
import com.debatetimer.domain.customize.CustomizeTimeBox;
import com.debatetimer.domain.customize.NormalTimeBox;
import com.debatetimer.domain.customize.Stance;
import com.debatetimer.domain.customize.TimeBasedTimeBox;
import com.debatetimer.entity.customize.CustomizeTableEntity;
import com.debatetimer.entity.customize.CustomizeTimeBox;
import com.debatetimer.entity.customize.CustomizeTimeBoxEntity;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.util.Collections;
import java.util.List;
import org.springframework.lang.Nullable;

Expand Down Expand Up @@ -36,12 +41,28 @@ public record CustomizeTimeBoxCreateRequest(
String speaker
) {

public CustomizeTimeBox toTimeBox(CustomizeTable customizeTable, int sequence) {
public CustomizeTimeBoxEntity toTimeBox(CustomizeTable customizeTable, int sequence) {
if (boxType.isTimeBased()) {
return new CustomizeTimeBox(new CustomizeTableEntity(customizeTable), sequence, stance, speechType,
return new CustomizeTimeBoxEntity(new CustomizeTableEntity(customizeTable), sequence, stance, speechType,
boxType, timePerTeam, timePerSpeaking, speaker);
}
return new CustomizeTimeBox(new CustomizeTableEntity(customizeTable), sequence, stance, speechType, boxType,
return new CustomizeTimeBoxEntity(new CustomizeTableEntity(customizeTable), sequence, stance, speechType, boxType,
time, speaker);
}

public CustomizeTimeBox toDomain() {
if (boxType.isTimeBased()) {
return new TimeBasedTimeBox(stance, speechType, speaker, timePerTeam, timePerSpeaking);
}
return new NormalTimeBox(stance, speechType, speaker, time, toBells(bell));
}

private List<Bell> toBells(List<BellRequest> bellRequests) {
if (bellRequests == null) {
return Collections.emptyList();
}
return bellRequests.stream()
.map(BellRequest::toDomain)
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package com.debatetimer.dto.customize.response;

import com.debatetimer.domain.customize.Bell;

public record BellResponse(
int time,
int count
) {

public BellResponse(Bell bell) {
this(bell.getTime(), bell.getCount());
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.debatetimer.dto.customize.response;

import com.debatetimer.domain.customize.CustomizeTable;
import com.debatetimer.domain.customize.CustomizeTimeBoxes;
import com.debatetimer.entity.customize.CustomizeTimeBox;
import com.debatetimer.domain.customize.CustomizeTimeBox;
import com.debatetimer.domain.customize.CustomizeTimeBoxEntities;
import com.debatetimer.entity.customize.CustomizeTimeBoxEntity;
import java.util.List;

public record CustomizeTableResponse(long id, CustomizeTableInfoResponse info, List<CustomizeTimeBoxResponse> table) {

public CustomizeTableResponse(
CustomizeTable customizeTable,
CustomizeTimeBoxes customizeTimeBoxes
CustomizeTimeBoxEntities customizeTimeBoxes
) {
this(customizeTable.getId(), new CustomizeTableInfoResponse(customizeTable),
toTimeBoxResponses(customizeTimeBoxes));
Expand All @@ -22,8 +23,24 @@ public CustomizeTableResponse(
this(customizeTable.getId(), new CustomizeTableInfoResponse(customizeTable), timeBoxResponses);
}

private static List<CustomizeTimeBoxResponse> toTimeBoxResponses(CustomizeTimeBoxes timeBoxes) {
List<CustomizeTimeBox> customizeTimeBoxes = timeBoxes.getTimeBoxes();
private static List<CustomizeTimeBoxResponse> toTimeBoxResponses(CustomizeTimeBoxEntities timeBoxes) {
List<CustomizeTimeBoxEntity> customizeTimeBoxes = timeBoxes.getTimeBoxes();
return customizeTimeBoxes
.stream()
.map(CustomizeTimeBoxResponse::new)
.toList();
}

public static CustomizeTableResponse ofDomain(CustomizeTable customizeTable,
List<CustomizeTimeBox> customizeTimeBoxes) { // TODO 정팩매 -> 생성자로 전환
return new CustomizeTableResponse(
customizeTable.getId(),
new CustomizeTableInfoResponse(customizeTable),
toTimeBoxResponses(customizeTimeBoxes)
);
}

private static List<CustomizeTimeBoxResponse> toTimeBoxResponses(List<CustomizeTimeBox> customizeTimeBoxes) {
return customizeTimeBoxes
.stream()
.map(CustomizeTimeBoxResponse::new)
Expand Down
Loading