Skip to content
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

refactor(user): desperate user service #42

Merged
merged 2 commits into from
Dec 17, 2024
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
@@ -0,0 +1,25 @@
package com.threedays.application.user.service

import com.threedays.application.user.port.inbound.UpdateDesiredPartner
import com.threedays.domain.user.entity.User
import com.threedays.domain.user.repository.UserRepository
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class UserDesiredPartnerService(
private val userRepository: UserRepository,
) : UpdateDesiredPartner {

@Transactional
override fun invoke(command: UpdateDesiredPartner.Command): User {
return userRepository
.get(command.userId)
.updateDesiredPartner(
birthYearRange = command.birthYearRange,
jobOccupations = command.jobOccupations,
preferDistance = command.preferDistance,
)
.also { userRepository.save(it) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.threedays.application.user.service

import com.threedays.application.auth.config.UserProperties
import com.threedays.application.user.port.inbound.GetUserProfileImageUploadUrl
import com.threedays.application.user.port.inbound.CompleteUserProfileImageUpload
import com.threedays.application.user.port.inbound.DeleteUserProfileImage
import com.threedays.application.user.port.outbound.UserProfileImagePort
import com.threedays.domain.user.repository.UserRepository
import org.springframework.stereotype.Service
import java.net.URL
import java.util.*

@Service
class UserProfileImageService(
private val userRepository: UserRepository,
private val userProfileImagePort: UserProfileImagePort,
private val userProperties: UserProperties,
) : GetUserProfileImageUploadUrl, CompleteUserProfileImageUpload, DeleteUserProfileImage {

override fun invoke(command: GetUserProfileImageUploadUrl.Command): GetUserProfileImageUploadUrl.Result {
val imageId: UUID = UUID.randomUUID()
val uploadUrl: URL = userProfileImagePort.getUploadUrl(
id = imageId,
extension = command.extension,
expiresIn = userProperties.profileImage.uploadExpiresIn,
maxContentLength = userProperties.profileImage.maxContentLength,
)

return GetUserProfileImageUploadUrl.Result(
imageId = imageId,
extension = command.extension,
url = uploadUrl,
uploadExpiresIn = userProperties.profileImage.uploadExpiresIn,
)
}

override fun invoke(command: CompleteUserProfileImageUpload.Command) {
userRepository
.get(command.userId)
.updateUserProfileImage(
id = command.imageId,
extension = command.extension,
getProfileImageUrlAction = userProfileImagePort::findImageUrlByIdAndExtension,
)
.let { userRepository.save(it) }
}

override fun invoke(command: DeleteUserProfileImage.Command) {
userRepository
.get(command.userId)
.deleteUserProfileImage(command.imageId, userProfileImagePort::deleteImageById)
.let { userRepository.save(it) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.threedays.application.user.service

import com.threedays.application.user.port.inbound.UpdateUserInfo
import com.threedays.application.user.port.inbound.PutProfileWidget
import com.threedays.application.user.port.inbound.DeleteProfileWidget
import com.threedays.domain.user.entity.User
import com.threedays.domain.user.repository.CompanyQueryRepository
import com.threedays.domain.user.repository.LocationQueryRepository
import com.threedays.domain.user.repository.UserRepository
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class UserProfileService(
private val userRepository: UserRepository,
private val locationQueryRepository: LocationQueryRepository,
private val companyQueryRepository: CompanyQueryRepository,
) : UpdateUserInfo, PutProfileWidget, DeleteProfileWidget {

@Transactional
override fun invoke(command: UpdateUserInfo.Command): User {
return userRepository
.get(command.userId)
.updateUserInfo(
name = command.name,
jobOccupation = command.jobOccupation,
locationIds = command.locationIds,
locationQueryRepository = locationQueryRepository,
companyId = command.companyId,
companyQueryRepository = companyQueryRepository,
allowSameCompany = command.allowSameCompany,
)
.also { userRepository.save(it) }
}

@Transactional
override fun invoke(command: PutProfileWidget.Command) {
userRepository
.get(command.userId)
.putProfileWidget(command.profileWidget)
.also { userRepository.save(it) }
}

@Transactional
override fun invoke(command: DeleteProfileWidget.Command) {
userRepository
.get(command.userId)
.deleteProfileWidget(command.type)
.also { userRepository.save(it) }
}

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
package com.threedays.application.user.service

import com.threedays.application.auth.config.AuthProperties
import com.threedays.application.auth.config.UserProperties
import com.threedays.application.auth.port.inbound.IssueLoginTokens
import com.threedays.application.user.port.inbound.CompleteUserProfileImageUpload
import com.threedays.application.user.port.inbound.DeleteProfileWidget
import com.threedays.application.user.port.inbound.DeleteUserProfileImage
import com.threedays.application.user.port.inbound.GetUserProfileImageUploadUrl
import com.threedays.application.user.port.inbound.PutProfileWidget
import com.threedays.application.user.port.inbound.RegisterUser
import com.threedays.application.user.port.inbound.UpdateDesiredPartner
import com.threedays.application.user.port.inbound.UpdateUserInfo
import com.threedays.application.user.port.outbound.UserProfileImagePort
import com.threedays.domain.user.entity.Company
import com.threedays.domain.user.entity.Location
import com.threedays.domain.user.entity.User
Expand All @@ -20,20 +11,15 @@ import com.threedays.domain.user.repository.LocationQueryRepository
import com.threedays.domain.user.repository.UserRepository
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.net.URL
import java.util.*

@Service
class UserService(
private val userRepository: UserRepository,
private val locationQueryRepository: LocationQueryRepository,
private val companyQueryRepository: CompanyQueryRepository,
private val issueLoginTokens: IssueLoginTokens,
private val userProfileImagePort: UserProfileImagePort,
private val authProperties: AuthProperties,
private val userProperties: UserProperties,
) : RegisterUser, PutProfileWidget, DeleteProfileWidget, UpdateUserInfo, UpdateDesiredPartner,
GetUserProfileImageUploadUrl, CompleteUserProfileImageUpload, DeleteUserProfileImage {
) : RegisterUser {

@Transactional
override fun invoke(command: RegisterUser.Command): RegisterUser.Result {
Expand Down Expand Up @@ -66,83 +52,4 @@ class UserService(
expiresIn = authProperties.accessTokenExpirationSeconds,
)
}

@Transactional
override fun invoke(command: PutProfileWidget.Command) {
userRepository
.get(command.userId)
.putProfileWidget(command.profileWidget)
.also { userRepository.save(it) }
}

@Transactional
override fun invoke(command: DeleteProfileWidget.Command) {
userRepository
.get(command.userId)
.deleteProfileWidget(command.type)
.also { userRepository.save(it) }
}

@Transactional
override fun invoke(command: UpdateUserInfo.Command): User {
return userRepository
.get(command.userId)
.updateUserInfo(
name = command.name,
jobOccupation = command.jobOccupation,
locationIds = command.locationIds,
locationQueryRepository = locationQueryRepository,
companyId = command.companyId,
companyQueryRepository = companyQueryRepository,
allowSameCompany = command.allowSameCompany,
)
.also { userRepository.save(it) }
}

override fun invoke(command: UpdateDesiredPartner.Command): User {
return userRepository
.get(command.userId)
.updateDesiredPartner(
birthYearRange = command.birthYearRange,
jobOccupations = command.jobOccupations,
preferDistance = command.preferDistance,
)
.also { userRepository.save(it) }
}

override fun invoke(command: GetUserProfileImageUploadUrl.Command): GetUserProfileImageUploadUrl.Result {
val imageId: UUID = UUID.randomUUID()
val uploadUrl: URL = userProfileImagePort.getUploadUrl(
id = imageId,
extension = command.extension,
expiresIn = userProperties.profileImage.uploadExpiresIn,
maxContentLength = userProperties.profileImage.maxContentLength,
)

return GetUserProfileImageUploadUrl.Result(
imageId = imageId,
extension = command.extension,
url = uploadUrl,
uploadExpiresIn = userProperties.profileImage.uploadExpiresIn,
)
}

override fun invoke(command: CompleteUserProfileImageUpload.Command) {
userRepository
.get(command.userId)
.updateUserProfileImage(
id = command.imageId,
extension = command.extension,
getProfileImageUrlAction = userProfileImagePort::findImageUrlByIdAndExtension,
)
.let { userRepository.save(it) }
}

override fun invoke(command: DeleteUserProfileImage.Command) {
userRepository
.get(command.userId)
.deleteUserProfileImage(command.imageId, userProfileImagePort::deleteImageById)
.let { userRepository.save(it) }
}

}
Loading