-
Notifications
You must be signed in to change notification settings - Fork 132
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
[Spring Core] 박소정 미션 제출합니다. #310
base: sojeong0202
Are you sure you want to change the base?
Changes from all commits
23a4c67
9139729
fd5faac
6b5a08b
63af66a
7ab452d
ea58a57
f6949a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package roomescape.controller; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import roomescape.dto.ReservationResponseDto; | ||
import roomescape.dto.ReservationSaveRequestDto; | ||
import roomescape.service.ReservationService; | ||
|
||
@Controller | ||
public class ReservationController { | ||
|
||
private final ReservationService reservationService; | ||
|
||
public ReservationController(ReservationService reservationService) { | ||
this.reservationService = reservationService; | ||
} | ||
|
||
@GetMapping("/reservation") | ||
public String goReservationPage() { | ||
return "new-reservation"; | ||
} | ||
|
||
@PostMapping("/reservations") | ||
public ResponseEntity<ReservationResponseDto> createReservation(@RequestBody ReservationSaveRequestDto requestDto) { | ||
ReservationResponseDto reservationResponseDto = reservationService.createReservation(requestDto); | ||
return ResponseEntity.created(URI.create("/reservations/" + reservationResponseDto.getId())) | ||
.body(reservationResponseDto); | ||
} | ||
|
||
@GetMapping("/reservations") | ||
public ResponseEntity<List<ReservationResponseDto>> readAllReservations() { | ||
|
||
return ResponseEntity.ok().body(reservationService.getAllReservations()); | ||
} | ||
|
||
@DeleteMapping("/reservations/{id}") | ||
public ResponseEntity<Void> deleteReservation(@PathVariable Long id) { | ||
reservationService.deleteReservation(id); | ||
|
||
return ResponseEntity.noContent().build(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package roomescape.controller; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import roomescape.dto.TimeResponseDto; | ||
import roomescape.dto.TimeSaveRequestDto; | ||
import roomescape.service.TimeService; | ||
|
||
@Controller | ||
public class TimeController { | ||
|
||
private final TimeService timeService; | ||
|
||
public TimeController(TimeService timeService) { | ||
this.timeService = timeService; | ||
} | ||
|
||
@GetMapping("/time") | ||
public String goReservationPage() { | ||
return "time"; | ||
} | ||
|
||
@PostMapping("/times") | ||
public ResponseEntity<TimeResponseDto> createTime(@RequestBody TimeSaveRequestDto requestDto) { | ||
TimeResponseDto timeResponseDto = timeService.createTime(requestDto); | ||
|
||
return ResponseEntity.created(URI.create("/times/" + timeResponseDto.getId())) | ||
.body(timeResponseDto); | ||
} | ||
|
||
@GetMapping("/times") | ||
public ResponseEntity<List<TimeResponseDto>> readAllTimes() { | ||
|
||
return ResponseEntity.ok().body(timeService.readAllTimes()); | ||
} | ||
|
||
@DeleteMapping("/times/{id}") | ||
public ResponseEntity<Void> deleteTime(@PathVariable Long id) { | ||
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.
|
||
timeService.deleteTime(id); | ||
|
||
return ResponseEntity.noContent().build(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package roomescape.domain; | ||
|
||
public class Time { | ||
|
||
private Long id; | ||
private String time; | ||
|
||
public Time() { | ||
} | ||
|
||
public Time(String time) { | ||
this.time = time; | ||
} | ||
|
||
public Time(Long id, String time) { | ||
this.id = id; | ||
this.time = time; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public String getTime() { | ||
return time; | ||
} | ||
} | ||
Comment on lines
+3
to
+27
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이라서 time 필드 없이 생성은 가능한데 time 필드를 채워주는 메서드가 없는 것 같아요! time 필드를 채워주는 메서드(setter)를 만드는 것보단 접근 지정자를 protected나 private으로 정상적으로 사용될 수 없는 객체가 만들어지는 경우는 의도적으로 막을 수 있을 것 같아요! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,41 @@ | ||
package roomescape; | ||
package roomescape.dto; | ||
|
||
import roomescape.domain.Reservation; | ||
|
||
public class ReservationResponseDto { | ||
|
||
private final Long id; | ||
private final String name; | ||
private final String date; | ||
private final String time; | ||
private Long id; | ||
private String name; | ||
private String date; | ||
private TimeResponseDto time; | ||
|
||
public ReservationResponseDto(Reservation reservation) { | ||
this.id = reservation.getId(); | ||
this.name = reservation.getName(); | ||
this.date = reservation.getDate(); | ||
this.time = reservation.getTime(); | ||
this.time = new TimeResponseDto(reservation.getTime()); | ||
} | ||
|
||
public ReservationResponseDto(Long id, Reservation reservation) { | ||
this.id = id; | ||
this.name = reservation.getName(); | ||
this.date = reservation.getDate(); | ||
this.time = reservation.getTime(); | ||
this.time = new TimeResponseDto(reservation.getTime()); | ||
} | ||
Comment on lines
12
to
24
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 Long getId() { | ||
return this.id; | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return this.name; | ||
return name; | ||
} | ||
|
||
public String getDate() { | ||
return this.date; | ||
return date; | ||
} | ||
|
||
public String getTime() { | ||
return this.time; | ||
public TimeResponseDto getTime() { | ||
return time; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
package roomescape; | ||
package roomescape.dto; | ||
|
||
public class ReservationSaveRequestDto { | ||
|
||
private String name; | ||
private String date; | ||
private String time; | ||
private Long time; | ||
|
||
public ReservationSaveRequestDto() { | ||
} | ||
|
||
public String getName() { | ||
return this.name; | ||
return name; | ||
} | ||
|
||
public String getDate() { | ||
return this.date; | ||
return date; | ||
} | ||
|
||
public String getTime() { | ||
return this.time; | ||
public Long getTime() { | ||
return time; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package roomescape.dto; | ||
|
||
import roomescape.domain.Time; | ||
|
||
public class TimeResponseDto { | ||
|
||
private Long id; | ||
private String time; | ||
|
||
public TimeResponseDto(Time time) { | ||
this.id = time.getId(); | ||
this.time = time.getTime(); | ||
} | ||
|
||
public TimeResponseDto(Long id, Time time) { | ||
this.id = id; | ||
this.time = time.getTime(); | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public String getTime() { | ||
return time; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package roomescape.dto; | ||
|
||
public class TimeSaveRequestDto { | ||
|
||
private String time; | ||
|
||
public TimeSaveRequestDto() { | ||
} | ||
|
||
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.
전
viewcontroller
를 만들어서 매핑을 해줘서 뭐가 좋을지 찾아봤는데, 각각의 장단점이 있는 것 같더군요.ViewController
를 따로 만드는 경우장점
단점
기존
Controller
에 코드를 추가하는 경우장점
단점
프로젝트의 크기에 따라
viewcontroller
를 만드는 것도 고려해보면 좋을 것 같습니다!