From fe7a701d48e0dd25d7d2502a3deee442db944c2b Mon Sep 17 00:00:00 2001 From: boorownie Date: Thu, 6 Jun 2024 22:21:58 +0900 Subject: [PATCH 01/19] =?UTF-8?q?fix:=20theme=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20=EB=A7=81=ED=81=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EB=B0=8F=20=EA=B8=B0=EC=A1=B4=20=EB=A7=81=ED=81=AC?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/templates/admin/index.html | 7 +++++-- .../resources/templates/admin/reservation-legacy.html | 7 +++++-- src/main/resources/templates/admin/reservation.html | 10 +++++++--- src/main/resources/templates/admin/time.html | 7 +++++-- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/main/resources/templates/admin/index.html b/src/main/resources/templates/admin/index.html index 417102cf..46199dc0 100644 --- a/src/main/resources/templates/admin/index.html +++ b/src/main/resources/templates/admin/index.html @@ -22,10 +22,13 @@ diff --git a/src/main/resources/templates/admin/reservation-legacy.html b/src/main/resources/templates/admin/reservation-legacy.html index 320ef3c7..73592458 100644 --- a/src/main/resources/templates/admin/reservation-legacy.html +++ b/src/main/resources/templates/admin/reservation-legacy.html @@ -22,10 +22,13 @@ diff --git a/src/main/resources/templates/admin/reservation.html b/src/main/resources/templates/admin/reservation.html index f31714eb..4c34ec90 100644 --- a/src/main/resources/templates/admin/reservation.html +++ b/src/main/resources/templates/admin/reservation.html @@ -22,10 +22,13 @@ @@ -42,6 +45,7 @@

방탈출 예약 페이지

예약번호 예약자 + 테마 날짜 시간 @@ -52,6 +56,6 @@

방탈출 예약 페이지

- + diff --git a/src/main/resources/templates/admin/time.html b/src/main/resources/templates/admin/time.html index b8449b31..e7a8abfe 100644 --- a/src/main/resources/templates/admin/time.html +++ b/src/main/resources/templates/admin/time.html @@ -22,10 +22,13 @@ From 97663d962984ffd9f557bf82ef9767926d0dea84 Mon Sep 17 00:00:00 2001 From: boorownie Date: Thu, 6 Jun 2024 22:22:41 +0900 Subject: [PATCH 02/19] =?UTF-8?q?feat:=20theme=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20html=20=EB=B0=8F=20js=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/static/js/reservation-new.js | 194 ++++++++++++++++++ src/main/resources/static/js/theme.js | 135 ++++++++++++ .../templates/admin/reservation-new.html | 61 ++++++ src/main/resources/templates/admin/theme.html | 60 ++++++ 4 files changed, 450 insertions(+) create mode 100644 src/main/resources/static/js/reservation-new.js create mode 100644 src/main/resources/static/js/theme.js create mode 100644 src/main/resources/templates/admin/reservation-new.html create mode 100644 src/main/resources/templates/admin/theme.html diff --git a/src/main/resources/static/js/reservation-new.js b/src/main/resources/static/js/reservation-new.js new file mode 100644 index 00000000..ec361a71 --- /dev/null +++ b/src/main/resources/static/js/reservation-new.js @@ -0,0 +1,194 @@ +let isEditing = false; +const RESERVATION_API_ENDPOINT = '/reservations'; +const TIME_API_ENDPOINT = '/times'; +const THEME_API_ENDPOINT = '/themes'; +const timesOptions = []; +const themesOptions = []; + +document.addEventListener('DOMContentLoaded', () => { + document.getElementById('add-button').addEventListener('click', addInputRow); + + requestRead(RESERVATION_API_ENDPOINT) + .then(render) + .catch(error => console.error('Error fetching reservations:', error)); + + fetchTimes(); + fetchThemes(); +}); + +function render(data) { + const tableBody = document.getElementById('table-body'); + tableBody.innerHTML = ''; + + data.forEach(item => { + const row = tableBody.insertRow(); + + row.insertCell(0).textContent = item.id; // 예약 id + row.insertCell(1).textContent = item.name; // 예약자명 + row.insertCell(2).textContent = item.theme.name; // 테마명 + row.insertCell(3).textContent = item.date; // 예약 날짜 + row.insertCell(4).textContent = item.time.startAt; // 시작 시간 + + const actionCell = row.insertCell(row.cells.length); + actionCell.appendChild(createActionButton('삭제', 'btn-danger', deleteRow)); + }); +} + +function fetchTimes() { + requestRead(TIME_API_ENDPOINT) + .then(data => { + timesOptions.push(...data); + }) + .catch(error => console.error('Error fetching time:', error)); +} + +function fetchThemes() { + requestRead(THEME_API_ENDPOINT) + .then(data => { + themesOptions.push(...data); + }) + .catch(error => console.error('Error fetching theme:', error)); +} + +function createSelect(options, defaultText, selectId, textProperty) { + const select = document.createElement('select'); + select.className = 'form-control'; + select.id = selectId; + + // 기본 옵션 추가 + const defaultOption = document.createElement('option'); + defaultOption.textContent = defaultText; + select.appendChild(defaultOption); + + // 넘겨받은 옵션을 바탕으로 드롭다운 메뉴 아이템 생성 + options.forEach(optionData => { + const option = document.createElement('option'); + option.value = optionData.id; + option.textContent = optionData[textProperty]; // 동적 속성 접근 + select.appendChild(option); + }); + + return select; +} + +function createActionButton(label, className, eventListener) { + const button = document.createElement('button'); + button.textContent = label; + button.classList.add('btn', className, 'mr-2'); + button.addEventListener('click', eventListener); + return button; +} + +function addInputRow() { + if (isEditing) return; // 이미 편집 중인 경우 추가하지 않음 + + const tableBody = document.getElementById('table-body'); + const row = tableBody.insertRow(); + isEditing = true; + + const nameInput = createInput('text'); + const dateInput = createInput('date'); + const timeDropdown = createSelect(timesOptions, "시간 선택", 'time-select', 'startAt'); + const themeDropdown = createSelect(themesOptions, "테마 선택", 'theme-select', 'name'); + + const cellFieldsToCreate = ['', nameInput, themeDropdown, dateInput, timeDropdown]; + + cellFieldsToCreate.forEach((field, index) => { + const cell = row.insertCell(index); + if (typeof field === 'string') { + cell.textContent = field; + } else { + cell.appendChild(field); + } + }); + + const actionCell = row.insertCell(row.cells.length); + actionCell.appendChild(createActionButton('확인', 'btn-custom', saveRow)); + actionCell.appendChild(createActionButton('취소', 'btn-secondary', () => { + row.remove(); + isEditing = false; + })); +} + +function createInput(type) { + const input = document.createElement('input'); + input.type = type; + input.className = 'form-control'; + return input; +} + +function createActionButton(label, className, eventListener) { + const button = document.createElement('button'); + button.textContent = label; + button.classList.add('btn', className, 'mr-2'); + button.addEventListener('click', eventListener); + return button; +} + +function saveRow(event) { + // 이벤트 전파를 막는다 + event.stopPropagation(); + + const row = event.target.parentNode.parentNode; + const nameInput = row.querySelector('input[type="text"]'); + const dateInput = row.querySelector('input[type="date"]'); + const timeSelect = row.querySelector('#time-select'); + const themeSelect = row.querySelector('#theme-select'); + + const reservation = { + name: nameInput.value, + date: dateInput.value, + timeId: timeSelect.value, + themeId: themeSelect.value + }; + + requestCreate(reservation) + .then(() => { + location.reload(); + }) + .catch(error => console.error('Error:', error)); + + isEditing = false; // isEditing 값을 false로 설정 +} + +function deleteRow(event) { + const row = event.target.closest('tr'); + const reservationId = row.cells[0].textContent; + + requestDelete(reservationId) + .then(() => row.remove()) + .catch(error => console.error('Error:', error)); +} + +function requestCreate(reservation) { + const requestOptions = { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify(reservation) + }; + + return fetch(RESERVATION_API_ENDPOINT, requestOptions) + .then(response => { + if (response.status === 200) return response.json(); + throw new Error('Create failed'); + }); +} + +function requestDelete(id) { + const requestOptions = { + method: 'DELETE', + }; + + return fetch(`${RESERVATION_API_ENDPOINT}/${id}`, requestOptions) + .then(response => { + if (response.status !== 200) throw new Error('Delete failed'); + }); +} + +function requestRead(endpoint) { + return fetch(endpoint) + .then(response => { + if (response.status === 200) return response.json(); + throw new Error('Read failed'); + }); +} diff --git a/src/main/resources/static/js/theme.js b/src/main/resources/static/js/theme.js new file mode 100644 index 00000000..502d0e0e --- /dev/null +++ b/src/main/resources/static/js/theme.js @@ -0,0 +1,135 @@ +let isEditing = false; +const API_ENDPOINT = '/themes'; +const cellFields = ['id', 'name', 'description', 'thumbnail']; +const createCellFields = ['', createInput(), createInput(), createInput()]; +function createBody(inputs) { + return { + name: inputs[0].value, + description: inputs[1].value, + thumbnail: inputs[2].value, + }; +} + +document.addEventListener('DOMContentLoaded', () => { + document.getElementById('add-button').addEventListener('click', addRow); + requestRead() + .then(render) + .catch(error => console.error('Error fetching times:', error)); +}); + +function render(data) { + const tableBody = document.getElementById('table-body'); + tableBody.innerHTML = ''; + + data.forEach(item => { + const row = tableBody.insertRow(); + + cellFields.forEach((field, index) => { + row.insertCell(index).textContent = item[field]; + }); + + const actionCell = row.insertCell(row.cells.length); + actionCell.appendChild(createActionButton('삭제', 'btn-danger', deleteRow)); + }); +} + +function addRow() { + if (isEditing) return; // 이미 편집 중인 경우 추가하지 않음 + + const tableBody = document.getElementById('table-body'); + const row = tableBody.insertRow(); + isEditing = true; + + createAddField(row); +} + +function createAddField(row) { + createCellFields.forEach((field, index) => { + const cell = row.insertCell(index); + if (typeof field === 'string') { + cell.textContent = field; + } else { + cell.appendChild(field); + } + }); + + const actionCell = row.insertCell(row.cells.length); + actionCell.appendChild(createActionButton('확인', 'btn-custom', saveRow)); + actionCell.appendChild(createActionButton('취소', 'btn-secondary', () => { + row.remove(); + isEditing = false; + })); +} + +function createInput() { + const input = document.createElement('input'); + input.className = 'form-control'; + return input; +} + +function createActionButton(label, className, eventListener) { + const button = document.createElement('button'); + button.textContent = label; + button.classList.add('btn', className, 'mr-2'); + button.addEventListener('click', eventListener); + return button; +} + +function saveRow(event) { + const row = event.target.parentNode.parentNode; + const inputs = row.querySelectorAll('input'); + const body = createBody(inputs); + + requestCreate(body) + .then(() => { + location.reload(); + }) + .catch(error => console.error('Error:', error)); + + isEditing = false; // isEditing 값을 false로 설정 +} + +function deleteRow(event) { + const row = event.target.closest('tr'); + const id = row.cells[0].textContent; + + requestDelete(id) + .then(() => row.remove()) + .catch(error => console.error('Error:', error)); +} + + +// request + +function requestCreate(data) { + const requestOptions = { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify(data) + }; + + return fetch(API_ENDPOINT, requestOptions) + .then(response => { + if (response.status === 200) return response.json(); + throw new Error('Create failed'); + }); +} + +function requestRead() { + return fetch(API_ENDPOINT) + .then(response => { + if (response.status === 200) return response.json(); + throw new Error('Read failed'); + }); +} + +function requestDelete(id) { + const requestOptions = { + method: 'DELETE', + }; + + return fetch(`${API_ENDPOINT}/${id}`, requestOptions) + .then(response => { + if (response.status !== 200) throw new Error('Delete failed'); + }); +} diff --git a/src/main/resources/templates/admin/reservation-new.html b/src/main/resources/templates/admin/reservation-new.html new file mode 100644 index 00000000..4c34ec90 --- /dev/null +++ b/src/main/resources/templates/admin/reservation-new.html @@ -0,0 +1,61 @@ + + + + + + 방탈출 어드민 + + + + + + + + +
+

방탈출 예약 페이지

+
+ +
+
+ + + + + + + + + + + + + +
예약번호예약자테마날짜시간
+
+ + + + diff --git a/src/main/resources/templates/admin/theme.html b/src/main/resources/templates/admin/theme.html new file mode 100644 index 00000000..794602e9 --- /dev/null +++ b/src/main/resources/templates/admin/theme.html @@ -0,0 +1,60 @@ + + + + + + 방탈출 어드민 + + + + + + + + +
+

테마 관리 페이지

+
+ +
+
+ + + + + + + + + + + + +
순서제목설명썸네일 URL
+
+ + + + From 04238093d64aa86339381199a3f930beeb440882 Mon Sep 17 00:00:00 2001 From: gjtmdwns Date: Fri, 21 Jun 2024 16:18:16 +0900 Subject: [PATCH 03/19] =?UTF-8?q?FEAT=20:=20PageController=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20-=20home=EA=B3=BC=20reservation=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=EB=A1=9C=20=EC=9D=B4=EB=8F=99=20=EA=B0=80?= =?UTF-8?q?=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../roomescape/controller/PageController.java | 17 ++++++ .../controller/ReservationController.java | 2 + .../java/roomescape/model/Reservation.java | 53 +++++++++++++++++++ src/main/resources/schema.sql | 0 4 files changed, 72 insertions(+) create mode 100644 src/main/java/roomescape/controller/PageController.java create mode 100644 src/main/java/roomescape/controller/ReservationController.java create mode 100644 src/main/java/roomescape/model/Reservation.java create mode 100644 src/main/resources/schema.sql diff --git a/src/main/java/roomescape/controller/PageController.java b/src/main/java/roomescape/controller/PageController.java new file mode 100644 index 00000000..0aa3145a --- /dev/null +++ b/src/main/java/roomescape/controller/PageController.java @@ -0,0 +1,17 @@ +package roomescape.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class PageController { + @GetMapping + public String home() { + return "admin/index"; + } + + @GetMapping("/admin/reservation") + public String reservation() { + return "admin/reservation-legacy"; + } +} diff --git a/src/main/java/roomescape/controller/ReservationController.java b/src/main/java/roomescape/controller/ReservationController.java new file mode 100644 index 00000000..ed362bfc --- /dev/null +++ b/src/main/java/roomescape/controller/ReservationController.java @@ -0,0 +1,2 @@ +package roomescape.controller;public class ReservationController { +} diff --git a/src/main/java/roomescape/model/Reservation.java b/src/main/java/roomescape/model/Reservation.java new file mode 100644 index 00000000..8ce39134 --- /dev/null +++ b/src/main/java/roomescape/model/Reservation.java @@ -0,0 +1,53 @@ +package roomescape.repository; + +import java.util.concurrent.atomic.AtomicLong; + +public class Reservation { + private Long id; + private String name; + private String date; + private String time; + + public Reservation(Long id, String name, String date, String time) { + this.id = id; + this.name = name; + this.date = date; + this.time = time; + } + + public static Reservation toEntity(Reservation reservation, AtomicLong id) { + return new Reservation(Long.valueOf(String.valueOf(id)), reservation.getName(), reservation.getDate(), reservation.getTime()); + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDate() { + return date; + } + + public void setDate(String date) { + this.date = date; + } + + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } +} diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql new file mode 100644 index 00000000..e69de29b From ee2eb721300fb2c6efb332dcc79193981b9b1925 Mon Sep 17 00:00:00 2001 From: gjtmdwns Date: Fri, 21 Jun 2024 16:19:51 +0900 Subject: [PATCH 04/19] =?UTF-8?q?FEAT=20:=20ReservationController=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20-=20=EC=98=88=EC=95=BD=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80,=20=EC=A1=B0=ED=9A=8C,=20=EC=82=AD=EC=A0=9C=20API=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ReservationController.java | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/main/java/roomescape/controller/ReservationController.java b/src/main/java/roomescape/controller/ReservationController.java index ed362bfc..de8e2176 100644 --- a/src/main/java/roomescape/controller/ReservationController.java +++ b/src/main/java/roomescape/controller/ReservationController.java @@ -1,2 +1,38 @@ -package roomescape.controller;public class ReservationController { +package roomescape.controller; + +import org.springframework.web.bind.annotation.*; +import roomescape.model.Reservation; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.atomic.AtomicLong; + +@RestController +@RequestMapping("/reservations") +public class ReservationController { + private List reservations = new ArrayList<>(); + private AtomicLong index = new AtomicLong(1); + + @PostMapping + public Reservation create(@RequestBody Reservation reservation) { + Reservation newReservation = Reservation.toEntity(reservation, index); + reservations.add(newReservation); + return newReservation; + } + + @GetMapping + public List read() { + return reservations; + } + + @DeleteMapping("/{id}") + public void delete(@PathVariable Long id) { + Reservation reservation = reservations.stream() + .filter(findReservation -> Objects.equals(findReservation.getId(), id)) + .findFirst() + .orElseThrow(RuntimeException::new); + + reservations.remove(reservation); + } } From 48d66bbb40ec7f2501c920137a88afc81c39f5db Mon Sep 17 00:00:00 2001 From: gjtmdwns Date: Fri, 21 Jun 2024 16:20:38 +0900 Subject: [PATCH 05/19] =?UTF-8?q?FEAT=20:=20Reservation=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20-=20id,=20=EC=98=88=EC=95=BD=EC=9E=90=EB=AA=85,=20?= =?UTF-8?q?=EB=82=A0=EC=A7=9C,=20=EC=8B=9C=EA=B0=84=EC=9D=84=20=EA=B0=96?= =?UTF-8?q?=EB=8A=94=20=EC=98=88=EC=95=BD=20=EA=B0=9D=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/roomescape/model/Reservation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/roomescape/model/Reservation.java b/src/main/java/roomescape/model/Reservation.java index 8ce39134..7f21fbd3 100644 --- a/src/main/java/roomescape/model/Reservation.java +++ b/src/main/java/roomescape/model/Reservation.java @@ -1,4 +1,4 @@ -package roomescape.repository; +package roomescape.model; import java.util.concurrent.atomic.AtomicLong; From 8d9a22b80580c1af987b5b56c193ea58a7510e16 Mon Sep 17 00:00:00 2001 From: gjtmdwns Date: Fri, 21 Jun 2024 16:21:23 +0900 Subject: [PATCH 06/19] =?UTF-8?q?CHORE=20:=201-2=EB=8B=A8=EA=B3=84=20?= =?UTF-8?q?=EC=88=98=ED=96=89=EC=9D=84=20=EC=9C=84=ED=95=9C=20sql=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/schema.sql | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index e69de29b..8d9ab275 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -0,0 +1,8 @@ +CREATE TABLE reservation +( + id BIGINT NOT NULL AUTO_INCREMENT, + name VARCHAR(255) NOT NULL, + date VARCHAR(255) NOT NULL, + time VARCHAR(255) NOT NULL, + PRIMARY KEY (id) +); From 1446d2916b38e8b19a7d13297003ba20d933e7c2 Mon Sep 17 00:00:00 2001 From: gjtmdwns Date: Sat, 22 Jun 2024 22:03:02 +0900 Subject: [PATCH 07/19] =?UTF-8?q?FEAT=20:=20ReservationRepository=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ReservationRepository.java | 53 +++++++++++++++++++ .../service/ReservationService.java | 2 + 2 files changed, 55 insertions(+) create mode 100644 src/main/java/roomescape/repository/ReservationRepository.java create mode 100644 src/main/java/roomescape/service/ReservationService.java diff --git a/src/main/java/roomescape/repository/ReservationRepository.java b/src/main/java/roomescape/repository/ReservationRepository.java new file mode 100644 index 00000000..bf4f4426 --- /dev/null +++ b/src/main/java/roomescape/repository/ReservationRepository.java @@ -0,0 +1,53 @@ +package roomescape.repository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.support.GeneratedKeyHolder; +import org.springframework.jdbc.support.KeyHolder; +import org.springframework.stereotype.Repository; +import roomescape.model.Reservation; + +import java.sql.PreparedStatement; +import java.util.List; + +@Repository +public class ReservationRepository { + private JdbcTemplate jdbcTemplate; + private RowMapper rowMapper = (resultSet, rowNum) -> new Reservation( + resultSet.getLong("id"), + resultSet.getString("name"), + resultSet.getString("date"), + resultSet.getString("time") + ); + + @Autowired + public ReservationRepository(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } + + public int save(Reservation reservation) { + KeyHolder keyHolder = new GeneratedKeyHolder(); + jdbcTemplate.update(connect -> { + PreparedStatement ps = connect.prepareStatement( + "INSERT INTO reservation (name, date, time) VALUES(?, ?, ?)", + new String[]{"id"}); + ps.setString(1, reservation.getName()); + ps.setString(2, reservation.getDate()); + ps.setString(3, reservation.getTime()); + return ps; + }, keyHolder); + + return (int)keyHolder.getKey().longValue(); + } + + public List readAll() { + String sql = "SELECT * FROM reservation"; + return jdbcTemplate.query(sql, rowMapper); + } + + public void deleteById(int id) { + String sql = "DELETE FROM reservation WHERE id = ?"; + jdbcTemplate.update(sql, id); + } +} diff --git a/src/main/java/roomescape/service/ReservationService.java b/src/main/java/roomescape/service/ReservationService.java new file mode 100644 index 00000000..169e8b86 --- /dev/null +++ b/src/main/java/roomescape/service/ReservationService.java @@ -0,0 +1,2 @@ +package roomescape.service;public class ReservationService { +} From bc7677c5cc55df46ecf5ef86932f72d9b65c92ce Mon Sep 17 00:00:00 2001 From: gjtmdwns Date: Sat, 22 Jun 2024 22:03:19 +0900 Subject: [PATCH 08/19] =?UTF-8?q?FEAT=20:=20ReservationService=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationService.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/main/java/roomescape/service/ReservationService.java b/src/main/java/roomescape/service/ReservationService.java index 169e8b86..6607fb42 100644 --- a/src/main/java/roomescape/service/ReservationService.java +++ b/src/main/java/roomescape/service/ReservationService.java @@ -1,2 +1,30 @@ -package roomescape.service;public class ReservationService { +package roomescape.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import roomescape.model.Reservation; +import roomescape.repository.ReservationRepository; + +import java.util.List; + +@Service +public class ReservationService { + private final ReservationRepository reservationRepository; + + @Autowired + public ReservationService(ReservationRepository reservationRepository) { + this.reservationRepository = reservationRepository; + } + + public int addReservation(Reservation reservation) { + return reservationRepository.save(reservation); + } + + public List lookUpReservation() { + return reservationRepository.readAll(); + } + + public void deleteReservation(int id) { + reservationRepository.deleteById(id); + } } From c078c96e908c887e895345ca4030d47bae32cfba Mon Sep 17 00:00:00 2001 From: gjtmdwns Date: Sat, 22 Jun 2024 22:03:56 +0900 Subject: [PATCH 09/19] =?UTF-8?q?CHORE=20:=20Repository=20=EB=B0=8F=20Serv?= =?UTF-8?q?ice=20=EC=83=9D=EC=84=B1=EC=97=90=20=EB=94=B0=EB=A5=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ReservationController.java | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/main/java/roomescape/controller/ReservationController.java b/src/main/java/roomescape/controller/ReservationController.java index de8e2176..42ec7f1b 100644 --- a/src/main/java/roomescape/controller/ReservationController.java +++ b/src/main/java/roomescape/controller/ReservationController.java @@ -1,38 +1,35 @@ package roomescape.controller; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import roomescape.model.Reservation; +import roomescape.service.ReservationService; -import java.util.ArrayList; +import java.sql.PreparedStatement; import java.util.List; -import java.util.Objects; -import java.util.concurrent.atomic.AtomicLong; @RestController @RequestMapping("/reservations") public class ReservationController { - private List reservations = new ArrayList<>(); - private AtomicLong index = new AtomicLong(1); + private final ReservationService reservationService; + + @Autowired + public ReservationController(ReservationService reservationService) { + this.reservationService = reservationService; + } @PostMapping - public Reservation create(@RequestBody Reservation reservation) { - Reservation newReservation = Reservation.toEntity(reservation, index); - reservations.add(newReservation); - return newReservation; + public int insert(@RequestBody Reservation reservation) { + return reservationService.addReservation(reservation); } @GetMapping public List read() { - return reservations; + return reservationService.lookUpReservation(); } @DeleteMapping("/{id}") - public void delete(@PathVariable Long id) { - Reservation reservation = reservations.stream() - .filter(findReservation -> Objects.equals(findReservation.getId(), id)) - .findFirst() - .orElseThrow(RuntimeException::new); - - reservations.remove(reservation); + public void delete(@PathVariable int id) { + reservationService.deleteReservation(id); } } From 788b9d27a2df0e085ce773d5a417ebb5c015db57 Mon Sep 17 00:00:00 2001 From: gjtmdwns Date: Sat, 22 Jun 2024 22:04:47 +0900 Subject: [PATCH 10/19] =?UTF-8?q?REFACOR=20:=20=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=EB=B2=A0=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.properties | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e69de29b..476363a8 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -0,0 +1,4 @@ +spring.h2.console.enabled=true +spring.h2.console.path=/h2-console +spring.datasource.url=jdbc:h2:mem:database +spring.datasource.driver-class-name=org.h2.Driver \ No newline at end of file From 2acf6628aeb3f90f263c06f9d129fe861c16808b Mon Sep 17 00:00:00 2001 From: gjtmdwns Date: Tue, 25 Jun 2024 21:12:34 +0900 Subject: [PATCH 11/19] =?UTF-8?q?FEAT=20:=20ReservationTimeController=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ReservationTimeController.java | 35 +++++++++++++++++++ .../roomescape/model/ReservationTime.java | 2 ++ .../repository/ReservationTimeRepository.java | 2 ++ .../service/ReservationTimeService.java | 2 ++ 4 files changed, 41 insertions(+) create mode 100644 src/main/java/roomescape/controller/ReservationTimeController.java create mode 100644 src/main/java/roomescape/model/ReservationTime.java create mode 100644 src/main/java/roomescape/repository/ReservationTimeRepository.java create mode 100644 src/main/java/roomescape/service/ReservationTimeService.java diff --git a/src/main/java/roomescape/controller/ReservationTimeController.java b/src/main/java/roomescape/controller/ReservationTimeController.java new file mode 100644 index 00000000..81245efc --- /dev/null +++ b/src/main/java/roomescape/controller/ReservationTimeController.java @@ -0,0 +1,35 @@ +package roomescape.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import roomescape.model.ReservationTime; +import roomescape.service.ReservationTimeService; + +import java.util.List; + +@RestController +@RequestMapping("/times") +public class ReservationTimeController { + + private ReservationTimeService reservationTimeService; + + @Autowired + public ReservationTimeController(ReservationTimeService reservationTimeService) { + this.reservationTimeService = reservationTimeService; + } + + @PostMapping + public ReservationTime insert(@RequestBody String startAt) { + return reservationTimeService.addReservation(startAt); + } + + @GetMapping + public List read() { + return reservationTimeService.lookUpReservationTime(); + } + + @DeleteMapping("/{id}") + public void delete(@PathVariable Long id) { + reservationTimeService.deleteReservation(id); + } +} diff --git a/src/main/java/roomescape/model/ReservationTime.java b/src/main/java/roomescape/model/ReservationTime.java new file mode 100644 index 00000000..48f25dcb --- /dev/null +++ b/src/main/java/roomescape/model/ReservationTime.java @@ -0,0 +1,2 @@ +package roomescape.model;public class ReservationTime { +} diff --git a/src/main/java/roomescape/repository/ReservationTimeRepository.java b/src/main/java/roomescape/repository/ReservationTimeRepository.java new file mode 100644 index 00000000..fb190790 --- /dev/null +++ b/src/main/java/roomescape/repository/ReservationTimeRepository.java @@ -0,0 +1,2 @@ +package roomescape.controller;public class ReservationTimeRepository { +} diff --git a/src/main/java/roomescape/service/ReservationTimeService.java b/src/main/java/roomescape/service/ReservationTimeService.java new file mode 100644 index 00000000..672d743e --- /dev/null +++ b/src/main/java/roomescape/service/ReservationTimeService.java @@ -0,0 +1,2 @@ +package roomescape.controller;public class ReservationTimeService { +} From 9ce9565696672e51fa8b440f30c7bbcf5ec5795e Mon Sep 17 00:00:00 2001 From: gjtmdwns Date: Tue, 25 Jun 2024 21:13:13 +0900 Subject: [PATCH 12/19] =?UTF-8?q?FEAT=20:=20ReservationTime=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20-=20id=EC=99=80=20startAt=EC=9D=84=20=EB=A9=A4?= =?UTF-8?q?=EB=B2=84=EB=A1=9C=20=EA=B0=80=EC=A7=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../roomescape/model/ReservationTime.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/roomescape/model/ReservationTime.java b/src/main/java/roomescape/model/ReservationTime.java index 48f25dcb..dbf4077f 100644 --- a/src/main/java/roomescape/model/ReservationTime.java +++ b/src/main/java/roomescape/model/ReservationTime.java @@ -1,2 +1,24 @@ -package roomescape.model;public class ReservationTime { +package roomescape.model; + +public class ReservationTime { + private Long id; + private String startAt; + + public ReservationTime(String startAt) { + this(0L, startAt); + } + + public ReservationTime(Long id, String startAt) { + this.id = id; + this.startAt = startAt; + } + + public Long getId() { + return id; + } + + public String getStartAt() { + return startAt; + } + } From a74051b03eb732d5b8a3a7940f80895db1b463fb Mon Sep 17 00:00:00 2001 From: gjtmdwns Date: Tue, 25 Jun 2024 21:13:55 +0900 Subject: [PATCH 13/19] =?UTF-8?q?FEAT=20:=20ReservationTimeRepository=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20-=20=EC=98=88=EC=95=BD=EC=8B=9C=EA=B0=84?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C,=20=EC=83=9D=EC=84=B1,=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ReservationTimeRepository.java | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/main/java/roomescape/repository/ReservationTimeRepository.java b/src/main/java/roomescape/repository/ReservationTimeRepository.java index fb190790..91d6072b 100644 --- a/src/main/java/roomescape/repository/ReservationTimeRepository.java +++ b/src/main/java/roomescape/repository/ReservationTimeRepository.java @@ -1,2 +1,50 @@ -package roomescape.controller;public class ReservationTimeRepository { +package roomescape.repository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.core.simple.SimpleJdbcInsert; +import org.springframework.jdbc.support.GeneratedKeyHolder; +import org.springframework.jdbc.support.KeyHolder; +import roomescape.model.ReservationTime; + +import javax.sql.DataSource; +import java.sql.*; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ReservationTimeRepository { + + private final JdbcTemplate jdbcTemplate; + private final SimpleJdbcInsert jdbcInsert; + + private final RowMapper rowMapper = (resultSet, rowNum) -> new ReservationTime( + resultSet.getLong("id"), + resultSet.getString("start_at") + ); + + @Autowired + public ReservationTimeRepository(JdbcTemplate jdbcTemplate, SimpleJdbcInsert jdbcInsert, DataSource dataSource) { + this.jdbcTemplate = jdbcTemplate; + this.jdbcInsert = new SimpleJdbcInsert(dataSource) + .withTableName("reservation_time") + .usingGeneratedKeyColumns("id"); + } + + public ReservationTime save(String startAt) { + Map params = new HashMap<>(); + params.put("startAt", startAt); + return new ReservationTime(jdbcInsert.executeAndReturnKey(params).longValue(), startAt); + } + + public List readAll() { + String sql = "SELECT * FROM reservation_time"; + return jdbcTemplate.query(sql, rowMapper); + } + + public void deleteById(Long id) { + String sql = "DELETE FROM reservation_time WHERE id = ?"; + jdbcTemplate.update(sql, id); + } } From 0d477e926fbd7cd56f64c7f62c743b0827c226ea Mon Sep 17 00:00:00 2001 From: gjtmdwns Date: Tue, 25 Jun 2024 21:14:13 +0900 Subject: [PATCH 14/19] =?UTF-8?q?FEAT=20:=20ReservationTimeService=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationTimeService.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/main/java/roomescape/service/ReservationTimeService.java b/src/main/java/roomescape/service/ReservationTimeService.java index 672d743e..8db0aeca 100644 --- a/src/main/java/roomescape/service/ReservationTimeService.java +++ b/src/main/java/roomescape/service/ReservationTimeService.java @@ -1,2 +1,32 @@ -package roomescape.controller;public class ReservationTimeService { +package roomescape.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import roomescape.model.ReservationTime; +import roomescape.repository.ReservationRepository; +import roomescape.repository.ReservationTimeRepository; + +import java.util.List; + +@Service +public class ReservationTimeService { + + private final ReservationTimeRepository reservationTimeRepository; + + @Autowired + public ReservationTimeService(ReservationTimeRepository reservationTimeRepository) { + this.reservationTimeRepository = reservationTimeRepository; + } + + public ReservationTime addReservation(String startAt) { + return reservationTimeRepository.save(startAt); + } + + public List lookUpReservationTime() { + return reservationTimeRepository.readAll(); + } + + public void deleteReservation(Long id) { + reservationTimeRepository.deleteById(id); + } } From f05616cf196bc30b2263016f967b88edf17a228c Mon Sep 17 00:00:00 2001 From: gjtmdwns Date: Tue, 25 Jun 2024 21:15:30 +0900 Subject: [PATCH 15/19] =?UTF-8?q?CHORE=20:=20=EC=98=A4=ED=83=88=EC=9E=90?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/roomescape/controller/ReservationController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/roomescape/controller/ReservationController.java b/src/main/java/roomescape/controller/ReservationController.java index 42ec7f1b..e4d3fb88 100644 --- a/src/main/java/roomescape/controller/ReservationController.java +++ b/src/main/java/roomescape/controller/ReservationController.java @@ -19,7 +19,7 @@ public ReservationController(ReservationService reservationService) { } @PostMapping - public int insert(@RequestBody Reservation reservation) { + public Long insert(@RequestBody Reservation reservation) { return reservationService.addReservation(reservation); } @@ -29,7 +29,7 @@ public List read() { } @DeleteMapping("/{id}") - public void delete(@PathVariable int id) { + public void delete(@PathVariable Long id) { reservationService.deleteReservation(id); } } From 37cd26b125ce197fa703fbb48ac4eddff5de5778 Mon Sep 17 00:00:00 2001 From: gjtmdwns Date: Tue, 25 Jun 2024 21:15:56 +0900 Subject: [PATCH 16/19] =?UTF-8?q?REFACTOR=20:=20time=5Fid=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/roomescape/model/Reservation.java | 30 ++++--------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/src/main/java/roomescape/model/Reservation.java b/src/main/java/roomescape/model/Reservation.java index 7f21fbd3..b583cdae 100644 --- a/src/main/java/roomescape/model/Reservation.java +++ b/src/main/java/roomescape/model/Reservation.java @@ -6,48 +6,28 @@ public class Reservation { private Long id; private String name; private String date; - private String time; + private Long timeId; - public Reservation(Long id, String name, String date, String time) { + public Reservation(Long id, String name, String date, Long timeId) { this.id = id; this.name = name; this.date = date; - this.time = time; - } - - public static Reservation toEntity(Reservation reservation, AtomicLong id) { - return new Reservation(Long.valueOf(String.valueOf(id)), reservation.getName(), reservation.getDate(), reservation.getTime()); + this.timeId = timeId; } public Long getId() { return id; } - public void setId(Long id) { - this.id = id; - } - public String getName() { return name; } - public void setName(String name) { - this.name = name; - } - public String getDate() { return date; } - public void setDate(String date) { - this.date = date; - } - - public String getTime() { - return time; - } - - public void setTime(String time) { - this.time = time; + public Long getTimeId() { + return timeId; } } From d3dac35c9f98e512db77d4f593512a05262b9db5 Mon Sep 17 00:00:00 2001 From: gjtmdwns Date: Tue, 25 Jun 2024 21:16:31 +0900 Subject: [PATCH 17/19] =?UTF-8?q?REFACTOR=20:=20SimpleJdbcInsert=EB=A5=BC?= =?UTF-8?q?=20=ED=99=9C=EC=9A=A9=ED=95=9C=20=EC=98=88=EC=95=BD=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ReservationRepository.java | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/src/main/java/roomescape/repository/ReservationRepository.java b/src/main/java/roomescape/repository/ReservationRepository.java index bf4f4426..f6684cc2 100644 --- a/src/main/java/roomescape/repository/ReservationRepository.java +++ b/src/main/java/roomescape/repository/ReservationRepository.java @@ -3,50 +3,59 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.core.simple.SimpleJdbcInsert; import org.springframework.jdbc.support.GeneratedKeyHolder; import org.springframework.jdbc.support.KeyHolder; import org.springframework.stereotype.Repository; import roomescape.model.Reservation; +import javax.sql.DataSource; import java.sql.PreparedStatement; +import java.util.HashMap; import java.util.List; +import java.util.Map; @Repository public class ReservationRepository { - private JdbcTemplate jdbcTemplate; - private RowMapper rowMapper = (resultSet, rowNum) -> new Reservation( + private final JdbcTemplate jdbcTemplate; + private final SimpleJdbcInsert jdbcInsert; + private final RowMapper rowMapper = (resultSet, rowNum) -> new Reservation( resultSet.getLong("id"), resultSet.getString("name"), resultSet.getString("date"), - resultSet.getString("time") + resultSet.getLong("time_id") ); @Autowired - public ReservationRepository(JdbcTemplate jdbcTemplate) { + public ReservationRepository(SimpleJdbcInsert jdbcInsert, JdbcTemplate jdbcTemplate, DataSource dataSource) { this.jdbcTemplate = jdbcTemplate; + this.jdbcInsert = new SimpleJdbcInsert(dataSource) + .withTableName("reservation") + .usingGeneratedKeyColumns("id"); } - public int save(Reservation reservation) { - KeyHolder keyHolder = new GeneratedKeyHolder(); - jdbcTemplate.update(connect -> { - PreparedStatement ps = connect.prepareStatement( - "INSERT INTO reservation (name, date, time) VALUES(?, ?, ?)", - new String[]{"id"}); - ps.setString(1, reservation.getName()); - ps.setString(2, reservation.getDate()); - ps.setString(3, reservation.getTime()); - return ps; - }, keyHolder); - - return (int)keyHolder.getKey().longValue(); + public Long save(Reservation reservation) { + Map params = new HashMap<>(); + params.put("id", reservation.getId()); + params.put("name", reservation.getName()); + params.put("date", reservation.getDate()); + params.put("time_id", reservation.getTimeId()); + + return jdbcInsert.executeAndReturnKey(params).longValue(); } public List readAll() { - String sql = "SELECT * FROM reservation"; + String sql = "SELECT \n" + + "r.id as reservation_id, \n" + + "r.name as reservation_name, \n" + + "r.date as reservation_date, \n" + + "t.id as time_id, \n" + + "t.start_at as time_start_at \n" + + "FROM reservation as r inner join reservation_time as t on r.time_id = t.id"; return jdbcTemplate.query(sql, rowMapper); } - public void deleteById(int id) { + public void deleteById(Long id) { String sql = "DELETE FROM reservation WHERE id = ?"; jdbcTemplate.update(sql, id); } From 100cd1db4ce975ac7d6d62ebd03f29c3826de2ca Mon Sep 17 00:00:00 2001 From: gjtmdwns Date: Tue, 25 Jun 2024 21:17:59 +0900 Subject: [PATCH 18/19] =?UTF-8?q?REFACTOR=20:=20addReservation=20=EB=A6=AC?= =?UTF-8?q?=ED=84=B4=20=ED=83=80=EC=9E=85=EC=9D=84=20Long=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/roomescape/service/ReservationService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/roomescape/service/ReservationService.java b/src/main/java/roomescape/service/ReservationService.java index 6607fb42..d326a4b7 100644 --- a/src/main/java/roomescape/service/ReservationService.java +++ b/src/main/java/roomescape/service/ReservationService.java @@ -16,7 +16,7 @@ public ReservationService(ReservationRepository reservationRepository) { this.reservationRepository = reservationRepository; } - public int addReservation(Reservation reservation) { + public Long addReservation(Reservation reservation) { return reservationRepository.save(reservation); } @@ -24,7 +24,7 @@ public List lookUpReservation() { return reservationRepository.readAll(); } - public void deleteReservation(int id) { + public void deleteReservation(Long id) { reservationRepository.deleteById(id); } } From bca58b1786da383d5901f8753e6c9e32d79be5e4 Mon Sep 17 00:00:00 2001 From: gjtmdwns Date: Tue, 25 Jun 2024 21:18:29 +0900 Subject: [PATCH 19/19] =?UTF-8?q?REFACTOR=20:=20reservation=5Ftime=20?= =?UTF-8?q?=EC=8A=A4=ED=82=A4=EB=A7=88=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/schema.sql | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 8d9ab275..5571e7d1 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -1,8 +1,16 @@ -CREATE TABLE reservation +CREATE TABLE reservation_time ( - id BIGINT NOT NULL AUTO_INCREMENT, - name VARCHAR(255) NOT NULL, - date VARCHAR(255) NOT NULL, - time VARCHAR(255) NOT NULL, + 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) +); \ No newline at end of file