diff --git a/build.gradle b/build.gradle index 57267157c..35d9c0b27 100644 --- a/build.gradle +++ b/build.gradle @@ -14,8 +14,11 @@ 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' + } test { diff --git a/src/main/java/roomescape/RoomescapeController.java b/src/main/java/roomescape/RoomescapeController.java new file mode 100644 index 000000000..35aed308e --- /dev/null +++ b/src/main/java/roomescape/RoomescapeController.java @@ -0,0 +1,12 @@ +package roomescape; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class RoomescapeController { + @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..42e2e7d05 --- /dev/null +++ b/src/main/java/roomescape/controller/ReservationController.java @@ -0,0 +1,41 @@ +package roomescape.controller; + +import java.util.ArrayList; +import java.util.List; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import roomescape.model.Reservation; + +@Controller +public class ReservationController { + private List reservations = new ArrayList<>(); + + @GetMapping("/reservation") + public String reservation() { + return "reservation"; + } + + @GetMapping("/reservations") + @ResponseBody + public String getReservation(Model model) { + reservations.add(new Reservation( + 1L, + "브라운", + "2023-01-01", + "10:00" + )); + + reservations.add(new Reservation( + 2L, + "브라운", + "2023-01-02", + "11:00" + )); + + model.addAttribute("reservations", reservations); + + return "reservation"; + } +} diff --git a/src/main/java/roomescape/model/Reservation.java b/src/main/java/roomescape/model/Reservation.java new file mode 100644 index 000000000..b08b3b2a2 --- /dev/null +++ b/src/main/java/roomescape/model/Reservation.java @@ -0,0 +1,31 @@ +package roomescape.model; + +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 Long getId() { + return id; + } + + public String getName() { + return name; + } + + public String getDate() { + return date; + } + + public String getTime() { + return time; + } +} diff --git a/src/test/java/roomescape/MissionStepTest.java b/src/test/java/roomescape/MissionStepTest.java index cf4efbe91..eab679100 100644 --- a/src/test/java/roomescape/MissionStepTest.java +++ b/src/test/java/roomescape/MissionStepTest.java @@ -4,6 +4,7 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; +import static org.hamcrest.Matchers.is; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) @@ -16,4 +17,18 @@ 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개임을 확인하세요. + } }