-
Notifications
You must be signed in to change notification settings - Fork 170
[Spring Core] 정민주 미션 제출합니다. #416
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
JoungMinJu
wants to merge
18
commits into
next-step:joungminju
Choose a base branch
from
JoungMinJu:step8-10
base: joungminju
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
18 commits
Select commit
Hold shift + click to select a range
54ab53c
step8 : 화면 매핑
JoungMinJu f6604d5
refactor : @RequestMapping 추가
JoungMinJu 4b42211
refactor : SpringFramework의 @Transaction으로 교체
JoungMinJu ca5ea51
step8 : 스키마 추가
JoungMinJu 7bfb606
step8
JoungMinJu 37d388d
step8 : TimeOutDto 객체 사용하지 않고 Time 사용하도록 변경
JoungMinJu 0576925
step8 : 테스트코드 추가
JoungMinJu 8e05790
step9 : 스키마 변경
JoungMinJu 28e6db0
step9 : new-reservation.html 사용하도록 변경
JoungMinJu 003c111
step9 : Reservation DTO 정의
JoungMinJu 97f9ec9
step9
JoungMinJu 049b660
step9 : 기존 테스트코드 다 정상 동작하도록 수정
JoungMinJu 5e028f6
step10
JoungMinJu 730c33c
step10 : repository -> dao로 변경
JoungMinJu d8f1700
step10 : dto 명칭 변경
JoungMinJu 31ddc07
step10 : 가독성을 위해 sql문 형식 변경
JoungMinJu 46f072f
step10 : validation 로직 동작하도록 수정 + 불필요한 생성자 제거
JoungMinJu 200ee7c
step10 : N+1 제거
JoungMinJu 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
37 changes: 17 additions & 20 deletions
37
src/main/java/roomescape/controller/ReservationController.java
This file contains hidden or 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 hidden or 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 hidden or 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,48 @@ | ||
| package roomescape.controller; | ||
|
|
||
| import java.net.URI; | ||
| import java.util.List; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| 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 roomescape.entity.dto.TimeCreateDto; | ||
| import roomescape.entity.value.Time; | ||
| import roomescape.service.ReservationService; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/times") | ||
| public class TimeController { | ||
|
|
||
| private final ReservationService reservationService; | ||
|
|
||
| public TimeController(ReservationService reservationService) { | ||
| this.reservationService = reservationService; | ||
| } | ||
|
|
||
| @GetMapping | ||
| public List<Time> getTimes() { | ||
| return reservationService.findAllTimes(); | ||
| } | ||
|
|
||
| @Transactional | ||
| @PostMapping | ||
| public ResponseEntity<Time> createTime(@RequestBody TimeCreateDto timeCreateDto) { | ||
| final Time time = reservationService.saveTime(timeCreateDto); | ||
| URI location = URI.create("/times/" + time.getId()); | ||
| return ResponseEntity.created(location).body(time); | ||
| } | ||
|
|
||
| @Transactional | ||
| @DeleteMapping("/{id}") | ||
| public ResponseEntity<Void> deleteTime(@PathVariable Long id) { | ||
| reservationService.deleteTimeById(id); | ||
| return ResponseEntity.noContent().build(); | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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
38 changes: 24 additions & 14 deletions
38
...ity/repository/ReservationRepository.java → ...roomescape/entity/dao/ReservationDao.java
This file contains hidden or 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 hidden or 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,65 @@ | ||
| package roomescape.entity.dao; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import javax.sql.DataSource; | ||
| import org.springframework.jdbc.core.JdbcTemplate; | ||
| import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; | ||
| import org.springframework.jdbc.core.namedparam.SqlParameterSource; | ||
| import org.springframework.jdbc.core.simple.SimpleJdbcInsert; | ||
| import org.springframework.stereotype.Component; | ||
| import roomescape.entity.dto.TimeCreateDto; | ||
| import roomescape.entity.value.Time; | ||
|
|
||
| @Component | ||
| public class TimeDao { | ||
|
|
||
| private final JdbcTemplate jdbcTemplate; | ||
| private final SimpleJdbcInsert simpleJdbcInsert; | ||
|
|
||
| public TimeDao(JdbcTemplate jdbcTemplate, DataSource source) { | ||
| this.jdbcTemplate = jdbcTemplate; | ||
| this.simpleJdbcInsert = new SimpleJdbcInsert(source) | ||
| .withTableName("time") | ||
| .usingGeneratedKeyColumns("id"); | ||
| } | ||
|
|
||
| public List<Time> findAll() { | ||
| String sql = "SELECT * FROM time"; | ||
| return jdbcTemplate.query(sql, (rs, rowNum) -> | ||
| new Time( | ||
| rs.getLong("id"), | ||
| rs.getString("time"))); | ||
| } | ||
|
|
||
| public Time save(TimeCreateDto timeCreateDto) { | ||
| SqlParameterSource params = new MapSqlParameterSource() | ||
| .addValue("time", timeCreateDto.getTime()); | ||
| long id = simpleJdbcInsert.executeAndReturnKey(params).longValue(); | ||
| return new Time(id, timeCreateDto.getTime()); | ||
| } | ||
|
|
||
| public Optional<Time> findById(Long id) { | ||
| String sql = "SELECT * FROM time WHERE id = ?"; | ||
| final List<Time> times = jdbcTemplate.query(sql, new Object[]{id}, (rs, rowNum) -> | ||
| new Time( | ||
| rs.getLong("id"), | ||
| rs.getString("time"))); | ||
| return times.stream().findFirst(); | ||
| } | ||
|
|
||
| public Optional<Time> findByTime(String time) { | ||
| String sql = "SELECT * FROM time WHERE time = ?"; | ||
| final List<Time> times = jdbcTemplate.query(sql, new Object[]{time}, (rs, rowNum) -> | ||
| new Time( | ||
| rs.getLong("id"), | ||
| rs.getString("time"))); | ||
| return times.stream().findFirst(); | ||
| } | ||
|
|
||
| public int deleteById(Long id) { | ||
| String sql = "DELETE FROM time WHERE id = ?"; | ||
| return jdbcTemplate.update(sql, id); | ||
| } | ||
|
|
||
| } |
26 changes: 26 additions & 0 deletions
26
src/main/java/roomescape/entity/dto/ReservationCreateDto.java
This file contains hidden or 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,26 @@ | ||
| package roomescape.entity.dto; | ||
|
|
||
| public class ReservationCreateDto { | ||
|
|
||
| private String name; | ||
| private String date; | ||
| private Long time; | ||
|
|
||
| public ReservationCreateDto(String name, String date, Long time) { | ||
| this.name = name; | ||
| this.date = date; | ||
| this.time = time; | ||
| } | ||
|
|
||
| public Long getTimeId() { | ||
| return time; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public String getDate() { | ||
| return date; | ||
| } | ||
| } |
This file contains hidden or 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,19 @@ | ||
| package roomescape.entity.dto; | ||
|
|
||
| public class TimeCreateDto { | ||
|
|
||
| private String time; | ||
|
|
||
| private TimeCreateDto() { | ||
| this.time = null; | ||
| } | ||
|
|
||
| public TimeCreateDto(String time) { | ||
| this.time = time; | ||
| } | ||
|
|
||
| public String getTime() { | ||
| return time; | ||
| } | ||
|
|
||
| } |
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.
이전 단계에서 적용하신
@Transactionalcontroller에 있는게 적절할까요? 아니면 새로 생긴 service layer에 있는 것이 적절할까요? 한번 고민해주시고 답해주세요!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.
음 get의 경우 굳이 Transactional을 안붙여도 되니, 필요한 메서드(POST, DELETE)에만 명시해주는 것이 더 좋은 구현방식일 것이라 생각했습니다!