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
16 changes: 15 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,26 @@ group = 'nextstep'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

// build.gradle 파일

// ... (plugins, group, version 등 상단 정보) ...

repositories {
mavenCentral()
}

// 이 'dependencies' 블록 안에 모든 의존성을 관리하세요.
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
// [필수 1] 웹 서버 엔진
implementation 'org.springframework.boot:spring-boot-starter-web'

// [필수 2] 웹 페이지 조립 엔진 (타임리프)
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'

// (참고) 'web' 스타터가 'starter'를 이미 포함하고 있으므로,
// 'spring-boot-starter'는 생략해도 괜찮습니다.

// 테스트에 필요한 의존성
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.rest-assured:rest-assured:5.3.1'
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/roomescape/controller/AdminController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package roomescape.controller;

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

@Controller
public class AdminController {

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

@GetMapping("/reservation")
public String reservation()
{
return "reservation";
}
Comment on lines +14 to +18

Choose a reason for hiding this comment

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

image 사진을 참고하여 이 부분의 Spring MVC 동작과정을 설명해볼까요? 분명히 도움이 될거예요 :)

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

import org.springframework.web.bind.annotation.*;
import roomescape.model.Reservation;

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

@RestController
@RequestMapping("/reservations")
public class ReservationController {
private final List<Reservation> reservations = new ArrayList<>();
Copy link

@c0mpuTurtle c0mpuTurtle Nov 10, 2025

Choose a reason for hiding this comment

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

이렇게 현재 ReservationController 내부에서 List를 직접 관리했을 때 생길 수 있는 문제는 어떤 것들이 있을까요?
키워드 : 동시성 문제, 데이터 영속성

(아직 데이터베이스가 없기도 하고, 예약 데이터 관리 예시 코드가 이렇게 주어져서 이렇게 코드 짜신 거 알고 있습니다.)


public ReservationController() {
reservations.add(new Reservation( "브라운", "2025-01-01", "10:00"));
reservations.add(new Reservation("코니", "2025-01-02", "11:00"));
}

@GetMapping
public List<Reservation> getAllReservations() {
return reservations;
}
}
Comment on lines +11 to +23

Choose a reason for hiding this comment

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

ReservationController가 직접 데이터를 관리하고 있네요.
지금 당장은 단순해서 필요없긴 한데, 데이터를 다루는 부분은 Service 레이어로 분리해두면 이후 기능 확장이나 DB 연동 시 훨씬 유연하게 유지보수할 수 있을 거예요.

기능이 얼마 없을 때, 미리 한 번 나누어 볼까요?

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

public class Reservation {

private String name;
private String date;
private String time;

public Reservation() {
}
Comment on lines +9 to +10

Choose a reason for hiding this comment

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

현재 쓰이고 있지 않는 생성자인 거 같은 데 왜 넣어두셨는 지 여쭤봐도 될까요?


public Reservation(String name, String date, String time) {
this.name = name;
this.date = date;
this.time = time;
}

public String getName() {
return name;
}

public String getDate() {
return date;
}

public String getTime() {
return time;
}
Comment on lines +18 to +28

Choose a reason for hiding this comment

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

객체를 만들면서 습관적으로 getter도 함께 추가하신 게 아닐까 추측해봅니다.
개인적으로는 사용하지 않는 메서드는 제거하는 편이 더 좋다고 생각해요.


Comment on lines +1 to +29

Choose a reason for hiding this comment

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

DTO를 도입해서 도메인 객체(Reservation)와 API 요청/응답 데이터를 분리하는 게 어떨까요?

아직은 예약 조회 기능만 있어서 사실 record를 사용하라고 조언해드리고 싶습니다.
하지만 이후에 예약 수정이나 삭제 기능이 추가될 예정이라면 record 형태의 DTO와 도메인 객체를 함께 두는 게 나을 거 같네요.

현재처럼 Reservation을 엔티티로 두면 해당 객체가 그대로 외부에 노출되기 때문에, 데이터 보안 측면에서 위험할 거 같아요.

}
14 changes: 14 additions & 0 deletions src/test/java/roomescape/MissionStepTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,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)); // 아직 생성 요청이 없으니 Controller에서 임의로 넣어준 Reservation 갯수 만큼 검증하거나 0개임을 확인하세요.
}
}