-
Notifications
You must be signed in to change notification settings - Fork 280
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
๐ 1๋จ๊ณ - ๊ตฌ๊ฐ ์ถ๊ฐ ๊ธฐ๋ฅ ๋ณ๊ฒฝ #225
base: sanhee
Are you sure you want to change the base?
Conversation
์ํ ์ข ์ ์ด ์ํ์ญ์ธ ๊ตฌ๊ฐ์ ๋จผ์ ์ฐพ๋๋ค. ๊ทธ ๋ค์, ํด๋น ๊ตฌ๊ฐ์ ํํ์ญ์ด ์ํ์ญ์ธ ๋ค๋ฅธ ๊ตฌ๊ฐ์ ์ฐพ๋๋ค. 2๋ฒ์ ๋ฐ๋ณตํ๋ค๊ฐ ํํ ์ข ์ ์ญ์ ์ฐพ์ผ๋ฉด ์กฐํ๋ฅผ ๋ฉ์ถ๋ค.
์ค๋์ ๊ตํ - ํจ์ ์ค๋ฒ๋ผ์ด๋๋ฅผ ์กฐ์ฌํ์.. List<Section> addSection(Section newSection) List<Section> addSection(Station upStation, Station downStation, int distance)
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 line = lineRepository.save(new Line( | ||
request.getName(), | ||
request.getColor() | ||
)); | ||
if (request.getUpStationId() != null && request.getDownStationId() != null && request.getDistance() != 0) { |
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.
if์ ์กฐ๊ฑด์ด ๋ณต์กํ๋ ๋ฉ์๋๋ก ์ถ์ถํด๋ณด๋๊ฒ ์ข๊ฒ ๋ค์
} | ||
|
||
@Transactional(readOnly = true) | ||
public LineResponse findById(Long id) { | ||
return createLineResponse(lineRepository.findById(id).orElseThrow(IllegalArgumentException::new)); | ||
Line findLine = lineRepository.findById(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.
findById(id).orElseThrow ์ด ์ฝ๋๊ฐ ์ค๋ณตํด์ ๋ฐ์ํ๊ณ ์์ผ๋ ๋ฉ์๋๋ก ์ถ์ถํด์ฃผ๋ฉด ์ด๋จ๊น์
Station station = stationService.findById(stationId); | ||
|
||
if (!line.getSections().get(line.getSections().size() - 1).getDownStation().equals(station)) { | ||
if (!line.getSections() |
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.
๊ฐ์ฒด์งํฅ ์ํ์ฒด์กฐ
4. ํ ์ค์ ์ ์ ํ๋๋ง ์ฐ๋๋ค.
line ๊ฐ์ฒด ๋ด๋ถ๋ก ์กฐ๊ฑด์ ์ฎ๊ฒจ๋ณด์๊ธฐ ๋ฐ๋๋๋ค.
throw new IllegalArgumentException(); | ||
} | ||
|
||
line.getSections().remove(line.getSections().size() - 1); | ||
line.getSections() |
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.
๊ฐ์ฒด์งํฅ ์ํ์ฒด์กฐ
4. ํ ์ค์ ์ ์ ํ๋๋ง ์ฐ๋๋ค.
|
||
import java.time.LocalDateTime; | ||
|
||
public class ErrorResponse{ |
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 class ErrorResponse{ | |
public class ErrorResponse { |
|
||
private List<Section> addSection(Section newSection) { | ||
|
||
AtomicBoolean normalCondition = new AtomicBoolean(true); |
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.
- Atomic ํด๋์ค๋ฅผ ์ฌ์ฉํ์ ์ด์ ๊ฐ ์์๊น์? ๋์์ฑ ๋ฌธ์ ๊ฐ ์๋ ๊ฑธ๋ก ๋ณด์ด๋ค์
- ๊ฐ ๋ฉ์๋๋ค์ด ์ด ๋ณ์์ ์์กดํ๋ ๋ก์ง์ ๋ง๋์ ๊ฒ ๊ฐ๋ค์. ์ธ๋ถ ์กฐ๊ฑด์ ์์กดํ์ง ์๋ ๋ ๋ฆฝ์ ์ธ ๋ฉ์๋๋ก ๋ง๋ค ๋ฐฉ๋ฒ์ ์์๊น์?
.filter(station -> !getStations().contains(newSection.getUpStation())) | ||
.filter(section -> !getStations().contains(newSection.getDownStation())) | ||
.findAny() | ||
.ifPresent(unused -> { |
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.
ifPresent๋ ์์ธ ์ฒ๋ฆฌํ ๋ ์ฌ์ฉํ์ง ์์ต๋๋ค.
orElseThrow๋ก ์ ์ฉํด๋ณด์๊ธฐ ๋ฐ๋๋๋ค.
|
||
for (Section section : sections) { | ||
Station upStation = section | ||
.getUpStation(); |
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.
์ํฐ๋ก ๊ตฌ๋ถํด์ผ ๋ ๋งํผ ๋ณต์กํ ์ฝ๋๊ฐ ์๋ ๊ฒ ๊ฐ์ผ๋ ๋ถํ์ํ ์ํฐ๋ ์ง์ํฉ์๋ค.
} | ||
|
||
if (upStation.equals(prevDownStation)) { | ||
if (downStation.equals(newSection.getDownStation())) { |
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.
for, if๋ก ์ด์ด์ง๋ 2๋์ค ์ฝ๋๋ค์ด ๋ณด์ด๋ค์
- 1๋์ค๋ง ์ฌ์ฉํ๋๋ก ๋ฉ์๋๋ฅผ์์ ํด๋ณด์๊ณ
- ๋ฉ์๋๋ฅผ 10์ค ์ด๋ด๋ก ์ค์ฌ๋ณด์ธ์.
newSection.getUpStation(), | ||
(oldSection.getDistance() - newSection.getDistance()) | ||
)); | ||
} else if (newSection.getDistance() > oldSection.getDistance()) { |
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.
- else if๋ฅผ ์ฌ์ฉํ์ง ์๋๋ก ๋ฐ๊ฟ๋ณด์๊ธฐ ๋ฐ๋๋๋ค. else if๊ฐ ๋ง์์ง๋ฉด ์ฝ๋ ๋ณต์ก๋๊ฐ ์ฌ๋ผ๊ฐ๋๋ค.
- dto๋ก ๊ฐ์ ์ ๋ฌํ ๋ ์ธ์๋ getter๋ฅผ ์ฌ์ฉํ์ง ๋ง์ธ์. section ๊ฐ์ฒด ๋ด๋ถ์์ ์ฒ๋ฆฌํ๋๋ก ์ฝ๋๋ฅผ ์์ ํ๋ฉด line ํด๋์ค์ ๋ณต์ก๋๋ฅผ ๋ฎ์ถ ์ ์์๊ฒ๋๋ค.
๋ค๋ฆ๊ฒ ๋ฆฌ๋ทฐ ์์ฒญ๋๋ฆฝ๋๋ค.
์๊ตฌ์ฌํญ์ ์๋ Line ๋จ์ํ ์คํธ์ ๊ตฌ๊ฐ๊ด๋ฆฌ ์ธ์ํ ์คํธ๋ฅผ ์๋ฃํ์ต๋๋ค.
์๊ฐ๋ด์ด ๋ฆฌ๋ทฐํด์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค.