-
Notifications
You must be signed in to change notification settings - Fork 170
[Spring MVC] 서현진 미션 제출합니다 #511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: nonactress
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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"; | ||
| } | ||
| } | ||
| 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<>(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ReservationController가 직접 데이터를 관리하고 있네요. 기능이 얼마 없을 때, 미리 한 번 나누어 볼까요? |
||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 객체를 만들면서 습관적으로 getter도 함께 추가하신 게 아닐까 추측해봅니다. |
||
|
|
||
|
Comment on lines
+1
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DTO를 도입해서 도메인 객체(Reservation)와 API 요청/응답 데이터를 분리하는 게 어떨까요? 아직은 예약 조회 기능만 있어서 사실 record를 사용하라고 조언해드리고 싶습니다. 현재처럼 Reservation을 엔티티로 두면 해당 객체가 그대로 외부에 노출되기 때문에, 데이터 보안 측면에서 위험할 거 같아요. |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.