-
Notifications
You must be signed in to change notification settings - Fork 45
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
실습 - 페이지 설정 #94
Open
movingone
wants to merge
11
commits into
next-step:movingone
Choose a base branch
from
movingone:step1
base: movingone
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
실습 - 페이지 설정 #94
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fe7a701
fix: theme 추가로 인한 링크 추가 및 기존 링크 수정
boorownie 97663d9
feat: theme 추가로 인한 html 및 js 파일 생성
boorownie 0d7aa86
feat : 실습페이지 설정
movingone 63dbae7
feat : step1 reserve manage
movingone 21bcea7
refactor : id change AtomomicLong id
movingone 23e18f1
feat : database connection
movingone 63396ac
feat : step3 time manage function add
movingone 0d588c0
fix : error
movingone be6b379
fix : admin/time page time add function problem
movingone bf86d25
feat : Time request response Add Error
movingone 8214b6e
fix : time page error
movingone 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
116 changes: 116 additions & 0 deletions
116
src/main/java/roomescape/controller/ReserveController.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,116 @@ | ||
package roomescape.controller; | ||
|
||
import org.springframework.jdbc.support.GeneratedKeyHolder; | ||
import org.springframework.jdbc.support.KeyHolder; | ||
import roomescape.domain.Reservation; | ||
import roomescape.domain.Time; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.sql.PreparedStatement; | ||
import java.sql.Statement; | ||
import java.util.List; | ||
|
||
@Controller | ||
public class ReserveController { | ||
|
||
private final JdbcTemplate jdbcTemplate; | ||
|
||
@Autowired | ||
public ReserveController(JdbcTemplate jdbcTemplate) { | ||
this.jdbcTemplate = jdbcTemplate; | ||
} | ||
|
||
@GetMapping("/") | ||
public String home() { | ||
return "index"; | ||
} | ||
|
||
@GetMapping("/admin/reservation") | ||
public String adminReservation() { | ||
return "admin/reservation"; | ||
} | ||
|
||
@GetMapping("/reservation") | ||
public List<Reservation> readReserve() { | ||
String sql = "select r.id as reservation_id," + | ||
"r.name as reservation_name," + | ||
"r.date as reservation_date," + | ||
"t.id as time_id," + | ||
"t.start_at time_start_at" + | ||
" from reservation as r " + | ||
"inner join reservation_time as t" + | ||
" on r.time_id = t.id"; | ||
return jdbcTemplate.query(sql, | ||
(rs, rowNum) -> { | ||
long reservationId = rs.getLong("id"); | ||
String name = rs.getString("name"); | ||
String date = rs.getString("date"); | ||
Time time = new Time(rs.getString("time")); | ||
return new Reservation(reservationId, name, date, time); | ||
}); | ||
} | ||
|
||
@GetMapping("/reservation/{id}") | ||
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 List<Reservation> findReserve(@PathVariable Long id) { | ||
String sql = "select id, name, date, time from reservation where id = ?"; | ||
return jdbcTemplate.query(sql, | ||
(rs, rowNum) -> { | ||
long reservationId = rs.getLong("id"); | ||
String name = rs.getString("name"); | ||
String date = rs.getString("date"); | ||
Time time = new Time(rs.getString("time")); | ||
return new Reservation(reservationId, name, date, time); | ||
}, id); | ||
} | ||
|
||
@PostMapping("/reservation") | ||
public void addReserve(@RequestBody Reservation reserve, Time time) { | ||
|
||
String sql = "insert into reservation(name, date, time_id) values (?, ?, ?)"; | ||
jdbcTemplate.update(sql, reserve.getName(), reserve.getDate(), time.getId()); | ||
} | ||
|
||
@DeleteMapping("/reservation/{id}") | ||
public int deleteReserve(@PathVariable Long id) { | ||
String sql = "delete from reservation where id = ?"; | ||
return jdbcTemplate.update(sql, id); | ||
} | ||
|
||
@PostMapping("/times") | ||
public ResponseEntity<Time> addTime(@RequestBody Time time) { | ||
String sql = "insert into reservation_time (start_at) values ?"; | ||
KeyHolder keyHolder = new GeneratedKeyHolder(); | ||
jdbcTemplate.update(connection -> { | ||
PreparedStatement ps = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); | ||
ps.setString(1, time.getStartAt()); | ||
return ps; | ||
}, keyHolder); | ||
|
||
Long id = keyHolder.getKey().longValue(); | ||
time.setId(id); | ||
|
||
return ResponseEntity.ok().body(time); | ||
} | ||
|
||
@GetMapping("/admin/time") | ||
public List<Time> checkTime() { | ||
String sql = "select id, start_at from reservation_time"; | ||
|
||
return jdbcTemplate.query(sql, | ||
(rs, rowNum) -> { | ||
Time time = new Time( | ||
rs.getString("start_at")); | ||
return time;}); | ||
} | ||
|
||
@DeleteMapping("/times/{id}") | ||
public ResponseEntity<Void> timeDelete(@PathVariable Long id) { | ||
String sql = "delete from reservation_time where id = ?"; | ||
jdbcTemplate.update(sql, id); | ||
return ResponseEntity.ok().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 roomescape.domain; | ||
|
||
public class Reservation { | ||
private long id; | ||
private String name; | ||
private String date; | ||
private Time time; | ||
|
||
public Reservation(long id, String name, String date, Time time) { | ||
this.id = id; | ||
this.name = name; | ||
this.date = date; | ||
this.time = time; | ||
} | ||
|
||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
|
||
public long getId() { | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getDate() { | ||
return date; | ||
} | ||
|
||
public Time getTime() { | ||
return time; | ||
} | ||
} |
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 roomescape.domain; | ||
|
||
public class Time { | ||
|
||
Long id; | ||
String startAt; | ||
|
||
public Time(String startAt) { | ||
this.startAt = startAt; | ||
} | ||
|
||
public Time() { | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public String getStartAt() { | ||
return startAt; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public void setStartAt(String startAt) { | ||
this.startAt = startAt; | ||
} | ||
} |
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,3 @@ | ||
spring.h2.console.enabled=true | ||
spring.h2.console.path=/h2-console | ||
spring.datasource.url=jdbc:h2:mem:database |
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,20 @@ | ||
create table reservation_time | ||
( | ||
id BIGINT NOT NULL AUTO_INCREMENT, | ||
start_at VARCHAR(255) NOT NULL, | ||
PRIMARY KEY (id) | ||
); | ||
|
||
create table reservation | ||
( | ||
id BIGINT NOT NULL AUTO_INCREMENT, | ||
name VARCHAR(255) NOT NULL, | ||
date VARCHAR(255) NOT NULL, | ||
time_id BIGINT, | ||
PRIMARY KEY (id), | ||
FOREIGN KEY (time_id) REFERENCES reservation_time (id) | ||
); | ||
|
||
|
||
select * | ||
from reservation_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.
Reservation
이라는 이름으로 도메인을 바꿔주셨으니,관련된 곳들도 이름을 바꿔볼까요?
(해당 class 이름 말고도 다른
reserve
들을 확인해주세요!)