From c484c440506d7d8b6006e95dabcb2193da66ba2c Mon Sep 17 00:00:00 2001 From: LHC0312 Date: Mon, 28 Oct 2024 04:39:35 +0900 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20=EC=9D=BC=EB=8B=A8=EA=B3=84=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 ++- .../roomescape/Controller/HomeController.java | 15 +++++++++++++++ src/test/java/roomescape/MissionStepTest.java | 3 +++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/main/java/roomescape/Controller/HomeController.java diff --git a/build.gradle b/build.gradle index 57267157c..fb197fc19 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,8 @@ repositories { } dependencies { - implementation 'org.springframework.boot:spring-boot-starter' + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'io.rest-assured:rest-assured:5.3.1' } diff --git a/src/main/java/roomescape/Controller/HomeController.java b/src/main/java/roomescape/Controller/HomeController.java new file mode 100644 index 000000000..398c9af94 --- /dev/null +++ b/src/main/java/roomescape/Controller/HomeController.java @@ -0,0 +1,15 @@ +package roomescape.Controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class HomeController { + + @GetMapping("/") + public String home() { + return "home"; + } + +} + diff --git a/src/test/java/roomescape/MissionStepTest.java b/src/test/java/roomescape/MissionStepTest.java index cf4efbe91..b926fcbbe 100644 --- a/src/test/java/roomescape/MissionStepTest.java +++ b/src/test/java/roomescape/MissionStepTest.java @@ -1,5 +1,7 @@ package roomescape; +import static org.hamcrest.core.Is.is; + import io.restassured.RestAssured; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @@ -16,4 +18,5 @@ public class MissionStepTest { .then().log().all() .statusCode(200); } + } From db7048d0f47e80582b1c4220682d69b33538df54 Mon Sep 17 00:00:00 2001 From: LHC0312 Date: Mon, 28 Oct 2024 04:39:35 +0900 Subject: [PATCH 2/8] =?UTF-8?q?feat:=20=EC=82=BC=EB=8B=A8=EA=B3=84=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 5 +- .../java/roomescape/Enum/ErrorStatus.java | 8 +++ .../roomescape/controller/HomeController.java | 15 +++++ .../controller/ReservationController.java | 58 +++++++++++++++++++ .../converter/ReservationConverter.java | 43 ++++++++++++++ .../java/roomescape/domain/Reservation.java | 19 ++++++ .../roomescape/dto/ReservationReqeustDto.java | 15 +++++ .../dto/ReservationResponseDto.java | 23 ++++++++ .../service/ReservationService.java | 12 ++++ .../service/ReservationServiceImpl.java | 46 +++++++++++++++ src/test/java/roomescape/MissionStepTest.java | 54 +++++++++++++++++ 11 files changed, 297 insertions(+), 1 deletion(-) create mode 100644 src/main/java/roomescape/Enum/ErrorStatus.java create mode 100644 src/main/java/roomescape/controller/HomeController.java create mode 100644 src/main/java/roomescape/controller/ReservationController.java create mode 100644 src/main/java/roomescape/converter/ReservationConverter.java create mode 100644 src/main/java/roomescape/domain/Reservation.java create mode 100644 src/main/java/roomescape/dto/ReservationReqeustDto.java create mode 100644 src/main/java/roomescape/dto/ReservationResponseDto.java create mode 100644 src/main/java/roomescape/service/ReservationService.java create mode 100644 src/main/java/roomescape/service/ReservationServiceImpl.java diff --git a/build.gradle b/build.gradle index 57267157c..702a1583a 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,10 @@ repositories { } dependencies { - implementation 'org.springframework.boot:spring-boot-starter' + implementation 'org.springframework.boot:spring-boot-starter-web' + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'io.rest-assured:rest-assured:5.3.1' } diff --git a/src/main/java/roomescape/Enum/ErrorStatus.java b/src/main/java/roomescape/Enum/ErrorStatus.java new file mode 100644 index 000000000..5a21f9056 --- /dev/null +++ b/src/main/java/roomescape/Enum/ErrorStatus.java @@ -0,0 +1,8 @@ +package roomescape.Enum; + +public enum ErrorStatus { + _NOT_FOUND_RESERVATION + + + +} diff --git a/src/main/java/roomescape/controller/HomeController.java b/src/main/java/roomescape/controller/HomeController.java new file mode 100644 index 000000000..526d77046 --- /dev/null +++ b/src/main/java/roomescape/controller/HomeController.java @@ -0,0 +1,15 @@ +package roomescape.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class HomeController { + + @GetMapping("/") + public String home() { + return "home"; + } + +} + diff --git a/src/main/java/roomescape/controller/ReservationController.java b/src/main/java/roomescape/controller/ReservationController.java new file mode 100644 index 000000000..e25be02ca --- /dev/null +++ b/src/main/java/roomescape/controller/ReservationController.java @@ -0,0 +1,58 @@ +package roomescape.controller; + +import java.net.URI; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +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.ResponseBody; + +import roomescape.converter.ReservationConverter; +import roomescape.domain.Reservation; +import roomescape.dto.ReservationReqeustDto; +import roomescape.dto.ReservationResponseDto; +import roomescape.dto.ReservationResponseDto.ResponseDto; +import roomescape.service.ReservationService; + +@RequiredArgsConstructor +@Controller +public class ReservationController { + + private final ReservationService reservationService; + + @GetMapping("/reservation") + public String reservation() { + return "home"; + } + + @GetMapping("/reservations") + public ResponseEntity reservations() { + List reservations = reservationService.findAll(); + return ResponseEntity.ok().body(ReservationConverter.toResponseDto(reservations)); + } + + @PostMapping("/reservations") + public ResponseEntity createReservation (@RequestBody ReservationReqeustDto.CreateReservationDto request) { + + Reservation reservation = ReservationConverter.toReservation(request); + reservationService.create(reservation); + + String url = "/reservations/" + reservation.getId(); + + return ResponseEntity.created(URI.create(url)).body(ReservationConverter.toResponseDto(reservation)); + } + + @DeleteMapping("/reservations/{id}") + public ResponseEntity createReservation (@PathVariable Integer id) { + + Reservation reservation = reservationService.delete(id); + return ResponseEntity.noContent().build(); + } + + +} \ No newline at end of file diff --git a/src/main/java/roomescape/converter/ReservationConverter.java b/src/main/java/roomescape/converter/ReservationConverter.java new file mode 100644 index 000000000..4d049cc16 --- /dev/null +++ b/src/main/java/roomescape/converter/ReservationConverter.java @@ -0,0 +1,43 @@ +package roomescape.converter; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.stream.Collectors; +import roomescape.domain.Reservation; +import roomescape.dto.ReservationReqeustDto; +import roomescape.dto.ReservationResponseDto; + +public class ReservationConverter { + + + public static ReservationResponseDto.ResponseDto toResponseDto(Reservation reservation) { + + LocalDateTime dateTime = reservation.getDateTime(); + + return ReservationResponseDto.ResponseDto.builder() + .id(reservation.getId()) + .name(reservation.getName()) + .date(dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) + .time(dateTime.format(DateTimeFormatter.ofPattern("HH:mm"))) + .build(); + } + + public static List toResponseDto(List reservations) { + return reservations.stream() + .map(ReservationConverter::toResponseDto).collect( + Collectors.toList()); + } + + public static Reservation toReservation(ReservationReqeustDto.CreateReservationDto request) { + + String string = request.getDate() + " " + request.getTime(); + LocalDateTime dateTime = LocalDateTime.parse(string, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")); + + return Reservation.builder() + .name(request.getName()) + .dateTime(dateTime) + .build(); + } + +} diff --git a/src/main/java/roomescape/domain/Reservation.java b/src/main/java/roomescape/domain/Reservation.java new file mode 100644 index 000000000..e8709430f --- /dev/null +++ b/src/main/java/roomescape/domain/Reservation.java @@ -0,0 +1,19 @@ +package roomescape.domain; + +import java.time.LocalDateTime; +import lombok.Builder; +import lombok.Getter; + + +@Builder +@Getter +public class Reservation { + + private Integer id; + private String name; + private LocalDateTime dateTime; + + public void generateId(Integer id) { + this.id = id; + } +} diff --git a/src/main/java/roomescape/dto/ReservationReqeustDto.java b/src/main/java/roomescape/dto/ReservationReqeustDto.java new file mode 100644 index 000000000..59fb21ee8 --- /dev/null +++ b/src/main/java/roomescape/dto/ReservationReqeustDto.java @@ -0,0 +1,15 @@ +package roomescape.dto; + +import lombok.Getter; + + +public class ReservationReqeustDto { + + @Getter + public static class CreateReservationDto { + private String name; + private String date; + private String time; + } +} + diff --git a/src/main/java/roomescape/dto/ReservationResponseDto.java b/src/main/java/roomescape/dto/ReservationResponseDto.java new file mode 100644 index 000000000..cb8418a66 --- /dev/null +++ b/src/main/java/roomescape/dto/ReservationResponseDto.java @@ -0,0 +1,23 @@ +package roomescape.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + + +public class ReservationResponseDto { + + @Getter + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class ResponseDto { + + private Integer id; + private String name; + private String date; + private String time; + } +} + diff --git a/src/main/java/roomescape/service/ReservationService.java b/src/main/java/roomescape/service/ReservationService.java new file mode 100644 index 000000000..d18b26519 --- /dev/null +++ b/src/main/java/roomescape/service/ReservationService.java @@ -0,0 +1,12 @@ +package roomescape.service; + +import java.util.List; +import roomescape.domain.Reservation; + +public interface ReservationService { + + Reservation findById(Integer id); + List findAll(); + Reservation create(final Reservation reservation); + Reservation delete(final Integer id); +} diff --git a/src/main/java/roomescape/service/ReservationServiceImpl.java b/src/main/java/roomescape/service/ReservationServiceImpl.java new file mode 100644 index 000000000..67ab33a67 --- /dev/null +++ b/src/main/java/roomescape/service/ReservationServiceImpl.java @@ -0,0 +1,46 @@ +package roomescape.service; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import org.springframework.stereotype.Service; +import roomescape.Enum.ErrorStatus; +import roomescape.domain.Reservation; + +@Service +public class ReservationServiceImpl implements ReservationService { + + static AtomicInteger index = new AtomicInteger(0); + private final List reservations = new ArrayList<>(); + + @Override + public Reservation create(Reservation reservation) { + + reservation.generateId(index.incrementAndGet()); + reservations.add(reservation); + + return reservation; + } + + @Override + public Reservation findById(Integer id) { + return reservations.stream() + .filter(reservation -> reservation.getId().equals(id)).findFirst() + .orElseThrow(() -> new RuntimeException(ErrorStatus._NOT_FOUND_RESERVATION.name())); + } + + @Override + public Reservation delete(Integer id) { + + Reservation reservation = this.findById(id); + reservations.remove(reservation); + + return reservation; + } + + @Override + public List findAll() { + return reservations; + } +} + diff --git a/src/test/java/roomescape/MissionStepTest.java b/src/test/java/roomescape/MissionStepTest.java index cf4efbe91..e5c8cb9f1 100644 --- a/src/test/java/roomescape/MissionStepTest.java +++ b/src/test/java/roomescape/MissionStepTest.java @@ -1,6 +1,11 @@ package roomescape; +import static org.hamcrest.core.Is.is; + import io.restassured.RestAssured; +import io.restassured.http.ContentType; +import java.util.HashMap; +import java.util.Map; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; @@ -16,4 +21,53 @@ public class MissionStepTest { .then().log().all() .statusCode(200); } + + @Test + void 이단계() { + RestAssured.given().log().all() + .when().get("/reservation") + .then().log().all() + .statusCode(200); + + RestAssured.given().log().all() + .when().get("/reservations") + .then().log().all() + .statusCode(200) + .body("size()", is(2)); // 아직 생성 요청이 없으니 Controller에서 임의로 넣어준 Reservation 갯수 만큼 검증하거나 0개임을 확인하세요. + } + + @Test + void 삼단계() { + Map params = new HashMap<>(); + params.put("name", "브라운"); + params.put("date", "2023-08-05"); + params.put("time", "15:40"); + + RestAssured.given().log().all() + .contentType(ContentType.JSON) + .body(params) + .when().post("/reservations") + .then().log().all() + .statusCode(201) + .header("Location", "/reservations/1") + .body("id", is(1)); + + RestAssured.given().log().all() + .when().get("/reservations") + .then().log().all() + .statusCode(200) + .body("size()", is(1)); + + RestAssured.given().log().all() + .when().delete("/reservations/1") + .then().log().all() + .statusCode(204); + + RestAssured.given().log().all() + .when().get("/reservations") + .then().log().all() + .statusCode(200) + .body("size()", is(0)); + } + } From 0ce729e284952a7218b49ddd73985c67d8a74cf5 Mon Sep 17 00:00:00 2001 From: LHC0312 Date: Tue, 5 Nov 2024 04:05:15 +0900 Subject: [PATCH 3/8] =?UTF-8?q?feat:=20=EC=82=AC=EB=8B=A8=EA=B3=84=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + .../java/roomescape/Enum/ErrorStatus.java | 8 ----- .../controller/ReservationController.java | 3 +- .../roomescape/dto/ReservationReqeustDto.java | 7 ++++ .../java/roomescape/handler/ErrorHandler.java | 15 +++++++++ .../handler/exception/UserException.java | 7 ++++ .../service/ReservationServiceImpl.java | 4 +-- src/test/java/roomescape/MissionStepTest.java | 32 ++++++++++++++++--- 8 files changed, 61 insertions(+), 16 deletions(-) delete mode 100644 src/main/java/roomescape/Enum/ErrorStatus.java create mode 100644 src/main/java/roomescape/handler/ErrorHandler.java create mode 100644 src/main/java/roomescape/handler/exception/UserException.java diff --git a/build.gradle b/build.gradle index 702a1583a..17e54d6c8 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,7 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-validation' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' diff --git a/src/main/java/roomescape/Enum/ErrorStatus.java b/src/main/java/roomescape/Enum/ErrorStatus.java deleted file mode 100644 index 5a21f9056..000000000 --- a/src/main/java/roomescape/Enum/ErrorStatus.java +++ /dev/null @@ -1,8 +0,0 @@ -package roomescape.Enum; - -public enum ErrorStatus { - _NOT_FOUND_RESERVATION - - - -} diff --git a/src/main/java/roomescape/controller/ReservationController.java b/src/main/java/roomescape/controller/ReservationController.java index e25be02ca..fb02fba53 100644 --- a/src/main/java/roomescape/controller/ReservationController.java +++ b/src/main/java/roomescape/controller/ReservationController.java @@ -1,5 +1,6 @@ package roomescape.controller; +import jakarta.validation.Valid; import java.net.URI; import java.util.List; import lombok.RequiredArgsConstructor; @@ -37,7 +38,7 @@ public ResponseEntity reservations() { } @PostMapping("/reservations") - public ResponseEntity createReservation (@RequestBody ReservationReqeustDto.CreateReservationDto request) { + public ResponseEntity createReservation (@RequestBody @Valid ReservationReqeustDto.CreateReservationDto request) { Reservation reservation = ReservationConverter.toReservation(request); reservationService.create(reservation); diff --git a/src/main/java/roomescape/dto/ReservationReqeustDto.java b/src/main/java/roomescape/dto/ReservationReqeustDto.java index 59fb21ee8..d99c24c08 100644 --- a/src/main/java/roomescape/dto/ReservationReqeustDto.java +++ b/src/main/java/roomescape/dto/ReservationReqeustDto.java @@ -1,5 +1,6 @@ package roomescape.dto; +import jakarta.validation.constraints.NotBlank; import lombok.Getter; @@ -7,8 +8,14 @@ public class ReservationReqeustDto { @Getter public static class CreateReservationDto { + + @NotBlank private String name; + + @NotBlank private String date; + + @NotBlank private String time; } } diff --git a/src/main/java/roomescape/handler/ErrorHandler.java b/src/main/java/roomescape/handler/ErrorHandler.java new file mode 100644 index 000000000..6beb16e8c --- /dev/null +++ b/src/main/java/roomescape/handler/ErrorHandler.java @@ -0,0 +1,15 @@ +package roomescape.handler; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import roomescape.handler.exception.UserException;; + +@ControllerAdvice +public class ErrorHandler { + + @ExceptionHandler(UserException.class) + public ResponseEntity handleException(UserException e) { + return ResponseEntity.badRequest().build(); + } +} diff --git a/src/main/java/roomescape/handler/exception/UserException.java b/src/main/java/roomescape/handler/exception/UserException.java new file mode 100644 index 000000000..87d2d95b7 --- /dev/null +++ b/src/main/java/roomescape/handler/exception/UserException.java @@ -0,0 +1,7 @@ +package roomescape.handler.exception; + +public class UserException extends RuntimeException { + public UserException(String message) { + super(message); + } +} diff --git a/src/main/java/roomescape/service/ReservationServiceImpl.java b/src/main/java/roomescape/service/ReservationServiceImpl.java index 67ab33a67..9a6cf1e88 100644 --- a/src/main/java/roomescape/service/ReservationServiceImpl.java +++ b/src/main/java/roomescape/service/ReservationServiceImpl.java @@ -4,8 +4,8 @@ import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import org.springframework.stereotype.Service; -import roomescape.Enum.ErrorStatus; import roomescape.domain.Reservation; +import roomescape.handler.exception.UserException; @Service public class ReservationServiceImpl implements ReservationService { @@ -26,7 +26,7 @@ public Reservation create(Reservation reservation) { public Reservation findById(Integer id) { return reservations.stream() .filter(reservation -> reservation.getId().equals(id)).findFirst() - .orElseThrow(() -> new RuntimeException(ErrorStatus._NOT_FOUND_RESERVATION.name())); + .orElseThrow(() -> new UserException("해당되는 예약을 찾을 수 없습니다")); } @Override diff --git a/src/test/java/roomescape/MissionStepTest.java b/src/test/java/roomescape/MissionStepTest.java index e5c8cb9f1..7bbb10f09 100644 --- a/src/test/java/roomescape/MissionStepTest.java +++ b/src/test/java/roomescape/MissionStepTest.java @@ -17,9 +17,9 @@ public class MissionStepTest { @Test void 일단계() { RestAssured.given().log().all() - .when().get("/") - .then().log().all() - .statusCode(200); + .when().get("/") + .then().log().all() + .statusCode(200); } @Test @@ -33,7 +33,8 @@ public class MissionStepTest { .when().get("/reservations") .then().log().all() .statusCode(200) - .body("size()", is(2)); // 아직 생성 요청이 없으니 Controller에서 임의로 넣어준 Reservation 갯수 만큼 검증하거나 0개임을 확인하세요. + .body("size()", + is(0)); // 아직 생성 요청이 없으니 Controller에서 임의로 넣어준 Reservation 갯수 만큼 검증하거나 0개임을 확인하세요. } @Test @@ -70,4 +71,25 @@ public class MissionStepTest { .body("size()", is(0)); } -} + @Test + void 사단계() { + Map params = new HashMap<>(); + params.put("name", "브라운"); + params.put("date", ""); + params.put("time", ""); + + // 필요한 인자가 없는 경우 + RestAssured.given().log().all() + .contentType(ContentType.JSON) + .body(params) + .when().post("/reservations") + .then().log().all() + .statusCode(400); + + // 삭제할 예약이 없는 경우 + RestAssured.given().log().all() + .when().delete("/reservations/1") + .then().log().all() + .statusCode(400); + } +} \ No newline at end of file From cb17d8d8306bab83e3662875d9bdbe986be7b3e4 Mon Sep 17 00:00:00 2001 From: LHC0312 Date: Thu, 7 Nov 2024 07:47:24 +0900 Subject: [PATCH 4/8] =?UTF-8?q?feat:=20=EC=98=A4,=20=EC=9C=A1=EB=8B=A8?= =?UTF-8?q?=EA=B3=84=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80=20refactor:?= =?UTF-8?q?=20Reservation=20=ED=95=84=EB=93=9C=20(date,=20time)=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 + .../controller/ReservationController.java | 2 +- .../converter/ReservationConverter.java | 19 ++++++--- .../java/roomescape/dao/ReservationDao.java | 41 +++++++++++++++++++ .../java/roomescape/domain/Reservation.java | 9 ++-- .../dto/ReservationResponseDto.java | 2 +- .../java/roomescape/handler/ErrorHandler.java | 3 +- .../service/ReservationService.java | 4 +- .../service/ReservationServiceImpl.java | 20 ++++++--- src/main/resources/application.properties | 0 src/main/resources/application.yml | 7 ++++ src/main/resources/schema.sql | 8 ++++ src/test/java/roomescape/MissionStepTest.java | 36 ++++++++++++++++ 13 files changed, 133 insertions(+), 20 deletions(-) create mode 100644 src/main/java/roomescape/dao/ReservationDao.java delete mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/application.yml create mode 100644 src/main/resources/schema.sql diff --git a/build.gradle b/build.gradle index 17e54d6c8..fa561bfa7 100644 --- a/build.gradle +++ b/build.gradle @@ -15,6 +15,8 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-validation' + implementation 'org.springframework.boot:spring-boot-starter-jdbc' + runtimeOnly 'com.h2database:h2' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' diff --git a/src/main/java/roomescape/controller/ReservationController.java b/src/main/java/roomescape/controller/ReservationController.java index fb02fba53..32c453d70 100644 --- a/src/main/java/roomescape/controller/ReservationController.java +++ b/src/main/java/roomescape/controller/ReservationController.java @@ -49,7 +49,7 @@ public ResponseEntity createReservation (@RequestBody @Valid ReservationReqeu } @DeleteMapping("/reservations/{id}") - public ResponseEntity createReservation (@PathVariable Integer id) { + public ResponseEntity createReservation (@PathVariable Long id) { Reservation reservation = reservationService.delete(id); return ResponseEntity.noContent().build(); diff --git a/src/main/java/roomescape/converter/ReservationConverter.java b/src/main/java/roomescape/converter/ReservationConverter.java index 4d049cc16..c7bf8ed8d 100644 --- a/src/main/java/roomescape/converter/ReservationConverter.java +++ b/src/main/java/roomescape/converter/ReservationConverter.java @@ -1,6 +1,8 @@ package roomescape.converter; +import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.List; import java.util.stream.Collectors; @@ -13,13 +15,14 @@ public class ReservationConverter { public static ReservationResponseDto.ResponseDto toResponseDto(Reservation reservation) { - LocalDateTime dateTime = reservation.getDateTime(); + LocalDate date = reservation.getDate(); + LocalTime time = reservation.getTime(); return ReservationResponseDto.ResponseDto.builder() .id(reservation.getId()) .name(reservation.getName()) - .date(dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) - .time(dateTime.format(DateTimeFormatter.ofPattern("HH:mm"))) + .date(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) + .time(time.format(DateTimeFormatter.ofPattern("HH:mm"))) .build(); } @@ -31,12 +34,16 @@ public static List toResponseDto(List rowMapper = (resultSet, rowNum) -> { + return Reservation.builder() + .id( resultSet.getLong("id")) + .name( resultSet.getString("name")) + .date( resultSet.getDate("date").toLocalDate()) + .time( resultSet.getTime("time").toLocalTime()) + .build(); + }; + + public ReservationDao(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } + + public Optional findById(Long id) { + return Optional.ofNullable(jdbcTemplate.queryForObject( + "id, name, date, time from reservation where id = ?", rowMapper, id + )); + } + + public List findAll() { + return jdbcTemplate.query( + "select id, name, date, time from reservation",rowMapper + ); + } + +} diff --git a/src/main/java/roomescape/domain/Reservation.java b/src/main/java/roomescape/domain/Reservation.java index e8709430f..34518a2d0 100644 --- a/src/main/java/roomescape/domain/Reservation.java +++ b/src/main/java/roomescape/domain/Reservation.java @@ -1,6 +1,8 @@ package roomescape.domain; +import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.LocalTime; import lombok.Builder; import lombok.Getter; @@ -9,11 +11,12 @@ @Getter public class Reservation { - private Integer id; + private Long id; private String name; - private LocalDateTime dateTime; + private LocalDate date; + private LocalTime time; - public void generateId(Integer id) { + public void generateId(Long id) { this.id = id; } } diff --git a/src/main/java/roomescape/dto/ReservationResponseDto.java b/src/main/java/roomescape/dto/ReservationResponseDto.java index cb8418a66..8a3049365 100644 --- a/src/main/java/roomescape/dto/ReservationResponseDto.java +++ b/src/main/java/roomescape/dto/ReservationResponseDto.java @@ -14,7 +14,7 @@ public class ReservationResponseDto { @AllArgsConstructor public static class ResponseDto { - private Integer id; + private Long id; private String name; private String date; private String time; diff --git a/src/main/java/roomescape/handler/ErrorHandler.java b/src/main/java/roomescape/handler/ErrorHandler.java index 6beb16e8c..fd1cf7a75 100644 --- a/src/main/java/roomescape/handler/ErrorHandler.java +++ b/src/main/java/roomescape/handler/ErrorHandler.java @@ -6,7 +6,8 @@ import roomescape.handler.exception.UserException;; @ControllerAdvice -public class ErrorHandler { +public class +ErrorHandler { @ExceptionHandler(UserException.class) public ResponseEntity handleException(UserException e) { diff --git a/src/main/java/roomescape/service/ReservationService.java b/src/main/java/roomescape/service/ReservationService.java index d18b26519..9f0eec371 100644 --- a/src/main/java/roomescape/service/ReservationService.java +++ b/src/main/java/roomescape/service/ReservationService.java @@ -5,8 +5,8 @@ public interface ReservationService { - Reservation findById(Integer id); + Reservation findById(Long id); List findAll(); Reservation create(final Reservation reservation); - Reservation delete(final Integer id); + Reservation delete(final Long id); } diff --git a/src/main/java/roomescape/service/ReservationServiceImpl.java b/src/main/java/roomescape/service/ReservationServiceImpl.java index 9a6cf1e88..d0b528a35 100644 --- a/src/main/java/roomescape/service/ReservationServiceImpl.java +++ b/src/main/java/roomescape/service/ReservationServiceImpl.java @@ -3,14 +3,21 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; +import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import roomescape.dao.ReservationDao; import roomescape.domain.Reservation; import roomescape.handler.exception.UserException; @Service +@RequiredArgsConstructor public class ReservationServiceImpl implements ReservationService { - static AtomicInteger index = new AtomicInteger(0); + private final ReservationDao reservationDao; + + static AtomicLong index = new AtomicLong(0); private final List reservations = new ArrayList<>(); @Override @@ -23,14 +30,15 @@ public Reservation create(Reservation reservation) { } @Override - public Reservation findById(Integer id) { - return reservations.stream() - .filter(reservation -> reservation.getId().equals(id)).findFirst() + public Reservation findById(Long id) { + + return reservationDao.findById(id) .orElseThrow(() -> new UserException("해당되는 예약을 찾을 수 없습니다")); + } @Override - public Reservation delete(Integer id) { + public Reservation delete(Long id) { Reservation reservation = this.findById(id); reservations.remove(reservation); @@ -40,7 +48,7 @@ public Reservation delete(Integer id) { @Override public List findAll() { - return reservations; + return reservationDao.findAll(); } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 000000000..9c90ce4eb --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,7 @@ +spring: + h2: + console: + enabled: true + path: /h2-console + datasource: + url: jdbc:h2:mem:database \ No newline at end of file diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql new file mode 100644 index 000000000..0754a8d8d --- /dev/null +++ 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) +); \ No newline at end of file diff --git a/src/test/java/roomescape/MissionStepTest.java b/src/test/java/roomescape/MissionStepTest.java index 7bbb10f09..a8a3fcd5c 100644 --- a/src/test/java/roomescape/MissionStepTest.java +++ b/src/test/java/roomescape/MissionStepTest.java @@ -1,14 +1,21 @@ package roomescape; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.hamcrest.core.Is.is; import io.restassured.RestAssured; import io.restassured.http.ContentType; +import java.sql.Connection; +import java.sql.SQLException; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.annotation.DirtiesContext; +import roomescape.domain.Reservation; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) @@ -92,4 +99,33 @@ public class MissionStepTest { .then().log().all() .statusCode(400); } + + @Autowired + private JdbcTemplate jdbcTemplate; + + @Test + void 오단계() { + try (Connection connection = jdbcTemplate.getDataSource().getConnection()) { + assertThat(connection).isNotNull(); + assertThat(connection.getCatalog()).isEqualTo("DATABASE"); + assertThat(connection.getMetaData().getTables(null, null, "RESERVATION", null).next()).isTrue(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + + @Test + void 육단계() { + jdbcTemplate.update("INSERT INTO reservation (name, date, time) VALUES (?, ?, ?)", "브라운", "2023-08-05", "15:40"); + + List reservations = RestAssured.given().log().all() + .when().get("/reservations") + .then().log().all() + .statusCode(200).extract() + .jsonPath().getList(".", Reservation.class); + + Integer count = jdbcTemplate.queryForObject("SELECT count(1) from reservation", Integer.class); + + assertThat(reservations.size()).isEqualTo(count); + } } \ No newline at end of file From 83407c64e479167b70d96b0a8b43b4b812b210b0 Mon Sep 17 00:00:00 2001 From: LHC0312 Date: Thu, 7 Nov 2024 07:47:24 +0900 Subject: [PATCH 5/8] =?UTF-8?q?feat:=20=EC=B9=A0=EB=8B=A8=EA=B3=84=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 + .../controller/ReservationController.java | 2 +- .../converter/ReservationConverter.java | 19 +++-- .../java/roomescape/dao/ReservationDao.java | 71 +++++++++++++++++++ .../java/roomescape/domain/Reservation.java | 9 ++- .../dto/ReservationResponseDto.java | 2 +- .../java/roomescape/handler/ErrorHandler.java | 3 +- .../service/ReservationService.java | 4 +- .../service/ReservationServiceImpl.java | 26 ++++--- src/main/resources/application.properties | 0 src/main/resources/application.yml | 7 ++ src/main/resources/schema.sql | 8 +++ src/test/java/roomescape/MissionStepTest.java | 63 ++++++++++++++++ 13 files changed, 191 insertions(+), 25 deletions(-) create mode 100644 src/main/java/roomescape/dao/ReservationDao.java delete mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/application.yml create mode 100644 src/main/resources/schema.sql diff --git a/build.gradle b/build.gradle index 17e54d6c8..fa561bfa7 100644 --- a/build.gradle +++ b/build.gradle @@ -15,6 +15,8 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-validation' + implementation 'org.springframework.boot:spring-boot-starter-jdbc' + runtimeOnly 'com.h2database:h2' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' diff --git a/src/main/java/roomescape/controller/ReservationController.java b/src/main/java/roomescape/controller/ReservationController.java index fb02fba53..32c453d70 100644 --- a/src/main/java/roomescape/controller/ReservationController.java +++ b/src/main/java/roomescape/controller/ReservationController.java @@ -49,7 +49,7 @@ public ResponseEntity createReservation (@RequestBody @Valid ReservationReqeu } @DeleteMapping("/reservations/{id}") - public ResponseEntity createReservation (@PathVariable Integer id) { + public ResponseEntity createReservation (@PathVariable Long id) { Reservation reservation = reservationService.delete(id); return ResponseEntity.noContent().build(); diff --git a/src/main/java/roomescape/converter/ReservationConverter.java b/src/main/java/roomescape/converter/ReservationConverter.java index 4d049cc16..c7bf8ed8d 100644 --- a/src/main/java/roomescape/converter/ReservationConverter.java +++ b/src/main/java/roomescape/converter/ReservationConverter.java @@ -1,6 +1,8 @@ package roomescape.converter; +import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.List; import java.util.stream.Collectors; @@ -13,13 +15,14 @@ public class ReservationConverter { public static ReservationResponseDto.ResponseDto toResponseDto(Reservation reservation) { - LocalDateTime dateTime = reservation.getDateTime(); + LocalDate date = reservation.getDate(); + LocalTime time = reservation.getTime(); return ReservationResponseDto.ResponseDto.builder() .id(reservation.getId()) .name(reservation.getName()) - .date(dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) - .time(dateTime.format(DateTimeFormatter.ofPattern("HH:mm"))) + .date(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) + .time(time.format(DateTimeFormatter.ofPattern("HH:mm"))) .build(); } @@ -31,12 +34,16 @@ public static List toResponseDto(List rowMapper = (resultSet, rowNum) -> { + + + return Reservation.builder() + .id(resultSet.getLong("id")) + .name(resultSet.getString("name")) + .date(resultSet.getDate("date").toLocalDate()) + .time(resultSet.getTime("time").toLocalTime()) + .build(); + }; + + public ReservationDao(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } + + public Optional findById(Long id) { + return jdbcTemplate.query( + "select id, name, date, time from reservation where id = ?", rowMapper, id + ).stream().findFirst(); + } + + public List findAll() { + return jdbcTemplate.query( + "select id, name, date, time from reservation", rowMapper + ); + } + + public Reservation save(Reservation reservation) { + KeyHolder keyHolder = new GeneratedKeyHolder(); + + jdbcTemplate.update(connection -> { + PreparedStatement ps = connection.prepareStatement( + "INSERT INTO reservation (name, date, time) values (?, ?, ?)", + new String[]{"id"} + ); + ps.setString(1, reservation.getName()); + ps.setString(2, reservation.getDate().toString()); + ps.setString(3, reservation.getTime().toString()); + return ps; + }, keyHolder); + Long id = keyHolder.getKey().longValue(); + reservation.generateId(id); + + return reservation; + } + + public void remove(Reservation reservation) { + jdbcTemplate.update( + "delete from reservation where id = ?", reservation.getId() + ); + } + +} \ No newline at end of file diff --git a/src/main/java/roomescape/domain/Reservation.java b/src/main/java/roomescape/domain/Reservation.java index e8709430f..34518a2d0 100644 --- a/src/main/java/roomescape/domain/Reservation.java +++ b/src/main/java/roomescape/domain/Reservation.java @@ -1,6 +1,8 @@ package roomescape.domain; +import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.LocalTime; import lombok.Builder; import lombok.Getter; @@ -9,11 +11,12 @@ @Getter public class Reservation { - private Integer id; + private Long id; private String name; - private LocalDateTime dateTime; + private LocalDate date; + private LocalTime time; - public void generateId(Integer id) { + public void generateId(Long id) { this.id = id; } } diff --git a/src/main/java/roomescape/dto/ReservationResponseDto.java b/src/main/java/roomescape/dto/ReservationResponseDto.java index cb8418a66..8a3049365 100644 --- a/src/main/java/roomescape/dto/ReservationResponseDto.java +++ b/src/main/java/roomescape/dto/ReservationResponseDto.java @@ -14,7 +14,7 @@ public class ReservationResponseDto { @AllArgsConstructor public static class ResponseDto { - private Integer id; + private Long id; private String name; private String date; private String time; diff --git a/src/main/java/roomescape/handler/ErrorHandler.java b/src/main/java/roomescape/handler/ErrorHandler.java index 6beb16e8c..fd1cf7a75 100644 --- a/src/main/java/roomescape/handler/ErrorHandler.java +++ b/src/main/java/roomescape/handler/ErrorHandler.java @@ -6,7 +6,8 @@ import roomescape.handler.exception.UserException;; @ControllerAdvice -public class ErrorHandler { +public class +ErrorHandler { @ExceptionHandler(UserException.class) public ResponseEntity handleException(UserException e) { diff --git a/src/main/java/roomescape/service/ReservationService.java b/src/main/java/roomescape/service/ReservationService.java index d18b26519..9f0eec371 100644 --- a/src/main/java/roomescape/service/ReservationService.java +++ b/src/main/java/roomescape/service/ReservationService.java @@ -5,8 +5,8 @@ public interface ReservationService { - Reservation findById(Integer id); + Reservation findById(Long id); List findAll(); Reservation create(final Reservation reservation); - Reservation delete(final Integer id); + Reservation delete(final Long id); } diff --git a/src/main/java/roomescape/service/ReservationServiceImpl.java b/src/main/java/roomescape/service/ReservationServiceImpl.java index 9a6cf1e88..459bbe271 100644 --- a/src/main/java/roomescape/service/ReservationServiceImpl.java +++ b/src/main/java/roomescape/service/ReservationServiceImpl.java @@ -3,44 +3,48 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; +import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import roomescape.dao.ReservationDao; import roomescape.domain.Reservation; import roomescape.handler.exception.UserException; @Service +@RequiredArgsConstructor public class ReservationServiceImpl implements ReservationService { - static AtomicInteger index = new AtomicInteger(0); + private final ReservationDao reservationDao; + private final List reservations = new ArrayList<>(); @Override public Reservation create(Reservation reservation) { - reservation.generateId(index.incrementAndGet()); - reservations.add(reservation); - - return reservation; + return reservationDao.save(reservation); } @Override - public Reservation findById(Integer id) { - return reservations.stream() - .filter(reservation -> reservation.getId().equals(id)).findFirst() + public Reservation findById(Long id) { + + return reservationDao.findById(id) .orElseThrow(() -> new UserException("해당되는 예약을 찾을 수 없습니다")); + } @Override - public Reservation delete(Integer id) { + public Reservation delete(Long id) { Reservation reservation = this.findById(id); - reservations.remove(reservation); + reservationDao.remove(reservation); return reservation; } @Override public List findAll() { - return reservations; + return reservationDao.findAll(); } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 000000000..1268ff0a2 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,7 @@ +spring: + h2: + console: + enabled: true + path: /h2-console + datasource: + url: jdbc:h2:mem \ No newline at end of file diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql new file mode 100644 index 000000000..0754a8d8d --- /dev/null +++ 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) +); \ No newline at end of file diff --git a/src/test/java/roomescape/MissionStepTest.java b/src/test/java/roomescape/MissionStepTest.java index 7bbb10f09..d8e53ab51 100644 --- a/src/test/java/roomescape/MissionStepTest.java +++ b/src/test/java/roomescape/MissionStepTest.java @@ -1,14 +1,21 @@ package roomescape; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.hamcrest.core.Is.is; import io.restassured.RestAssured; import io.restassured.http.ContentType; +import java.sql.Connection; +import java.sql.SQLException; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.annotation.DirtiesContext; +import roomescape.domain.Reservation; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) @@ -92,4 +99,60 @@ public class MissionStepTest { .then().log().all() .statusCode(400); } + + @Autowired + private JdbcTemplate jdbcTemplate; + + @Test + void 오단계() { + try (Connection connection = jdbcTemplate.getDataSource().getConnection()) { + assertThat(connection).isNotNull(); + assertThat(connection.getCatalog()).isEqualTo("DATABASE"); + assertThat(connection.getMetaData().getTables(null, null, "RESERVATION", null).next()).isTrue(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + + @Test + void 육단계() { + jdbcTemplate.update("INSERT INTO reservation (name, date, time) VALUES (?, ?, ?)", "브라운", "2023-08-05", "15:40"); + + List reservations = RestAssured.given().log().all() + .when().get("/reservations") + .then().log().all() + .statusCode(200).extract() + .jsonPath().getList(".", Reservation.class); + + Integer count = jdbcTemplate.queryForObject("SELECT count(1) from reservation", Integer.class); + + assertThat(reservations.size()).isEqualTo(count); + } + + @Test + void 칠단계() { + Map params = new HashMap<>(); + params.put("name", "브라운"); + params.put("date", "2023-08-05"); + params.put("time", "10:00"); + + RestAssured.given().log().all() + .contentType(ContentType.JSON) + .body(params) + .when().post("/reservations") + .then().log().all() + .statusCode(201) + .header("Location", "/reservations/1"); + + Integer count = jdbcTemplate.queryForObject("SELECT count(1) from reservation", Integer.class); + assertThat(count).isEqualTo(1); + + RestAssured.given().log().all() + .when().delete("/reservations/1") + .then().log().all() + .statusCode(204); + + Integer countAfterDelete = jdbcTemplate.queryForObject("SELECT count(1) from reservation", Integer.class); + assertThat(countAfterDelete).isEqualTo(0); + } } \ No newline at end of file From b240cc9a17070975a7c5ebd6ec283270801c29a9 Mon Sep 17 00:00:00 2001 From: LHC0312 Date: Thu, 7 Nov 2024 15:56:48 +0900 Subject: [PATCH 6/8] =?UTF-8?q?feat:=20=ED=8C=94=EB=8B=A8=EA=B3=84=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../roomescape/Controller/TimeController.java | 48 ++++++++++++++ .../roomescape/converter/TimeConverter.java | 33 ++++++++++ src/main/java/roomescape/dao/TimeDao.java | 66 +++++++++++++++++++ src/main/java/roomescape/domain/Time.java | 16 +++++ .../java/roomescape/dto/TimeRequestDto.java | 11 ++++ .../java/roomescape/dto/TimeResponseDto.java | 18 +++++ .../java/roomescape/handler/ErrorHandler.java | 12 +++- .../exception/ReservationException.java | 7 ++ .../handler/exception/TimeException.java | 7 ++ .../handler/exception/UserException.java | 7 -- .../service/ReservationServiceImpl.java | 7 +- .../java/roomescape/service/TimeService.java | 12 ++++ .../roomescape/service/TimeServiceImpl.java | 49 ++++++++++++++ src/main/resources/application.yml | 2 +- src/main/resources/schema.sql | 7 ++ src/test/java/roomescape/MissionStepTest.java | 25 +++++++ 16 files changed, 311 insertions(+), 16 deletions(-) create mode 100644 src/main/java/roomescape/Controller/TimeController.java create mode 100644 src/main/java/roomescape/converter/TimeConverter.java create mode 100644 src/main/java/roomescape/dao/TimeDao.java create mode 100644 src/main/java/roomescape/domain/Time.java create mode 100644 src/main/java/roomescape/dto/TimeRequestDto.java create mode 100644 src/main/java/roomescape/dto/TimeResponseDto.java create mode 100644 src/main/java/roomescape/handler/exception/ReservationException.java create mode 100644 src/main/java/roomescape/handler/exception/TimeException.java delete mode 100644 src/main/java/roomescape/handler/exception/UserException.java create mode 100644 src/main/java/roomescape/service/TimeService.java create mode 100644 src/main/java/roomescape/service/TimeServiceImpl.java diff --git a/src/main/java/roomescape/Controller/TimeController.java b/src/main/java/roomescape/Controller/TimeController.java new file mode 100644 index 000000000..5f14b721b --- /dev/null +++ b/src/main/java/roomescape/Controller/TimeController.java @@ -0,0 +1,48 @@ +package roomescape.controller; + +import java.net.URI; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +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 roomescape.converter.TimeConverter; +import roomescape.domain.Time; +import roomescape.dto.TimeRequestDto; +import roomescape.dto.TimeResponseDto; +import roomescape.dto.TimeResponseDto.ResponseDto; +import roomescape.service.TimeService; + +@RequiredArgsConstructor +@Controller +public class TimeController { + + private final TimeService timeService; + + @GetMapping("/times") + public ResponseEntity> getTimes() { + List