Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/roomescape/HomeController.java
Original file line number Diff line number Diff line change
@@ -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";
}
}
31 changes: 31 additions & 0 deletions src/main/java/roomescape/Reservation.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
31 changes: 31 additions & 0 deletions src/main/java/roomescape/ReservationController.java
Original file line number Diff line number Diff line change
@@ -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<Reservation> reservations = new ArrayList<>();

public ReservationController() {
reservations.add(new Reservation(1L, "브라운", "2023-01-01", "10:00"));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add()로 초기 데이터를 넣으면 리스트가 mutable 상태가 됩니다.
테스트용 고정 데이터라면 List.of()로 불변 리스트로 선언해도 좋을 것 같아요. 선택은 자유입니다. 혹시 가변 리스트 생성을 한 특별한 이유가 있을까요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 감사합니다! 특별한 이유는 따로 없고, List.of()으로 쓰는 것을 생각하지 못했습니다..ㅎㅎ 개인적으로 ArrayList가 제일 익숙하기도 하고 직전에 컨트롤러 CRUD 실습을 했어서 ArrayList로 그냥 자연스럽게 썼던 것 같아요. 다음에는 이런 부분도 더 신경 써보겠습니다!!

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<Reservation> getReservations() {
return reservations;
}

}
16 changes: 16 additions & 0 deletions src/test/java/roomescape/MissionStepTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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개 확인
}
}