-
Notifications
You must be signed in to change notification settings - Fork 1
[release] 현재까지 진행상황 main으로 병합 #162
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
73da634
[feat] 유저 인증 관련 공통 어노테이션 추가
seung-in-Yoo 8c4abe0
[feat] 유저 인증 관련 리졸버 추가 (컨트롤러 메서드 파라미터에 로그인한 사용자 ID를 자동으로 주입)
seung-in-Yoo fb407c2
[feat] 리졸버 설정을 위한 WebMvcConfig 설정 추가
seung-in-Yoo d21dca8
[refactor] 각 컨트롤러에 리졸버 적용
seung-in-Yoo 6bbf817
[test] 웨이블존 리뷰 등록 관련 테스트 코드 작성
seung-in-Yoo f7e0c4c
[refactor] 웨이블존 상세 조회 ResponseDto에 위도,경도 필드 추가
seung-in-Yoo 3e56e8d
[refactor] WaybleZoneService 상세 매핑에 위도,경도 추가
seung-in-Yoo cf2b256
[test] 웨이블존 목록 조회 관련 테스트 코드 작성
seung-in-Yoo c5e7a17
Merge pull request #161 from Wayble-Project/feature/seungin
seung-in-Yoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/main/java/com/wayble/server/auth/resolver/CurrentUser.java
This file contains hidden or 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,8 @@ | ||
| package com.wayble.server.auth.resolver; | ||
|
|
||
| import java.lang.annotation.*; | ||
|
|
||
| @Target(ElementType.PARAMETER) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Documented | ||
| public @interface CurrentUser {} |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/wayble/server/auth/resolver/CurrentUserArgumentResolver.java
This file contains hidden or 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,45 @@ | ||
| package com.wayble.server.auth.resolver; | ||
|
|
||
| import org.springframework.core.MethodParameter; | ||
| import org.springframework.security.core.Authentication; | ||
| import org.springframework.security.core.context.SecurityContextHolder; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.web.bind.support.WebDataBinderFactory; | ||
| import org.springframework.web.context.request.NativeWebRequest; | ||
| import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
| import org.springframework.web.method.support.ModelAndViewContainer; | ||
|
|
||
| @Component | ||
| public class CurrentUserArgumentResolver implements HandlerMethodArgumentResolver { | ||
|
|
||
| @Override | ||
| public boolean supportsParameter(MethodParameter parameter) { | ||
| return parameter.hasParameterAnnotation(CurrentUser.class) | ||
| && Long.class.equals(parameter.getParameterType()); | ||
| } | ||
|
|
||
| @Override | ||
| public Object resolveArgument(MethodParameter parameter, | ||
| ModelAndViewContainer mav, | ||
| NativeWebRequest webRequest, | ||
| WebDataBinderFactory binderFactory) { | ||
| Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | ||
| if (auth == null) { | ||
| throw new IllegalStateException("인증 정보가 없습니다."); | ||
| } | ||
|
|
||
| Object principal = auth.getPrincipal(); | ||
| if (principal instanceof Long l) return l; | ||
| if (principal instanceof Integer i) return i.longValue(); | ||
| if (principal instanceof String s) { | ||
| try { | ||
| return Long.parseLong(s); | ||
| } catch (NumberFormatException ignored) {} | ||
| } | ||
| try { | ||
| return Long.parseLong(auth.getName()); | ||
| } catch (Exception e) { | ||
| throw new IllegalStateException("userId를 추출할 수 없습니다.", e); | ||
| } | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/wayble/server/common/config/WebMvcConfig.java
This file contains hidden or 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,21 @@ | ||
| package com.wayble.server.common.config; | ||
|
|
||
| import com.wayble.server.auth.resolver.CurrentUserArgumentResolver; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Configuration | ||
| @RequiredArgsConstructor | ||
| public class WebMvcConfig implements WebMvcConfigurer { | ||
|
|
||
| private final CurrentUserArgumentResolver currentUserArgumentResolver; | ||
|
|
||
| @Override | ||
| public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) { | ||
| resolvers.add(currentUserArgumentResolver); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
106 changes: 106 additions & 0 deletions
106
src/test/java/com/wayble/server/review/service/ReviewServiceTest.java
This file contains hidden or 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,106 @@ | ||
| package com.wayble.server.review.service; | ||
|
|
||
| import com.wayble.server.common.exception.ApplicationException; | ||
| import com.wayble.server.review.dto.ReviewRegisterDto; | ||
| import com.wayble.server.review.entity.Review; | ||
| import com.wayble.server.review.entity.ReviewImage; | ||
| import com.wayble.server.review.repository.ReviewImageRepository; | ||
| import com.wayble.server.review.repository.ReviewRepository; | ||
| import com.wayble.server.user.entity.User; | ||
| import com.wayble.server.user.repository.UserRepository; | ||
| import com.wayble.server.wayblezone.entity.WaybleZone; | ||
| import com.wayble.server.wayblezone.repository.WaybleZoneRepository; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.ArgumentCaptor; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
| import static org.mockito.Mockito.*; | ||
|
|
||
| class ReviewServiceTest { | ||
|
|
||
| private final ReviewRepository reviewRepository = mock(ReviewRepository.class); | ||
| private final ReviewImageRepository reviewImageRepository = mock(ReviewImageRepository.class); | ||
| private final WaybleZoneRepository waybleZoneRepository = mock(WaybleZoneRepository.class); | ||
| private final UserRepository userRepository = mock(UserRepository.class); | ||
|
|
||
| private final ReviewService sut = | ||
| new ReviewService(reviewRepository, reviewImageRepository, waybleZoneRepository, userRepository); | ||
|
|
||
| @Test | ||
| @DisplayName("리뷰 등록 성공 - 평점 갱신, 카운트 증가, 이미지 저장") | ||
| void t1() { | ||
| Long zoneId = 10L; | ||
| Long userId = 5L; | ||
|
|
||
| WaybleZone zone = mock(WaybleZone.class); | ||
| when(waybleZoneRepository.findById(zoneId)).thenReturn(Optional.of(zone)); | ||
| when(zone.getRating()).thenReturn(4.0); | ||
| when(zone.getReviewCount()).thenReturn(1L); | ||
|
|
||
| User user = mock(User.class); | ||
| when(userRepository.findById(userId)).thenReturn(Optional.of(user)); | ||
|
|
||
| ReviewRegisterDto dto = new ReviewRegisterDto( | ||
| "뷰가 좋고 접근성이 좋아요", | ||
| 5.0, | ||
| LocalDate.of(2025, 6, 30), | ||
| List.of("주차장 있음", "장애인 화장실 있음"), | ||
| List.of("https://image.url/review1.jpg") | ||
| ); | ||
|
|
||
| doAnswer(invocation -> invocation.getArgument(0)) | ||
| .when(reviewRepository).save(any(Review.class)); | ||
|
|
||
| sut.registerReview(zoneId, userId, dto); | ||
|
|
||
|
|
||
| verify(reviewRepository, times(1)).save(any(Review.class)); | ||
|
|
||
| ArgumentCaptor<Double> ratingCaptor = ArgumentCaptor.forClass(Double.class); | ||
| verify(zone, times(1)).updateRating(ratingCaptor.capture()); | ||
|
|
||
| assertEquals(4.5, ratingCaptor.getValue(), 1e-6); | ||
|
|
||
| verify(zone, times(1)).addReviewCount(1L); | ||
| verify(reviewImageRepository, times(1)).save(any(ReviewImage.class)); | ||
| verify(waybleZoneRepository, times(1)).save(zone); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("리뷰 등록 실패 - 웨이블존 없음") | ||
| void t2() { | ||
| Long zoneId = 99L; | ||
| Long userId = 1L; | ||
| when(waybleZoneRepository.findById(zoneId)).thenReturn(Optional.empty()); | ||
|
|
||
| ReviewRegisterDto dto = new ReviewRegisterDto( | ||
| "좋아요", 4.0, LocalDate.now(), List.of("주차장"), List.of() | ||
| ); | ||
|
|
||
| assertThrows(ApplicationException.class, | ||
| () -> sut.registerReview(zoneId, userId, dto)); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("리뷰 등록 실패 - 유저 없음") | ||
| void t3() { | ||
| Long zoneId = 10L; | ||
| Long userId = 999L; | ||
|
|
||
| WaybleZone zone = mock(WaybleZone.class); | ||
| when(waybleZoneRepository.findById(zoneId)).thenReturn(Optional.of(zone)); | ||
| when(userRepository.findById(userId)).thenReturn(Optional.empty()); | ||
|
|
||
| ReviewRegisterDto dto = new ReviewRegisterDto( | ||
| "좋아요", 4.0, LocalDate.now(), List.of("주차장"), List.of() | ||
| ); | ||
|
|
||
| assertThrows(ApplicationException.class, | ||
| () -> sut.registerReview(zoneId, userId, dto)); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
verify 파라미터 타입 불일치 가능성 (1L vs 1)
서비스 구현은
zone.addReviewCount(1)을 호출합니다. 엔티티 메서드가int혹은Integer를 받는 경우 현재 검증(1L)은 시그니처가 달라 실패할 수 있습니다. 테스트를 구현과 동일한 타입으로 맞춰주세요.🤖 Prompt for AI Agents