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 @@ -9,6 +9,7 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.gtable.global.api.ApiUtils;
Expand Down Expand Up @@ -86,4 +87,15 @@ public ResponseEntity<?> deleteStore(@PathVariable Long storeId) {
)
);
}

@GetMapping("/search")
public ResponseEntity<?> searchStores(@RequestParam("name") String name) {
return ResponseEntity
.ok()
.body(
ApiUtils.success(
storeService.searchStoresByName(name)
)
);
}
Comment on lines +91 to +100
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

엔티티 직접 반환으로 API 응답 일관성/보안 문제
서비스가 Store 엔티티를 그대로 반환하므로 컨트롤러도 그대로 노출하고 있습니다. 기존 엔드포인트는 모두 DTO를 사용하므로 API 스키마가 달라집니다. 또한 내부 필드(삭제 플래그 등) 노출 가능성이 있습니다. 서비스·DTO 구조가 정리된 뒤 응답 타입도 함께 수정해 주세요.
추가로 name 파라미터에 대해 @NotBlank 등 검증을 적용하면 부적절한 요청을 미연에 방지할 수 있습니다.

🤖 Prompt for AI Agents
In src/main/java/com/example/gtable/store/controller/StoreController.java around
lines 91 to 100, the searchStores method currently returns Store entities
directly, causing inconsistency with other endpoints that use DTOs and risking
exposure of internal fields. Refactor the method to convert the Store entities
returned by storeService.searchStoresByName(name) into appropriate DTOs before
returning them in the response. Also, add validation annotation such as
@NotBlank to the 'name' request parameter to prevent invalid requests early.

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface StoreRepository extends JpaRepository<Store, Long> {
List<Store> findAllByDeletedFalse();

Optional<Store> findByStoreIdAndDeletedFalse(Long storeId);

List<Store> findByNameContainingIgnoreCaseAndDeletedFalse(String name);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.example.gtable.store.service;

import java.util.List;

import com.example.gtable.store.dto.StoreCreateRequest;
import com.example.gtable.store.dto.StoreCreateResponse;
import com.example.gtable.store.dto.StoreReadDto;
import com.example.gtable.store.dto.StoreReadResponse;
import com.example.gtable.store.dto.StoreUpdateRequest;
import com.example.gtable.store.model.Store;

public interface StoreService {

Expand All @@ -18,4 +21,6 @@ public interface StoreService {

String deleteStore(Long storeId);

List<StoreReadDto> searchStoresByName(String name);

}
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,11 @@ public String deleteStore(Long storeId) {

return "Store ID " + storeId + " 삭제되었습니다.";
}

@Override
public List<StoreReadDto> searchStoresByName(String name) {
List<Store> stores = storeRepository.findByNameContainingIgnoreCaseAndDeletedFalse(name);
return stores.stream().map(StoreReadDto::fromEntity).toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down