๐ 3๋จ๊ณ - ์งํ์ฒ ๊ตฌ๊ฐ ๊ด๋ฆฌ#970
๐ 3๋จ๊ณ - ์งํ์ฒ ๊ตฌ๊ฐ ๊ด๋ฆฌ#970janeljs wants to merge 19 commits intonext-step:janeljsfrom
Conversation
testrace
left a comment
There was a problem hiding this comment.
์๋
ํ์ธ์ ๐
3๋จ๊ณ ๊น๋ํ๊ฒ ์ ๊ตฌํํด ์ฃผ์
จ๋ค์ ๐
๋ช ๊ฐ์ง ์ฝ๋ฉํธ ๋จ๊ฒผ๋๋ฐ ํ์ธํด ์ฃผ์๊ณ ๋ค์ ๋ฆฌ๋ทฐ ์์ฒญํด ์ฃผ์ธ์
| 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.
์ฌ์ฉํ์ง ์๋ ์์กด์ฑ์ด ์ถ๊ฐ๋์๋ค์ ๐
| import java.util.List; | ||
| import java.util.stream.Stream; | ||
|
|
||
| public class Sections { |
| 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.
๋๋ฉ์ธ ๋ก์ง์ด DTO์ ํฌํจ๋ ๊ฒ ๊ฐ์์
CreateSectionRequest๋ฅผ ํ์ฉํ์ง ์๊ณ ๊ตฌ๊ฐ์ ์ถ๊ฐํ๋ค๋ฉด ๊ตฌ๊ฐ ์ถ๊ฐ ์ ์ฝ์ ๋ฌด์ํ ์ ์๊ฒ ๋๋๋ฐ์
๊ตฌ๊ฐ์ ์ถ๊ฐํ ๋ Sectios ๋ด๋ถ์์ ๊ฒ์ฆ์ด ์ด๋ค์ ธ์ผํ์ง ์์๊น์?
There was a problem hiding this comment.
ํ ๋ง๋ค์ใ ใ ๋ฆฌ๋ทฐ ๋ฐ์ํ์ต๋๋ค~! ๋๋ถ์ ์ฝ๋๊ฐ ํจ์ฌ ๊น๋ํด์ก๋ค์ ๐ 63c094a
| if (!line.getTerminalStationId().equals(stationId)) { | ||
| throw new InvalidSectionRequestException("๋ง์ง๋ง ๊ตฌ๊ฐ๋ง ์ญ์ ํ ์ ์์ต๋๋ค."); | ||
| } |
There was a problem hiding this comment.
getter๋ฅผ ํ์ฉํด ๋น๊ตํ๊ธฐ ๋ณด๋ค line์๊ฒ ๋ฉ์์ง๋ฅผ ๋ณด๋ด๋ฉด ์ด๋จ๊น์?
| 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.
๋ค๋ฅธ DTO์ ๋ค๋ฅด๊ฒ record๋ฅผ ์ฌ์ฉํ์ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค ๐ค
There was a problem hiding this comment.
์ด๊ฑฐ ์ธํ ๋ฆฌ์ ์ด๊ฐ ์ถ์ฒํด์ฃผ๊ธธ๋ ํธ๊ธฐ์ฌ์ ํ ๋ฒ ์จ๋ดค์ต๋๋ค ๐
| List<Section> findAllByLine_Id(Long lineId); | ||
|
|
||
| Optional<Section> findByLine_IdAndDownStation_Id(Long lineId, Long downStationId); |
There was a problem hiding this comment.
๋ฉ์๋๋ช ์ปจ๋ฒค์ ์ด ๋ง์ง ์์ ๊ฒ ๊ฐ์์ ๐ข
There was a problem hiding this comment.
camelCase๊ฐ ์๋๊ธฐ๋ ํ๋ฐ ์๋์์ฑ ์ถ์ฒ ์ด๋ฆ์ _๊ฐ ์๊ณ , ๊ฐ๋
์ฑ์ด ์กฐ๊ธ ์ข์์ง๋ ์ธก๋ฉด๋ ์๋ ๊ฒ ๊ฐ์์ ๊ทธ๋๋ก ์ฌ์ฉํ์ต๋๋ค.
์ ๊ฐ ์ค๋ฌด์์๋ ์ฃผ๋ก ๋ง์ด๋ฐํฐ์ค๋ฅผ ์ฌ์ฉํ์ฌ ์ ๋ชจ๋ฅด๋๋ฐ ๋ณดํต์ camelCase๋ฅผ ์ฌ์ฉํ๋์?
(querydsl ๋ฉ์๋๋ ๋ค๋ฅธ ๋ฉ์๋์ ํต์ผ์ฑ์ ์๊ฐํ๋ฉด ๊ทธ๊ฒ ๋ง๋ ๊ฑฐ ๊ฐ๊ธฐ๋ ํ๋ค์ใ
ใ
)
There was a problem hiding this comment.
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.
Line#addSection ๋ฅผ ํ์ฉํ๋ฉด ์ด๋จ๊น์?
| 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.
์ ๊ท ํํ ์ข
์ ์ญ์ ์ถ๊ฐํ ๊ฒฝ์ฐ ์ ๊ท์ญ์ด ๊ตฌ๊ฐ์ ํฌํจ๋์ด ์๋ค๋ ๊ฒ๋ณด๋ค ํํ ์ข
์ ์ญ์์ ๊ฒ์ฆํ๋ฉด ์ด๋จ๊น์?
containsExactly ๋ฅผ ํ์ฉํด์ ์ญ ๋ชฉ๋ก ์์๋ฅผ ๊ฒ์ฆํ๋ฉด ์ข์ ๊ฒ ๊ฐ์๋ฐ ์ด๋ป๊ฒ ์๊ฐํ์๋์?
There was a problem hiding this comment.
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 { |
- null ์ฒดํฌ ์ถ๊ฐ - color ์ ๋ฐ์ดํธ ์ถ๊ฐ
testrace
left a comment
There was a problem hiding this comment.
์๋
ํ์ธ์ ์ง์ ๋ ๐
ํผ๋๋ฐฑ ๋ฐ์ ์ํด์ฃผ์
จ๋ค์ ๐
์ง๋ ์ฝ๋ฉํธ์์ ์ค๋ช
์ด ๋ถ์กฑํ ๋ถ๋ถ์ด ์๋ ๊ฒ ๊ฐ์ ์ถ๊ฐ ์ฝ๋ฉํธ ๋จ๊ฒผ์ต๋๋ค
ํ์ธํด ์ฃผ์๊ณ ๋ค์ ๋ฆฌ๋ทฐ ์์ฒญ ๋ถํ๋๋ ค์
| public void add(Section section) { | ||
| if (!sections.isEmpty()) { | ||
| validateUpStationId(section); | ||
| validateDownStationId(section); | ||
| validateDistance(section); | ||
| } | ||
|
|
||
| sections.add(section); |
There was a problem hiding this comment.
๊ตฌ๊ฐ ๋ฑ๋ก ๊ธฐ๋ฅ์ฒ๋ผ ๊ตฌ๊ฐ ์ ๊ฑฐ ๋ฉ์๋๋ ์ถ๊ฐํ๋ฉด ์ด๋จ๊น์?
| } | ||
|
|
||
| public List<SectionResponse> findSections(Long lineId) { | ||
| List<Section> sections = sectionRepository.findAllByLine_Id(lineId); |
There was a problem hiding this comment.
๋
ธ์ ์ ํฌํจ๋ ๊ตฌ๊ฐ๋ค์ 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.
addSection ๋ฉ์๋์ฒ๋ผ line ์ ์กฐํํ ํ์ ๋ฉ์์ง๋ฅผ ๋ณด๋ด์ ๊ตฌ๊ฐ์ ์ญ์ ํ๋ฉด ์ด๋จ๊น์?
์ญ์ ๊ธฐ๋ฅ์ด๋ @Transactional๋ ์ถ๊ฐ๋๋ฉด ์ข์ ๊ฒ ๊ฐ์์
line.deleteSection(stationId);
| assertThat(sectionResponse.getUpStationId()).isEqualTo(์ ๋ถ๋น์ _ํํ์ข ์ ์ญ_ID); | ||
| assertThat(sectionResponse.getDownStationId()).isEqualTo(์ ๋ถ๋น์ _์ ๊ท์ญ_ID); | ||
| assertThat(sectionResponse.getDistance()).isEqualTo(5); |
There was a problem hiding this comment.
์ฌ์ค ๋ณ๊ฒฝ ์ ๊ณผ ๋ค๋ฅด์ง ์๋ค๊ณ ์๊ฐ๋ค์ด์ ๐
์ธ์ ํ
์คํธ๋ ๋ธ๋๋ฐ์ค ํ
์คํธ์ด๋ ํ๋ ํ๋์ ๊ตฌ๊ฐ์ด ์ด๋ป๊ฒ ๊ตฌ์ฑ๋์๋์ง ๊ด์ฌ ์๊ธฐ ๋ณด๋ค
๊ตฌ๊ฐ์ด ์ถ๊ฐ๋์์ ๋ ๋
ธ์ ์ด ๊ฐ์ง๋ ์ ์ฒด ์ญ ๋ชฉ๋ก์ด ์ํ๋๋๋ก(์์๋๋ก) ๊ตฌ์ฑ๋์๋์ง๊ฐ ๋ ๊ด์ฌ์ด ํฌ๋ค๊ณ ์๊ฐํด์ ํผ๋๋ฐฑ ๋๋ ธ์๋๋ฐ์
๋
ธ์ ์ A-B-C ์ญ์ด ์์ ๋ ํํ์ญ(C-D ๊ตฌ๊ฐ)์ ์ถ๊ฐํ๋ฉด ๋
ธ์ ์ ์ ์ฒด ์ญ ๋ชฉ๋ก์ A-B-C-D๊ฐ ๋์์์ ๊ฒ์ฆํ๋ฉด
์ธ์ ํ
์คํธ๋ฅผ ์ฝ๋ ์
์ฅ์์ ๊ตฌ๊ฐ ์ถ๊ฐ ๊ธฐ๋ฅ์ ๋น ๋ฅด๊ฒ ํ์
ํ ์ ์์ ๊ฒ ๊ฐ์์
| @Column(length = 20, nullable = false) | ||
| private String name; | ||
|
|
||
| @Setter |
There was a problem hiding this comment.
setter๋ฅผ ์ ๊ณตํ๊ธฐ ๋ณด๋ค update or modify ๋ฉ์๋๋ฅผ ์ ๊ณตํ๊ณ
๋ฉ์๋ ๋ด๋ถ์์ ๊ฐ์ ์์ ํ๋๋ก ํ๋ฉด ์ด๋จ๊น์?
| setIfNotNull(modifyLineRequest.getName(), line::setName); | ||
| setIfNotNull(modifyLineRequest.getColor(), line::setColor); |
There was a problem hiding this comment.
setIfNotNull ๋ฉ์๋๋ฅผ ๊ฑฐ์น์ง ์๊ณ line ์ ๊ฐ์ ๋ณ๊ฒฝํ๋ฉด ๋๋ฉ์ธ์ ์ ์ฝ์ฌํญ์ด ์ง์ผ์ง์ง ์์ ๊ฒ ๊ฐ์์
null ์ฒดํฌ๋ฅผ line ๋ด๋ถ์์ ๊ฒ์ฆํ๋ฉด ์ด๋จ๊น์?
์ก์ฉ์ฃผ ๋ฆฌ๋ทฐ์ด๋ ์๋ ํ์ธ์~
๋ฆฌ๋ทฐ์ด ์์ง์ ์ ๋๋ค.
3๋จ๊ณ - ์งํ์ฒ ๊ตฌ๊ฐ ๊ด๋ฆฌ๋ฆฌ๋ทฐ ์์ฒญ๋๋ฆฝ๋๋ค.ํ ๋์ ๋ฐ๋น ์ ์์ ๋ฏธ์ ์ ๋ชปํ๋ค๊ฐ ๋ฆ๊ฒ๋๋ง ์กฐ๊ธ์ฉ ํด๋ณด๋ ค๊ณ PR ๋ณด๋ ๋๋ค ๐ญ
์ ๋ฒ์ ๋ต๋ณ์ฃผ์ ์ฝ๋ฉํธ๋ค ๋์์ด ๋ง์ด ๋์์ต๋๋ค.
์ด๋ฒ ๋จ๊ณ๋ ๋ฆฌ๋ทฐ ์ ๋ถํ๋๋ฆฌ๊ฒ ์ต๋๋ค~! ๐