Skip to content
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
wants to merge 11 commits into
base: movingone
Choose a base branch
from
15 changes: 7 additions & 8 deletions src/main/java/roomescape/controller/ReserveController.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,23 @@ public int deleteReserve(@PathVariable Long id) {
return jdbcTemplate.update(sql, id);
}

@GetMapping("/admin/time")
public String adminTime() {
return "admin/time";
}
@PostMapping("/times")
public ResponseEntity<String> addTime(@RequestBody Time time) {
String sql = "insert into reservation_time(start_at) values ?";
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);

return ResponseEntity.ok().body("success");
Long id = keyHolder.getKey().longValue();
time.setId(id);

return ResponseEntity.ok().body(time);
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

시간을 추가함에 따라서 화면에서도 추가된 시간이 보여야 한다 생각했는데 차이가 없습니다
시간을 추가한 순간 PostMappingGetMapping이 동시에 일어나는 개념일까요?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

시간이 추가가 되면 프론트엔드 로직에서 서버에게 시간 리스트를 요청해요.
Screenshot 2024-07-12 at 6 34 11 PM
위의 사진에서 보시듯 GET localhost:8080/times 요청을 보내는데요,
현재 동건님 서버에서는 해당 api 를 제공하고 있지 않습니다!
한 번 만들어주시면 될 것 같아요 :)


@GetMapping("/admin/times")
@GetMapping("/admin/time")
public List<Time> checkTime() {
String sql = "select id, start_at from reservation_time";

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ create table reservation
);


select *
from reservation_time;