Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.rest-assured:rest-assured:5.3.1'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
}

test {
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/roomescape/controller/ReservationController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package roomescape.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import roomescape.dto.Reservation;

import java.util.ArrayList;
import java.util.List;

@Controller
public class ReservationController {

private List<Reservation> reservations = new ArrayList<>();

@GetMapping("/reservation")
public String reservation(){
return "/reservation.html";
Copy link

Choose a reason for hiding this comment

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

뷰 이름만 사용하셔도 됩니다! return "reservation" 하셔도 자동으로 templates/reservation.html을 찾아서 렌더링할 거예요.

Copy link

Choose a reason for hiding this comment

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

그리고 지금 Model 에 데이터가 없어요. 리스트를 담아서 전달해야 합니다~

}

@GetMapping("/reservations")
public ResponseEntity<List<Reservation>> reservations(){
Copy link

Choose a reason for hiding this comment

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

ResponseEntity 를 사용하셨군요! 좋아요. 하지만 우리 학습 키워드 중 하나가 @ResponseBody 인 만큼 이것을 사용해보는 건 어떨까요?


Reservation reservation1=new Reservation(1L,"브라운","2023-01-01","10:00");
reservations.add(reservation1);

return ResponseEntity.ok(reservations);

}
}
18 changes: 18 additions & 0 deletions src/main/java/roomescape/controller/StartController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package roomescape.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class StartController {

@GetMapping("/")
public String home(){
return "/home.html";
}




}
20 changes: 20 additions & 0 deletions src/main/java/roomescape/dto/Reservation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package roomescape.dto;

import java.sql.Date;
import java.sql.Time;
import java.time.LocalDate;
import java.time.LocalTime;

public class Reservation {
public Long id;
Copy link

Choose a reason for hiding this comment

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

제가 놓쳤네요! 필드의 접근 지정자를 무엇으로 설정해야 할까요? public vs private 에 대해 공부해보면 좋을 것 같습니다.

public String name;
public String date; //우선 String으로.. 차후 Date로 형변환 필요하면 교체..
public String time; //동일!!

public Reservation(Long id,String name,String date,String time){
this.id=id;
this.name=name;
this.date=date;
this.time=time;
}
}
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);
}

@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(1)); // 아직 생성 요청이 없으니 Controller에서 임의로 넣어준 Reservation 갯수(=1) 만큼 검증.
}
}