File tree Expand file tree Collapse file tree 3 files changed +15
-1
lines changed
src/main/kotlin/org/gitanimals/render Expand file tree Collapse file tree 3 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ class PersonaController(
2525
2626 @GetMapping(" /users/{username}" )
2727 fun getUserByName (@PathVariable(" username" ) username : String ): UserResponse {
28- return UserResponse .from(userService.getUserByName (username))
28+ return UserResponse .from(userService.getUserByNameWithAllContributions (username))
2929 }
3030
3131 @GetMapping(" /personas/{persona-id}" )
Original file line number Diff line number Diff line change 11package org.gitanimals.render.domain
22
33import org.springframework.data.jpa.repository.JpaRepository
4+ import org.springframework.data.jpa.repository.Query
5+ import org.springframework.data.repository.query.Param
46
57interface UserRepository : JpaRepository <User , Long > {
68
79 fun findByName (name : String ): User ?
810
11+ @Query(
12+ """
13+ select u from User as u
14+ left join fetch u.contributions
15+ where u.name = :name
16+ """
17+ )
18+ fun findByNameWithContributions (@Param(" name" ) name : String ): User ?
19+
920 fun existsByName (name : String ): Boolean
1021}
Original file line number Diff line number Diff line change @@ -48,6 +48,9 @@ class UserService(
4848 fun getUserByName (name : String ): User = userRepository.findByName(name)
4949 ? : throw IllegalArgumentException (" Cannot find exists user by name \" $name \" " )
5050
51+ fun getUserByNameWithAllContributions (name : String ): User = userRepository.findByName(name)
52+ ? : throw IllegalArgumentException (" Cannot find exists user by name \" $name \" " )
53+
5154 @Transactional
5255 fun createNewUser (name : String , contributions : Map <Int , Int >): User =
5356 userRepository.save(User .newUser(name, contributions))
You canโt perform that action at this time.
0 commit comments