Skip to content

Commit ad9fc14

Browse files
committed
feat: 홈 화면 생성, 예약 조회
- Gradle 수정 - HomeController, ReservationController 생성 - Reservation dto 생성
1 parent 13c25ff commit ad9fc14

File tree

5 files changed

+101
-0
lines changed

5 files changed

+101
-0
lines changed

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ dependencies {
1616
implementation 'org.springframework.boot:spring-boot-starter'
1717
testImplementation 'org.springframework.boot:spring-boot-starter-test'
1818
testImplementation 'io.rest-assured:rest-assured:5.3.1'
19+
20+
implementation 'org.springframework.boot:spring-boot-starter-web'
21+
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
1922
}
2023

2124
test {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package roomescape.controller;
2+
3+
import org.springframework.stereotype.Controller;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
6+
@Controller
7+
public class HomeController {
8+
9+
@RequestMapping("/")
10+
public String home(){
11+
return "home";
12+
}
13+
14+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package roomescape.controller;
2+
3+
import org.springframework.stereotype.Controller;
4+
import org.springframework.web.bind.annotation.GetMapping;
5+
import org.springframework.web.bind.annotation.RequestBody;
6+
import org.springframework.web.bind.annotation.RequestMapping;
7+
import org.springframework.web.bind.annotation.ResponseBody;
8+
import roomescape.dto.Reservation;
9+
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
import java.util.concurrent.atomic.AtomicLong;
13+
14+
@Controller
15+
public class ReservationController {
16+
17+
private List<Reservation> reservations = new ArrayList<>();
18+
private AtomicLong index = new AtomicLong(1);
19+
20+
public ReservationController() {
21+
reservations.add(new Reservation(1L, "브라운", "2023-01-01", "10:00"));
22+
reservations.add(new Reservation(2L, "브라운", "2023-01-02", "11:00"));
23+
reservations.add(new Reservation(3L, "브라운", "2023-01-03", "12:00"));
24+
}
25+
26+
@GetMapping("/reservation")
27+
public String reservationPage(){
28+
return "reservation";
29+
}
30+
31+
@ResponseBody
32+
@GetMapping("/reservations")
33+
public List<Reservation> reservationList(){
34+
return reservations;
35+
}
36+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package roomescape.dto;
2+
3+
public class Reservation {
4+
5+
private Long id;
6+
private String name;
7+
private String date;
8+
private String time;
9+
10+
public Reservation(Long id, String name, String date, String time) {
11+
this.id = id;
12+
this.name = name;
13+
this.date = date;
14+
this.time = time;
15+
}
16+
17+
public Long getId() {
18+
return id;
19+
}
20+
21+
public String getName() {
22+
return name;
23+
}
24+
25+
public String getDate() {
26+
return date;
27+
}
28+
29+
public String getTime() {
30+
return time;
31+
}
32+
}

src/test/java/roomescape/MissionStepTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.junit.jupiter.api.Test;
55
import org.springframework.boot.test.context.SpringBootTest;
66
import org.springframework.test.annotation.DirtiesContext;
7+
import static org.hamcrest.Matchers.is;
78

89
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
910
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
@@ -16,4 +17,19 @@ public class MissionStepTest {
1617
.then().log().all()
1718
.statusCode(200);
1819
}
20+
21+
@Test
22+
void 이단계() {
23+
RestAssured.given().log().all()
24+
.when().get("/reservation")
25+
.then().log().all()
26+
.statusCode(200);
27+
28+
RestAssured.given().log().all()
29+
.when().get("/reservations")
30+
.then().log().all()
31+
.statusCode(200)
32+
.body("size()", is(3)); // 아직 생성 요청이 없으니 Controller에서 임의로 넣어준 Reservation 갯수 만큼 검증하거나 0개임을 확인하세요.
33+
}
34+
1935
}

0 commit comments

Comments
 (0)