-
Notifications
You must be signed in to change notification settings - Fork 305
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
π 3λ¨κ³ - μ§νμ² κ΅¬κ° κ΄λ¦¬ #970
base: janeljs
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μλ
νμΈμ π
3λ¨κ³ κΉλνκ² μ ꡬνν΄ μ£Όμ
¨λ€μ π
λͺ κ°μ§ μ½λ©νΈ λ¨κ²Όλλ° νμΈν΄ μ£Όμκ³ λ€μ 리뷰 μμ²ν΄ μ£ΌμΈμ
build.gradle
Outdated
@@ -31,6 +31,7 @@ dependencies { | |||
testImplementation 'io.rest-assured:rest-assured:4.5.1' | |||
testImplementation 'com.navercorp.fixturemonkey:fixture-monkey-starter:0.5.8' | |||
testImplementation 'com.google.guava:guava:16+' | |||
testImplementation 'org.mockito:mockito-core' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ¬μ©νμ§ μλ μμ‘΄μ±μ΄ μΆκ°λμλ€μ π
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μμ νμμ΅λλ€~! 348513e
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
public class Sections { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μΌκΈ 컬λ μ νμ© π
public void validateUpStationId(Line line) { | ||
if (!Objects.equals(upStationId, line.getTerminalStationId())) { | ||
throw new InvalidSectionRequestException("ν΄λΉ λ Έμ μ ννμ’ μ μμ΄ μλ μμ΄ μνμμΌλ‘ μ€μ λμμ΅λλ€.", | ||
Map.of( | ||
"lineId", line.getId().toString(), | ||
"upStationId", upStationId.toString(), | ||
"downStationId", downStationId.toString() | ||
)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λλ©μΈ λ‘μ§μ΄ DTOμ ν¬ν¨λ κ² κ°μμ
CreateSectionRequestλ₯Ό νμ©νμ§ μκ³ κ΅¬κ°μ μΆκ°νλ€λ©΄ κ΅¬κ° μΆκ° μ μ½μ 무μν μ μκ² λλλ°μ
ꡬκ°μ μΆκ°ν λ Sectios λ΄λΆμμ κ²μ¦μ΄ μ΄λ€μ ΈμΌνμ§ μμκΉμ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ν λ§λ€μγ γ 리뷰 λ°μνμ΅λλ€~! λλΆμ μ½λκ° ν¨μ¬ κΉλν΄μ‘λ€μ π 63c094a
if (!line.getTerminalStationId().equals(stationId)) { | ||
throw new InvalidSectionRequestException("λ§μ§λ§ ꡬκ°λ§ μμ ν μ μμ΅λλ€."); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getterλ₯Ό νμ©ν΄ λΉκ΅νκΈ° λ³΄λ€ lineμκ² λ©μμ§λ₯Ό 보λ΄λ©΄ μ΄λ¨κΉμ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리뷰 λ°μνμ΅λλ€γ γ 63c094a
public class StationResponse { | ||
private final Long id; | ||
private final String name; | ||
public record StationResponse(Long id, String name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λ€λ₯Έ DTOμ λ€λ₯΄κ² recordλ₯Ό μ¬μ©νμ μ΄μ κ° κΆκΈν©λλ€ π€
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ΄κ±° μΈν 리μ μ΄κ° μΆμ²ν΄μ£ΌκΈΈλ νΈκΈ°μ¬μ ν λ² μ¨λ΄€μ΅λλ€ π
List<Section> findAllByLine_Id(Long lineId); | ||
|
||
Optional<Section> findByLine_IdAndDownStation_Id(Long lineId, Long downStationId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λ©μλλͺ 컨벀μ μ΄ λ§μ§ μμ κ² κ°μμ π’
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
camelCaseκ° μλκΈ°λ νλ° μλμμ± μΆμ² μ΄λ¦μ _
κ° μκ³ , κ°λ
μ±μ΄ μ‘°κΈ μ’μμ§λ μΈ‘λ©΄λ μλ κ² κ°μμ κ·Έλλ‘ μ¬μ©νμ΅λλ€.
μ κ° μ€λ¬΄μμλ μ£Όλ‘ λ§μ΄λ°ν°μ€λ₯Ό μ¬μ©νμ¬ μ λͺ¨λ₯΄λλ° λ³΄ν΅μ camelCaseλ₯Ό μ¬μ©νλμ?
(querydsl λ©μλλ λ€λ₯Έ λ©μλμ ν΅μΌμ±μ μκ°νλ©΄ κ·Έκ² λ§λ κ±° κ°κΈ°λ νλ€μγ
γ
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional<Section> findByLineIdAndDownStationId(Long lineId, Long downStationId);
μ²λΌ κ³ μΉλκΉ Unable to locate Attribute with the the given name [downStationId] on this ManagedType [subway.common.BaseEntity]
μλ¬κ° λ°μνλ λ¬Έμ λ μλ€μ. _
κ° μμΌλ©΄ Station downStation
λ΄λΆμ idλ‘ μΈμμ λͺ»νλ κ² κ°μμ. π’
Section section = Section.builder() | ||
.line(line) | ||
.upStation(upStation) | ||
.downStation(downStation) | ||
.distance(createSectionRequest.getDistance()) | ||
.build(); | ||
|
||
Section savedSection = sectionRepository.save(section); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line#addSection λ₯Ό νμ©νλ©΄ μ΄λ¨κΉμ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리뷰 λ°μνμ΅λλ€~ 63c094a
assertThat(getResponse.jsonPath().getList("upStationId", Long.class)).containsAnyOf(μ λΆλΉμ _ννμ’ μ μ_ID); | ||
assertThat(getResponse.jsonPath().getList("downStationId", Long.class)).containsAnyOf(μ λΆλΉμ _μ κ·μ_ID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ κ· νν μ’
μ μμ μΆκ°ν κ²½μ° μ κ·μμ΄ κ΅¬κ°μ ν¬ν¨λμ΄ μλ€λ κ²λ³΄λ€ νν μ’
μ μμμ κ²μ¦νλ©΄ μ΄λ¨κΉμ?
containsExactly λ₯Ό νμ©ν΄μ μ λͺ©λ‘ μμλ₯Ό κ²μ¦νλ©΄ μ’μ κ² κ°μλ° μ΄λ»κ² μκ°νμλμ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertThat(getResponse.jsonPath().getList("upStationId", Long.class)).containsExactly(μ λΆλΉμ _μνμ’
μ μ_ID, μ λΆλΉμ _ννμ’
μ μ_ID);
assertThat(getResponse.jsonPath().getList("downStationId", Long.class)).containsExactly(μ λΆλΉμ _ννμ’
μ μ_ID, μ λΆλΉμ _μ κ·μ_ID);
assertThat(getResponse.jsonPath().getList("distance")).containsExactly(10, 5);
λ§μνμ λλ‘ μμ²λΌ μμ±ν΄λ³΄μλλ° μ΄ν΄νλ €λ©΄ 3μ΄ μ λ λ²νΌλ§μ΄ 걸리λ κ² κ°κΈ°λ ν΄μ μμ μλ‘ μμ±λ ꡬκ°λ§ isEqualTo()
λ‘ κ²μ¦νλλ‘ μμ ν΄λ³΄μμ΅λλ€! eb8b58c
assertThat(sectionResponse.getUpStationId()).isEqualTo(μ λΆλΉμ _ννμ’
μ μ_ID);
assertThat(sectionResponse.getDownStationId()).isEqualTo(μ λΆλΉμ _μ κ·μ_ID);
assertThat(sectionResponse.getDistance()).isEqualTo(5);
@Nested | ||
@DisplayName("μλ‘μ΄ κ΅¬κ° λ±λ‘ μ€ν¨") | ||
class CreateSectionWithInvalidRequest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μμΈ ν μ€νΈ π
- null μ²΄ν¬ μΆκ° - color μ λ°μ΄νΈ μΆκ°
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μλ
νμΈμ μ§μ λ π
νΌλλ°± λ°μ μν΄μ£Όμ
¨λ€μ π
μ§λ μ½λ©νΈμμ μ€λͺ
μ΄ λΆμ‘±ν λΆλΆμ΄ μλ κ² κ°μ μΆκ° μ½λ©νΈ λ¨κ²Όμ΅λλ€
νμΈν΄ μ£Όμκ³ λ€μ 리뷰 μμ² λΆνλλ €μ
public void add(Section section) { | ||
if (!sections.isEmpty()) { | ||
validateUpStationId(section); | ||
validateDownStationId(section); | ||
validateDistance(section); | ||
} | ||
|
||
sections.add(section); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
κ΅¬κ° λ±λ‘ κΈ°λ₯μ²λΌ κ΅¬κ° μ κ±° λ©μλλ μΆκ°νλ©΄ μ΄λ¨κΉμ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리뷰 λ°μνμ΅λλ€!γ γ eb1ecaf
} | ||
|
||
public List<SectionResponse> findSections(Long lineId) { | ||
List<Section> sections = sectionRepository.findAllByLine_Id(lineId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λ
Έμ μ ν¬ν¨λ ꡬκ°λ€μ line κ°μ²΄λ₯Ό νμ©ν΄μ κ°μ Έμ¬ μκ° μλλ°μ
sectionRepository λμ line κ°μ²΄λ₯Ό νμ©ν΄μ κ΅¬κ° λͺ©λ‘μ μ‘°ννλ©΄ μ΄λ¨κΉμ?
List<Section> sections = sectionRepository.findAllByLine_Id(lineId); | |
Line line = findLineById(lineId); | |
List<Section> sections = line.getSections(); |
public void deleteSection(Long lineId, Long stationId) { | ||
Line line = findLineById(lineId); | ||
|
||
if (line.hasLessThanTwoSections()) { | ||
throw new InvalidSectionRequestException("ꡬκ°μ΄ 2κ° μ΄μμΌ λλ§ μμ ν μ μμ΅λλ€."); | ||
} | ||
|
||
if (!line.isTerminalStationId(stationId)) { | ||
throw new InvalidSectionRequestException("λ§μ§λ§ ꡬκ°λ§ μμ ν μ μμ΅λλ€."); | ||
} | ||
|
||
Section section = sectionRepository.findByLine_IdAndDownStation_Id(lineId, stationId) | ||
.orElseThrow(() -> new NotFoundException( | ||
Map.of( | ||
"lineId", lineId.toString(), | ||
"stationId", stationId.toString() | ||
))); | ||
|
||
sectionRepository.delete(section); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addSection λ©μλμ²λΌ line μ μ‘°νν νμ λ©μμ§λ₯Ό 보λ΄μ ꡬκ°μ μμ νλ©΄ μ΄λ¨κΉμ?
μμ κΈ°λ₯μ΄λ @Transactional
λ μΆκ°λλ©΄ μ’μ κ² κ°μμ
line.deleteSection(stationId)
;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리뷰 λ°μνμ΅λλ€!γ γ eb1ecaf
assertThat(sectionResponse.getUpStationId()).isEqualTo(μ λΆλΉμ _ννμ’ μ μ_ID); | ||
assertThat(sectionResponse.getDownStationId()).isEqualTo(μ λΆλΉμ _μ κ·μ_ID); | ||
assertThat(sectionResponse.getDistance()).isEqualTo(5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ¬μ€ λ³κ²½ μ κ³Ό λ€λ₯΄μ§ μλ€κ³ μκ°λ€μ΄μ π
μΈμ ν
μ€νΈλ λΈλλ°μ€ ν
μ€νΈμ΄λ νλ νλμ ꡬκ°μ΄ μ΄λ»κ² ꡬμ±λμλμ§ κ΄μ¬ μκΈ° 보λ€
ꡬκ°μ΄ μΆκ°λμμ λ λ
Έμ μ΄ κ°μ§λ μ 체 μ λͺ©λ‘μ΄ μνλλλ‘(μμλλ‘) ꡬμ±λμλμ§κ° λ κ΄μ¬μ΄ ν¬λ€κ³ μκ°ν΄μ νΌλλ°± λλ Έμλλ°μ
λ
Έμ μ A-B-C μμ΄ μμ λ ννμ(C-D ꡬκ°)μ μΆκ°νλ©΄ λ
Έμ μ μ 체 μ λͺ©λ‘μ A-B-C-Dκ° λμμμ κ²μ¦νλ©΄
μΈμ ν
μ€νΈλ₯Ό μ½λ μ
μ₯μμ κ΅¬κ° μΆκ° κΈ°λ₯μ λΉ λ₯΄κ² νμ
ν μ μμ κ² κ°μμ
@@ -21,6 +21,7 @@ public class Line extends BaseEntity { | |||
@Column(length = 20, nullable = false) | |||
private String name; | |||
|
|||
@Setter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setterλ₯Ό μ 곡νκΈ° λ³΄λ€ update
or modify
λ©μλλ₯Ό μ 곡νκ³
λ©μλ λ΄λΆμμ κ°μ μμ νλλ‘ νλ©΄ μ΄λ¨κΉμ?
setIfNotNull(modifyLineRequest.getName(), line::setName); | ||
setIfNotNull(modifyLineRequest.getColor(), line::setColor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setIfNotNull λ©μλλ₯Ό κ±°μΉμ§ μκ³ line μ κ°μ λ³κ²½νλ©΄ λλ©μΈμ μ μ½μ¬νμ΄ μ§μΌμ§μ§ μμ κ² κ°μμ
null 체ν¬λ₯Ό line λ΄λΆμμ κ²μ¦νλ©΄ μ΄λ¨κΉμ?
μ‘μ©μ£Ό 리뷰μ΄λ μλ νμΈμ~
λ¦¬λ·°μ΄ μμ§μ μ λλ€.
3λ¨κ³ - μ§νμ² κ΅¬κ° κ΄λ¦¬
리뷰 μμ²λ립λλ€.ν λμ λ°λΉ μ μμ λ―Έμ μ λͺ»νλ€κ° λ¦κ²λλ§ μ‘°κΈμ© ν΄λ³΄λ €κ³ PR 보λ λλ€ π
μ λ²μ λ΅λ³μ£Όμ μ½λ©νΈλ€ λμμ΄ λ§μ΄ λμμ΅λλ€.
μ΄λ² λ¨κ³λ 리뷰 μ λΆνλλ¦¬κ² μ΅λλ€~! π