From d0ef8784386a8046be85e703803fa419d8396691 Mon Sep 17 00:00:00 2001 From: spig0126 Date: Sat, 1 Jun 2024 17:34:38 +0900 Subject: [PATCH 1/9] Chore[step8]: add gradle dependency - add spring boot data-jpa dependency --- build.gradle | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 57267157c..738895123 100644 --- a/build.gradle +++ b/build.gradle @@ -13,11 +13,19 @@ repositories { } dependencies { - implementation 'org.springframework.boot:spring-boot-starter' + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' + implementation 'org.springframework.boot:spring-boot-starter-jdbc' + implementation 'org.springframework.boot:spring-boot-starter-validation' + implementation 'jakarta.validation:jakarta.validation-api:3.0.0' + runtimeOnly 'com.h2database:h2' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'io.rest-assured:rest-assured:5.3.1' + testImplementation "junit:junit:4.12" } test { useJUnitPlatform() + jvmArgs '-Xshare:off' } From 4cf1889a43d701fcdeb377317564c100e4cd92ee Mon Sep 17 00:00:00 2001 From: spig0126 Date: Sat, 1 Jun 2024 18:48:52 +0900 Subject: [PATCH 2/9] Chore[step8]: add 'time' table in sql --- src/main/resources/schema.sql | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/resources/schema.sql diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql new file mode 100644 index 000000000..4ea1598ba --- /dev/null +++ b/src/main/resources/schema.sql @@ -0,0 +1,16 @@ +CREATE TABLE time +( + id BIGINT NOT NULL AUTO_INCREMENT, + time 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 time(id) +); \ No newline at end of file From dcc87b3be27cd3dbfb25da2953df67f2a4ff9161 Mon Sep 17 00:00:00 2001 From: spig0126 Date: Sat, 1 Jun 2024 18:54:08 +0900 Subject: [PATCH 3/9] =?UTF-8?q?Feat[step8]:=20=EC=8B=9C=EA=B0=84=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - create layered architecture for time - use custom exception (TimeNotFoundException) --- .../advice/GlobalControllerAdvice.java | 35 +++++++++++++ .../roomescape/controller/TimeController.java | 50 +++++++++++++++++++ src/main/java/roomescape/domain/Time.java | 25 ++++++++++ .../exception/TimeNotFoundException.java | 7 +++ .../roomescape/repository/TimeRepository.java | 10 ++++ .../java/roomescape/service/TimeService.java | 39 +++++++++++++++ 6 files changed, 166 insertions(+) create mode 100644 src/main/java/roomescape/advice/GlobalControllerAdvice.java create mode 100644 src/main/java/roomescape/controller/TimeController.java create mode 100644 src/main/java/roomescape/domain/Time.java create mode 100644 src/main/java/roomescape/exception/TimeNotFoundException.java create mode 100644 src/main/java/roomescape/repository/TimeRepository.java create mode 100644 src/main/java/roomescape/service/TimeService.java diff --git a/src/main/java/roomescape/advice/GlobalControllerAdvice.java b/src/main/java/roomescape/advice/GlobalControllerAdvice.java new file mode 100644 index 000000000..7e625f848 --- /dev/null +++ b/src/main/java/roomescape/advice/GlobalControllerAdvice.java @@ -0,0 +1,35 @@ +package roomescape.advice; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +import roomescape.exception.DatabaseOperationException; +import roomescape.exception.ReservationNotFoundException; +import roomescape.exception.TimeNotFoundException; + +@ControllerAdvice +public class GlobalControllerAdvice { + @ExceptionHandler(ReservationNotFoundException.class) + public ResponseEntity handleReservationNotFoundException(ReservationNotFoundException ex) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ex.getMessage()); + } + + @ExceptionHandler(DatabaseOperationException.class) + public ResponseEntity handleDatabaseOperationException(DatabaseOperationException ex) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ex.getMessage()); + } + + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity handleValidationExceptions(MethodArgumentNotValidException ex) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ex.getMessage()); + } + + @ExceptionHandler(TimeNotFoundException.class) + public ResponseEntity handleTimeNotFoundException(TimeNotFoundException ex) { + System.out.println("---------------------HI"); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ex.getMessage()); + } +} diff --git a/src/main/java/roomescape/controller/TimeController.java b/src/main/java/roomescape/controller/TimeController.java new file mode 100644 index 000000000..d9965a2a8 --- /dev/null +++ b/src/main/java/roomescape/controller/TimeController.java @@ -0,0 +1,50 @@ +package roomescape.controller; + +import jakarta.validation.Valid; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import roomescape.domain.Time; +import roomescape.service.TimeService; + +import java.net.URI; +import java.util.List; + +@Controller +public class TimeController { + @Autowired + private TimeService timeService; + + @GetMapping("/time") + public String time() { + return "time"; + } + + @GetMapping("/times") + public ResponseEntity> getTimes() { + List