Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 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
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
34 changes: 34 additions & 0 deletions src/main/java/roomescape/controller/ReservationController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package roomescape.controller;

import org.springframework.http.ResponseEntity;
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.dto.Reservation;

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

@Controller
public class ReservationController {

Reservation reservation1=new Reservation(1L,"브라운","2023-01-01","10:00");
Reservation reservation2=new Reservation(2L,"브라운","2023-01-02","11:00");
private List<Reservation> reservations = new ArrayList<>(Arrays.asList(reservation1,reservation2));

@GetMapping("/reservation")
public String reservation(Model model){

model.addAttribute(reservations);
return "reservation";
}

@GetMapping("/reservations")
@ResponseBody
public List<Reservation> reservations(){

return 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";
}




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