-
Notifications
You must be signed in to change notification settings - Fork 306
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๋จ๊ณ - ์งํ์ฒ ๊ตฌ๊ฐ ๊ด๋ฆฌ #968
Open
nice7677
wants to merge
10
commits into
next-step:nice7677
Choose a base branch
from
nice7677:step3
base: nice7677
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
10 commits
Select commit
Hold shift + click to select a range
381f5e8
docs: step3 ๊ธฐ๋ฅ ์๊ตฌ์ฌํญ ์์
nice7677 67490c6
refactor: 3๋จ๊ณ ์ ์์
nice7677 a39d069
feat: section ์ถ๊ฐ
nice7677 9faf292
feat: section ์ถ๊ฐ
nice7677 9d242ab
feat: section ๋ฑ๋ก ๊ธฐ๋ฅ ์ถ๊ฐ
nice7677 94546e8
feat: section ์ ๊ฑฐ ๊ธฐ๋ฅ ์ถ๊ฐ
nice7677 dd4107c
test: given when then ์ฃผ์
nice7677 00ace5c
docs: ๋ฌธ์ ์์
nice7677 31c2473
test: ์๋ฌ ์ฒ๋ฆฌ ์์ธ ํ
์คํธ
nice7677 d780f95
refactor: ์์ฐ๋ ์ฝ๋ ์ญ์
nice7677 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
Empty file.
16 changes: 16 additions & 0 deletions
16
src/main/java/subway/common/execption/CustomExceptionHandler.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package subway.common.execption; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import subway.common.execption.response.ErrorResponse; | ||
|
||
@ControllerAdvice | ||
public class CustomExceptionHandler { | ||
|
||
@ExceptionHandler(IllegalArgumentException.class) | ||
public ResponseEntity<ErrorResponse> handleIllegalArgumentException(IllegalArgumentException e) { | ||
return ResponseEntity.badRequest().body(ErrorResponse.of(e.getMessage())); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/subway/common/execption/response/ErrorResponse.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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package subway.common.execption.response; | ||
|
||
public class ErrorResponse { | ||
|
||
private final String message; | ||
|
||
public ErrorResponse(String message) { | ||
this.message = message; | ||
} | ||
|
||
public static ErrorResponse of(String message) { | ||
return new ErrorResponse(message); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ErrorResponse{" + | ||
"message='" + message + '\'' + | ||
'}'; | ||
} | ||
|
||
public String getMessage() { | ||
return 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,75 @@ | ||
package subway.line.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import subway.line.code.LineValidateTypeCode; | ||
import subway.line.domain.Line; | ||
import subway.line.dto.request.LineRequest; | ||
import subway.line.dto.request.SectionRequest; | ||
import subway.line.dto.response.LineResponse; | ||
import subway.line.dto.response.SectionResponse; | ||
import subway.line.service.LineService; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/lines") | ||
public class LineController { | ||
|
||
private final LineService lineService; | ||
|
||
public LineController(LineService LineService) { | ||
this.lineService = LineService; | ||
} | ||
|
||
@PostMapping() | ||
public ResponseEntity<LineResponse> createLine(@RequestBody LineRequest LineRequest) { | ||
LineResponse Line = lineService.saveLine(LineValidateTypeCode.SAVE, LineRequest); | ||
return ResponseEntity.created(URI.create("/lines/" + Line.getId())).body(Line); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<LineResponse> inquiryLine(@PathVariable Long id) { | ||
LineResponse Line = lineService.inquiryLine(id); | ||
return ResponseEntity.ok().body(Line); | ||
} | ||
|
||
@GetMapping("") | ||
public ResponseEntity<List<LineResponse>> inquiryLines() { | ||
List<LineResponse> Lines = lineService.inquiryLines(); | ||
return ResponseEntity.ok().body(Lines); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public ResponseEntity<LineResponse> updateLine(@PathVariable Long id, @RequestBody LineRequest LineRequest) { | ||
LineRequest.saveId(id); | ||
LineResponse Line = lineService.saveLine(LineValidateTypeCode.UPDATE, LineRequest); | ||
return ResponseEntity.ok().body(Line); | ||
} | ||
|
||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity<LineResponse> deleteLine(@PathVariable Long id) { | ||
lineService.deleteLine(id); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
@PostMapping("/{id}/sections") | ||
public ResponseEntity<SectionResponse> createSection(@PathVariable Long id, @RequestBody SectionRequest sectionRequest) { | ||
return ResponseEntity.created(URI.create("/lines/" + id + "/sections")).body(lineService.updateSection(id, sectionRequest)); | ||
} | ||
|
||
@GetMapping("/{id}/sections") | ||
public ResponseEntity<List<SectionResponse>> inquirySection(@PathVariable Long id) { | ||
return ResponseEntity.ok().body(lineService.inquirySection(id)); | ||
} | ||
|
||
@DeleteMapping("/{id}/sections") | ||
public ResponseEntity<SectionResponse> deleteSection(@PathVariable Long id, @RequestParam Long stationId) { | ||
lineService.deleteSection(id, stationId); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
|
||
} |
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,51 @@ | ||
package subway.line.domain; | ||
|
||
import subway.station.domain.Station; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
public class Section { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "line_id", nullable = false) | ||
private Line line; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "station_id", nullable = false) | ||
private Station station; | ||
|
||
public Section() { | ||
} | ||
|
||
public Section(Line line, Station station) { | ||
this.line = line; | ||
this.station = station; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public Line getLine() { | ||
return line; | ||
} | ||
|
||
public Station getStation() { | ||
return station; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Section{" + | ||
"id=" + id + | ||
", line=" + line + | ||
", station=" + station + | ||
'}'; | ||
} | ||
|
||
} |
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,43 @@ | ||
package subway.line.domain; | ||
|
||
import subway.station.domain.Station; | ||
|
||
import javax.persistence.Embeddable; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.OneToOne; | ||
import java.io.Serializable; | ||
|
||
@Embeddable | ||
public class Stations implements Serializable { | ||
|
||
@OneToOne | ||
@JoinColumn(name = "up_station_id", nullable = false) | ||
private Station upStation; | ||
|
||
@OneToOne | ||
@JoinColumn(name = "down_station_id", nullable = false) | ||
private Station downStation; | ||
|
||
public Stations() {} | ||
|
||
public Stations(Station upStation, Station downStation) { | ||
this.upStation = upStation; | ||
this.downStation = downStation; | ||
} | ||
|
||
public Station getUpStation() { | ||
return upStation; | ||
} | ||
|
||
public Station getDownStation() { | ||
return downStation; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Stations{" + | ||
"upStation=" + upStation + | ||
", downStation=" + downStation + | ||
'}'; | ||
} | ||
} |
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,32 @@ | ||
package subway.line.dto.request; | ||
|
||
public class SectionRequest { | ||
|
||
private final Long id; | ||
private final Long downStationId; | ||
private final Long upStationId; | ||
private final Long distance; | ||
|
||
public SectionRequest(Long id, Long downStationId, Long upStationId, Long distance) { | ||
this.id = id; | ||
this.downStationId = downStationId; | ||
this.upStationId = upStationId; | ||
this.distance = distance; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public Long getDownStationId() { | ||
return downStationId; | ||
} | ||
|
||
public Long getUpStationId() { | ||
return upStationId; | ||
} | ||
|
||
public Long 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.
Station์ด ์๋๋ผ Stations๊ฐ ๋ค์ด๊ฐ์ผ ํ์ง ์์๊น์? ๐ค Stations์ Section์ ์ฐ๊ฒฐ๊ณ ๋ฆฌ๊ฐ ์์ด๋ณด์ฌ์.
๊ทธ๋ฆฌ๊ณ line์์ section์ ๊ฐ์ง๊ณ ์์ด์ผ ํ ๊น์? stations์ ๊ฐ์ง๊ณ ์์ด์ผ ํ ๊น์? ์ ๋ถ๋ถ์ ๋ํด ๊ณ ๋ฏผํด๋ด์ฃผ์ธ์!
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.
์๊ฐ๋ชปํ๋ค์ ๊ทธ๋ ๊ฒํ๋ฉด ํด๊ฒฐ๋๋ ๋ฌธ์ ์๋๋ฐ ๋๊ณ ๋์์ ๋ง๋ค์๋ค์๐