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
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ 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
13 changes: 13 additions & 0 deletions src/main/java/roomescape/HomeController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package roomescape;

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

@Controller
public class HomeController {

@GetMapping("/")
public String home() {
return "home";
}
}
4 changes: 4 additions & 0 deletions src/main/java/roomescape/Reservation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package roomescape;


public record Reservation(long id, String name, String date, String time) {}
Copy link

Choose a reason for hiding this comment

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

자바엔 long과 Long 타입이 있습니다. 이 글 을 참고하여 둘의 차이점과 각각 어느 때에 쓰이는지 알아보면 좋을 것 같습니다.

Copy link
Author

Choose a reason for hiding this comment

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

자바엔 long과 Long 타입이 있습니다. 이 글 을 참고하여 둘의 차이점과 각각 어느 때에 쓰이는지 알아보면 좋을 것 같습니다.

감사합니다!! 찾아 봤는데 long은 저희가 늘 쓰는 primitive type이라 int의 범위를 초과하는 숫자를 다룰 때 쓰고, Long은 long을 객체 형태로 감싼 wrapper 클래스라서 다양한 메서드(parseLong())등을 사용하고 싶을 때 쓰는것 같습니다.

Copy link

Choose a reason for hiding this comment

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

record 를 사용하셨네요! class 와 record 의 차이점이 무엇인가요? record를 사용하면 장점이 무엇인가요?

Copy link
Author

Choose a reason for hiding this comment

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

class는 저희가 일반적으로 사용하는 data와 operations모두 가질 수 있고, 생성자, getter등은 직접 구현해야되는데 record 같은 경우에는 스프링을 배울 때 처음 알았던 불변 data 저장 할 수 있는 기능인데 생성자, getter등을 자동으로 생성해줘서 더 간결해진다는 장점이 있습니다.

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

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

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

@Controller
public class ReservationController {

// Temporary data
private final List<Reservation> reservations = new ArrayList<>(
List.of(
new Reservation(1L, "브라운", "2023-01-01", "10:00"),
new Reservation(2L, "브라운", "2023-01-02", "11:00"),
new Reservation(3L, "브라운", "2023-01-03", "12:00")
)
);

// render reservation.html
@GetMapping("/reservation")
public String reservationPage() {
return "reservation";
}

// JSON list
@GetMapping("/reservations")
@ResponseBody
public List<Reservation> list() {
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);
}

@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(3));
}
}