Skip to content
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

Open
wants to merge 34 commits into
base: sanhee
Choose a base branch
from

Conversation

sanhee
Copy link

@sanhee sanhee commented Feb 5, 2022

๋’ค๋Šฆ๊ฒŒ ๋ฆฌ๋ทฐ ์š”์ฒญ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

์š”๊ตฌ์‚ฌํ•ญ์— ์žˆ๋Š” Line ๋‹จ์œ„ํ…Œ์ŠคํŠธ์™€ ๊ตฌ๊ฐ„๊ด€๋ฆฌ ์ธ์ˆ˜ํ…Œ์ŠคํŠธ๋ฅผ ์™„๋ฃŒํ–ˆ์Šต๋‹ˆ๋‹ค.

์‹œ๊ฐ„๋‚ด์–ด ๋ฆฌ๋ทฐํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

sanhee added 30 commits February 2, 2022 15:29
์ƒํ–‰ ์ข…์ ์ด ์ƒํ–‰์—ญ์ธ ๊ตฌ๊ฐ„์„ ๋จผ์ € ์ฐพ๋Š”๋‹ค.
๊ทธ ๋‹ค์Œ, ํ•ด๋‹น ๊ตฌ๊ฐ„์˜ ํ•˜ํ–‰์—ญ์ด ์ƒํ–‰์—ญ์ธ ๋‹ค๋ฅธ ๊ตฌ๊ฐ„์„ ์ฐพ๋Š”๋‹ค.
2๋ฒˆ์„ ๋ฐ˜๋ณตํ•˜๋‹ค๊ฐ€ ํ•˜ํ–‰ ์ข…์ ์—ญ์„ ์ฐพ์œผ๋ฉด ์กฐํšŒ๋ฅผ ๋ฉˆ์ถ˜๋‹ค.
์˜ค๋Š˜์˜ ๊ตํ›ˆ
- ํ•จ์ˆ˜ ์˜ค๋ฒ„๋ผ์ด๋“œ๋ฅผ ์กฐ์‹ฌํ•˜์ž..

List<Section> addSection(Section newSection)

List<Section> addSection(Station upStation, Station downStation, int distance)
Copy link

@kang-hyungu kang-hyungu left a 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) {

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)

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()

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()

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{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public class ErrorResponse{
public class ErrorResponse {


private List<Section> addSection(Section newSection) {

AtomicBoolean normalCondition = new AtomicBoolean(true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Atomic ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”? ๋™์‹œ์„ฑ ๋ฌธ์ œ๊ฐ€ ์—†๋Š” ๊ฑธ๋กœ ๋ณด์ด๋„ค์š”
  2. ๊ฐ ๋ฉ”์„œ๋“œ๋“ค์ด ์ด ๋ณ€์ˆ˜์— ์˜์กดํ•˜๋Š” ๋กœ์ง์„ ๋งŒ๋“œ์‹  ๊ฒƒ ๊ฐ™๋„ค์š”. ์™ธ๋ถ€ ์กฐ๊ฑด์— ์˜์กดํ•˜์ง€ ์•Š๋Š” ๋…๋ฆฝ์ ์ธ ๋ฉ”์„œ๋“œ๋กœ ๋งŒ๋“ค ๋ฐฉ๋ฒ•์€ ์—†์„๊นŒ์š”?

.filter(station -> !getStations().contains(newSection.getUpStation()))
.filter(section -> !getStations().contains(newSection.getDownStation()))
.findAny()
.ifPresent(unused -> {

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();

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())) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for, if๋กœ ์ด์–ด์ง€๋Š” 2๋Ž์Šค ์ฝ”๋“œ๋“ค์ด ๋ณด์ด๋„ค์š”

  1. 1๋Ž์Šค๋งŒ ์‚ฌ์šฉํ•˜๋„๋ก ๋ฉ”์„œ๋“œ๋ฅผ์ˆ˜์ •ํ•ด๋ณด์‹œ๊ณ 
  2. ๋ฉ”์„œ๋“œ๋ฅผ 10์ค„ ์ด๋‚ด๋กœ ์ค„์—ฌ๋ณด์„ธ์š”.

newSection.getUpStation(),
(oldSection.getDistance() - newSection.getDistance())
));
} else if (newSection.getDistance() > oldSection.getDistance()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. else if๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋„๋ก ๋ฐ”๊ฟ”๋ณด์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค. else if๊ฐ€ ๋งŽ์•„์ง€๋ฉด ์ฝ”๋“œ ๋ณต์žก๋„๊ฐ€ ์˜ฌ๋ผ๊ฐ‘๋‹ˆ๋‹ค.
  2. dto๋กœ ๊ฐ’์„ ์ „๋‹ฌํ•  ๋•Œ ์™ธ์—๋Š” getter๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ๋งˆ์„ธ์š”. section ๊ฐ์ฒด ๋‚ด๋ถ€์—์„œ ์ฒ˜๋ฆฌํ•˜๋„๋ก ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•˜๋ฉด line ํด๋ž˜์Šค์˜ ๋ณต์žก๋„๋ฅผ ๋‚ฎ์ถœ ์ˆ˜ ์žˆ์„๊ฒ๋‹ˆ๋‹ค.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants