-
Notifications
You must be signed in to change notification settings - Fork 1
[REFACTOR] 타임박스 도메인 - 엔티티 분리 / 서비스 로직 개선 #201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9b7091e
4bdacb0
63d28cf
41d9672
1b35e5f
6917a44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package com.debatetimer.entity.customize; | ||
|
|
||
| import com.debatetimer.domain.customize.Bell; | ||
| import com.debatetimer.exception.custom.DTClientErrorException; | ||
| import com.debatetimer.exception.errorcode.ClientErrorCode; | ||
| import jakarta.persistence.Column; | ||
|
|
@@ -46,6 +47,12 @@ public BellEntity(CustomizeTimeBoxEntity customizeTimeBox, int time, int count) | |
| this.count = count; | ||
| } | ||
|
|
||
| public BellEntity(CustomizeTimeBoxEntity customizeTimeBox, Bell bell) { | ||
| this.customizeTimeBox = customizeTimeBox; | ||
| this.time = bell.getTime(); | ||
| this.count = bell.getCount(); | ||
| } | ||
|
|
||
| private void validateTime(int time) { | ||
| if (time < 0) { | ||
| throw new DTClientErrorException(ClientErrorCode.INVALID_BELL_TIME); | ||
|
|
@@ -57,4 +64,12 @@ private void validateCount(int count) { | |
| throw new DTClientErrorException(ClientErrorCode.INVALID_BELL_COUNT); | ||
| } | ||
| } | ||
|
|
||
| public Bell toDomain() { | ||
| return new Bell(time, count); | ||
| } | ||
|
|
||
| public boolean isContained(CustomizeTimeBoxEntity timeBox) { | ||
| return this.customizeTimeBox.getId().equals(timeBox.getId()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [사소한 제안] CustomizeTimeBoxEntity 한테 isSame(CustomizeTimeBoxEntity)로 시켜도 될 것 같아요 |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package com.debatetimer.entity.customize; | ||
|
|
||
| import com.debatetimer.domain.customize.Bell; | ||
| import com.debatetimer.domain.customize.CustomizeTimeBox; | ||
| import java.util.Collections; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
| import lombok.Getter; | ||
|
|
||
| public class CustomizeTimeBoxEntities { | ||
|
|
||
| private static final Comparator<CustomizeTimeBoxEntity> TIME_BOX_COMPARATOR = Comparator | ||
| .comparing(CustomizeTimeBoxEntity::getSequence); | ||
|
|
||
| @Getter | ||
| private final List<CustomizeTimeBoxEntity> timeBoxes; | ||
|
|
||
| private final List<BellEntity> bells; | ||
|
|
||
| public CustomizeTimeBoxEntities(List<CustomizeTimeBoxEntity> timeBoxes) { | ||
| this.timeBoxes = timeBoxes.stream() | ||
| .sorted(TIME_BOX_COMPARATOR) | ||
| .toList(); | ||
| this.bells = Collections.emptyList(); | ||
| } | ||
|
|
||
| public CustomizeTimeBoxEntities(List<CustomizeTimeBoxEntity> timeBoxes, List<BellEntity> bells) { | ||
| this.timeBoxes = timeBoxes.stream() | ||
| .sorted(TIME_BOX_COMPARATOR) | ||
| .toList(); | ||
| this.bells = bells; | ||
| } | ||
|
Comment on lines
+27
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 나중에 V1 제거할 때 bell을 포함하는 이름으로 바꿔야 할려나요
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아 이게... TimeBox 안에 Bell 이 포함된 개념이라고 생각해서 bell 관련 정보를 따로 명시하지는 않았음(ex. Car 안에 Name이 포함되어 있는 느낌?) |
||
|
|
||
| public List<CustomizeTimeBox> toDomain() { | ||
| return timeBoxes.stream() | ||
| .map(timebox -> timebox.toDomain(getBells(timebox))) | ||
| .toList(); | ||
| } | ||
|
|
||
| private List<Bell> getBells(CustomizeTimeBoxEntity timeBox) { | ||
| return bells.stream() | ||
| .filter(bell -> bell.isContained(timeBox)) | ||
| .map(BellEntity::toDomain) | ||
| .toList(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,15 +3,17 @@ | |
| import com.debatetimer.entity.customize.BellEntity; | ||
| 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; | ||
|
|
||
| public interface BellRepository extends Repository<BellEntity, Long> { | ||
|
|
||
| BellEntity save(BellEntity bell); | ||
|
|
||
| List<BellEntity> findByCustomizeTimeBox(CustomizeTimeBoxEntity customizeTimeBox); | ||
|
|
||
| void deleteAllByCustomizeTimeBoxIn(List<CustomizeTimeBoxEntity> customizeTimeBoxes); | ||
| @Query("DELETE FROM BellEntity b WHERE b.customizeTimeBox.customizeTable.id = :tableId") | ||
| @Modifying(clearAutomatically = true, flushAutomatically = true) | ||
| void deleteAllByTable(long tableId); | ||
|
Comment on lines
+14
to
+16
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이거 쿼리가 궁금해서 한번 테스트로 확인해봤더니 흠... 데이터 양을 생각하면 괜찮을 것 같긴한데... 나중에 최적화를 해보면 좋을 것 같네요
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [궁금한 질문] 이거 진짜 그냥 궁금해서 남기는 질문인데 timeBox in 절이 아니라 tableid 받아서 삭제하게 한 이유가 있나요? 사용성 측면에선 더 좋아졌다고 생각하는데 도메인 적으로는 시간표 - 타임박스의 벨이 약간 거리감이 있는 느낌이라 커찬이 생각한 리팩터링 의도가 순수히 궁금해요!
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 동시성 이슈 기억하시나요? |
||
|
|
||
| List<BellEntity> findAllByCustomizeTimeBoxIn(List<CustomizeTimeBoxEntity> timeBoxes); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.