-
Notifications
You must be signed in to change notification settings - Fork 45
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
Feature/2단계 예외처리및리팩터링 #109
base: koreacat
Are you sure you want to change the base?
The head ref may contain hidden characters: "feature/2\uB2E8\uACC4_\uC608\uC678\uCC98\uB9AC\uBC0F\uB9AC\uD329\uD130\uB9C1"
Changes from all commits
fe7a701
97663d9
fda5143
8a2b2d1
786cbae
4054898
b2ccce3
48d151f
0139a8c
d55729f
86a271d
9fe480b
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,24 @@ | ||
package roomescape.controller; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
@Controller | ||
@RequestMapping("/admin") | ||
public class AdminPageController { | ||
@GetMapping("/reservation") | ||
public String reservation() { | ||
return "/admin/reservation-new"; | ||
} | ||
|
||
@GetMapping("/time") | ||
public String time() { | ||
return "/admin/time"; | ||
} | ||
|
||
@GetMapping("/theme") | ||
public String theme() { | ||
return "/admin/theme"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
package roomescape.controller; | ||
|
||
import jakarta.validation.Valid; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import roomescape.dto.ReservationRq; | ||
import roomescape.dto.ReservationRs; | ||
import roomescape.service.ReservationService; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
|
||
@RestController | ||
|
@@ -17,25 +19,21 @@ public ReservationController(ReservationService reservationService) { | |
this.reservationService = reservationService; | ||
} | ||
|
||
// 예약 조회 | ||
@GetMapping | ||
public ResponseEntity<List<ReservationRs>> getReservations() { | ||
List<ReservationRs> reservations = reservationService.getAllReservations(); | ||
return ResponseEntity.ok().body(reservations); | ||
} | ||
|
||
// 예약 추가 | ||
@PostMapping | ||
public ResponseEntity<ReservationRs> addReservation(@RequestBody ReservationRq reservationRq) { | ||
public ResponseEntity<ReservationRs> addReservation(@RequestBody @Valid ReservationRq reservationRq) { | ||
ReservationRs reservationRs = reservationService.addReservation(reservationRq); | ||
return ResponseEntity.ok().body(reservationRs); | ||
return ResponseEntity.created(URI.create("/reservations/" + reservationRs.getId())).body(reservationRs); | ||
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. Http Status Code 를 적절히 잘 활용해주셨네요 👍 |
||
} | ||
|
||
// 예약 취소 | ||
@DeleteMapping("/{id}") | ||
public ResponseEntity<Void> deleteReservation(@PathVariable Long id) { | ||
reservationService.deleteReservation(id); | ||
return ResponseEntity.ok().build(); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package roomescape.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import roomescape.dto.ThemeRq; | ||
import roomescape.dto.ThemeRs; | ||
import roomescape.service.ThemeService; | ||
|
||
import java.net.URI; | ||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/themes") | ||
public class ThemeController { | ||
private final ThemeService themeService; | ||
|
||
public ThemeController(ThemeService themeService) { | ||
this.themeService = themeService; | ||
} | ||
|
||
// 테마 조회 | ||
@GetMapping | ||
public ResponseEntity<List<ThemeRs>> getThemes() { | ||
List<ThemeRs> themes = themeService.getAllThemes(); | ||
return ResponseEntity.ok().body(themes); | ||
} | ||
|
||
// 테마 추가 | ||
@PostMapping | ||
public ResponseEntity<ThemeRs> addTheme(@RequestBody ThemeRq themeRq) { | ||
ThemeRs themeRs = themeService.addTheme(themeRq); | ||
return ResponseEntity.created(URI.create("/themes/" + themeRs.getId())).body(themeRs); | ||
} | ||
|
||
// 테마 삭제 | ||
@DeleteMapping("/{id}") | ||
public ResponseEntity<Void> deleteTheme(@PathVariable Long id) { | ||
themeService.deleteTheme(id); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,32 @@ | ||
package roomescape.dto; | ||
|
||
import java.time.LocalDate; | ||
|
||
import jakarta.validation.constraints.Future; | ||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
public class ReservationRq { | ||
@NotEmpty(message = "Reservation name must not be empty") | ||
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. 문자열 검증에는 |
||
private String name; | ||
private String date; | ||
|
||
@NotNull(message = "Reservation date must not be null") | ||
@Future(message = "Reservation date must be in the future") | ||
private LocalDate date; | ||
|
||
@NotNull(message = "Reservation time ID must not be null") | ||
private Long timeId; | ||
|
||
@NotNull(message = "Theme ID must not be null") | ||
private Long themeId; | ||
|
||
public ReservationRq() {} | ||
|
||
public ReservationRq(String name, String date, Long timeId) { | ||
public ReservationRq(String name, LocalDate date, Long timeId, Long themeId) { | ||
this.name = name; | ||
this.date = date; | ||
this.timeId = timeId; | ||
this.themeId = themeId; | ||
} | ||
|
||
public String getName() { | ||
|
@@ -21,11 +37,11 @@ public void setName(String name) { | |
this.name = name; | ||
} | ||
|
||
public String getDate() { | ||
public LocalDate getDate() { | ||
return date; | ||
} | ||
|
||
public void setDate(String date) { | ||
public void setDate(LocalDate date) { | ||
this.date = date; | ||
} | ||
|
||
|
@@ -36,4 +52,12 @@ public Long getTimeId() { | |
public void setTimeId(Long timeId) { | ||
this.timeId = timeId; | ||
} | ||
|
||
public Long getThemeId() { | ||
return themeId; | ||
} | ||
|
||
public void setThemeId(Long themeId) { | ||
this.themeId = themeId; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
package roomescape.dto; | ||
|
||
import java.time.LocalTime; | ||
|
||
public class ReservationTimeRq { | ||
private String startAt; | ||
private LocalTime startAt; | ||
|
||
public ReservationTimeRq() {} | ||
|
||
public ReservationTimeRq(String startAt) { | ||
public ReservationTimeRq(LocalTime startAt) { | ||
this.startAt = startAt; | ||
} | ||
|
||
public String getStartAt() { | ||
public LocalTime getStartAt() { | ||
return startAt; | ||
} | ||
|
||
public void setStartAt(String startAt) { | ||
public void setStartAt(LocalTime startAt) { | ||
this.startAt = startAt; | ||
} | ||
} |
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.
spring validation을 적용해주셨군요 👍