-
Notifications
You must be signed in to change notification settings - Fork 303
๐ 2๋จ๊ณ - ์งํ์ฒ ๋ ธ์ ๊ด๋ฆฌ (์งํ์ฒ ๋ ธ์ ์์ฑ) #956
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
Open
jeongwon-iee
wants to merge
6
commits into
next-step:jeongwon-iee
Choose a base branch
from
jeongwon-iee:mission1
base: jeongwon-iee
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
6 commits
Select commit
Hold shift + click to select a range
c95802d
feature: ๊ตฌ๊ธ ํ์ด์ง ์ ๊ทผ ํ
์คํธ ์ถ๊ฐ
6be5975
[1๋จ๊ณ] ์งํ์ฒ ์ญ ๋ชฉ๋ก ์กฐํ, ์ญ์ ํ
์คํธ ์ถ๊ฐ
jeongwon-iee 331dcb8
[๋ฆฌ๋ทฐ๋ฐ์] Fixture๋ก given ์ค๋ณต์ฝ๋ ํจ์ํ
jeongwon-iee f3b7a0c
[1๋จ๊ณ] ์ธ์ํ
์คํธ ๊ฒฉ๋ฆฌ
jeongwon-iee 5341cd6
[2๋จ๊ณ] ๋ฆฌํฉํฐ๋ง ๋ฐ ์งํ์ฒ ๋
ธ์ ์์ฑ ๊ธฐ๋ฅ ์ถ๊ฐ
jeongwon-iee 1d3a69a
[ISSUE-#4] ์คํ๋ง ์ํ๋ฆฌํฐ ํํฐ ์ถ๊ฐ ๋ฐ ์ค์จ๊ฑฐ ์์ธ์ฒ๋ฆฌ
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,12 @@ | ||
package subway; | ||
|
||
public interface SubwayService<T, V> { | ||
|
||
V create(T request); | ||
|
||
// SubwayResponse get(SubwayRequest subwayRequest); | ||
// | ||
// SubwayResponse update(SubwayRequest subwayRequest); | ||
// | ||
// SubwayResponse delete(SubwayRequest subwayRequest); | ||
} |
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,30 @@ | ||
package subway.line; | ||
|
||
import java.net.URI; | ||
|
||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import subway.line.request.LineRequest; | ||
import subway.line.response.LineResponse; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
public class LineController { | ||
|
||
private final LineService lineService; | ||
|
||
@PostMapping( | ||
value = "/lines", | ||
consumes = MediaType.APPLICATION_JSON_VALUE, | ||
produces = MediaType.APPLICATION_JSON_VALUE | ||
) | ||
public ResponseEntity<LineResponse> createLine(@RequestBody LineRequest lineRequest) { | ||
LineResponse line = lineService.create(lineRequest); | ||
return ResponseEntity.created(URI.create("/lines/" + line.getId())).body(line); | ||
} | ||
} |
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,8 @@ | ||
package subway.line; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import subway.line.domain.Line; | ||
|
||
public interface LineRepository extends JpaRepository<Line, Long> { | ||
} |
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,57 @@ | ||
package subway.line; | ||
|
||
import java.util.Arrays; | ||
|
||
import javax.transaction.Transactional; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import subway.SubwayService; | ||
import subway.line.domain.Line; | ||
import subway.line.request.LineRequest; | ||
import subway.line.response.LineResponse; | ||
import subway.station.StationRepository; | ||
import subway.station.domain.Station; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class LineService implements SubwayService<LineRequest, LineResponse> { | ||
|
||
private final LineRepository lineRepository; | ||
private final StationRepository stationRepository; | ||
|
||
@Transactional | ||
@Override | ||
public LineResponse create(LineRequest lineRequest) { | ||
return saveLine(lineRequest); | ||
} | ||
|
||
private LineResponse saveLine(LineRequest lineRequest) { | ||
Line line = lineRepository.save(new Line( | ||
lineRequest.getName(), | ||
lineRequest.getColor(), | ||
lineRequest.getUpStationId(), | ||
lineRequest.getDownStationId(), | ||
lineRequest.getDistance() | ||
)); | ||
return createLineResponse(line); | ||
} | ||
|
||
private LineResponse createLineResponse(Line line) { | ||
Station upStation = getStation(line.getUpStationId()); | ||
Station downStation = getStation(line.getDownStationId()); | ||
|
||
return LineResponse.builder() | ||
.id(line.getId()) | ||
.name(line.getName()) | ||
.color(line.getColor()) | ||
.stations(Arrays.asList(upStation, downStation)) | ||
.build(); | ||
} | ||
|
||
private Station getStation(Long id) { | ||
return stationRepository.findById(id) | ||
.orElseGet(() -> stationRepository.save(new Station("์งํ์ฒ ์ญ" + id))); | ||
} | ||
} |
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,38 @@ | ||
package subway.line.domain; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@Entity | ||
public class Line { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
@Column(length = 20, nullable = false) | ||
jeongwon-iee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private String name; | ||
@Column(length = 20, nullable = false) | ||
private String color; | ||
@Column(nullable = false) | ||
private Long upStationId; | ||
@Column(nullable = false) | ||
private Long downStationId; | ||
@Column(nullable = false) | ||
private Long distance; | ||
|
||
public Line(String name, String color, Long upStationId, Long downStationId, Long distance) { | ||
this.name = name; | ||
this.color = color; | ||
this.upStationId = upStationId; | ||
this.downStationId = downStationId; | ||
this.distance = 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,16 @@ | ||
package subway.line.request; | ||
jeongwon-iee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class LineRequest { | ||
|
||
private final String name; | ||
jeongwon-iee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private final String color; | ||
private final Long upStationId; | ||
private final Long downStationId; | ||
private final Long 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,18 @@ | ||
package subway.line.response; | ||
|
||
import java.util.List; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import subway.station.domain.Station; | ||
|
||
@Getter | ||
@Builder | ||
public class LineResponse { | ||
|
||
private final Long id; | ||
private final String name; | ||
private final String color; | ||
private final List<Station> stations; | ||
|
||
} |
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
4 changes: 3 additions & 1 deletion
4
src/main/java/subway/StationRepository.java โ ...ava/subway/station/StationRepository.java
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package subway; | ||
package subway.station; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import subway.station.domain.Station; | ||
|
||
public interface StationRepository extends JpaRepository<Station, Long> { | ||
} |
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.
์๋น์ค ๋ ์ด์ด์ ์ธํฐํ์ด์ค ๋ถ๋ฆฌ ์๋ ๐
ํ์ง๋ง ํฐ ๋ชฉ์ ์์ด ๋ฐ๋ณต์ ์ผ๋ก ์ธํฐํ์ด์ค๋ฅผ ๋ถ๋ฆฌํ์ ๊ฑฐ๋ผ๋ฉด ๋ฐ๋ก ๊ตฌํ์ฒด๋ฅผ ๋ง๋ค์ด๋ ์ข๋ค๊ณ ์๊ฐํฉ๋๋ค.
์๋ ๋งํฌ ์ฐธ๊ณ ํด์ฃผ์ธ์!
https://velog.io/@hsw0194/Spring-Boot%EC%97%90%EC%84%9C-interface%EB%A5%BC-%EC%82%AC%EC%9A%A9%ED%95%B4%EC%95%BC-%ED%95%A0%EA%B9%8C
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.
StaionService, LineService, StationService ๋ชจ๋ ๋์ผํ๊ฒ ์์ฑ, ์กฐํ, ๋ชฉ๋ก, ์ญ์ ๋ฉ์๋๊ฐ ์๊ธฐ์
SubwayService๋ก ์ธํฐํ์ด์ค๋ฅผ ๋ง๋ค์ด๋๊ณ ์ฌ์ฌ์ฉํ๋๊ฒ ์ ์ง๋ณด์ ์ธก๋ฉด์์ ์ข์ ๊ฒ ๊ฐ๋ค๊ณ ์๊ฐํ์ต๋๋ค โป