-
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๋จ๊ณ - ์งํ์ฒ ๊ตฌ๊ฐ ๊ด๋ฆฌ #938
Open
jwoo-o
wants to merge
4
commits into
next-step:jwoo-o
Choose a base branch
from
jwoo-o:step3
base: jwoo-o
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
30b5295
doc : update README.md
jwoo-o ecc4272
refect : ์งํ์ฒ ์ญ ์ธ์ํ
์คํธ step์ผ๋ก ๋ถ๋ฆฌ
jwoo-o 5e67bf1
feat : ์งํ์ฒ ๋
ธ์ ๊ตฌ๊ฐ ์ถ๊ฐ,์ญ์ ๊ธฐ๋ฅ ๊ฐ๋ฐ
jwoo-o c84d171
test : ์งํ์ฒ ๊ตฌ๊ฐ ์ถ๊ฐ,์ญ์ ์ธ์ํ
์คํธ
jwoo-o File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package subway.common.exception; | ||
|
||
public class ErrorMessage { | ||
|
||
public static String SECTION_INTEGRITY_ADD_ERROR_MESSAGE = "์งํ์ฒ ๊ตฌ๊ฐ ์ถ๊ฐ ์กฐ๊ฑด์ ์๋ฐฐ๋ฉ๋๋ค"; | ||
public static String SECTION_INTEGRITY_REMOVE_ERROR_MESSAGE = "์งํ์ฒ ๊ตฌ๊ฐ ์ญ์ ์กฐ๊ฑด์ ์๋ฐฐ๋ฉ๋๋ค"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package subway.line.domain; | ||
|
||
import subway.station.domain.Station; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
|
||
@Entity | ||
public class Section { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "lineId") | ||
private Line line; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "upStationId") | ||
private Station upStation; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "downStationId") | ||
private Station downStation; | ||
|
||
private int distance; | ||
|
||
public Section(Line line, Station upStation, Station downStation, int distance) { | ||
this.line = line; | ||
this.upStation = upStation; | ||
this.downStation = downStation; | ||
this.distance = distance; | ||
} | ||
|
||
public Section() { | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public Line getLine() { | ||
return line; | ||
} | ||
|
||
public Station getDownStation() { | ||
return downStation; | ||
} | ||
|
||
public Station getUpStation() { | ||
return upStation; | ||
} | ||
|
||
public int getDistance() { | ||
return distance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package subway.line.domain; | ||
|
||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
import javax.persistence.CascadeType; | ||
import javax.persistence.OneToMany; | ||
|
||
import subway.common.exception.ErrorMessage; | ||
|
||
import javax.persistence.Embeddable; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import subway.station.domain.Station; | ||
|
||
@Embeddable | ||
public class Sections { | ||
|
||
@OneToMany(mappedBy = "line", orphanRemoval = true, cascade = CascadeType.ALL) | ||
private List<Section> sections; | ||
Comment on lines
+16
to
+20
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. ์ผ๊ธ ์ปฌ๋ ์ ํ์ฉ ๐ |
||
|
||
public Sections() { | ||
this.sections = new ArrayList<>(); | ||
} | ||
|
||
public void addSection(Section section) { | ||
if (notValidSection(section) && alreadyValidSection(section)) { | ||
throw new IllegalArgumentException(ErrorMessage.SECTION_INTEGRITY_ADD_ERROR_MESSAGE); | ||
} | ||
sections.add(section); | ||
} | ||
|
||
public List<Station> getStations() { | ||
List<Station> stations = sections.stream() | ||
.map(Section::getUpStation) | ||
.collect(Collectors.toList()); | ||
setLastStations(stations); | ||
Comment on lines
+34
to
+37
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. stream์ flatMap ๋ฉ์๋๋ฅผ ํ์ฉํด ๋ณด์ ๋ ์ข์ ๊ฒ ๊ฐ์์ ๐ |
||
|
||
return stations; | ||
} | ||
|
||
public void deleteSection(Station station) { | ||
if(isNotLastStation(station) || sections.size() < 2) { | ||
throw new IllegalArgumentException(ErrorMessage.SECTION_INTEGRITY_REMOVE_ERROR_MESSAGE); | ||
} | ||
sections.remove(sections.size() - 1); | ||
} | ||
|
||
private boolean notValidSection(Section section) { | ||
if (sections.size() > 0) { | ||
Station endStation = sections.get(sections.size() - 1).getDownStation(); | ||
return !endStation.equals(section.getUpStation()); | ||
} | ||
return false; | ||
} | ||
|
||
private boolean alreadyValidSection(Section section) { | ||
return sections.stream() | ||
.map(Section::getDownStation) | ||
.anyMatch(station -> station.getId().equals(section.getDownStation().getId())); | ||
} | ||
|
||
private void setLastStations(List<Station> stations) { | ||
getLastSection().ifPresent(section -> stations.add(section.getDownStation())); | ||
} | ||
|
||
private Optional<Section> getLastSection() { | ||
if (sections.size() > 0) { | ||
return Optional.of(sections.get(sections.size() - 1)); | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
private boolean isNotLastStation(Station station) { | ||
|
||
return getLastSection() | ||
.filter(section -> section.getDownStation().getId().equals(station.getId())) | ||
.isEmpty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package subway.line.dto; | ||
|
||
import subway.line.domain.Section; | ||
|
||
public class SectionRequest { | ||
|
||
private long upStationId; | ||
private long downStationId; | ||
private int distance; | ||
|
||
public long getUpStationId() { | ||
return upStationId; | ||
} | ||
|
||
public long getDownStationId() { | ||
return downStationId; | ||
} | ||
|
||
public int getDistance() { | ||
return distance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package subway.line.dto; | ||
|
||
import subway.station.dto.StationResponse; | ||
|
||
public class SectionResponse { | ||
|
||
private Long id; | ||
private StationResponse upStation; | ||
private StationResponse downStation; | ||
private int distance; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public StationResponse getUpStation() { | ||
return upStation; | ||
} | ||
|
||
public StationResponse getDownStation() { | ||
return downStation; | ||
} | ||
|
||
public int getDistance() { | ||
return distance; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ๊ฐ์ฒด์
์ธ์๋ก ๋ฐ์ Section ๋ด๋ถ์ line ํ๋๊ฐ ์๋ก ๋ค๋ฅด๋ฉด ์ด๋ป๊ฒ ๋ ๊น์?
์ธ์๋ก ๋ฐ์ Section์ line์ ์ฌํ ๋นํ๋ฉด ์ข์ ๊ฒ ๊ฐ์๋ฐ ์ง์ฐ๋ ์๊ฐ์ ์ด๋ ์ ๊ฐ์?
section.setLine(this);