-
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?
Conversation
🌱<인사>안녕하세요, 현진님 🙂 ❓<질문에 대한 답>(현진) 테스트 코드 2단계 is메소드의 의존성을 못 찾겠어요.-> import static org.hamcrest.Matchers.is;보통 assertThat() 메서드와 함께 사용되며, |
| package roomescape.model; | ||
|
|
||
| public class Reservation { | ||
|
|
||
| private String name; | ||
| private String date; | ||
| private String time; | ||
|
|
||
| public Reservation() { | ||
| } | ||
|
|
||
| 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; | ||
| } | ||
|
|
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.
DTO를 도입해서 도메인 객체(Reservation)와 API 요청/응답 데이터를 분리하는 게 어떨까요?
아직은 예약 조회 기능만 있어서 사실 record를 사용하라고 조언해드리고 싶습니다.
하지만 이후에 예약 수정이나 삭제 기능이 추가될 예정이라면 record 형태의 DTO와 도메인 객체를 함께 두는 게 나을 거 같네요.
현재처럼 Reservation을 엔티티로 두면 해당 객체가 그대로 외부에 노출되기 때문에, 데이터 보안 측면에서 위험할 거 같아요.
| public 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.
현재 쓰이고 있지 않는 생성자인 거 같은 데 왜 넣어두셨는 지 여쭤봐도 될까요?
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public String getDate() { | ||
| return date; | ||
| } | ||
|
|
||
| public String getTime() { | ||
| return time; | ||
| } |
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.
객체를 만들면서 습관적으로 getter도 함께 추가하신 게 아닐까 추측해봅니다.
개인적으로는 사용하지 않는 메서드는 제거하는 편이 더 좋다고 생각해요.
| @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 comment
The reason will be displayed to describe this comment to others. Learn more.
이렇게 현재 ReservationController 내부에서 List를 직접 관리했을 때 생길 수 있는 문제는 어떤 것들이 있을까요?
키워드 : 동시성 문제, 데이터 영속성
(아직 데이터베이스가 없기도 하고, 예약 데이터 관리 예시 코드가 이렇게 주어져서 이렇게 코드 짜신 거 알고 있습니다.)
| @GetMapping("/reservation") | ||
| public String reservation() | ||
| { | ||
| return "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.
| public class ReservationController { | ||
| private final List<Reservation> reservations = new ArrayList<>(); | ||
|
|
||
| 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; | ||
| } | ||
| } |
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.
ReservationController가 직접 데이터를 관리하고 있네요.
지금 당장은 단순해서 필요없긴 한데, 데이터를 다루는 부분은 Service 레이어로 분리해두면 이후 기능 확장이나 DB 연동 시 훨씬 유연하게 유지보수할 수 있을 거예요.
기능이 얼마 없을 때, 미리 한 번 나누어 볼까요?
|
미션 정말 잘 진행해주셨네요 🙂 |

안녕하세요! 혜빈님 처음 리뷰 받게 되었습니다. 잘 부탁드립니다!!
AdminController클래스home: 웹사이트의 메인 페이지(/)로 접속하면(GET), home.html 템플릿 파일을 찾아 렌더링하여 반환하라는 코드입니다.reservation: reservation.html 페이지를 보여주는 컨트롤러와, 임의의 예약 목록(JSON)을 반환하는 API 컨트롤러를 각각 구현한 코드입니다.ReservationController클래스: 서버 시작 시 '브라운'과 '코니'라는 임시 예약 2건을 미리 생성해두고, GET /reservations API 요청이 오면 이 목록 전체를 JSON으로 반환하는 코드입니다.궁금한 점