-
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๋จ๊ณ - ์งํ์ฒ ๊ตฌ๊ฐ ์ถ๊ฐ ๊ธฐ๋ฅ ๊ฐ์ #606
Open
jjisun
wants to merge
15
commits into
next-step:jjisun
Choose a base branch
from
jjisun:step1
base: jjisun
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
15 commits
Select commit
Hold shift + click to select a range
df2d0b1
3rd init
boorownie c66bb09
4th init
boorownie 37f79e0
5th init
boorownie 3244b9d
6th init
boorownie b01ce62
step1: ๊ตฌ๊ธ ํ์ด์ง ์ ๊ทผ ํ
์คํธ
jjisun d202435
step1: ๊ตฌ๊ธ ํ์ด์ง ์ ๊ทผ ํ
์คํธ (#763)
jjisun 053adea
๐ 2๋จ๊ณ - ์งํ์ฒ ๋
ธ์ ๊ด๋ฆฌ (#899)
jjisun ecccf73
test: ์งํ์ฒ ๊ตฌ๊ฐ ์ถ๊ฐ, ์ญ์ ์ธ์ํ
์คํธ ์์ฑ, ๊ธฐ์กด ํ
์คํธ ์์
jjisun 02b8012
feat: ์งํ์ฒ ๊ตฌ๊ฐ ์ถ๊ฐ, ์ญ์ ๊ตฌํ
jjisun 80cea42
test: ์งํ์ฒ ๊ตฌ๊ฐ ์ถ๊ฐ ๊ธฐ๋ฅ ๊ฐ์ ์ธ์ํ
์คํธ ์์ฑ
jjisun c350315
refactor: ์งํ์ฒ ๊ตฌ๊ฐ ๊ด๋ฆฌ ๋ฆฌํฉํ ๋ง ๋ฆฌ๋ทฐ ๋ฐ์
jjisun 81dc0c6
Merge branch 'step3' into tdd-step1
jjisun 293651e
feature: ์งํ์ฒ ๊ตฌ๊ฐ ์ถ๊ฐ ๊ธฐ๋ฅ ๊ฐ์
jjisun 7cc45cf
Merge branch 'step4' into step1
jjisun 10f13fa
Merge branch 'jjisun' into step1
jjisun 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package subway; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class SubwayApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(SubwayApplication.class, args); | ||
} | ||
|
||
} |
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,36 @@ | ||
package subway.common; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.metamodel.EntityType; | ||
import javax.transaction.Transactional; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class DatabaseCleaner { | ||
private final EntityManager entityManager; | ||
private final List<String> tableNames; | ||
|
||
public DatabaseCleaner(final EntityManager entityManager) { | ||
this.entityManager = entityManager; | ||
this.tableNames = entityManager.getMetamodel() | ||
.getEntities() | ||
.stream() | ||
.map(EntityType::getName) | ||
.map(String::toLowerCase) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Transactional | ||
public void execute() { | ||
entityManager.flush(); | ||
entityManager.createNativeQuery("SET REFERENTIAL_INTEGRITY FALSE").executeUpdate(); | ||
|
||
for (String tableName : tableNames) { | ||
entityManager.createNativeQuery("TRUNCATE TABLE " + tableName).executeUpdate(); | ||
} | ||
|
||
entityManager.createNativeQuery("SET REFERENTIAL_INTEGRITY TRUE").executeUpdate(); | ||
} | ||
} |
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,47 @@ | ||
package subway.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import subway.dto.request.LineModifyRequest; | ||
import subway.dto.request.LineRequest; | ||
import subway.dto.response.LineResponse; | ||
import subway.service.LineService; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class LineController { | ||
private final LineService lineService; | ||
|
||
@PostMapping("/lines") | ||
public ResponseEntity<LineResponse> createLine(@RequestBody LineRequest request) { | ||
LineResponse line = lineService.saveLine(request); | ||
return ResponseEntity.created(URI.create("/lines/" + line.getId())).body(line); | ||
} | ||
|
||
@GetMapping("/lines") | ||
public ResponseEntity<List<LineResponse>> findLines() { | ||
return ResponseEntity.ok(lineService.findLines()); | ||
} | ||
|
||
@GetMapping("/lines/{id}") | ||
public ResponseEntity<LineResponse> findLine(@PathVariable Long id) { | ||
LineResponse line = lineService.findLineResponse(id); | ||
return ResponseEntity.created(URI.create("/lines/" + line.getId())).body(line); | ||
} | ||
|
||
@DeleteMapping("/lines/{id}") | ||
public ResponseEntity<Void> deleteLine(@PathVariable Long id) { | ||
lineService.deleteLine(id); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
@PutMapping("/lines/{id}") | ||
public ResponseEntity<Void> modifyStation(@PathVariable Long id, @RequestBody LineModifyRequest request) { | ||
lineService.modifyLine(id, request); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package subway.controller; | ||
|
||
import java.net.URI; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import subway.dto.request.SectionRequest; | ||
import subway.dto.response.LineResponse; | ||
import subway.service.SectionService; | ||
|
||
@RequestMapping("/lines/{id}/sections") | ||
@RestController | ||
@RequiredArgsConstructor | ||
public class SectionController { | ||
|
||
private final SectionService sectionService; | ||
|
||
@PostMapping | ||
public ResponseEntity<LineResponse> addSection(@PathVariable Long id, @RequestBody SectionRequest request) { | ||
LineResponse line = sectionService.addSection(id, request); | ||
return ResponseEntity.created(URI.create("/lines/" + line.getId())).body(line); | ||
} | ||
|
||
@DeleteMapping | ||
public ResponseEntity<Void> deleteSection(@PathVariable Long id, Long stationId) { | ||
sectionService.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package subway.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import subway.dto.request.StationRequest; | ||
import subway.dto.response.StationResponse; | ||
import subway.service.StationService; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
|
||
@RestController | ||
public class StationController { | ||
private StationService stationService; | ||
|
||
public StationController(StationService stationService) { | ||
this.stationService = stationService; | ||
} | ||
|
||
@PostMapping("/stations") | ||
public ResponseEntity<StationResponse> createStation(@RequestBody StationRequest stationRequest) { | ||
StationResponse station = stationService.saveStation(stationRequest); | ||
return ResponseEntity.created(URI.create("/stations/" + station.getId())).body(station); | ||
} | ||
|
||
@GetMapping(value = "/stations") | ||
public ResponseEntity<List<StationResponse>> showStations() { | ||
return ResponseEntity.ok().body(stationService.findAllStations()); | ||
} | ||
|
||
@DeleteMapping("/stations/{id}") | ||
public ResponseEntity<Void> deleteStation(@PathVariable Long id) { | ||
stationService.deleteStationById(id); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package subway.dto.request; | ||
|
||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class LineModifyRequest { | ||
private String name; | ||
private String color; | ||
|
||
@Builder | ||
public LineModifyRequest(String name, String color) { | ||
this.name = name; | ||
this.color = color; | ||
} | ||
} |
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,23 @@ | ||
package subway.dto.request; | ||
|
||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class LineRequest { | ||
private String name; | ||
private String color; | ||
private Long upStationId; | ||
private Long downStationId; | ||
private Long distance; | ||
|
||
@Builder | ||
public LineRequest(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,18 @@ | ||
package subway.dto.request; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class SectionRequest { | ||
private Long upStationId; | ||
private Long downStationId; | ||
private Long distance; | ||
|
||
@Builder | ||
public SectionRequest(Long upStationId, Long downStationId, Long distance) { | ||
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,9 @@ | ||
package subway.dto.request; | ||
|
||
public class StationRequest { | ||
private String name; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
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,41 @@ | ||
package subway.dto.response; | ||
|
||
|
||
import java.util.stream.Collectors; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import subway.entity.Line; | ||
import subway.entity.Station; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
public class LineResponse { | ||
private Long id; | ||
private String name; | ||
private String color; | ||
private List<StationResponse> stations; | ||
|
||
private Long totalDistance; | ||
|
||
@Builder | ||
public LineResponse(Long id, String name, String color, List<StationResponse> stations, Long totalDistance) { | ||
this.id = id; | ||
this.name = name; | ||
this.color = color; | ||
this.stations = stations; | ||
this.totalDistance = totalDistance; | ||
} | ||
|
||
public static LineResponse from(Line line) { | ||
return LineResponse.builder() | ||
.id(line.getId()) | ||
.name(line.getName()) | ||
.color(line.getColor()) | ||
.stations(line.getStations().stream() | ||
.map(StationResponse::from) | ||
.collect(Collectors.toList())) | ||
.totalDistance(line.getSections().totalDistance()) | ||
.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package subway.dto.response; | ||
|
||
import lombok.Builder; | ||
import subway.entity.Station; | ||
|
||
public class StationResponse { | ||
private Long id; | ||
private String name; | ||
|
||
@Builder | ||
public StationResponse(Long id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
|
||
public static StationResponse from(Station station) { | ||
return StationResponse.builder() | ||
.id(station.getId()) | ||
.name(station.getName()) | ||
.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package subway.entity; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import javax.persistence.Embedded; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import subway.dto.request.LineModifyRequest; | ||
|
||
@Getter | ||
@Entity | ||
@NoArgsConstructor | ||
public class Line { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private String name; | ||
|
||
private String color; | ||
|
||
@Embedded | ||
private Sections sections; | ||
|
||
@Builder | ||
public Line(String name, String color, Section section) { | ||
this.name = name; | ||
this.color = color; | ||
this.sections = Sections.builder() | ||
.sections(Arrays.asList(section)) | ||
.build(); | ||
} | ||
|
||
public List<Station> getStations() { | ||
return this.sections.stations(); | ||
} | ||
|
||
public void modify(LineModifyRequest request) { | ||
this.name = request.getName(); | ||
this.color = request.getColor(); | ||
} | ||
} |
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.
์ธ์ํ ์คํธ ๊ฒฉ๋ฆฌ ๐