Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/weekly/11' into feat/#142-mypage
Browse files Browse the repository at this point in the history
  • Loading branch information
wndlthsk committed Nov 14, 2024
2 parents 249cf14 + 17a7808 commit 44e2dc3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.support.PageableExecutionUtils;
import org.springframework.stereotype.Repository;
Expand Down Expand Up @@ -41,7 +40,10 @@ public Page<Place> findPlacesByDistance(String longitude, String latitude, Pagea
.limit(pageable.getPageSize())
.fetch();

return new PageImpl<>(places, pageable, places.size());
JPAQuery<Long> countQuery = jpaQueryFactory.select(place.id.count()) // 중복 제거
.from(place);

return PageableExecutionUtils.getPage(places, pageable, countQuery::fetchOne);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public CorsFilter corsFilter() {
var source = new UrlBasedCorsConfigurationSource();
var config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("https://www.inplace.my");
config.addAllowedOriginPattern("https://www.inplace.my");
config.addAllowedOriginPattern("https://api.inplace.my");
config.addAllowedHeader("Origin");
config.addAllowedHeader("Accept");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import java.io.IOException;

@Slf4j
public class CustomAccessDeniedHandler implements AccessDeniedHandler {

@Value("${spring.redirect.front-end-url}")
private String frontEndUrl;

@Override
public void handle(HttpServletRequest request, HttpServletResponse response,
AccessDeniedException accessDeniedException) throws IOException {
AccessDeniedException accessDeniedException) throws IOException {
log.info("Access denied");
response.sendRedirect(frontEndUrl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
Expand All @@ -13,8 +14,6 @@
import team7.inplace.global.exception.InplaceException;
import team7.inplace.global.exception.code.AuthorizationErrorCode;

import java.io.IOException;

@Slf4j
public class CustomFailureHandler implements AuthenticationFailureHandler {

Expand All @@ -28,10 +27,11 @@ public CustomFailureHandler(ObjectMapper objectMapper) {

@Override
public void onAuthenticationFailure(
HttpServletRequest request,
HttpServletResponse response,
AuthenticationException exception
HttpServletRequest request,
HttpServletResponse response,
AuthenticationException exception
) throws IOException {
log.info("Authentication failure");
String accept = request.getHeader("Accept");
if (StringUtils.hasText(accept) && accept.contains("text/html")) {
response.sendRedirect(frontEndUrl);
Expand All @@ -40,13 +40,13 @@ public void onAuthenticationFailure(
}

private void setErrorResponse(
HttpServletResponse response,
InplaceException inplaceException
HttpServletResponse response,
InplaceException inplaceException
) throws IOException {
response.setStatus(inplaceException.getHttpStatus().value());
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail(
inplaceException.getHttpStatus(), inplaceException.getMessage());
inplaceException.getHttpStatus(), inplaceException.getMessage());
response.getWriter().write(objectMapper.writeValueAsString(problemDetail));
}
}
2 changes: 1 addition & 1 deletion src/main/resources/sql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ create table places
latitude text not null,
longitude text not null,
menu_img_url text null,
category enum ('CAFE', 'JAPANESE', 'KOREAN', 'NONE', 'RESTAURANT', 'WESTERN') not null
category enum ('CAFE', 'JAPANESE', 'KOREAN', 'NONE', 'RESTAURANT', 'WESTERN') not null,

FULLTEXT INDEX ft_name_ngram (name) WITH PARSER ngram,
INDEX idx_long_lat (longitude(15), latitude(15))
Expand Down

0 comments on commit 44e2dc3

Please sign in to comment.