Skip to content

Commit

Permalink
🛠️ Refactor UserService to avoid direct repository access across pack…
Browse files Browse the repository at this point in the history
…ages
  • Loading branch information
alpakar02 committed Jan 22, 2025
1 parent 48f582b commit 3a12f41
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,9 @@ class ProfileService(
fun getProfileEntityByUserId(userId: String): ProfileEntity {
return profileRepository.findByUserId(userId) ?: throw ProfileNotFoundException()
}

@Transactional
fun saveProfileEntity(profileEntity: ProfileEntity) {
profileRepository.save(profileEntity)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.toyProject7.karrot.user.service

import com.toyProject7.karrot.profile.persistence.ProfileEntity
import com.toyProject7.karrot.profile.persistence.ProfileRepository
import com.toyProject7.karrot.profile.service.ProfileService
import com.toyProject7.karrot.user.AuthenticateException
import com.toyProject7.karrot.user.SignInInvalidPasswordException
import com.toyProject7.karrot.user.SignInUserNotFoundException
Expand Down Expand Up @@ -29,8 +29,8 @@ import java.time.Instant
@Service
class UserService(
private val userRepository: UserRepository,
private val profileRepository: ProfileRepository,
private val normalUserRepository: NormalUserRepository,
private val profileService: ProfileService,
) {
@Transactional
fun signUp(
Expand Down Expand Up @@ -78,7 +78,7 @@ class UserService(
ProfileEntity(
user = user,
)
profileRepository.save(profileEntity)
profileService.saveProfileEntity(profileEntity)

return User.fromEntity(user)
}
Expand Down Expand Up @@ -135,8 +135,7 @@ class UserService(
ProfileEntity(
user = newUser,
)

profileRepository.save(profileEntity)
profileService.saveProfileEntity(profileEntity)

User.fromEntity(savedUser) // Convert and return as User DTO
}
Expand Down

0 comments on commit 3a12f41

Please sign in to comment.