diff --git a/build.gradle b/build.gradle index 57267157c..f2c2b382b 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,9 @@ 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/HomeController.java b/src/main/java/roomescape/HomeController.java new file mode 100644 index 000000000..525b60949 --- /dev/null +++ b/src/main/java/roomescape/HomeController.java @@ -0,0 +1,15 @@ +// 어드민 페이지 home.html 반환 +package roomescape; + +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/Reservation.java b/src/main/java/roomescape/Reservation.java new file mode 100644 index 000000000..7a9aacc3c --- /dev/null +++ b/src/main/java/roomescape/Reservation.java @@ -0,0 +1,31 @@ +package roomescape; + +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/main/java/roomescape/ReservationController.java b/src/main/java/roomescape/ReservationController.java new file mode 100644 index 000000000..84c85d025 --- /dev/null +++ b/src/main/java/roomescape/ReservationController.java @@ -0,0 +1,31 @@ +package roomescape; + +import java.util.*; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +public class ReservationController { + + private List reservations = new ArrayList<>(); + + public ReservationController() { + reservations.add(new Reservation(1L, "브라운", "2023-01-01", "10:00")); + reservations.add(new Reservation(2L, "브라운", "2023-01-02", "11:00")); + } + + // /reservation 요청 시 html 응답 + @GetMapping("/reservation") + public String reservation() { + return "reservation"; + } + + // /reservations 예약 목록 조회 요청 처리 + @GetMapping("/reservations") + @ResponseBody + public List getReservations() { + return reservations; + } + +} diff --git a/src/test/java/roomescape/MissionStepTest.java b/src/test/java/roomescape/MissionStepTest.java index cf4efbe91..b4d6424d0 100644 --- a/src/test/java/roomescape/MissionStepTest.java +++ b/src/test/java/roomescape/MissionStepTest.java @@ -5,6 +5,8 @@ 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) public class MissionStepTest { @@ -16,4 +18,18 @@ public class MissionStepTest { .then().log().all() .statusCode(200); } + + // 요구사항 테스트 + 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개임을 확인하세요. -> 2개 확인 + } }