Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.babzip.backend.global.response.ResponseBody;
import com.babzip.backend.global.response.ResponseUtil;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
Expand All @@ -17,8 +18,10 @@
public class GlobalExceptionHandler {

@ExceptionHandler(BusinessException.class)
public ResponseEntity<ResponseBody<Void>> businessException(BusinessException e) {
public ResponseEntity<ResponseBody<Void>> businessException(BusinessException e, HttpServletRequest request) {
ExceptionType exceptionType = e.getExceptionType();
log.error("🔥 [{} {}] 요청 중 예외 발생: {}", request.getMethod(), request.getRequestURI(), e.getMessage(), e);

return ResponseEntity.status(exceptionType.getStatus())
.body(ResponseUtil.createFailureResponse(exceptionType));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.Authentication;
Expand All @@ -29,9 +31,17 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
private static final String BEARER_PREFIX = "Bearer ";
private final AuthenticationManager authenticationManager;
private final RequestMatcher requestMatcher = new RequestHeaderRequestMatcher(HttpHeaders.AUTHORIZATION);
private static final Logger log = LoggerFactory.getLogger(JwtAuthenticationFilter.class);


@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {

String method = request.getMethod();
String uri = request.getRequestURI();

log.info("🔍 API 요청: {} {}", method, uri);

// Authorization 헤더가 있을 때만 필터를 거쳐감
// 인증이 필요없는 작업은 이 필터를 거치지 않음
if (!requestMatcher.matches(request)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.babzip.backend.guestbook.dto.response.GuestbookSearchResponse;
import com.babzip.backend.guestbook.service.GuestbookService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
Expand All @@ -20,6 +21,7 @@
@RequiredArgsConstructor
@RestController
@RequestMapping("/guestbook")
@Slf4j
public class GuestbookController implements GuestBookApi {

private final GuestbookService guestbookService;
Expand Down Expand Up @@ -53,6 +55,7 @@ public ResponseEntity<ResponseBody<Void>> updatePartial(
@RequestBody GuestbookRequestDto requestDto
) {
guestbookService.updatePartial(userId, requestDto);
log.info("정상 작동");
return ResponseEntity.ok(ResponseUtil.createSuccessResponse());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
import com.babzip.backend.user.repository.UserRepository;
import jakarta.persistence.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Service
@Slf4j
public class GuestbookService {

private final GuestbookRepository guestbookRepository;
Expand Down Expand Up @@ -47,7 +49,9 @@ public Page<GuestbookResponseDto> getByUserId(Long userId, Pageable pageable) {
public void updatePartial(Long userId, GuestbookRequestDto dto) {
Guestbook guestbook = guestbookRepository.findByKakaoPlaceIdAndUserId(dto.kakaoPlaceId(), userId)
.orElseThrow(() -> new BusinessException(ExceptionType.GUEST_BOOK_NOT_FOUND));
log.info("정상 작동");
guestbook.updatePartial(dto.restaurantName(), dto.kakaoPlaceId(), dto.content(), dto.rating());
log.info("정상 작동");
}

@Transactional
Expand Down