Skip to content

Commit

Permalink
[#38] refacotr: 유효성 검증 validation으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
hsik0225 committed Jun 4, 2020
1 parent a54884a commit 6eed69d
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -10,8 +11,11 @@ public class GlobalRestExceptionHandler {

@ExceptionHandler(Exception.class)
protected ResponseEntity<String> handleServerException(Exception e) {
return new ResponseEntity<>("서버 에러입니다..", HttpStatus.INTERNAL_SERVER_ERROR);
return new ResponseEntity<>("서버 에러입니다", HttpStatus.INTERNAL_SERVER_ERROR);
}


@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
protected ResponseEntity<String> HttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) {
return new ResponseEntity<>("지원하지 않는 메소드입니다", HttpStatus.METHOD_NOT_ALLOWED);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.codesquad.airbnb.common.exception;

public class InputMistakeException extends RuntimeException {

public InputMistakeException() {
super();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.codesquad.airbnb.common.exception;

public class InputNothingException {
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
package com.codesquad.airbnb.reservation.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.*;

import javax.validation.constraints.Min;

@Getter
@NoArgsConstructor
@Setter
@AllArgsConstructor
@ToString
public class Guest {

@Min(1)
private int numberOfAdults;

private int numberOfKids;

private int numberOfBabies;

public void checkInput() {
if(numberOfAdults == 0 && numberOfKids == 0 && numberOfBabies == 0) {
throw new IllegalArgumentException("Please Input Guests!");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.*;

import javax.validation.constraints.NotNull;
import java.time.LocalDate;

@Getter
Expand All @@ -11,24 +12,9 @@
@ToString
public class ReservationDate {

@NotNull
private LocalDate checkInDate = LocalDate.MIN;

@NotNull
private LocalDate checkOutDate = LocalDate.MAX;

public void checkInput() {
validCheckInDate();
validCheckOutDate();
}

private void validCheckInDate() {
if (checkInDate.equals(LocalDate.MIN)) {
throw new IllegalArgumentException("Please Input Check-In-Date!");
}
}

private void validCheckOutDate() {
if (checkOutDate.equals(LocalDate.MAX)) {
throw new IllegalArgumentException("Please Input Check-Out-Date!");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,11 @@ public class ReservationController {

@GetMapping("/reservations")
public Confirmation showBillAndReview(@RequestParam Long roomId, @Valid ReservationDate reservationDate, @Valid Guest guest) {
reservationDate.checkInput();
guest.checkInput();
return viewDAO.showBillAndReview(utilDAO, roomId, reservationDate, guest);
}

@PostMapping("/reservations")
public ResponseEntity<HttpStatus> reserve(@RequestParam Long roomId, @RequestParam Long userId, @Valid ReservationDate reservationDate, @Valid Guest guest) {
reservationDate.checkInput();
guest.checkInput();
reservationDAO.reserve(utilDAO, roomId, userId, reservationDate, guest);
return new ResponseEntity<>(HttpStatus.CREATED);
}
Expand Down
6 changes: 2 additions & 4 deletions BE/src/main/java/com/codesquad/airbnb/room/domain/Budget.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.codesquad.airbnb.room.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.*;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class Budget {

private int lowestPrice;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public Main main(UtilDAO utilDAO, ReservationDate reservationDate, Guest guest,
"LEFT OUTER JOIN reservations r3 on r.room_id = r3.room_id " +
"LEFT OUTER JOIN dates d on r3.room_id = d.room_id " +
"WHERE (p.price BETWEEN ? AND ?) " +
"GROUP BY r.room_id";
"GROUP BY r.room_id " +
"LIMIT 5";

RowMapper<RoomDetail> roomRowMapper = new RowMapper<RoomDetail>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ public class MainController {
private final ViewDAO viewDAO;

@GetMapping("")
public Main showMain(@Valid ReservationDate reservationDate,
@Valid Guest guest,
@Valid Budget budget) {
public Main showMain(ReservationDate reservationDate,
Guest guest,
Budget budget) {

return viewDAO.main(utilDAO, reservationDate, guest, budget);
}

@GetMapping("/budget")
public Statistics showPriceStatistics(@Valid ReservationDate reservationDate) {
reservationDate.checkInput();
return viewDAO.showStatistics(reservationDate);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.codesquad.airbnb.user.ui;

import com.codesquad.airbnb.user.application.LoginService;
import com.codesquad.airbnb.user.domain.GitHubOAuthProperty;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down

0 comments on commit 6eed69d

Please sign in to comment.