diff --git a/src/main/java/com/debatetimer/domain/customize/Bell.java b/src/main/java/com/debatetimer/domain/customize/Bell.java new file mode 100644 index 00000000..58fb4443 --- /dev/null +++ b/src/main/java/com/debatetimer/domain/customize/Bell.java @@ -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); + } + } +} diff --git a/src/main/java/com/debatetimer/domain/customize/CustomizeTimeBoxDomain.java b/src/main/java/com/debatetimer/domain/customize/CustomizeTimeBox.java similarity index 90% rename from src/main/java/com/debatetimer/domain/customize/CustomizeTimeBoxDomain.java rename to src/main/java/com/debatetimer/domain/customize/CustomizeTimeBox.java index 18ac7e84..498c9179 100644 --- a/src/main/java/com/debatetimer/domain/customize/CustomizeTimeBoxDomain.java +++ b/src/main/java/com/debatetimer/domain/customize/CustomizeTimeBox.java @@ -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; @@ -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); @@ -69,4 +70,6 @@ public final String getSpeaker() { @Nullable public abstract Integer getTimePerSpeaking(); + + public abstract List getBells(); } diff --git a/src/main/java/com/debatetimer/domain/customize/CustomizeTimeBoxEntities.java b/src/main/java/com/debatetimer/domain/customize/CustomizeTimeBoxEntities.java new file mode 100644 index 00000000..442845ac --- /dev/null +++ b/src/main/java/com/debatetimer/domain/customize/CustomizeTimeBoxEntities.java @@ -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 TIME_BOX_COMPARATOR = Comparator + .comparing(CustomizeTimeBoxEntity::getSequence); + + private final List timeBoxes; + + public CustomizeTimeBoxEntities(List timeBoxes) { + this.timeBoxes = timeBoxes.stream() + .sorted(TIME_BOX_COMPARATOR) + .toList(); + } +} diff --git a/src/main/java/com/debatetimer/domain/customize/CustomizeTimeBoxes.java b/src/main/java/com/debatetimer/domain/customize/CustomizeTimeBoxes.java deleted file mode 100644 index 585c8bd0..00000000 --- a/src/main/java/com/debatetimer/domain/customize/CustomizeTimeBoxes.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.debatetimer.domain.customize; - -import com.debatetimer.entity.customize.CustomizeTimeBox; -import java.util.Comparator; -import java.util.List; -import lombok.Getter; - -@Getter -public class CustomizeTimeBoxes { - - private static final Comparator TIME_BOX_COMPARATOR = Comparator - .comparing(CustomizeTimeBox::getSequence); - - private final List timeBoxes; - - public CustomizeTimeBoxes(List timeBoxes) { - this.timeBoxes = timeBoxes.stream() - .sorted(TIME_BOX_COMPARATOR) - .toList(); - } -} diff --git a/src/main/java/com/debatetimer/domain/customize/NormalTimeBoxDomain.java b/src/main/java/com/debatetimer/domain/customize/NormalTimeBox.java similarity index 74% rename from src/main/java/com/debatetimer/domain/customize/NormalTimeBoxDomain.java rename to src/main/java/com/debatetimer/domain/customize/NormalTimeBox.java index a17800d8..4e413aad 100644 --- a/src/main/java/com/debatetimer/domain/customize/NormalTimeBoxDomain.java +++ b/src/main/java/com/debatetimer/domain/customize/NormalTimeBox.java @@ -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 bells; - public NormalTimeBoxDomain(Stance stance, String speechType, @Nullable String speaker, Integer time) { + public NormalTimeBox(Stance stance, String speechType, @Nullable String speaker, Integer time, List bells) { super(stance, speechType, speaker); - validateTime(time); this.time = time; + this.bells = bells; } private void validateTime(Integer time) { @@ -47,4 +49,9 @@ public Integer getTimePerTeam() { public Integer getTimePerSpeaking() { return null; } + + @Override + public List getBells() { + return bells; + } } diff --git a/src/main/java/com/debatetimer/domain/customize/TimeBasedTimeBoxDomain.java b/src/main/java/com/debatetimer/domain/customize/TimeBasedTimeBox.java similarity index 79% rename from src/main/java/com/debatetimer/domain/customize/TimeBasedTimeBoxDomain.java rename to src/main/java/com/debatetimer/domain/customize/TimeBasedTimeBox.java index 30dba5ab..40018cab 100644 --- a/src/main/java/com/debatetimer/domain/customize/TimeBasedTimeBoxDomain.java +++ b/src/main/java/com/debatetimer/domain/customize/TimeBasedTimeBox.java @@ -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); @@ -69,4 +71,9 @@ public Integer getTimePerTeam() { public Integer getTimePerSpeaking() { return timePerSpeaking; } + + @Override + public List getBells() { + return Collections.emptyList(); + } } diff --git a/src/main/java/com/debatetimer/dto/customize/request/BellRequest.java b/src/main/java/com/debatetimer/dto/customize/request/BellRequest.java index 0c846580..fa5f2d88 100644 --- a/src/main/java/com/debatetimer/dto/customize/request/BellRequest.java +++ b/src/main/java/com/debatetimer/dto/customize/request/BellRequest.java @@ -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); + } } diff --git a/src/main/java/com/debatetimer/dto/customize/request/CustomizeTableCreateRequest.java b/src/main/java/com/debatetimer/dto/customize/request/CustomizeTableCreateRequest.java index e0eb509e..f4f9baf1 100644 --- a/src/main/java/com/debatetimer/dto/customize/request/CustomizeTableCreateRequest.java +++ b/src/main/java/com/debatetimer/dto/customize/request/CustomizeTableCreateRequest.java @@ -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; @@ -13,13 +14,19 @@ public record CustomizeTableCreateRequest( @Valid List 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 toTimeBoxList() { // TODO 메서드 네이밍 변경 toTimeBoxList() -> toTimeBoxes() + return table.stream() + .map(CustomizeTimeBoxCreateRequest::toDomain) + .toList(); } } diff --git a/src/main/java/com/debatetimer/dto/customize/request/CustomizeTimeBoxCreateRequest.java b/src/main/java/com/debatetimer/dto/customize/request/CustomizeTimeBoxCreateRequest.java index 97397215..0507ad3b 100644 --- a/src/main/java/com/debatetimer/dto/customize/request/CustomizeTimeBoxCreateRequest.java +++ b/src/main/java/com/debatetimer/dto/customize/request/CustomizeTimeBoxCreateRequest.java @@ -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; @@ -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 toBells(List bellRequests) { + if (bellRequests == null) { + return Collections.emptyList(); + } + return bellRequests.stream() + .map(BellRequest::toDomain) + .toList(); + } } diff --git a/src/main/java/com/debatetimer/dto/customize/response/BellResponse.java b/src/main/java/com/debatetimer/dto/customize/response/BellResponse.java index ce2dae8c..0ec2b060 100644 --- a/src/main/java/com/debatetimer/dto/customize/response/BellResponse.java +++ b/src/main/java/com/debatetimer/dto/customize/response/BellResponse.java @@ -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()); + } } diff --git a/src/main/java/com/debatetimer/dto/customize/response/CustomizeTableResponse.java b/src/main/java/com/debatetimer/dto/customize/response/CustomizeTableResponse.java index 587e61c5..906bc27e 100644 --- a/src/main/java/com/debatetimer/dto/customize/response/CustomizeTableResponse.java +++ b/src/main/java/com/debatetimer/dto/customize/response/CustomizeTableResponse.java @@ -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 table) { public CustomizeTableResponse( CustomizeTable customizeTable, - CustomizeTimeBoxes customizeTimeBoxes + CustomizeTimeBoxEntities customizeTimeBoxes ) { this(customizeTable.getId(), new CustomizeTableInfoResponse(customizeTable), toTimeBoxResponses(customizeTimeBoxes)); @@ -22,8 +23,24 @@ public CustomizeTableResponse( this(customizeTable.getId(), new CustomizeTableInfoResponse(customizeTable), timeBoxResponses); } - private static List toTimeBoxResponses(CustomizeTimeBoxes timeBoxes) { - List customizeTimeBoxes = timeBoxes.getTimeBoxes(); + private static List toTimeBoxResponses(CustomizeTimeBoxEntities timeBoxes) { + List customizeTimeBoxes = timeBoxes.getTimeBoxes(); + return customizeTimeBoxes + .stream() + .map(CustomizeTimeBoxResponse::new) + .toList(); + } + + public static CustomizeTableResponse ofDomain(CustomizeTable customizeTable, + List customizeTimeBoxes) { // TODO 정팩매 -> 생성자로 전환 + return new CustomizeTableResponse( + customizeTable.getId(), + new CustomizeTableInfoResponse(customizeTable), + toTimeBoxResponses(customizeTimeBoxes) + ); + } + + private static List toTimeBoxResponses(List customizeTimeBoxes) { return customizeTimeBoxes .stream() .map(CustomizeTimeBoxResponse::new) diff --git a/src/main/java/com/debatetimer/dto/customize/response/CustomizeTimeBoxResponse.java b/src/main/java/com/debatetimer/dto/customize/response/CustomizeTimeBoxResponse.java index e62f17fb..ce90f96a 100644 --- a/src/main/java/com/debatetimer/dto/customize/response/CustomizeTimeBoxResponse.java +++ b/src/main/java/com/debatetimer/dto/customize/response/CustomizeTimeBoxResponse.java @@ -1,8 +1,11 @@ package com.debatetimer.dto.customize.response; +import com.debatetimer.domain.customize.Bell; import com.debatetimer.domain.customize.CustomizeBoxType; +import com.debatetimer.domain.customize.CustomizeTimeBox; import com.debatetimer.domain.customize.Stance; -import com.debatetimer.entity.customize.CustomizeTimeBox; +import com.debatetimer.entity.customize.CustomizeTimeBoxEntity; +import java.util.Collections; import java.util.List; public record CustomizeTimeBoxResponse( @@ -16,7 +19,7 @@ public record CustomizeTimeBoxResponse( String speaker ) { - public CustomizeTimeBoxResponse(CustomizeTimeBox customizeTimeBox) { + public CustomizeTimeBoxResponse(CustomizeTimeBoxEntity customizeTimeBox) { this( customizeTimeBox.getStance(), customizeTimeBox.getSpeechType(), @@ -29,7 +32,7 @@ public CustomizeTimeBoxResponse(CustomizeTimeBox customizeTimeBox) { ); } - public CustomizeTimeBoxResponse(CustomizeTimeBox customizeTimeBox, List bell) { + public CustomizeTimeBoxResponse(CustomizeTimeBoxEntity customizeTimeBox, List bell) { this( customizeTimeBox.getStance(), customizeTimeBox.getSpeechType(), @@ -42,10 +45,32 @@ public CustomizeTimeBoxResponse(CustomizeTimeBox customizeTimeBox, List toResponses(List bells) { + if (bells.isEmpty()) { + return null; + } + return bells.stream() + .map(BellResponse::new) + .toList(); + } } diff --git a/src/main/java/com/debatetimer/entity/customize/BellEntity.java b/src/main/java/com/debatetimer/entity/customize/BellEntity.java index 43d4df71..fefc80ab 100644 --- a/src/main/java/com/debatetimer/entity/customize/BellEntity.java +++ b/src/main/java/com/debatetimer/entity/customize/BellEntity.java @@ -31,13 +31,13 @@ public class BellEntity { @NotNull @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "customize_time_box_id") - private CustomizeTimeBox customizeTimeBox; + private CustomizeTimeBoxEntity customizeTimeBox; @Column(name = "bell_time") private int time; private int count; - public BellEntity(CustomizeTimeBox customizeTimeBox, int time, int count) { + public BellEntity(CustomizeTimeBoxEntity customizeTimeBox, int time, int count) { validateTime(time); validateCount(count); diff --git a/src/main/java/com/debatetimer/entity/customize/CustomizeTimeBox.java b/src/main/java/com/debatetimer/entity/customize/CustomizeTimeBoxEntity.java similarity index 96% rename from src/main/java/com/debatetimer/entity/customize/CustomizeTimeBox.java rename to src/main/java/com/debatetimer/entity/customize/CustomizeTimeBoxEntity.java index 64e85be6..04fe115e 100644 --- a/src/main/java/com/debatetimer/entity/customize/CustomizeTimeBox.java +++ b/src/main/java/com/debatetimer/entity/customize/CustomizeTimeBoxEntity.java @@ -13,16 +13,18 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +@Table(name = "customize_time_box") @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class CustomizeTimeBox { +public class CustomizeTimeBoxEntity { public static final int SPEECH_TYPE_MAX_LENGTH = 10; public static final int TIME_MULTIPLIER = 2; @@ -56,7 +58,7 @@ public class CustomizeTimeBox { private Integer timePerTeam; private Integer timePerSpeaking; - public CustomizeTimeBox( + public CustomizeTimeBoxEntity( CustomizeTableEntity customizeTableEntity, int sequence, Stance stance, @@ -80,7 +82,7 @@ public CustomizeTimeBox( this.boxType = boxType; } - public CustomizeTimeBox( + public CustomizeTimeBoxEntity( CustomizeTableEntity customizeTableEntity, int sequence, Stance stance, diff --git a/src/main/java/com/debatetimer/exception/errorcode/ClientErrorCode.java b/src/main/java/com/debatetimer/exception/errorcode/ClientErrorCode.java index e0ac6cf3..59eb8cb9 100644 --- a/src/main/java/com/debatetimer/exception/errorcode/ClientErrorCode.java +++ b/src/main/java/com/debatetimer/exception/errorcode/ClientErrorCode.java @@ -1,10 +1,10 @@ package com.debatetimer.exception.errorcode; import com.debatetimer.domain.customize.Agenda; +import com.debatetimer.domain.customize.Bell; import com.debatetimer.domain.customize.TableName; import com.debatetimer.domain.customize.TeamName; -import com.debatetimer.entity.customize.BellEntity; -import com.debatetimer.entity.customize.CustomizeTimeBox; +import com.debatetimer.entity.customize.CustomizeTimeBoxEntity; import lombok.Getter; import org.springframework.http.HttpStatus; @@ -29,11 +29,11 @@ public enum ClientErrorCode implements ResponseErrorCode { INVALID_TIME_BASED_TIME(HttpStatus.BAD_REQUEST, "팀 발언 시간은 개인 발언 시간보다 길어야합니다"), INVALID_TIME_BOX_SPEECH_TYPE_LENGTH( HttpStatus.BAD_REQUEST, - "발언 유형 이름은 1자 이상 %d자 이하여야 합니다.".formatted(CustomizeTimeBox.SPEECH_TYPE_MAX_LENGTH) + "발언 유형 이름은 1자 이상 %d자 이하여야 합니다.".formatted(CustomizeTimeBoxEntity.SPEECH_TYPE_MAX_LENGTH) ), INVALID_TIME_BOX_SPEAKER_LENGTH( HttpStatus.BAD_REQUEST, - "발언자 이름은 1자 이상 %d자 이하여야 합니다.".formatted(CustomizeTimeBox.SPEAKER_MAX_LENGTH) + "발언자 이름은 1자 이상 %d자 이하여야 합니다.".formatted(CustomizeTimeBoxEntity.SPEAKER_MAX_LENGTH) ), INVALID_TEAM_NAME_LENGTH( HttpStatus.BAD_REQUEST, @@ -68,7 +68,7 @@ public enum ClientErrorCode implements ResponseErrorCode { FILE_UPLOAD_ERROR(HttpStatus.BAD_REQUEST, "파일 업로드에 실패했습니다."), INVALID_BELL_TIME(HttpStatus.BAD_REQUEST, "벨 시간은 0 이상의 정수여야 합니다."), - INVALID_BELL_COUNT(HttpStatus.BAD_REQUEST, "벨 카운트는 1 이상 %d 이하의 정수여야 합니다.".formatted(BellEntity.MAX_BELL_COUNT)), + INVALID_BELL_COUNT(HttpStatus.BAD_REQUEST, "벨 카운트는 1 이상 %d 이하의 정수여야 합니다.".formatted(Bell.MAX_BELL_COUNT)), ; private final HttpStatus status; diff --git a/src/main/java/com/debatetimer/repository/customize/BellRepository.java b/src/main/java/com/debatetimer/repository/customize/BellRepository.java index 78569835..8dd571d6 100644 --- a/src/main/java/com/debatetimer/repository/customize/BellRepository.java +++ b/src/main/java/com/debatetimer/repository/customize/BellRepository.java @@ -1,7 +1,7 @@ package com.debatetimer.repository.customize; import com.debatetimer.entity.customize.BellEntity; -import com.debatetimer.entity.customize.CustomizeTimeBox; +import com.debatetimer.entity.customize.CustomizeTimeBoxEntity; import java.util.List; import org.springframework.data.repository.Repository; @@ -9,9 +9,9 @@ public interface BellRepository extends Repository { BellEntity save(BellEntity bell); - List findByCustomizeTimeBox(CustomizeTimeBox customizeTimeBox); + List findByCustomizeTimeBox(CustomizeTimeBoxEntity customizeTimeBox); - void deleteAllByCustomizeTimeBoxIn(List customizeTimeBoxes); + void deleteAllByCustomizeTimeBoxIn(List customizeTimeBoxes); - List findAllByCustomizeTimeBoxIn(List timeBoxes); + List findAllByCustomizeTimeBoxIn(List timeBoxes); } diff --git a/src/main/java/com/debatetimer/repository/customize/CustomizeTimeBoxRepository.java b/src/main/java/com/debatetimer/repository/customize/CustomizeTimeBoxRepository.java index aeae7418..298ea6c4 100644 --- a/src/main/java/com/debatetimer/repository/customize/CustomizeTimeBoxRepository.java +++ b/src/main/java/com/debatetimer/repository/customize/CustomizeTimeBoxRepository.java @@ -1,33 +1,33 @@ package com.debatetimer.repository.customize; -import com.debatetimer.domain.customize.CustomizeTimeBoxes; +import com.debatetimer.domain.customize.CustomizeTimeBoxEntities; import com.debatetimer.entity.customize.CustomizeTableEntity; -import com.debatetimer.entity.customize.CustomizeTimeBox; +import com.debatetimer.entity.customize.CustomizeTimeBoxEntity; import java.util.List; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.Repository; import org.springframework.transaction.annotation.Transactional; -public interface CustomizeTimeBoxRepository extends Repository { +public interface CustomizeTimeBoxRepository extends Repository { - CustomizeTimeBox save(CustomizeTimeBox timeBox); + CustomizeTimeBoxEntity save(CustomizeTimeBoxEntity timeBox); @Transactional - default List saveAll(List timeBoxes) { + default List saveAll(List timeBoxes) { return timeBoxes.stream() .map(this::save) .toList(); } - List findAllByCustomizeTable(CustomizeTableEntity table); + List findAllByCustomizeTable(CustomizeTableEntity table); - default CustomizeTimeBoxes findTableTimeBoxes(CustomizeTableEntity table) { - List timeBoxes = findAllByCustomizeTable(table); - return new CustomizeTimeBoxes(timeBoxes); + default CustomizeTimeBoxEntities findTableTimeBoxes(CustomizeTableEntity table) { + List timeBoxes = findAllByCustomizeTable(table); + return new CustomizeTimeBoxEntities(timeBoxes); } - @Query("DELETE FROM CustomizeTimeBox ctb WHERE ctb.customizeTable = :table") + @Query("DELETE FROM CustomizeTimeBoxEntity ctb WHERE ctb.customizeTable = :table") @Modifying(clearAutomatically = true, flushAutomatically = true) void deleteAllByTable(CustomizeTableEntity table); } diff --git a/src/main/java/com/debatetimer/service/customize/CustomizeService.java b/src/main/java/com/debatetimer/service/customize/CustomizeService.java index 7281a77a..cc9e7fee 100644 --- a/src/main/java/com/debatetimer/service/customize/CustomizeService.java +++ b/src/main/java/com/debatetimer/service/customize/CustomizeService.java @@ -1,11 +1,12 @@ package com.debatetimer.service.customize; import com.debatetimer.domain.customize.CustomizeTable; -import com.debatetimer.domain.customize.CustomizeTimeBoxes; +import com.debatetimer.domain.customize.CustomizeTimeBoxEntities; import com.debatetimer.domain.member.Member; import com.debatetimer.dto.customize.request.CustomizeTableCreateRequest; import com.debatetimer.dto.customize.response.CustomizeTableResponse; import com.debatetimer.entity.customize.CustomizeTableEntity; +import com.debatetimer.entity.customize.CustomizeTimeBoxEntity; import com.debatetimer.repository.customize.CustomizeTableRepository; import com.debatetimer.repository.customize.CustomizeTimeBoxRepository; import java.util.List; @@ -25,14 +26,14 @@ public CustomizeTableResponse save(CustomizeTableCreateRequest tableCreateReques CustomizeTable table = tableCreateRequest.toTable(member); CustomizeTableEntity savedTable = tableRepository.save(new CustomizeTableEntity(table)); - CustomizeTimeBoxes savedCustomizeTimeBoxes = saveTimeBoxes(tableCreateRequest, savedTable.toDomain()); + CustomizeTimeBoxEntities savedCustomizeTimeBoxes = saveTimeBoxes(tableCreateRequest, savedTable.toDomain()); return new CustomizeTableResponse(savedTable.toDomain(), savedCustomizeTimeBoxes); } @Transactional(readOnly = true) public CustomizeTableResponse findTable(long tableId, Member member) { CustomizeTableEntity tableEntity = tableRepository.getByIdAndMember(tableId, member); - CustomizeTimeBoxes timeBoxes = timeBoxRepository.findTableTimeBoxes(tableEntity); + CustomizeTimeBoxEntities timeBoxes = timeBoxRepository.findTableTimeBoxes(tableEntity); return new CustomizeTableResponse(tableEntity.toDomain(), timeBoxes); } @@ -47,14 +48,14 @@ public CustomizeTableResponse updateTable( existingTable.updateTable(renewedTable); timeBoxRepository.deleteAllByTable(existingTable); - CustomizeTimeBoxes savedCustomizeTimeBoxes = saveTimeBoxes(tableCreateRequest, existingTable.toDomain()); + CustomizeTimeBoxEntities savedCustomizeTimeBoxes = saveTimeBoxes(tableCreateRequest, existingTable.toDomain()); return new CustomizeTableResponse(existingTable.toDomain(), savedCustomizeTimeBoxes); } @Transactional public CustomizeTableResponse updateUsedAt(long tableId, Member member) { CustomizeTableEntity tableEntity = tableRepository.getByIdAndMember(tableId, member); - CustomizeTimeBoxes timeBoxes = timeBoxRepository.findTableTimeBoxes(tableEntity); + CustomizeTimeBoxEntities timeBoxes = timeBoxRepository.findTableTimeBoxes(tableEntity); tableEntity.updateUsedAt(); return new CustomizeTableResponse(tableEntity.toDomain(), timeBoxes); @@ -67,13 +68,13 @@ public void deleteTable(long tableId, Member member) { tableRepository.delete(table); } - private CustomizeTimeBoxes saveTimeBoxes( + private CustomizeTimeBoxEntities saveTimeBoxes( CustomizeTableCreateRequest tableCreateRequest, CustomizeTable table ) { - CustomizeTimeBoxes customizeTimeBoxes = tableCreateRequest.toTimeBoxes(table); - List savedTimeBoxes = timeBoxRepository.saveAll( + CustomizeTimeBoxEntities customizeTimeBoxes = tableCreateRequest.toTimeBoxes(table); + List savedTimeBoxes = timeBoxRepository.saveAll( customizeTimeBoxes.getTimeBoxes()); - return new CustomizeTimeBoxes(savedTimeBoxes); + return new CustomizeTimeBoxEntities(savedTimeBoxes); } } diff --git a/src/main/java/com/debatetimer/service/customize/CustomizeServiceV2.java b/src/main/java/com/debatetimer/service/customize/CustomizeServiceV2.java index 423948a7..f4e6cf48 100644 --- a/src/main/java/com/debatetimer/service/customize/CustomizeServiceV2.java +++ b/src/main/java/com/debatetimer/service/customize/CustomizeServiceV2.java @@ -1,7 +1,7 @@ package com.debatetimer.service.customize; import com.debatetimer.domain.customize.CustomizeTable; -import com.debatetimer.domain.customize.CustomizeTimeBoxes; +import com.debatetimer.domain.customize.CustomizeTimeBoxEntities; import com.debatetimer.domain.member.Member; import com.debatetimer.dto.customize.request.BellRequest; import com.debatetimer.dto.customize.request.CustomizeTableCreateRequest; @@ -11,7 +11,7 @@ import com.debatetimer.dto.customize.response.CustomizeTimeBoxResponse; import com.debatetimer.entity.customize.BellEntity; import com.debatetimer.entity.customize.CustomizeTableEntity; -import com.debatetimer.entity.customize.CustomizeTimeBox; +import com.debatetimer.entity.customize.CustomizeTimeBoxEntity; import com.debatetimer.repository.customize.BellRepository; import com.debatetimer.repository.customize.CustomizeTableRepository; import com.debatetimer.repository.customize.CustomizeTimeBoxRepository; @@ -40,7 +40,7 @@ public CustomizeTableResponse save(CustomizeTableCreateRequest tableCreateReques @Transactional(readOnly = true) public CustomizeTableResponse findTable(long tableId, Member member) { CustomizeTableEntity tableEntity = tableRepository.getByIdAndMember(tableId, member); - CustomizeTimeBoxes timeBoxes = timeBoxRepository.findTableTimeBoxes(tableEntity); + CustomizeTimeBoxEntities timeBoxes = timeBoxRepository.findTableTimeBoxes(tableEntity); List timeBoxResponses = timeBoxes.getTimeBoxes() .stream() .map(this::getTimeBoxResponse) @@ -66,7 +66,7 @@ public CustomizeTableResponse updateTable( @Transactional public CustomizeTableResponse updateUsedAt(long tableId, Member member) { CustomizeTableEntity tableEntity = tableRepository.getByIdAndMember(tableId, member); - CustomizeTimeBoxes timeBoxes = timeBoxRepository.findTableTimeBoxes(tableEntity); + CustomizeTimeBoxEntities timeBoxes = timeBoxRepository.findTableTimeBoxes(tableEntity); tableEntity.updateUsedAt(); List timeBoxResponses = timeBoxes.getTimeBoxes() .stream() @@ -100,11 +100,11 @@ private CustomizeTimeBoxResponse createTimeBoxResponse( CustomizeTable table, int sequence ) { - CustomizeTimeBox savedTimeBox = timeBoxRepository.save(request.toTimeBox(table, sequence)); + CustomizeTimeBoxEntity savedTimeBox = timeBoxRepository.save(request.toTimeBox(table, sequence)); return createTimeBoxResponse(request.bell(), savedTimeBox); } - private CustomizeTimeBoxResponse createTimeBoxResponse(List bellRequests, CustomizeTimeBox timeBox) { + private CustomizeTimeBoxResponse createTimeBoxResponse(List bellRequests, CustomizeTimeBoxEntity timeBox) { if (timeBox.getBoxType().isTimeBased()) { return new CustomizeTimeBoxResponse(timeBox, null); } @@ -118,7 +118,7 @@ private CustomizeTimeBoxResponse createTimeBoxResponse(List bellReq return new CustomizeTimeBoxResponse(timeBox, bellResponses); } - private CustomizeTimeBoxResponse getTimeBoxResponse(CustomizeTimeBox timeBox) { + private CustomizeTimeBoxResponse getTimeBoxResponse(CustomizeTimeBoxEntity timeBox) { if (timeBox.getBoxType().isTimeBased()) { return new CustomizeTimeBoxResponse(timeBox, null); } @@ -130,7 +130,7 @@ private CustomizeTimeBoxResponse getTimeBoxResponse(CustomizeTimeBox timeBox) { return new CustomizeTimeBoxResponse(timeBox, bellResponses); } - private void deleteBell(CustomizeTimeBoxes savedCustomizeTimeBoxes) { + private void deleteBell(CustomizeTimeBoxEntities savedCustomizeTimeBoxes) { bellRepository.deleteAllByCustomizeTimeBoxIn(savedCustomizeTimeBoxes.getTimeBoxes()); } } diff --git a/src/test/java/com/debatetimer/domain/customize/BellTest.java b/src/test/java/com/debatetimer/domain/customize/BellTest.java new file mode 100644 index 00000000..a99f40eb --- /dev/null +++ b/src/test/java/com/debatetimer/domain/customize/BellTest.java @@ -0,0 +1,46 @@ +package com.debatetimer.domain.customize; + +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import com.debatetimer.exception.custom.DTClientErrorException; +import com.debatetimer.exception.errorcode.ClientErrorCode; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +class BellTest { + + @Nested + class Validate { + + @Test + void 벨_시간이_음수면_생성되지_않는다() { + assertThatThrownBy(() -> new Bell(-1, 1)) + .isInstanceOf(DTClientErrorException.class) + .hasMessage(ClientErrorCode.INVALID_BELL_TIME.getMessage()); + } + + @Test + void 벨_시간은_0이상이어야_한다() { + assertThatCode(() -> new Bell(0, 1)) + .doesNotThrowAnyException(); + } + + @ValueSource(ints = {0, Bell.MAX_BELL_COUNT + 1}) + @ParameterizedTest + void 벨_횟수는_정해진_횟수_바깥일_경우_생성되지_않는다(int count) { + assertThatThrownBy(() -> new Bell(1, count)) + .isInstanceOf(DTClientErrorException.class) + .hasMessage(ClientErrorCode.INVALID_BELL_COUNT.getMessage()); + } + + @ValueSource(ints = {1, Bell.MAX_BELL_COUNT}) + @ParameterizedTest + void 벨_횟수는_정해진_횟수_이내여야_한다(int count) { + assertThatCode(() -> new Bell(1, count)) + .doesNotThrowAnyException(); + } + } +} diff --git a/src/test/java/com/debatetimer/domain/customize/CustomizeTimeBoxesTest.java b/src/test/java/com/debatetimer/domain/customize/CustomizeTimeBoxEntitiesTest.java similarity index 66% rename from src/test/java/com/debatetimer/domain/customize/CustomizeTimeBoxesTest.java rename to src/test/java/com/debatetimer/domain/customize/CustomizeTimeBoxEntitiesTest.java index 57c3122a..6db5cee9 100644 --- a/src/test/java/com/debatetimer/domain/customize/CustomizeTimeBoxesTest.java +++ b/src/test/java/com/debatetimer/domain/customize/CustomizeTimeBoxEntitiesTest.java @@ -4,7 +4,7 @@ import com.debatetimer.domain.member.Member; import com.debatetimer.entity.customize.CustomizeTableEntity; -import com.debatetimer.entity.customize.CustomizeTimeBox; +import com.debatetimer.entity.customize.CustomizeTimeBoxEntity; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Arrays; @@ -12,7 +12,7 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -class CustomizeTimeBoxesTest { +class CustomizeTimeBoxEntitiesTest { @Nested class SortedBySequence { @@ -23,13 +23,13 @@ class SortedBySequence { CustomizeTable table = new CustomizeTable(member, "토론 테이블", "주제", "찬성", "반대", true, true, LocalDateTime.now()); CustomizeTableEntity testTable = new CustomizeTableEntity(table); - CustomizeTimeBox firstBox = new CustomizeTimeBox(testTable, 1, Stance.PROS, "입론", + CustomizeTimeBoxEntity firstBox = new CustomizeTimeBoxEntity(testTable, 1, Stance.PROS, "입론", CustomizeBoxType.NORMAL, 300, "콜리"); - CustomizeTimeBox secondBox = new CustomizeTimeBox(testTable, 2, Stance.PROS, "입론", + CustomizeTimeBoxEntity secondBox = new CustomizeTimeBoxEntity(testTable, 2, Stance.PROS, "입론", CustomizeBoxType.NORMAL, 300, "콜리2"); - List timeBoxes = new ArrayList<>(Arrays.asList(secondBox, firstBox)); + List timeBoxes = new ArrayList<>(Arrays.asList(secondBox, firstBox)); - CustomizeTimeBoxes actual = new CustomizeTimeBoxes(timeBoxes); + CustomizeTimeBoxEntities actual = new CustomizeTimeBoxEntities(timeBoxes); assertThat(actual.getTimeBoxes()).containsExactly(firstBox, secondBox); } diff --git a/src/test/java/com/debatetimer/domain/customize/CustomizeTimeBoxDomainTest.java b/src/test/java/com/debatetimer/domain/customize/CustomizeTimeBoxTest.java similarity index 74% rename from src/test/java/com/debatetimer/domain/customize/CustomizeTimeBoxDomainTest.java rename to src/test/java/com/debatetimer/domain/customize/CustomizeTimeBoxTest.java index be331821..cab0b3d7 100644 --- a/src/test/java/com/debatetimer/domain/customize/CustomizeTimeBoxDomainTest.java +++ b/src/test/java/com/debatetimer/domain/customize/CustomizeTimeBoxTest.java @@ -5,27 +5,29 @@ import com.debatetimer.exception.custom.DTClientErrorException; import com.debatetimer.exception.errorcode.ClientErrorCode; +import java.util.Collections; +import java.util.List; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.NullAndEmptySource; import org.junit.jupiter.params.provider.ValueSource; -class CustomizeTimeBoxDomainTest { +class CustomizeTimeBoxTest { @Nested class ValidateStance { @Test void 발언_입장은_비어있을_수_없다() { - assertThatThrownBy(() -> new InheritedCustomizeTimeBoxDomain(null, "비토", "발언자")) + assertThatThrownBy(() -> new InheritedCustomizeTimeBox(null, "비토", "발언자")) .isInstanceOf(DTClientErrorException.class) .hasMessage(ClientErrorCode.INVALID_TIME_BOX_STANCE.getMessage()); } @Test void 발언_입장은_유효한_값이어야_한다() { - assertThatCode(() -> new InheritedCustomizeTimeBoxDomain(Stance.PROS, "비토", "발언자")) + assertThatCode(() -> new InheritedCustomizeTimeBox(Stance.PROS, "비토", "발언자")) .doesNotThrowAnyException(); } } @@ -35,9 +37,9 @@ class ValidateSpeechType { @Test void 발언_종류는_특정_글자를_초과할_수_없다() { - String speechType = "a".repeat(CustomizeTimeBoxDomain.SPEECH_TYPE_MAX_LENGTH + 1); + String speechType = "a".repeat(CustomizeTimeBox.SPEECH_TYPE_MAX_LENGTH + 1); - assertThatThrownBy(() -> new InheritedCustomizeTimeBoxDomain(Stance.PROS, speechType, "비토")) + assertThatThrownBy(() -> new InheritedCustomizeTimeBox(Stance.PROS, speechType, "비토")) .isInstanceOf(DTClientErrorException.class) .hasMessage(ClientErrorCode.INVALID_TIME_BOX_SPEECH_TYPE_LENGTH.getMessage()); } @@ -46,16 +48,16 @@ class ValidateSpeechType { @NullAndEmptySource @ValueSource(strings = {" ", "\n\t"}) void 발언_종류는_비어있을_수_없다(String emptySpeechType) { - assertThatThrownBy(() -> new InheritedCustomizeTimeBoxDomain(Stance.PROS, emptySpeechType, "비토")) + assertThatThrownBy(() -> new InheritedCustomizeTimeBox(Stance.PROS, emptySpeechType, "비토")) .isInstanceOf(DTClientErrorException.class) .hasMessage(ClientErrorCode.INVALID_TIME_BOX_SPEECH_TYPE_LENGTH.getMessage()); } @Test void 발언_종류는_특정_글자_이내이어야_한다() { - String speechType = "a".repeat(CustomizeTimeBoxDomain.SPEECH_TYPE_MAX_LENGTH); + String speechType = "a".repeat(CustomizeTimeBox.SPEECH_TYPE_MAX_LENGTH); - assertThatCode(() -> new InheritedCustomizeTimeBoxDomain(Stance.PROS, speechType, "비토")) + assertThatCode(() -> new InheritedCustomizeTimeBox(Stance.PROS, speechType, "비토")) .doesNotThrowAnyException(); } } @@ -65,23 +67,23 @@ class ValidateSpeaker { @Test void 발언자_이름은_특정_글자를_초과할_수_없다() { - String speaker = "a".repeat(CustomizeTimeBoxDomain.SPEAKER_MAX_LENGTH + 1); + String speaker = "a".repeat(CustomizeTimeBox.SPEAKER_MAX_LENGTH + 1); - assertThatThrownBy(() -> new InheritedCustomizeTimeBoxDomain(Stance.PROS, "비토", speaker)) + assertThatThrownBy(() -> new InheritedCustomizeTimeBox(Stance.PROS, "비토", speaker)) .isInstanceOf(DTClientErrorException.class) .hasMessage(ClientErrorCode.INVALID_TIME_BOX_SPEAKER_LENGTH.getMessage()); } @Test void 발언자_이름은_비어있을_수_있다() { - assertThatCode(() -> new InheritedCustomizeTimeBoxDomain(Stance.PROS, "비토", null)) + assertThatCode(() -> new InheritedCustomizeTimeBox(Stance.PROS, "비토", null)) .doesNotThrowAnyException(); } } - static class InheritedCustomizeTimeBoxDomain extends CustomizeTimeBoxDomain { + static class InheritedCustomizeTimeBox extends CustomizeTimeBox { - protected InheritedCustomizeTimeBoxDomain(Stance stance, String speechType, String speaker) { + protected InheritedCustomizeTimeBox(Stance stance, String speechType, String speaker) { super(stance, speechType, speaker); } @@ -109,5 +111,10 @@ public Integer getTimePerTeam() { public Integer getTimePerSpeaking() { return 0; } + + @Override + public List getBells() { + return Collections.emptyList(); + } } } diff --git a/src/test/java/com/debatetimer/domain/customize/NormalTimeBoxDomainTest.java b/src/test/java/com/debatetimer/domain/customize/NormalTimeBoxTest.java similarity index 73% rename from src/test/java/com/debatetimer/domain/customize/NormalTimeBoxDomainTest.java rename to src/test/java/com/debatetimer/domain/customize/NormalTimeBoxTest.java index 810ea4ce..c70bf53a 100644 --- a/src/test/java/com/debatetimer/domain/customize/NormalTimeBoxDomainTest.java +++ b/src/test/java/com/debatetimer/domain/customize/NormalTimeBoxTest.java @@ -5,10 +5,11 @@ import com.debatetimer.exception.custom.DTClientErrorException; import com.debatetimer.exception.errorcode.ClientErrorCode; +import java.util.Collections; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -class NormalTimeBoxDomainTest { +class NormalTimeBoxTest { @Nested class ValidateTime { @@ -17,7 +18,7 @@ class ValidateTime { void 시간은_0보다_커야_한다() { Integer time = 0; - assertThatThrownBy(() -> new NormalTimeBoxDomain(Stance.PROS, "비토", null, time)) + assertThatThrownBy(() -> new NormalTimeBox(Stance.PROS, "비토", null, time, Collections.emptyList())) .isInstanceOf(DTClientErrorException.class) .hasMessage(ClientErrorCode.INVALID_TIME_BOX_TIME.getMessage()); } @@ -26,7 +27,7 @@ class ValidateTime { void 시간은_비어있지_않아야_한다() { Integer time = null; - assertThatThrownBy(() -> new NormalTimeBoxDomain(Stance.PROS, "비토", null, time)) + assertThatThrownBy(() -> new NormalTimeBox(Stance.PROS, "비토", null, time, Collections.emptyList())) .isInstanceOf(DTClientErrorException.class) .hasMessage(ClientErrorCode.INVALID_TIME_BOX_TIME.getMessage()); } @@ -35,7 +36,7 @@ class ValidateTime { void 시간은_양수여야_한다() { Integer time = 1; - assertThatCode(() -> new NormalTimeBoxDomain(Stance.PROS, "비토", null, time)) + assertThatCode(() -> new NormalTimeBox(Stance.PROS, "비토", null, time, Collections.emptyList())) .doesNotThrowAnyException(); } } diff --git a/src/test/java/com/debatetimer/domain/customize/TimeBasedTimeBoxDomainTest.java b/src/test/java/com/debatetimer/domain/customize/TimeBasedTimeBoxTest.java similarity index 75% rename from src/test/java/com/debatetimer/domain/customize/TimeBasedTimeBoxDomainTest.java rename to src/test/java/com/debatetimer/domain/customize/TimeBasedTimeBoxTest.java index 484d0e1a..41d27641 100644 --- a/src/test/java/com/debatetimer/domain/customize/TimeBasedTimeBoxDomainTest.java +++ b/src/test/java/com/debatetimer/domain/customize/TimeBasedTimeBoxTest.java @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -class TimeBasedTimeBoxDomainTest { +class TimeBasedTimeBoxTest { @Nested class ValidateStance { @@ -18,7 +18,7 @@ class ValidateStance { Stance stance = Stance.PROS; assertThatThrownBy( - () -> new TimeBasedTimeBoxDomain(stance, "자유발언", "비토", 120, 60)) + () -> new TimeBasedTimeBox(stance, "자유발언", "비토", 120, 60)) .isInstanceOf(DTClientErrorException.class) .hasMessage(ClientErrorCode.INVALID_TIME_BOX_STANCE.getMessage()); } @@ -28,7 +28,7 @@ class ValidateStance { Stance stance = Stance.NEUTRAL; assertThatCode( - () -> new TimeBasedTimeBoxDomain(stance, "자유발언", "비토", 120, 60)) + () -> new TimeBasedTimeBox(stance, "자유발언", "비토", 120, 60)) .doesNotThrowAnyException(); } } @@ -42,7 +42,7 @@ class ValidateTimes { int timePerSpeaking = 1; assertThatThrownBy( - () -> new TimeBasedTimeBoxDomain(Stance.NEUTRAL, "자유발언", "비토", timePerTeam, timePerSpeaking)) + () -> new TimeBasedTimeBox(Stance.NEUTRAL, "자유발언", "비토", timePerTeam, timePerSpeaking)) .isInstanceOf(DTClientErrorException.class) .hasMessage(ClientErrorCode.INVALID_TIME_BOX_TIME.getMessage()); } @@ -53,7 +53,7 @@ class ValidateTimes { int timePerSpeaking = 1; assertThatThrownBy( - () -> new TimeBasedTimeBoxDomain(Stance.NEUTRAL, "자유발언", "비토", timePerTeam, timePerSpeaking)) + () -> new TimeBasedTimeBox(Stance.NEUTRAL, "자유발언", "비토", timePerTeam, timePerSpeaking)) .isInstanceOf(DTClientErrorException.class) .hasMessage(ClientErrorCode.INVALID_TIME_BOX_TIME.getMessage()); } @@ -64,7 +64,7 @@ class ValidateTimes { int timePerTeam = 1; assertThatThrownBy( - () -> new TimeBasedTimeBoxDomain(Stance.NEUTRAL, "자유발언", "비토", timePerTeam, timePerSpeaking)) + () -> new TimeBasedTimeBox(Stance.NEUTRAL, "자유발언", "비토", timePerTeam, timePerSpeaking)) .isInstanceOf(DTClientErrorException.class) .hasMessage(ClientErrorCode.INVALID_TIME_BOX_TIME.getMessage()); } @@ -75,7 +75,7 @@ class ValidateTimes { int timePerTeam = 1; assertThatCode( - () -> new TimeBasedTimeBoxDomain(Stance.NEUTRAL, "자유발언", "비토", timePerTeam, timePerSpeaking)) + () -> new TimeBasedTimeBox(Stance.NEUTRAL, "자유발언", "비토", timePerTeam, timePerSpeaking)) .doesNotThrowAnyException(); } @@ -85,7 +85,7 @@ class ValidateTimes { int timePerSpeaking = timePerTeam + 1; assertThatThrownBy( - () -> new TimeBasedTimeBoxDomain(Stance.NEUTRAL, "자유발언", "비토", timePerTeam, timePerSpeaking)) + () -> new TimeBasedTimeBox(Stance.NEUTRAL, "자유발언", "비토", timePerTeam, timePerSpeaking)) .isInstanceOf(DTClientErrorException.class) .hasMessage(ClientErrorCode.INVALID_TIME_BASED_TIME.getMessage()); } diff --git a/src/test/java/com/debatetimer/entity/customize/CustomizeTimeBoxTest.java b/src/test/java/com/debatetimer/entity/customize/CustomizeTimeBoxEntityTest.java similarity index 79% rename from src/test/java/com/debatetimer/entity/customize/CustomizeTimeBoxTest.java rename to src/test/java/com/debatetimer/entity/customize/CustomizeTimeBoxEntityTest.java index e535d2e3..3db1b1d4 100644 --- a/src/test/java/com/debatetimer/entity/customize/CustomizeTimeBoxTest.java +++ b/src/test/java/com/debatetimer/entity/customize/CustomizeTimeBoxEntityTest.java @@ -14,7 +14,7 @@ import org.junit.jupiter.params.provider.NullSource; import org.junit.jupiter.params.provider.ValueSource; -class CustomizeTimeBoxTest { +class CustomizeTimeBoxEntityTest { @Nested class ValidateSequence { @@ -25,7 +25,7 @@ class ValidateSequence { CustomizeTableEntity table = new CustomizeTableEntity(); CustomizeBoxType customizeBoxType = CustomizeBoxType.TIME_BASED; - assertThatThrownBy(() -> new CustomizeTimeBox(table, sequence, Stance.NEUTRAL, "자유토론", + assertThatThrownBy(() -> new CustomizeTimeBoxEntity(table, sequence, Stance.NEUTRAL, "자유토론", customizeBoxType, 120, 60, "발언자")) .isInstanceOf(DTClientErrorException.class) .hasMessage(ClientErrorCode.INVALID_TIME_BOX_SEQUENCE.getMessage()); @@ -42,7 +42,7 @@ class ValidateTime { CustomizeBoxType customizeBoxType = CustomizeBoxType.NORMAL; assertThatThrownBy( - () -> new CustomizeTimeBox(table, 1, Stance.CONS, "자유토론", + () -> new CustomizeTimeBoxEntity(table, 1, Stance.CONS, "자유토론", customizeBoxType, time, 60, "발언자")) .isInstanceOf(DTClientErrorException.class) .hasMessage(ClientErrorCode.INVALID_TIME_BOX_TIME.getMessage()); @@ -56,9 +56,9 @@ class ValidateSpeaker { void 발언자_이름은_일정길이_이내로_허용된다() { CustomizeTableEntity table = new CustomizeTableEntity(); CustomizeBoxType customizeBoxType = CustomizeBoxType.NORMAL; - String speaker = "k".repeat(CustomizeTimeBox.SPEAKER_MAX_LENGTH + 1); + String speaker = "k".repeat(CustomizeTimeBoxEntity.SPEAKER_MAX_LENGTH + 1); - assertThatThrownBy(() -> new CustomizeTimeBox(table, 1, Stance.CONS, "입론", + assertThatThrownBy(() -> new CustomizeTimeBoxEntity(table, 1, Stance.CONS, "입론", customizeBoxType, 120, speaker)) .isInstanceOf(DTClientErrorException.class) .hasMessage(ClientErrorCode.INVALID_TIME_BOX_SPEAKER_LENGTH.getMessage()); @@ -70,7 +70,7 @@ class ValidateSpeaker { CustomizeTableEntity table = new CustomizeTableEntity(); CustomizeBoxType customizeBoxType = CustomizeBoxType.NORMAL; - assertThatCode(() -> new CustomizeTimeBox(table, 1, Stance.CONS, "입론", + assertThatCode(() -> new CustomizeTimeBoxEntity(table, 1, Stance.CONS, "입론", customizeBoxType, 120, speaker)) .doesNotThrowAnyException(); } @@ -81,7 +81,7 @@ class ValidateSpeaker { CustomizeTableEntity table = new CustomizeTableEntity(); CustomizeBoxType customizeBoxType = CustomizeBoxType.NORMAL; - CustomizeTimeBox timeBox = new CustomizeTimeBox(table, 1, Stance.CONS, "입론", + CustomizeTimeBoxEntity timeBox = new CustomizeTimeBoxEntity(table, 1, Stance.CONS, "입론", customizeBoxType, 120, speaker); assertThat(timeBox.getSpeaker()).isNull(); @@ -96,7 +96,7 @@ class ValidateCustomizeTime { CustomizeTableEntity table = new CustomizeTableEntity(); CustomizeBoxType customizeBoxType = CustomizeBoxType.TIME_BASED; - assertThatCode(() -> new CustomizeTimeBox(table, 1, Stance.NEUTRAL, "자유토론", + assertThatCode(() -> new CustomizeTimeBoxEntity(table, 1, Stance.NEUTRAL, "자유토론", customizeBoxType, 120, 60, "발언자") ).doesNotThrowAnyException(); } @@ -106,7 +106,7 @@ class ValidateCustomizeTime { CustomizeTableEntity table = new CustomizeTableEntity(); CustomizeBoxType customizeBoxType = CustomizeBoxType.TIME_BASED; - assertThatThrownBy(() -> new CustomizeTimeBox(table, 1, Stance.NEUTRAL, "자유토론", customizeBoxType, 10, + assertThatThrownBy(() -> new CustomizeTimeBoxEntity(table, 1, Stance.NEUTRAL, "자유토론", customizeBoxType, 10, "발언자")).isInstanceOf(DTClientErrorException.class) .hasMessage(ClientErrorCode.INVALID_TIME_BOX_FORMAT.getMessage()); } @@ -117,7 +117,7 @@ class ValidateCustomizeTime { CustomizeBoxType notTimeBasedBoxType = CustomizeBoxType.NORMAL; assertThatThrownBy( - () -> new CustomizeTimeBox(table, 1, Stance.NEUTRAL, "자유토론", notTimeBasedBoxType, 120, 60, + () -> new CustomizeTimeBoxEntity(table, 1, Stance.NEUTRAL, "자유토론", notTimeBasedBoxType, 120, 60, "발언자")).isInstanceOf(DTClientErrorException.class) .hasMessage(ClientErrorCode.INVALID_TIME_BOX_FORMAT.getMessage()); } @@ -128,7 +128,7 @@ class ValidateCustomizeTime { Integer timePerTeam = 60; Integer timePerSpeaking = null; - assertThatCode(() -> new CustomizeTimeBox(table, 1, Stance.NEUTRAL, "자유토론", CustomizeBoxType.TIME_BASED, + assertThatCode(() -> new CustomizeTimeBoxEntity(table, 1, Stance.NEUTRAL, "자유토론", CustomizeBoxType.TIME_BASED, timePerTeam, timePerSpeaking, "발언자")).doesNotThrowAnyException(); } @@ -138,7 +138,7 @@ class ValidateCustomizeTime { int timePerTeam = 60; int timePerSpeaking = 59; - assertThatCode(() -> new CustomizeTimeBox(table, 1, Stance.NEUTRAL, "자유토론", CustomizeBoxType.TIME_BASED, + assertThatCode(() -> new CustomizeTimeBoxEntity(table, 1, Stance.NEUTRAL, "자유토론", CustomizeBoxType.TIME_BASED, timePerTeam, timePerSpeaking, "발언자")).doesNotThrowAnyException(); } @@ -148,7 +148,7 @@ class ValidateCustomizeTime { int timePerTeam = 60; int timePerSpeaking = 61; - assertThatThrownBy(() -> new CustomizeTimeBox(table, 1, Stance.NEUTRAL, "자유토론", CustomizeBoxType.TIME_BASED, + assertThatThrownBy(() -> new CustomizeTimeBoxEntity(table, 1, Stance.NEUTRAL, "자유토론", CustomizeBoxType.TIME_BASED, timePerTeam, timePerSpeaking, "발언자")).isInstanceOf(DTClientErrorException.class) .hasMessage(ClientErrorCode.INVALID_TIME_BASED_TIME.getMessage()); } @@ -156,10 +156,10 @@ class ValidateCustomizeTime { @Test void 발언_유형의_길이는_일정_범위_이내여야_한다() { CustomizeTableEntity table = new CustomizeTableEntity(); - String longSpeechType = "s".repeat(CustomizeTimeBox.SPEECH_TYPE_MAX_LENGTH + 1); + String longSpeechType = "s".repeat(CustomizeTimeBoxEntity.SPEECH_TYPE_MAX_LENGTH + 1); assertThatThrownBy( - () -> new CustomizeTimeBox(table, 1, Stance.NEUTRAL, longSpeechType, CustomizeBoxType.TIME_BASED, + () -> new CustomizeTimeBoxEntity(table, 1, Stance.NEUTRAL, longSpeechType, CustomizeBoxType.TIME_BASED, 120, 60, "발언자")).isInstanceOf(DTClientErrorException.class) .hasMessage(ClientErrorCode.INVALID_TIME_BOX_SPEECH_TYPE_LENGTH.getMessage()); } @@ -173,10 +173,10 @@ class getTime { int timePerTeam = 300; int timePerSpeaking = 120; CustomizeTableEntity table = new CustomizeTableEntity(); - CustomizeTimeBox timeBasedTimeBox = new CustomizeTimeBox(table, 1, Stance.CONS, "자유 토론", + CustomizeTimeBoxEntity timeBasedTimeBox = new CustomizeTimeBoxEntity(table, 1, Stance.CONS, "자유 토론", CustomizeBoxType.TIME_BASED, timePerTeam, timePerSpeaking, "콜리"); - assertThat(timeBasedTimeBox.getTime()).isEqualTo(timePerTeam * CustomizeTimeBox.TIME_MULTIPLIER); + assertThat(timeBasedTimeBox.getTime()).isEqualTo(timePerTeam * CustomizeTimeBoxEntity.TIME_MULTIPLIER); } } } diff --git a/src/test/java/com/debatetimer/fixture/BellGenerator.java b/src/test/java/com/debatetimer/fixture/BellGenerator.java index b9698fd3..1c2392ce 100644 --- a/src/test/java/com/debatetimer/fixture/BellGenerator.java +++ b/src/test/java/com/debatetimer/fixture/BellGenerator.java @@ -1,7 +1,7 @@ package com.debatetimer.fixture; import com.debatetimer.entity.customize.BellEntity; -import com.debatetimer.entity.customize.CustomizeTimeBox; +import com.debatetimer.entity.customize.CustomizeTimeBoxEntity; import com.debatetimer.repository.customize.BellRepository; import org.springframework.stereotype.Component; @@ -14,7 +14,7 @@ public BellGenerator(BellRepository bellRepository) { this.bellRepository = bellRepository; } - public BellEntity generate(CustomizeTimeBox timeBox, int time, int count) { + public BellEntity generate(CustomizeTimeBoxEntity timeBox, int time, int count) { BellEntity bell = new BellEntity(timeBox, time, count); return bellRepository.save(bell); } diff --git a/src/test/java/com/debatetimer/fixture/CustomizeTimeBoxGenerator.java b/src/test/java/com/debatetimer/fixture/CustomizeTimeBoxGenerator.java index d7ab3acc..e068269d 100644 --- a/src/test/java/com/debatetimer/fixture/CustomizeTimeBoxGenerator.java +++ b/src/test/java/com/debatetimer/fixture/CustomizeTimeBoxGenerator.java @@ -3,7 +3,7 @@ import com.debatetimer.domain.customize.CustomizeBoxType; import com.debatetimer.domain.customize.Stance; import com.debatetimer.entity.customize.CustomizeTableEntity; -import com.debatetimer.entity.customize.CustomizeTimeBox; +import com.debatetimer.entity.customize.CustomizeTimeBoxEntity; import com.debatetimer.repository.customize.CustomizeTimeBoxRepository; import org.springframework.stereotype.Component; @@ -16,8 +16,8 @@ public CustomizeTimeBoxGenerator(CustomizeTimeBoxRepository customizeTimeBoxRepo this.customizeTimeBoxRepository = customizeTimeBoxRepository; } - public CustomizeTimeBox generate(CustomizeTableEntity testTable, CustomizeBoxType boxType, int sequence) { - CustomizeTimeBox timeBox = new CustomizeTimeBox( + public CustomizeTimeBoxEntity generate(CustomizeTableEntity testTable, CustomizeBoxType boxType, int sequence) { + CustomizeTimeBoxEntity timeBox = new CustomizeTimeBoxEntity( testTable, sequence, Stance.PROS, @@ -29,9 +29,9 @@ public CustomizeTimeBox generate(CustomizeTableEntity testTable, CustomizeBoxTyp return customizeTimeBoxRepository.save(timeBox); } - public CustomizeTimeBox generateNotExistSpeaker(CustomizeTableEntity testTable, CustomizeBoxType boxType, - int sequence) { - CustomizeTimeBox timeBox = new CustomizeTimeBox( + public CustomizeTimeBoxEntity generateNotExistSpeaker(CustomizeTableEntity testTable, CustomizeBoxType boxType, + int sequence) { + CustomizeTimeBoxEntity timeBox = new CustomizeTimeBoxEntity( testTable, sequence, Stance.PROS, diff --git a/src/test/java/com/debatetimer/repository/customize/CustomizeTimeBoxRepositoryTest.java b/src/test/java/com/debatetimer/repository/customize/CustomizeTimeBoxRepositoryTest.java index 6b5f5df0..c0d42904 100644 --- a/src/test/java/com/debatetimer/repository/customize/CustomizeTimeBoxRepositoryTest.java +++ b/src/test/java/com/debatetimer/repository/customize/CustomizeTimeBoxRepositoryTest.java @@ -6,7 +6,7 @@ import com.debatetimer.domain.customize.CustomizeBoxType; import com.debatetimer.domain.member.Member; import com.debatetimer.entity.customize.CustomizeTableEntity; -import com.debatetimer.entity.customize.CustomizeTimeBox; +import com.debatetimer.entity.customize.CustomizeTimeBoxEntity; import com.debatetimer.repository.BaseRepositoryTest; import java.util.List; import org.junit.jupiter.api.Nested; @@ -27,12 +27,12 @@ class FindAllByCustomizeTableEntity { Member bito = memberGenerator.generate("default2@gmail.com"); CustomizeTableEntity chanTable = customizeTableGenerator.generate(chan); CustomizeTableEntity bitoTable = customizeTableGenerator.generate(bito); - CustomizeTimeBox chanBox1 = customizeTimeBoxGenerator.generate(chanTable, CustomizeBoxType.NORMAL, 1); - CustomizeTimeBox chanBox2 = customizeTimeBoxGenerator.generate(chanTable, CustomizeBoxType.NORMAL, 2); + CustomizeTimeBoxEntity chanBox1 = customizeTimeBoxGenerator.generate(chanTable, CustomizeBoxType.NORMAL, 1); + CustomizeTimeBoxEntity chanBox2 = customizeTimeBoxGenerator.generate(chanTable, CustomizeBoxType.NORMAL, 2); customizeTimeBoxGenerator.generate(bitoTable, CustomizeBoxType.NORMAL, 2); customizeTimeBoxGenerator.generate(bitoTable, CustomizeBoxType.NORMAL, 2); - List foundBoxes = customizeTimeBoxRepository.findAllByCustomizeTable(chanTable); + List foundBoxes = customizeTimeBoxRepository.findAllByCustomizeTable(chanTable); assertThat(foundBoxes).containsExactly(chanBox1, chanBox2); } @@ -50,7 +50,7 @@ class DeleteAllByTable { customizeTimeBoxRepository.deleteAllByTable(chanTable); - List timeBoxes = customizeTimeBoxRepository.findAllByCustomizeTable(chanTable); + List timeBoxes = customizeTimeBoxRepository.findAllByCustomizeTable(chanTable); assertThat(timeBoxes).isEmpty(); } @@ -65,7 +65,7 @@ class DeleteAllByTable { customizeTimeBoxRepository.deleteAllByTable(deletedTable); - List timeBoxes = customizeTimeBoxRepository.findAllByCustomizeTable(filledTable); + List timeBoxes = customizeTimeBoxRepository.findAllByCustomizeTable(filledTable); assertThat(timeBoxes).hasSize(2); } diff --git a/src/test/java/com/debatetimer/service/customize/CustomizeServiceTest.java b/src/test/java/com/debatetimer/service/customize/CustomizeServiceTest.java index 0223170a..410c0042 100644 --- a/src/test/java/com/debatetimer/service/customize/CustomizeServiceTest.java +++ b/src/test/java/com/debatetimer/service/customize/CustomizeServiceTest.java @@ -13,7 +13,7 @@ import com.debatetimer.dto.customize.request.CustomizeTimeBoxCreateRequest; import com.debatetimer.dto.customize.response.CustomizeTableResponse; import com.debatetimer.entity.customize.CustomizeTableEntity; -import com.debatetimer.entity.customize.CustomizeTimeBox; +import com.debatetimer.entity.customize.CustomizeTimeBoxEntity; import com.debatetimer.exception.custom.DTClientErrorException; import com.debatetimer.exception.errorcode.ClientErrorCode; import com.debatetimer.service.BaseServiceTest; @@ -48,7 +48,7 @@ class Save { CustomizeTableResponse savedTableResponse = customizeService.save(customizeTableCreateRequest, chan); CustomizeTableEntity foundTable = customizeTableRepository.getByIdAndMember(savedTableResponse.id(), chan); - List foundTimeBoxes = customizeTimeBoxRepository.findAllByCustomizeTable(foundTable); + List foundTimeBoxes = customizeTimeBoxRepository.findAllByCustomizeTable(foundTable); assertAll( () -> assertThat(foundTable.getName()).isEqualTo(customizeTableCreateRequest.info().name()), @@ -109,7 +109,7 @@ class UpdateTable { customizeService.updateTable(renewTableRequest, chanTable.getId(), chan); CustomizeTableEntity updatedTable = customizeTableRepository.getByIdAndMember(chanTable.getId(), chan); - List updatedTimeBoxes = customizeTimeBoxRepository.findAllByCustomizeTable(updatedTable); + List updatedTimeBoxes = customizeTimeBoxRepository.findAllByCustomizeTable(updatedTable); assertAll( () -> assertThat(updatedTable.getId()).isEqualTo(chanTable.getId()), @@ -205,7 +205,7 @@ class DeleteTable { customizeService.deleteTable(chanTable.getId(), chan); Optional foundTable = customizeTableRepository.findById(chanTable.getId()); - List timeBoxes = customizeTimeBoxRepository.findAllByCustomizeTable( + List timeBoxes = customizeTimeBoxRepository.findAllByCustomizeTable( chanTable); assertAll( diff --git a/src/test/java/com/debatetimer/service/customize/CustomizeServiceV2Test.java b/src/test/java/com/debatetimer/service/customize/CustomizeServiceV2Test.java index 50811628..252be593 100644 --- a/src/test/java/com/debatetimer/service/customize/CustomizeServiceV2Test.java +++ b/src/test/java/com/debatetimer/service/customize/CustomizeServiceV2Test.java @@ -14,7 +14,7 @@ import com.debatetimer.dto.customize.response.CustomizeTableResponse; import com.debatetimer.entity.customize.BellEntity; import com.debatetimer.entity.customize.CustomizeTableEntity; -import com.debatetimer.entity.customize.CustomizeTimeBox; +import com.debatetimer.entity.customize.CustomizeTimeBoxEntity; import com.debatetimer.exception.custom.DTClientErrorException; import com.debatetimer.exception.errorcode.ClientErrorCode; import com.debatetimer.service.BaseServiceTest; @@ -49,7 +49,8 @@ class Save { CustomizeTableResponse savedTableResponse = customizeService.save(customizeTableCreateRequest, chan); CustomizeTableEntity foundTable = customizeTableRepository.getByIdAndMember(savedTableResponse.id(), chan); - List foundTimeBoxes = customizeTimeBoxRepository.findAllByCustomizeTable(foundTable); + List foundTimeBoxes = customizeTimeBoxRepository.findAllByCustomizeTable( + foundTable); List foundBells = bellRepository.findAllByCustomizeTimeBoxIn(foundTimeBoxes); assertAll( @@ -67,8 +68,8 @@ class FindTable { void 사용자_지정_토론_테이블을_조회한다() { Member chan = memberGenerator.generate("default@gmail.com"); CustomizeTableEntity chanTable = customizeTableGenerator.generate(chan); - CustomizeTimeBox customizeTimeBox = customizeTimeBoxGenerator.generate(chanTable, CustomizeBoxType.NORMAL, - 1); + CustomizeTimeBoxEntity customizeTimeBox = customizeTimeBoxGenerator.generate( + chanTable, CustomizeBoxType.NORMAL, 1); customizeTimeBoxGenerator.generate(chanTable, CustomizeBoxType.NORMAL, 2); bellGenerator.generate(customizeTimeBox, 1, 1); bellGenerator.generate(customizeTimeBox, 1, 2); @@ -117,7 +118,8 @@ class UpdateTable { customizeService.updateTable(renewTableRequest, chanTable.getId(), chan); CustomizeTableEntity updatedTable = customizeTableRepository.getByIdAndMember(chanTable.getId(), chan); - List updatedTimeBoxes = customizeTimeBoxRepository.findAllByCustomizeTable(updatedTable); + List updatedTimeBoxes = customizeTimeBoxRepository.findAllByCustomizeTable( + updatedTable); List bells = bellRepository.findAllByCustomizeTimeBoxIn(updatedTimeBoxes); assertAll( @@ -215,7 +217,7 @@ class DeleteTable { customizeService.deleteTable(chanTable.getId(), chan); Optional foundTable = customizeTableRepository.findById(chanTable.getId()); - List timeBoxes = customizeTimeBoxRepository.findAllByCustomizeTable( + List timeBoxes = customizeTimeBoxRepository.findAllByCustomizeTable( chanTable); List bells = bellRepository.findAllByCustomizeTimeBoxIn(timeBoxes);