Skip to content

Commit 69c8f89

Browse files
authored
Merge pull request #62 from DIDIM-ai/fix/#61-userjr-nplus1
Fix/#61 userjr nplus1
2 parents e61eea3 + 38e0434 commit 69c8f89

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/main/java/com/likelion/ai_teacher_a/domain/userJr/repository/UserJrRepository.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.springframework.data.repository.query.Param;
88

99
import java.util.List;
10+
import java.util.Optional;
1011

1112
public interface UserJrRepository extends JpaRepository<UserJr, Long> {
1213

@@ -21,4 +22,13 @@ public interface UserJrRepository extends JpaRepository<UserJr, Long> {
2122
boolean existsByUserIdAndNickname(Long userId, String nickname);
2223

2324
void deleteAllByUser(User user);
25+
26+
@Query("""
27+
SELECT uj FROM UserJr uj
28+
LEFT JOIN FETCH uj.user
29+
LEFT JOIN FETCH uj.image
30+
WHERE uj.userJrId = :userJrId
31+
""")
32+
Optional<UserJr> findByIdWithUserAndImage(@Param("userJrId") Long userJrId);
33+
2434
}

src/main/java/com/likelion/ai_teacher_a/domain/userJr/service/UserJrService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ public List<UserJrResponseDto> findByParent(Long userId) {
8282
}
8383

8484
public UserJrResponseDto findById(Long userJrId, Long userId) {
85-
UserJr userJr = userJrRepository.findById(userJrId)
85+
UserJr userJr = userJrRepository.findByIdWithUserAndImage(userJrId)
8686
.filter(jr -> jr.getUser().getId().equals(userId))
8787
.orElseThrow(() -> new RuntimeException("자녀 정보를 찾을 수 없거나 권한이 없습니다."));
88+
8889
return UserJrResponseDto.from(userJr);
8990
}
9091

@@ -117,7 +118,6 @@ public void delete(Long userJrId, Long userId) {
117118
}
118119

119120

120-
121121
private boolean isValidGrade(int grade) {
122122
return grade >= 1 && grade <= 6;
123123
}

0 commit comments

Comments
 (0)