-
Notifications
You must be signed in to change notification settings - Fork 83
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
[1 - 3단계 방탈출 사용자 예약] 이든(최승준) 미션 제출합니다. #57
Changes from 19 commits
bd5a99e
b0bd9bb
ba6b536
3592c1d
75c7ee4
ec2e3b0
e37964d
a8a4a02
0fe2794
540fdee
5d6008e
7307152
4f592bd
7331554
17af3db
9e8790e
e951bbb
3bbd400
40d021b
ff72e78
fe93600
60d7ed3
478963c
45fbf52
efb21f8
f7177bd
1f76b8f
772631f
ac95a28
830df0c
cd175dc
2d9aa37
23b6a97
35935dc
5604c83
230ce75
4cec0d8
04131d6
a0899cf
7b816fd
4a9a980
0f8ef2c
0470138
c983dfd
41fa7a2
818b1eb
a2905fc
79de6f5
604a0c0
a0f45d0
15276bd
b40b582
7620bc5
f6b6e37
4014865
80690a0
272a414
3175c22
81687e0
bc3aaf6
a80fcbd
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 |
---|---|---|
@@ -1,61 +1,65 @@ | ||
package roomescape.controller; | ||
|
||
import java.net.URI; | ||
import java.time.LocalDate; | ||
import java.util.List; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.springframework.format.annotation.DateTimeFormat; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.http.HttpStatus; | ||
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 org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import roomescape.dto.reservation.ReservationAvailableTimeResponse; | ||
import roomescape.dto.reservation.ReservationRequest; | ||
import roomescape.dto.reservation.ReservationResponse; | ||
import roomescape.dto.reservation.ReservationTimeInfosResponse; | ||
import roomescape.dto.reservation.ReservationsResponse; | ||
import roomescape.global.dto.response.ApiResponse; | ||
import roomescape.service.ReservationService; | ||
|
||
import java.time.LocalDate; | ||
|
||
@RestController | ||
@RequestMapping("/reservations") | ||
public class ReservationController { | ||
|
||
private final ReservationService reservationService; | ||
|
||
public ReservationController(ReservationService reservationService) { | ||
public ReservationController(final ReservationService reservationService) { | ||
this.reservationService = reservationService; | ||
} | ||
|
||
@GetMapping | ||
public ResponseEntity<List<ReservationResponse>> readReservations() { | ||
List<ReservationResponse> reservationResponses = reservationService.findAllReservations(); | ||
|
||
return ResponseEntity.ok(reservationResponses); | ||
@GetMapping("/reservations") | ||
@ResponseStatus(HttpStatus.OK) | ||
public ApiResponse<ReservationsResponse> getAllReservations() { | ||
return ApiResponse.success(reservationService.findAllReservations()); | ||
} | ||
|
||
@GetMapping("/themes/{themeId}") | ||
public ResponseEntity<List<ReservationAvailableTimeResponse>> readAvailableTimeReservations( | ||
@PathVariable | ||
Long themeId, | ||
@RequestParam | ||
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) { | ||
return ResponseEntity.ok(reservationService.findReservationByDateAndThemeId(date, themeId)); | ||
@GetMapping("/reservations/themes/{themeId}/times") | ||
@ResponseStatus(HttpStatus.OK) | ||
public ApiResponse<ReservationTimeInfosResponse> getReservationTimeInfos( | ||
@PathVariable final Long themeId, | ||
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") final LocalDate date) { | ||
return ApiResponse.success(reservationService.findReservationsByDateAndThemeId(date, themeId)); | ||
} | ||
|
||
@PostMapping | ||
public ResponseEntity<ReservationResponse> createReservation(@RequestBody ReservationRequest reservationRequest) { | ||
ReservationResponse reservationResponse = reservationService.createReservation(reservationRequest); | ||
@PostMapping("/reservations") | ||
@ResponseStatus(HttpStatus.CREATED) | ||
public ApiResponse<ReservationResponse> saveReservation( | ||
@RequestBody final ReservationRequest reservationRequest, | ||
HttpServletResponse response | ||
) { | ||
ReservationResponse reservationResponse = reservationService.addReservation(reservationRequest); | ||
|
||
return ResponseEntity.created(URI.create("/reservations/" + reservationResponse.id())) | ||
.body(reservationResponse); | ||
response.setHeader("Location", "/reservations/" + reservationResponse.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. Location이라는 변수명이 실수할 여지가 있어서 수정 전 방식대로 활용하시는 것도 좋다고 생각합니다 ㅎ 이런 방법도 있습니다. @PostMapping("/reservations")
public ResponseEntity<ApiResponse<ReservationResponse>> saveReservation(
@RequestBody final ReservationRequest reservationRequest
) {
ReservationResponse reservationResponse = reservationService.addReservation(reservationRequest);
URI location = ServletUriComponentsBuilder.fromCurrentRequest()
.path("/{id}")
.buildAndExpand(reservationResponse.id())
.toUri();
return ResponseEntity.created(location).body(ApiResponse.success(reservationResponse));
} 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. 지금처럼 일반 문자열로 관리하면 충분히 실수할 여지가 있을 것 같습니다..! 그런데 로직이 너무 길어지는 느낌이 있어서 response.setHeader(HttpHeaders.LOCATION, "/reservations/" + reservationResponse.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. 네네 우려하는 부분은 매직넘버이니 좋은 처리입니다 ㅎ |
||
return ApiResponse.success(reservationResponse); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity<Void> deleteReservation(@PathVariable Long id) { | ||
reservationService.deleteReservation(id); | ||
@DeleteMapping("/reservations/{id}") | ||
@ResponseStatus(HttpStatus.NO_CONTENT) | ||
public ApiResponse<Void> removeReservation(@PathVariable final Long id) { | ||
reservationService.removeReservationById(id); | ||
|
||
return ResponseEntity.noContent().build(); | ||
return ApiResponse.success(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,67 @@ | ||
package roomescape.controller; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
import org.springframework.http.ResponseEntity; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.springframework.format.annotation.DateTimeFormat; | ||
import org.springframework.http.HttpStatus; | ||
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 org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import roomescape.dto.theme.ThemeRequest; | ||
import roomescape.dto.theme.ThemeResponse; | ||
import roomescape.dto.theme.ThemesResponse; | ||
import roomescape.global.dto.response.ApiResponse; | ||
import roomescape.service.ThemeService; | ||
|
||
import java.time.LocalDate; | ||
|
||
@RestController | ||
@RequestMapping("/themes") | ||
public class ThemeController { | ||
|
||
private final ThemeService themeService; | ||
|
||
public ThemeController(ThemeService themeService) { | ||
public ThemeController(final ThemeService themeService) { | ||
this.themeService = themeService; | ||
} | ||
|
||
@GetMapping | ||
public ResponseEntity<List<ThemeResponse>> readThemes() { | ||
List<ThemeResponse> themeResponses = themeService.findAllThemes(); | ||
@GetMapping("/themes") | ||
@ResponseStatus(HttpStatus.OK) | ||
public ApiResponse<ThemesResponse> getAllThemes() { | ||
|
||
return ResponseEntity.ok(themeResponses); | ||
return ApiResponse.success(themeService.findAllThemes()); | ||
} | ||
|
||
@GetMapping("/top") | ||
public ResponseEntity<List<ThemeResponse>> readTopNThemes(@RequestParam int count) { | ||
List<ThemeResponse> themeResponses = themeService.findTopNThemes(count); | ||
|
||
return ResponseEntity.ok(themeResponses); | ||
@GetMapping("/themes/top") | ||
@ResponseStatus(HttpStatus.OK) | ||
public ApiResponse<ThemesResponse> getTopNThemesBetweenDate( | ||
@RequestParam final int count, | ||
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") final LocalDate startAt, | ||
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") final LocalDate endAt | ||
) { | ||
return ApiResponse.success(themeService.findTopNThemes(count, startAt, endAt)); | ||
} | ||
|
||
@PostMapping | ||
public ResponseEntity<ThemeResponse> createTheme(@RequestBody ThemeRequest request) { | ||
ThemeResponse response = themeService.createTheme(request); | ||
@PostMapping("/themes") | ||
@ResponseStatus(HttpStatus.CREATED) | ||
public ApiResponse<ThemeResponse> saveTheme( | ||
@RequestBody final ThemeRequest request, | ||
HttpServletResponse response | ||
) { | ||
ThemeResponse themeResponse = themeService.addTheme(request); | ||
response.setHeader("Location", "/themes/" + themeResponse.id()); | ||
|
||
return ResponseEntity.created(URI.create("/themes/" + response.id())) | ||
.body(response); | ||
return ApiResponse.success(themeResponse); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity<Void> deleteTheme(@PathVariable Long id) { | ||
themeService.deleteTheme(id); | ||
@DeleteMapping("/themes/{id}") | ||
@ResponseStatus(HttpStatus.NO_CONTENT) | ||
public ApiResponse<Void> removeTheme(@PathVariable final Long id) { | ||
themeService.removeThemeById(id); | ||
|
||
return ResponseEntity.noContent().build(); | ||
return ApiResponse.success(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,53 @@ | ||
package roomescape.controller; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
import org.springframework.http.ResponseEntity; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.springframework.http.HttpStatus; | ||
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 org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import roomescape.dto.time.TimeRequest; | ||
import roomescape.dto.time.TimeResponse; | ||
import roomescape.dto.time.TimesResponse; | ||
import roomescape.global.dto.response.ApiResponse; | ||
import roomescape.service.TimeService; | ||
|
||
@RestController | ||
@RequestMapping("/times") | ||
public class TimeController { | ||
|
||
private final TimeService timeService; | ||
|
||
public TimeController(TimeService timeService) { | ||
public TimeController(final TimeService timeService) { | ||
this.timeService = timeService; | ||
} | ||
|
||
@GetMapping | ||
public ResponseEntity<List<TimeResponse>> readTimes() { | ||
List<TimeResponse> timeResponses = timeService.findAllTimes(); | ||
@GetMapping("/times") | ||
@ResponseStatus(HttpStatus.OK) | ||
public ApiResponse<TimesResponse> getAllTimes() { | ||
|
||
return ResponseEntity.ok(timeResponses); | ||
return ApiResponse.success(timeService.findAllTimes()); | ||
} | ||
|
||
@PostMapping | ||
public ResponseEntity<TimeResponse> createTime(@RequestBody TimeRequest timeRequest) { | ||
TimeResponse timeResponse = timeService.createTime(timeRequest); | ||
@PostMapping("/times") | ||
@ResponseStatus(HttpStatus.CREATED) | ||
public ApiResponse<TimeResponse> saveTime( | ||
@RequestBody final TimeRequest timeRequest, | ||
HttpServletResponse response | ||
) { | ||
TimeResponse timeResponse = timeService.addTime(timeRequest); | ||
response.setHeader("Location", "/times/" + timeResponse.id()); | ||
|
||
return ResponseEntity.created(URI.create("/times/" + timeResponse.id())) | ||
.body(timeResponse); | ||
return ApiResponse.success(timeResponse); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity<Void> deleteTime(@PathVariable Long id) { | ||
timeService.deleteTime(id); | ||
@DeleteMapping("/times/{id}") | ||
@ResponseStatus(HttpStatus.NO_CONTENT) | ||
public ApiResponse<Void> removeTime(@PathVariable final Long id) { | ||
timeService.removeTimeById(id); | ||
|
||
return ResponseEntity.noContent().build(); | ||
return ApiResponse.success(); | ||
} | ||
} |
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.
꼼꼼한 API 문서네요 ㅎ 👍