-
Notifications
You must be signed in to change notification settings - Fork 170
[Spring MVC] 서현진 3,4단게 미션제출합니다. #519
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4ea6d0e
feat : 1,2단계 미션 제출
c713260
feat : 1,2단계 미션 제출 및 테스트 코드 수정
460e494
feat : is() 메소드를 위한 import문 추가
c97ea81
refactor : record 적용
d6c310c
feat : service 계층 생성
dcdb9f1
feat : 3단계 제출
a493121
feat : 4단계 제출
f9935e5
fix(dto) : local date, local time 으로 변경
08145b9
feat(repository) : 레포지토리 구현 및 계층 구현
b7fd4b7
Merge branch 'nonactress' into nonactress
nonactress b3d2c0b
fix : 개행 정리
1ea9e34
Merge branch 'nonactress' of https://github.com/nonactress/spring-roo…
2bc21d8
fix : 개행 정리
2a5c805
refactor : 레포지토리를 서비스에 연결
20d0881
delete : 안쓰는 dto 삭제
b6887e0
refactor : localtime,date를 위한 dto 변환
675e113
refactor : localtime,date를 위한 레포지토리 변환
9934f11
refactor : localtime,date를 위한 어노테이션 변경(notBlank->notNull)
9b0add5
refactor : 개형정리
1422774
refactor : 개형정리2
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| ### 컨트롤러 (Controller) | ||
| - `AdminController`: `@Controller`를 사용하여 웹 페이지를 반환합니다. 사용자가 특정 경로로 접속했을 때, 해당하는 HTML 파일을 렌더링하여 보여줍니다. | ||
| - `/`: `home.html` (홈 페이지) | ||
| - `/reservation`: `reservation.html` (예약 관리 페이지) | ||
| - `ReservationController`: `@RestController`를 사용하여 RESTful API를 제공합니다. HTTP 요청을 받아 `ReservationService`를 호출하고, 그 결과를 JSON 형태로 반환합니다. | ||
| - `GET /reservations`: 모든 예약 목록을 조회합니다. | ||
| - `POST /reservations`: 새로운 예약을 생성합니다. | ||
| - `DELETE /reservations/{id}`: 특정 예약을 삭제합니다. | ||
|
|
||
| ### 서비스 (Service) | ||
| - `ReservationService`: 핵심 비즈니스 로직을 담당합니다. | ||
| - 예약 데이터를 `List<Reservation>` 형태로 메모리에 저장하고 관리합니다. | ||
| - `AtomicLong`을 사용하여 예약 ID를 순차적으로 생성합니다. | ||
| - 주요 메서드: | ||
| - `getAllReservations()`: 전체 예약 목록을 반환합니다. | ||
| - `addReservation()`: 새로운 예약을 리스트에 추가하고, 생성된 예약 객체를 반환합니다. | ||
| - `deleteReservation()`: ID를 기준으로 예약을 찾아 리스트에서 삭제합니다. 존재하지 않는 ID일 경우 `IllegalArgumentException`을 발생시킵니다. | ||
|
|
||
| ## 📝 API 엔드포인트 | ||
|
|
||
| | Method | URL | 설명 | | ||
| | --- | --- | --- | | ||
| | `GET` | `/reservations` | 모든 예약을 조회합니다. | | ||
| | `POST` | `/reservations` | 새로운 예약을 생성합니다. | | ||
| | `DELETE` | `/reservations/{id}` | 특정 ID의 예약을 삭제합니다. | | ||
|
|
||
| ### `POST /reservations` 요청 예시 | ||
|
|
||
| **Request Body:** | ||
| ```json | ||
| { | ||
| "name": "woowahan", | ||
| "date": "2025-11-13", | ||
| "time": "14:00" | ||
| } | ||
| ``` | ||
|
|
||
| **Response (201 Created):** | ||
| ```json | ||
| { | ||
| "id": 1, | ||
| "name": "woowahan", | ||
| "date": "2025-11-13", | ||
| "time": "14:00" | ||
| } | ||
| ``` | ||
|
|
||
| ## 📄 페이지 | ||
|
|
||
| - **홈**: `http://localhost:8080/` | ||
| - **예약 관리**: `http://localhost:8080/reservation` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 17 additions & 5 deletions
22
src/main/java/roomescape/dto/ReservationCreateRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,30 @@ | ||
| package roomescape.dto; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonFormat; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import roomescape.model.Reservation; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.LocalTime; | ||
|
|
||
|
|
||
| public record ReservationCreateRequest( | ||
|
|
||
| @NotBlank(message = "이름은 필수 항목입니다.") | ||
| String name, | ||
|
|
||
| @NotBlank(message = "날짜는 필수 항목입니다.") | ||
| String date, | ||
| @NotNull(message = "날짜는 필수 항목입니다.") | ||
| @JsonFormat(pattern = "yyyy-MM-dd") | ||
| LocalDate date, | ||
|
|
||
| @NotBlank(message = "시간은 필수 항목입니다.") | ||
| String time | ||
| @NotNull(message = "시간은 필수 항목입니다.") | ||
| @JsonFormat(pattern = "HH:mm") | ||
| LocalTime time | ||
| ) { | ||
|
|
||
| public Reservation toEntity() { | ||
| return new Reservation(name, date, time); | ||
| } | ||
| } | ||
|
|
||
|
|
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,23 @@ | ||
| package roomescape.dto; | ||
|
|
||
| import roomescape.model.Reservation; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.LocalTime; | ||
|
|
||
| public record ReservationResponse( | ||
| long id, | ||
| String name, | ||
| String date, | ||
| String time | ||
| ) | ||
| { | ||
| public static ReservationResponse from(Reservation reservation) { | ||
| return new ReservationResponse( | ||
| reservation.getId(), | ||
| reservation.getName(), | ||
| reservation.getDate(), | ||
| reservation.getTime() | ||
| ); | ||
| } | ||
| long id, | ||
| String name, | ||
| LocalDate date, | ||
| LocalTime time | ||
| ) { | ||
| public static ReservationResponse from(Reservation reservation) { | ||
| return new ReservationResponse( | ||
| reservation.getId(), | ||
| reservation.getName(), | ||
| reservation.getDate(), | ||
| reservation.getTime() | ||
| ); | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,37 +1,27 @@ | ||
| package roomescape.model; | ||
|
|
||
| public class Reservation | ||
| { | ||
| Long id; | ||
| String name; | ||
| String date; | ||
| String time; | ||
| import java.time.LocalDate; | ||
| import java.time.LocalTime; | ||
|
|
||
| public class Reservation { | ||
| private Long id; | ||
| private String name; | ||
| private LocalDate date; | ||
| private LocalTime time; | ||
|
|
||
| public Long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public String getDate() { | ||
| return date; | ||
| } | ||
|
|
||
| public String getTime() { | ||
| return time; | ||
| } | ||
|
|
||
| public Reservation(String name, String date, String time) { | ||
| public Reservation(Long id, String name, LocalDate date, LocalTime time) { | ||
| this.id = id; | ||
| this.name = name; | ||
| this.date = date; | ||
| this.time = time; | ||
| } | ||
|
|
||
| public Reservation(Long id, String name, String date, String time) { | ||
| this(name, date, time); | ||
| this.id = id; | ||
| public Reservation(String name, LocalDate date, LocalTime time) { | ||
| this(null, name, date, time); | ||
| } | ||
|
|
||
| public Long getId() { return id; } | ||
| public String getName() { return name; } | ||
| public LocalDate getDate() { return date; } | ||
| public LocalTime getTime() { return time; } | ||
| } |
62 changes: 62 additions & 0 deletions
62
src/main/java/roomescape/repository/ReservationRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package roomescape.repository; | ||
|
|
||
| import org.springframework.stereotype.Repository; | ||
| import roomescape.model.Reservation; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.LocalTime; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.concurrent.atomic.AtomicLong; | ||
|
|
||
| @Repository | ||
| public class ReservationRepository { | ||
|
|
||
| private final List<Reservation> reservations = new ArrayList<>(); | ||
| private final AtomicLong counter = new AtomicLong(); | ||
|
|
||
| public ReservationRepository() { | ||
| this.save(new Reservation( | ||
| null, | ||
| "브라운", | ||
| LocalDate.of(2025, 1, 1), | ||
| LocalTime.of(12, 0) | ||
| )); | ||
|
|
||
| this.save(new Reservation( | ||
| null, | ||
| "코니", | ||
| LocalDate.of(2025, 1, 2), | ||
| LocalTime.of(11, 0) | ||
| )); | ||
| } | ||
|
|
||
| public List<Reservation> findAll() { | ||
| return new ArrayList<>(reservations); | ||
| } | ||
|
|
||
| public Reservation save(Reservation reservation) { | ||
| Reservation savedReservation = new Reservation( | ||
| counter.incrementAndGet(), | ||
| reservation.getName(), | ||
| reservation.getDate(), | ||
| reservation.getTime() | ||
| ); | ||
| reservations.add(savedReservation); | ||
| return savedReservation; | ||
| } | ||
|
|
||
| public boolean existsById(Long id) { | ||
| return reservations.stream() | ||
| .anyMatch(reservation -> reservation.getId().equals(id)); | ||
| } | ||
|
|
||
| public void deleteById(Long id) { | ||
| reservations.removeIf(reservation -> reservation.getId().equals(id)); | ||
| } | ||
|
|
||
| public void clear() { | ||
| reservations.clear(); | ||
| counter.set(0L); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🔥 Request Change
사용이 안되고 있습니다
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.
넵 수정해보겠습니다.
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.
2a5c805