-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: 슬롯 확장 수정, 유저별 텃밭 조회 기능 #135
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
The head ref may contain hidden characters: "131-\uC2AC\uB86F-\uD655\uC7A5-\uB85C\uC9C1-\uBC18\uC601"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package com.example.cp_main_be.domain.member.user.presentation; | ||
|
|
||
| import com.example.cp_main_be.domain.garden.garden.domain.Garden; | ||
| import com.example.cp_main_be.domain.member.user.domain.User; | ||
| import com.example.cp_main_be.domain.member.user.domain.repository.UserRepository; | ||
| import com.example.cp_main_be.domain.member.user.dto.request.AvatarChangeRequest; | ||
|
|
@@ -13,6 +14,9 @@ | |
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.Valid; | ||
| import jakarta.websocket.server.PathParam; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
|
|
@@ -80,6 +84,21 @@ public ResponseEntity<ApiResponse<UserRegisterResponse.LevelStatusResponseDTO>> | |
| return ResponseEntity.ok(ApiResponse.success(levelStatusResponseDTO)); | ||
| } | ||
|
|
||
| @Operation( | ||
| summary = "내 텃밭 ID 목록 조회", | ||
| description = "현재 로그인한 유저와 연결된 모든 텃밭의 ID 목록을 조회합니다. 텃밭 슬롯 번호 순으로 정렬됩니다.") | ||
| @GetMapping("/me/gardens") | ||
| public ResponseEntity<ApiResponse<List<Long>>> getMyGardenIds( | ||
| @AuthenticationPrincipal User user) { | ||
| List<Long> gardenIds = | ||
| user.getGardens().stream() | ||
| .sorted(Comparator.comparing(Garden::getSlotNumber)) | ||
| .map(Garden::getId) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| return ResponseEntity.ok(ApiResponse.success(gardenIds)); | ||
| } | ||
|
Comment on lines
+87
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chain컨트롤러에서 LAZY 컬렉션 접근 위험 및 N+1 가능성
권장 리포지토리/서비스 예시: // GardenRepository
@Query("select g.id from Garden g where g.user.id = :userId order by g.slotNumber asc")
List<Long> findIdsByUserIdOrderBySlot(Long userId);-List<Long> gardenIds =
- user.getGardens().stream()
- .sorted(Comparator.comparing(Garden::getSlotNumber))
- .map(Garden::getId)
- .collect(Collectors.toList());
+List<Long> gardenIds = gardenService.findMyGardenIds(user.getId());검증 스크립트(매핑 확인): 🏁 Script executed: #!/bin/bash
# User 엔티티에서 gardens 컬렉션 fetch 타입/매핑 확인
rg -n -C3 'class\s+User\b'
rg -n -C2 '@OneToMany[^\n]*gardens'Length of output: 750 이전 스크립트가 🏁 Script executed: #!/bin/bash
# User 엔티티에서 @OneToMany 어노테이션 위치와 속성 확인
rg -n -C3 '@OneToMany' src/main/java/com/example/cp_main_be/domain/member/user/domain/User.java
# User 엔티티에서 gardens 필드 선언부 확인
rg -n -C3 'gardens' src/main/java/com/example/cp_main_be/domain/member/user/domain/User.javaLength of output: 1488 컨트롤러에서 LAZY 컬렉션 직접 접근 위험 – 서비스 계층으로 조회 로직 이동 필요 현재
제안하는 리팩터링
이렇게 하면
🤖 Prompt for AI Agents |
||
|
|
||
| @Operation(summary = "유저 정보 조회", description = "유저 정보를 조회합니다") | ||
| @GetMapping("/{userId}") | ||
| public ResponseEntity<ApiResponse<UserProfileResponse>> getUserInfo( | ||
|
|
||
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.
🛠️ Refactor suggestion
슬롯 확장 동시성 취약 — 중복 슬롯/초과 생성 가능성
동시 요청에서
currentGardenCount기반 계산은 경쟁 조건을 유발합니다. 사용자별 슬롯 행 잠금 또는 고유 제약 + 비관적 잠금으로 방어하세요.DB/리포지토리/서비스 제안:
🤖 Prompt for AI Agents