-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from CODESQUAD-AIRBNB/develop-BE
[Team-24][BE] airbnb 프로젝트 PR #3
- Loading branch information
Showing
32 changed files
with
932 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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 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
48 changes: 48 additions & 0 deletions
48
be/src/main/java/kr/codesquad/airbnb/AuthenticationFilter.java
This file contains 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,48 @@ | ||
package kr.codesquad.airbnb; | ||
|
||
import kr.codesquad.airbnb.exception.ErrorCode; | ||
import kr.codesquad.airbnb.response.ErrorResponse; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.filter.GenericFilterBean; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.annotation.WebFilter; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
@WebFilter(urlPatterns = "/api/*") | ||
@Slf4j | ||
public class AuthenticationFilter extends GenericFilterBean { | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | ||
HttpServletRequest req = (HttpServletRequest) request; | ||
String token = req.getHeader("token"); | ||
|
||
if (!token.equals("member1")) { | ||
setForbiddenResponse((HttpServletResponse) response); | ||
return; | ||
} | ||
|
||
chain.doFilter(request, response); | ||
} | ||
|
||
public void setForbiddenResponse(HttpServletResponse response) { | ||
ErrorCode errorCode = ErrorCode.FORBIDDEN_USER; | ||
log.error("AuthenticationFilter reject request to server. cause = {}", errorCode.getDetail()); | ||
response.setStatus(errorCode.getHttpStatus().value()); | ||
response.setContentType("application/json"); | ||
response.setCharacterEncoding("UTF-8"); | ||
ErrorResponse errorResponse = new ErrorResponse(errorCode); | ||
try { | ||
String json = errorResponse.convertToJson(); | ||
response.getWriter().write(json); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
be/src/main/java/kr/codesquad/airbnb/controller/RoomController.java
This file contains 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,32 @@ | ||
package kr.codesquad.airbnb.controller; | ||
|
||
import kr.codesquad.airbnb.dto.RoomPriceStatisticRequest; | ||
import kr.codesquad.airbnb.exception.CustomException; | ||
import kr.codesquad.airbnb.exception.ErrorCode; | ||
import kr.codesquad.airbnb.response.CommonResponse; | ||
import kr.codesquad.airbnb.service.RoomService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.validation.Valid; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1") | ||
public class RoomController { | ||
|
||
private final RoomService roomService; | ||
|
||
/** | ||
* 체크인, 체크아웃 날짜를 입력받고, 예약 가능한 숙소의 1박 요금 통계를 반환 | ||
*/ | ||
@ResponseBody | ||
@GetMapping("/rooms/statistic/price") | ||
public CommonResponse viewRoomPriceStatistic(@ModelAttribute @Valid RoomPriceStatisticRequest roomPriceStatisticRequest) { | ||
if (roomPriceStatisticRequest.getCheckIn().isAfter(roomPriceStatisticRequest.getCheckOut())) { | ||
throw new CustomException(ErrorCode.FORBIDDEN_CHECK_OUT_DATE_IS_BEFORE_CHECK_IN); | ||
} | ||
|
||
return CommonResponse.okCommonResponse(roomService.findStatisticOfRoomPrice(roomPriceStatisticRequest)); | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 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
5 changes: 5 additions & 0 deletions
5
be/src/main/java/kr/codesquad/airbnb/domain/RoomDiscountTax.java
This file contains 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
17 changes: 17 additions & 0 deletions
17
be/src/main/java/kr/codesquad/airbnb/dto/CategorizedPrice.java
This file contains 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,17 @@ | ||
package kr.codesquad.airbnb.dto; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class CategorizedPrice { | ||
|
||
private Integer min; | ||
private Integer max; | ||
private Integer count; | ||
|
||
public CategorizedPrice(RangeOfPrice rangeOfPrice, Integer count) { | ||
this.min = rangeOfPrice.getMin(); | ||
this.max = rangeOfPrice.getMax(); | ||
this.count = count; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
be/src/main/java/kr/codesquad/airbnb/dto/RangeOfPrice.java
This file contains 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,37 @@ | ||
package kr.codesquad.airbnb.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public enum RangeOfPrice { | ||
|
||
RANGE_0_TO_50000(0, 50000), | ||
RANGE_50001_TO_100000(50001, 100000), | ||
RANGE_100001_TO_150000(100001, 150000), | ||
RANGE_150001_TO_200000(150001, 200000), | ||
RANGE_200001_TO_250000(200001, 250000), | ||
RANGE_250001_TO_300000(250001, 300000), | ||
RANGE_300001_TO_350000(300001, 350000), | ||
RANGE_350001_TO_400000(350001, 400000), | ||
RANGE_400001_TO_450000(400001, 450000), | ||
RANGE_450001_TO_500000(450001, 500000), | ||
RANGE_500001_TO_550000(500001, 550000), | ||
RANGE_550001_TO_600000(550001, 600000), | ||
RANGE_600001_TO_650000(600001, 650000), | ||
RANGE_650001_TO_700000(650001, 700000), | ||
RANGE_700001_TO_750000(700001, 750000), | ||
RANGE_750001_TO_800000(750001, 800000), | ||
RANGE_800001_TO_850000(800001, 850000), | ||
RANGE_850001_TO_900000(850001, 900000), | ||
RANGE_900001_TO_950000(900001, 950000), | ||
RANGE_950001_TO_1000000(950001, 1000000), | ||
RANGE_1000001_TO_1050000(1000001, 1050000), | ||
RANGE_1050001_TO_1100000(1050001, 1100000), | ||
|
||
; | ||
|
||
private final Integer min; | ||
private final Integer max; | ||
} |
Oops, something went wrong.