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 @@ -66,7 +66,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
"/api-docs/**",
"/swagger-resources/**",
"/webjars/**",
"/demo-ui.html"
"/demo-ui.html",
"/v1/menus//all-menus/stores/**"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

URL 패턴의 이중 슬래시 검증 필요

URL 패턴에 이중 슬래시(//)가 포함되어 있습니다. 이것이 의도된 것인지 확인이 필요합니다.

다음 스크립트로 실제 컨트롤러 엔드포인트와 일치하는지 확인해주세요:


🏁 Script executed:

#!/bin/bash
# 실제 메뉴 관련 엔드포인트 패턴 확인
ast-grep --pattern '@RequestMapping($$$)' | grep -i menu
ast-grep --pattern '@GetMapping($$$)' | grep -i menu
rg -A 2 -B 2 "v1/menus.*all-menus.*stores"

Length of output: 1855


이중 슬래시 오타 수정 필요

보안 설정에서 등록한 패턴

"/v1/menus//all-menus/stores/**"

는 실제 컨트롤러의 엔드포인트

@RequestMapping("/v1/menus")
@GetMapping("/all-menus/stores/{storeId}")

가 제공하는 /v1/menus/all-menus/stores/{storeId} 경로와 매칭되지 않습니다.
결과적으로 해당 API가 인증 없이 접근 허용 목록에 들어가지 않아 의도와 다르게 인증이 요구될 수 있습니다.

수정 제안:

  • 파일: nowait-app-user-api/src/main/java/com/nowait/applicationuser/config/security/SecurityConfig.java
  • 줄 70
  • "/v1/menus//all-menus/stores/**"
  • "/v1/menus/all-menus/stores/**"

해당 패턴을 위와 같이 변경하여 실제 엔드포인트와 일치시키고, 의도한 대로 인증 없이 접근 가능하도록 해주세요.

<details>
<summary>🤖 Prompt for AI Agents</summary>

In
nowait-app-user-api/src/main/java/com/nowait/applicationuser/config/security/SecurityConfig.java
at line 70, fix the double slash typo in the URL pattern
"/v1/menus//all-menus/stores/" by changing it to
"/v1/menus/all-menus/stores/
" so it correctly matches the controller endpoint
and allows unauthenticated access as intended.


</details>

<!-- fingerprinting:phantom:poseidon:panther -->

<!-- This is an auto-generated comment by CodeRabbit -->

)
.permitAll()
.anyRequest().authenticated() // 그외 요청은 허가된 사람만 인가
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
@AllArgsConstructor
@Schema(description = "주점 대기 현황 정보 DTO")
public class StoreWaitingInfo {
@Schema(description = "배너 첫번째 이미지", example = "https://cdn.gtable.com/profile/user1.jpg")
private String bannerImageUrl;

@Schema(description = "학과 이름", example = "경영학과")
private String departmentName;

@Schema(description = "주점 ID", example = "1")
private String storeId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.nowait.applicationuser.store.dto.StoreWaitingInfo;
import com.nowait.domaincorerdb.department.entity.Department;
import com.nowait.domaincorerdb.department.repository.DepartmentRepository;
import com.nowait.domaincorerdb.store.entity.ImageType;
import com.nowait.domaincorerdb.store.entity.Store;
import com.nowait.domaincorerdb.store.entity.StoreImage;
import com.nowait.domaincorerdb.store.exception.StoreNotFoundException;
Expand Down Expand Up @@ -238,7 +239,20 @@ public List<StoreWaitingInfo> getStoresByWaitingCount(boolean desc) {
.map(Store::getName)
.orElse(UNKNOWN_STORE_NAME);

result.add(new StoreWaitingInfo(storeId, storeName, count != null ? count : 0));
Store store = storeRepository.findById(Long.valueOf(storeId))
.orElseThrow(StoreNotFoundException::new);
Department department = departmentRepository.getReferenceById(store.getDepartmentId());
List<StoreImage> storeImageList = storeImageRepository.findByStoreAndImageType(store, ImageType.BANNER);

String imageUrl = storeImageList.isEmpty() ? null : storeImageList.get(0).getImageUrl();

result.add(new StoreWaitingInfo(
imageUrl,
department.getName(),
storeId,
storeName,
count != null ? count : 0
));
Comment on lines +242 to +255
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

성능 최적화 및 예외 처리 개선 필요

현재 구현에서 다음 문제점들이 있습니다:

  1. Store 엔티티를 두 번 조회하는 비효율성 (238라인과 242라인)
  2. getReferenceById 사용으로 인한 잠재적 LazyInitializationException
  3. Department가 존재하지 않을 경우의 예외 처리 부재

다음과 같이 리팩토링을 권장합니다:

-				// DB에서 storeName 조회
-				String storeName = storeRepository.findById(Long.valueOf(storeId))
-					.map(Store::getName)
-					.orElse(UNKNOWN_STORE_NAME);
-
-				Store store = storeRepository.findById(Long.valueOf(storeId))
-					.orElseThrow(StoreNotFoundException::new);
-				Department department = departmentRepository.getReferenceById(store.getDepartmentId());
-				List<StoreImage> storeImageList = storeImageRepository.findByStoreAndImageType(store, ImageType.BANNER);
-
-				String imageUrl = storeImageList.isEmpty() ? null : storeImageList.get(0).getImageUrl();
-
-				result.add(new StoreWaitingInfo(
-					imageUrl,
-					department.getName(),
-					storeId,
-					storeName,
-					count != null ? count : 0
-				));
+				Store store = storeRepository.findById(Long.valueOf(storeId))
+					.orElseThrow(StoreNotFoundException::new);
+				
+				String departmentName = departmentRepository.findById(store.getDepartmentId())
+					.map(Department::getName)
+					.orElse("Unknown Department");
+				
+				List<StoreImage> storeImageList = storeImageRepository.findByStoreAndImageType(store, ImageType.BANNER);
+				String imageUrl = storeImageList.isEmpty() ? null : storeImageList.get(0).getImageUrl();
+
+				result.add(new StoreWaitingInfo(
+					imageUrl,
+					departmentName,
+					storeId,
+					store.getName(),
+					count != null ? count : 0
+				));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Store store = storeRepository.findById(Long.valueOf(storeId))
.orElseThrow(StoreNotFoundException::new);
Department department = departmentRepository.getReferenceById(store.getDepartmentId());
List<StoreImage> storeImageList = storeImageRepository.findByStoreAndImageType(store, ImageType.BANNER);
String imageUrl = storeImageList.isEmpty() ? null : storeImageList.get(0).getImageUrl();
result.add(new StoreWaitingInfo(
imageUrl,
department.getName(),
storeId,
storeName,
count != null ? count : 0
));
Store store = storeRepository.findById(Long.valueOf(storeId))
.orElseThrow(StoreNotFoundException::new);
String departmentName = departmentRepository.findById(store.getDepartmentId())
.map(Department::getName)
.orElse("Unknown Department");
List<StoreImage> storeImageList = storeImageRepository.findByStoreAndImageType(store, ImageType.BANNER);
String imageUrl = storeImageList.isEmpty() ? null : storeImageList.get(0).getImageUrl();
result.add(new StoreWaitingInfo(
imageUrl,
departmentName,
storeId,
store.getName(),
count != null ? count : 0
));
🤖 Prompt for AI Agents
In
nowait-app-user-api/src/main/java/com/nowait/applicationuser/store/service/StoreServiceImpl.java
around lines 242 to 255, avoid fetching the Store entity twice by reusing the
initially retrieved Store object. Replace getReferenceById for Department with a
safe fetch method like findById to prevent LazyInitializationException, and add
proper exception handling if the Department is not found. This will optimize
performance and improve robustness by ensuring all entities are properly loaded
and exceptions are handled gracefully.

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.nowait.domaincorerdb.store.repository;

import static com.nowait.domaincorerdb.store.entity.ImageType.*;

import java.util.List;
import java.util.Optional;

Expand All @@ -18,4 +20,8 @@ public interface StoreImageRepository extends JpaRepository<StoreImage, Long> {
List<StoreImage> findByStore_StoreIdIn(List<Long> storeIds);

Optional<StoreImage> findByStoreStoreIdAndImageType(Long storeId, ImageType imageType);

List<StoreImage> findByStoreAndImageType(Store store, ImageType imageType);


}